PageRenderTime 28ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/servers/jain-slee/resources/jcc/jcc-camel-provider/java/src/main/java/org/mobicents/jcc/inap/OriginatingConnection.java

http://mobicents.googlecode.com/
Java | 406 lines | 236 code | 62 blank | 108 comment | 11 complexity | 4e91b3e3caff01fb54cda875513d5084 MD5 | raw file
Possible License(s): LGPL-3.0, GPL-3.0, LGPL-2.1, GPL-2.0, CC-BY-SA-3.0, CC0-1.0, Apache-2.0, BSD-3-Clause
  1. /*
  2. * JBoss, Home of Professional Open Source
  3. * Copyright 2011, Red Hat, Inc. and individual contributors
  4. * by the @authors tag. See the copyright.txt in the distribution for a
  5. * full listing of individual contributors.
  6. *
  7. * This is free software; you can redistribute it and/or modify it
  8. * under the terms of the GNU Lesser General Public License as
  9. * published by the Free Software Foundation; either version 2.1 of
  10. * the License, or (at your option) any later version.
  11. *
  12. * This software is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public
  18. * License along with this software; if not, write to the Free
  19. * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  20. * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
  21. */
  22. /*
  23. * The Java Call Control API for CAMEL 2
  24. *
  25. * The source code contained in this file is in in the public domain.
  26. * It can be used in any project or product without prior permission,
  27. * license or royalty payments. There is NO WARRANTY OF ANY KIND,
  28. * EXPRESS, IMPLIED OR STATUTORY, INCLUDING, WITHOUT LIMITATION,
  29. * THE IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE,
  30. * AND DATA ACCURACY. We do not warrant or make any representations
  31. * regarding the use of the software or the results thereof, including
  32. * but not limited to the correctness, accuracy, reliability or
  33. * usefulness of the software.
  34. */
  35. package org.mobicents.jcc.inap;
  36. import java.io.IOException;
  37. import javax.csapi.cc.jcc.InvalidArgumentException;
  38. import javax.csapi.cc.jcc.InvalidPartyException;
  39. import javax.csapi.cc.jcc.InvalidStateException;
  40. import javax.csapi.cc.jcc.JccAddress;
  41. import javax.csapi.cc.jcc.JccConnectionEvent;
  42. import javax.csapi.cc.jcc.JccEvent;
  43. import javax.csapi.cc.jcc.MethodNotSupportedException;
  44. import javax.csapi.cc.jcc.MidCallData;
  45. import javax.csapi.cc.jcc.PrivilegeViolationException;
  46. import javax.csapi.cc.jcc.ResourceUnavailableException;
  47. import org.mobicents.jcc.inap.address.JccCalledPartyBCDNumber;
  48. import org.mobicents.jcc.inap.address.JccCallingPartyNumber;
  49. import org.mobicents.jcc.inap.protocol.ApplyCharging;
  50. import org.mobicents.jcc.inap.protocol.CallInformationRequest;
  51. import org.mobicents.jcc.inap.protocol.Connect;
  52. import org.mobicents.jcc.inap.protocol.Continue;
  53. import org.mobicents.jcc.inap.protocol.Operation;
  54. import org.mobicents.jcc.inap.protocol.RequestBCSMState;
  55. import org.mobicents.jcc.inap.protocol.parms.BCSMEvent;
  56. import org.mobicents.jcc.inap.protocol.parms.CalledPartyNumber;
  57. import org.mobicents.jcc.inap.protocol.parms.LegID;
  58. import org.mobicents.jcc.inap.protocol.parms.RequestedInformationType;
  59. import org.mobicents.jcc.inap.protocol.parms.RequestedInformationTypeList;
  60. import org.apache.log4j.Logger;
  61. import org.mobicents.protocols.ss7.sccp.parameter.SccpAddress;
  62. import org.mobicents.protocols.ss7.tcap.api.TCAPProvider;
  63. import org.mobicents.protocols.ss7.tcap.api.tc.dialog.Dialog;
  64. import org.mobicents.protocols.ss7.tcap.api.tc.dialog.events.TCContinueRequest;
  65. import org.mobicents.protocols.ss7.tcap.asn.comp.Invoke;
  66. import org.mobicents.protocols.ss7.tcap.asn.comp.OperationCode;
  67. import org.mobicents.protocols.ss7.tcap.asn.comp.Parameter;
  68. /**
  69. *
  70. * @author Oleg Kulikov
  71. */
  72. public class OriginatingConnection extends AbstractConnection {
  73. private JccCalledPartyBCDNumber destinationAddress;
  74. private String lastAddress;
  75. private String originalAddress;
  76. private String redirectedAddress;
  77. private static final Logger logger = Logger.getLogger(OriginatingConnection.class);
  78. /** Creates a new instance of OriginatingConnection */
  79. public OriginatingConnection(ConnectionID connectionID, JccCallImpl call, JccAddress address,TCAPProvider tcapProvider,Dialog tcapDialog) {
  80. super(connectionID, call, address, tcapProvider, tcapDialog);
  81. }
  82. /**
  83. * (Non Java-doc).
  84. * @see javax.csapi.cc.jcc.JccConnection#selectRoute().
  85. */
  86. public void selectRoute(String digits) throws MethodNotSupportedException, InvalidStateException, ResourceUnavailableException, PrivilegeViolationException, InvalidPartyException {
  87. //we assume that format of the digits may be as follows:
  88. //destination#genericNumber which can be used to represent callerID
  89. String tokens[] = digits.split("#");
  90. destinationAddress.setName(tokens[0]);
  91. if (tokens.length > 1) {
  92. ((JccCallingPartyNumber) address).setCallerID(tokens[1]);
  93. }
  94. if (isBlocked()) {
  95. resume();
  96. }
  97. }
  98. /**
  99. * (Non Java-doc).
  100. * @see javax.csapi.cc.jcc.JccConnection#answer().
  101. */
  102. public void answer() throws PrivilegeViolationException, ResourceUnavailableException, InvalidStateException, MethodNotSupportedException {
  103. throw new MethodNotSupportedException();
  104. }
  105. /**
  106. * (Non Java-doc).
  107. * @see javax.csapi.cc.jcc.JccConnection#attachMedia().
  108. */
  109. public void attachMedia() throws PrivilegeViolationException, ResourceUnavailableException, InvalidStateException {
  110. }
  111. /**
  112. * (Non Java-doc).
  113. * @see javax.csapi.cc.jcc.JccConnection#detachMedia().
  114. */
  115. public void detachMedia() throws PrivilegeViolationException, ResourceUnavailableException, InvalidStateException {
  116. }
  117. /**
  118. * (Non Java-doc).
  119. * @see javax.csapi.cc.jcc.JccConnection#getLastAddress().
  120. */
  121. public String getLastAddress() {
  122. return null;
  123. }
  124. /**
  125. * (Non Java-doc).
  126. * @see javax.csapi.cc.jcc.JccConnection#getOriginalAddress().
  127. */
  128. public String getOriginalAddress() {
  129. return null;
  130. }
  131. /**
  132. * (Non Java-doc).
  133. * @see javax.csapi.cc.jcc.JccConnection#getDestinationAddress().
  134. */
  135. public String getDestinationAddress() {
  136. return destinationAddress == null ? null : destinationAddress.getName();
  137. }
  138. /**
  139. * (Non Java-doc).
  140. * @see javax.csapi.cc.jcc.JccConnection#getOriginatingAddress().
  141. */
  142. public JccAddress getOriginatingAddress() {
  143. return address;
  144. }
  145. /**
  146. * (Non Java-doc).
  147. * @see javax.csapi.cc.jcc.JccConnection#getRedirectingAddress().
  148. */
  149. public String getRedirectedAddress() {
  150. return null;
  151. }
  152. /**
  153. * (Non Java-doc).
  154. * @see javax.csapi.cc.jcc.JccConnection#routeConnection().
  155. */
  156. public void routeConnection(boolean b) throws InvalidStateException, ResourceUnavailableException, PrivilegeViolationException, MethodNotSupportedException, InvalidPartyException, InvalidArgumentException {
  157. }
  158. /**
  159. * (Non Java-doc).
  160. * @see javax.csapi.cc.jcc.JccConnection#getMidCallData().
  161. */
  162. public MidCallData getMidCallData() throws InvalidStateException, ResourceUnavailableException, MethodNotSupportedException {
  163. return null;
  164. }
  165. public void onAuthorizeCallAttempt() {
  166. //should never happen
  167. }
  168. public void onAddressCollect() {
  169. }
  170. public void onAddressAnalyze(JccConnectionEventImpl evt) {
  171. logger.info(this + "ADDRESS_ANALYZE, " + getCauseName(cause));
  172. if (logger.isDebugEnabled()) {
  173. logger.debug(this + "onAddressAnalyze(): reset timeout timer");
  174. }
  175. timer.reset(ADDRESS_ANALYZE_TIMEOUT);
  176. destinationAddress = evt.destAddress;
  177. JccEvent event = new JccConnectionEventImpl(
  178. JccConnectionEvent.CONNECTION_CALL_DELIVERY,
  179. this,
  180. JccConnectionEvent.CAUSE_NORMAL);
  181. queueEvent(event);
  182. }
  183. public void onCallDelivery() {
  184. logger.info(this + "CALL_DELIVERY, " + getCauseName(cause));
  185. if (logger.isDebugEnabled()) {
  186. logger.debug(this + "onCallDelivery(): reset timeout timer");
  187. }
  188. timer.reset(CALL_DELIVERY_TIMEOUT);
  189. if (logger.isDebugEnabled()) {
  190. logger.debug(this + "onCallDelivery(): sending signaling message to MSC");
  191. }
  192. CalledPartyNumber routeNumber = destinationAddress.getRouteNumber();
  193. if (logger.isDebugEnabled()) {
  194. logger.debug(this + "connecting to " + routeNumber);
  195. }
  196. Connect connect = new Connect(routeNumber);
  197. //assign callerID
  198. JccCallingPartyNumber cpn = (JccCallingPartyNumber) getAddress();
  199. if (cpn.getGenericNumber() != null) {
  200. connect.setGenericNumber(cpn.getGenericNumber());
  201. }
  202. RequestBCSMState bcsm = new RequestBCSMState();
  203. bcsm.add(new BCSMEvent(BCSMEvent.O_ANSWER));
  204. bcsm.add(new BCSMEvent(BCSMEvent.O_NO_ANSWER));
  205. bcsm.add(new BCSMEvent(BCSMEvent.O_CALLED_PARTY_BUSY));
  206. bcsm.add(new BCSMEvent(BCSMEvent.O_ABANDON));
  207. //Aply charging
  208. ApplyCharging applyCharging = new ApplyCharging(
  209. LegID.SENDING_SIDE_ID,
  210. LegID.FIRST_LEG);
  211. RequestedInformationTypeList list = new RequestedInformationTypeList();
  212. list.add(RequestedInformationType.CALL_STOP_TIME);
  213. list.add(RequestedInformationType.CALL_CONNECTED_ELAPSED_TIME);
  214. list.add(RequestedInformationType.RELEASE_CAUSE);
  215. LegID legID = new LegID(LegID.SENDING_SIDE_ID, LegID.SECOND_LEG);
  216. CallInformationRequest cir = new CallInformationRequest(list, legID);
  217. Continue cont = new Continue();
  218. try {
  219. Invoke invoke = super.tcapProvider.getComponentPrimitiveFactory().createTCInvokeRequest();
  220. invoke.setInvokeId(super.tcapDialog.getNewInvokeId());
  221. //components.add(new Invoke(1, applyCharging));
  222. OperationCode oc = super.tcapProvider.getComponentPrimitiveFactory().createOperationCode( );
  223. oc.setLocalOperationCode(new Long(Operation.APPLY_CHARGING));
  224. invoke.setOperationCode(oc);
  225. //now set apply charging.
  226. Parameter parameter = super.tcapProvider.getComponentPrimitiveFactory().createParameter();
  227. parameter.setPrimitive(ApplyCharging._IS_PRIMITIVE);
  228. parameter.setTag(ApplyCharging._TAG);
  229. parameter.setTagClass(ApplyCharging._TAG_CLASS);
  230. parameter.setData(applyCharging.toByteArray());
  231. invoke.setParameter(parameter);
  232. tcapDialog.sendComponent(invoke);
  233. //components.add(new Invoke(2, bcsm));
  234. invoke = super.tcapProvider.getComponentPrimitiveFactory().createTCInvokeRequest();
  235. invoke.setInvokeId(super.tcapDialog.getNewInvokeId());
  236. oc = super.tcapProvider.getComponentPrimitiveFactory().createOperationCode();
  237. oc.setLocalOperationCode(new Long(Operation.REQUEST_REPORT_BCSM_EVENT));
  238. invoke.setOperationCode(oc);
  239. parameter = super.tcapProvider.getComponentPrimitiveFactory().createParameter();
  240. parameter.setPrimitive(RequestBCSMState._IS_PRIMITIVE);
  241. parameter.setTag(RequestBCSMState._TAG);
  242. parameter.setTagClass(RequestBCSMState._TAG_CLASS);
  243. parameter.setData(bcsm.toByteArray());
  244. invoke.setParameter(parameter);
  245. tcapDialog.sendComponent(invoke);
  246. //components.add(new Invoke(3, cir));
  247. invoke = super.tcapProvider.getComponentPrimitiveFactory().createTCInvokeRequest();
  248. invoke.setInvokeId(super.tcapDialog.getNewInvokeId());
  249. oc = super.tcapProvider.getComponentPrimitiveFactory().createOperationCode();
  250. oc.setLocalOperationCode( new Long(Operation.CALL_INFORMATION_REQUEST));
  251. invoke.setOperationCode(oc);
  252. parameter = super.tcapProvider.getComponentPrimitiveFactory().createParameter();
  253. parameter.setPrimitive(CallInformationRequest._IS_PRIMITIVE);
  254. parameter.setTag(CallInformationRequest._TAG);
  255. parameter.setTagClass(CallInformationRequest._TAG_CLASS);
  256. parameter.setData(cir.toByteArray());
  257. invoke.setParameter(parameter);
  258. tcapDialog.sendComponent(invoke);
  259. //components.add(new Invoke(4, connect));
  260. invoke = super.tcapProvider.getComponentPrimitiveFactory().createTCInvokeRequest();
  261. invoke.setInvokeId(super.tcapDialog.getNewInvokeId());
  262. oc = super.tcapProvider.getComponentPrimitiveFactory().createOperationCode();
  263. oc.setLocalOperationCode( new Long(Operation.CONNECT));
  264. invoke.setOperationCode(oc);
  265. parameter = super.tcapProvider.getComponentPrimitiveFactory().createParameter();
  266. parameter.setPrimitive(Connect._IS_PRIMITIVE);
  267. parameter.setTag(Connect._TAG);
  268. parameter.setTagClass( Connect._TAG_CLASS);
  269. parameter.setData(connect.toByteArray());
  270. invoke.setParameter(parameter);
  271. tcapDialog.sendComponent(invoke);
  272. //components.add(new Invoke(5, cont));
  273. TCContinueRequest continueRequest = this.tcapProvider.getDialogPrimitiveFactory().createContinue(this.tcapDialog);
  274. //add this, so dialog can create APDU with answer
  275. continueRequest.setApplicationContextName(super.tcapDialog.getApplicationContextName());
  276. continueRequest.setUserInformation(super.tcapDialog.getUserInformation());
  277. this.tcapDialog.send(continueRequest);
  278. //switch called and calling party addresses
  279. // SccpAddress calledPartyAddress = connectionID.getCallingPartyAddress();
  280. // SccpAddress callingPartyAddress = connectionID.getCalledPartyAddress();
  281. // call.provider.send(calledPartyAddress, callingPartyAddress, message);
  282. } catch (Exception e) {
  283. logger.error("I/O Error", e);
  284. JccEvent evt = new JccConnectionEventImpl(
  285. JccConnectionEvent.CONNECTION_FAILED,
  286. this,
  287. JccEvent.CAUSE_GENERAL_FAILURE);
  288. queueEvent(evt);
  289. }
  290. }
  291. public void onAlerting() {
  292. //never happen
  293. }
  294. public void onConnected() {
  295. logger.info(this + "CONNECTED, " + getCauseName(cause));
  296. if (logger.isDebugEnabled()) {
  297. logger.debug(this + "onConnected(): reset timeout timer");
  298. }
  299. try {
  300. timer.reset(CONNECTED_TIMEOUT);
  301. if (logger.isDebugEnabled()) {
  302. logger.debug(this + "onConnected(): sending signaling message to MSC");
  303. }
  304. RequestBCSMState bcsm = new RequestBCSMState();
  305. bcsm.add(new BCSMEvent(BCSMEvent.O_DISCONNECT, new LegID(LegID.SENDING_SIDE_ID, LegID.FIRST_LEG)));
  306. bcsm.add(new BCSMEvent(BCSMEvent.O_DISCONNECT, new LegID(LegID.SENDING_SIDE_ID, LegID.SECOND_LEG)));
  307. Continue cont = new Continue();
  308. //Components components = new Components();
  309. //components.add(new Invoke(1, bcsm));
  310. Invoke invoke = super.tcapProvider.getComponentPrimitiveFactory().createTCInvokeRequest();
  311. invoke.setInvokeId(super.tcapDialog.getNewInvokeId());
  312. OperationCode oc = super.tcapProvider.getComponentPrimitiveFactory().createOperationCode();
  313. oc.setLocalOperationCode(new Long(Operation.REQUEST_REPORT_BCSM_EVENT));
  314. invoke.setOperationCode(oc);
  315. Parameter parameter = super.tcapProvider.getComponentPrimitiveFactory().createParameter();
  316. parameter.setPrimitive(RequestBCSMState._IS_PRIMITIVE);
  317. parameter.setTag(RequestBCSMState._TAG);
  318. parameter.setTagClass(RequestBCSMState._TAG_CLASS);
  319. parameter.setData(bcsm.toByteArray());
  320. tcapDialog.sendComponent(invoke);
  321. //components.add(new Invoke(2, cont));
  322. //continue does not have parameter
  323. invoke = super.tcapProvider.getComponentPrimitiveFactory().createTCInvokeRequest();
  324. invoke.setInvokeId(super.tcapDialog.getNewInvokeId());
  325. oc = super.tcapProvider.getComponentPrimitiveFactory().createOperationCode();
  326. oc.setLocalOperationCode( new Long(Operation.CONTINUE));
  327. invoke.setOperationCode(oc);
  328. tcapDialog.sendComponent(invoke);
  329. TCContinueRequest message = this.tcapProvider.getDialogPrimitiveFactory().createContinue(this.tcapDialog);
  330. this.tcapDialog.send(message);
  331. //switch called and calling party addresses
  332. // SccpAddress calledPartyAddress = connectionID.getCallingPartyAddress();
  333. //SccpAddress callingPartyAddress = connectionID.getCalledPartyAddress();
  334. //call.provider.send(calledPartyAddress, callingPartyAddress, message);
  335. } catch (Exception e) {
  336. logger.error("I/O Error", e);
  337. JccEvent evt = new JccConnectionEventImpl(
  338. JccConnectionEvent.CONNECTION_FAILED,
  339. this,
  340. JccEvent.CAUSE_GENERAL_FAILURE);
  341. queueEvent(evt);
  342. }
  343. }
  344. }