PageRenderTime 69ms CodeModel.GetById 21ms RepoModel.GetById 2ms app.codeStats 0ms

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

http://mobicents.googlecode.com/
Java | 353 lines | 242 code | 53 blank | 58 comment | 9 complexity | 2e91da7c303be25379179eb794f7d1aa 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.apache.log4j.Logger;
  48. import org.mobicents.jcc.inap.address.JccCalledPartyNumber;
  49. import org.mobicents.jcc.inap.address.JccCallingPartyNumber;
  50. import org.mobicents.jcc.inap.protocol.ApplyCharging;
  51. import org.mobicents.jcc.inap.protocol.CallInformationRequest;
  52. import org.mobicents.jcc.inap.protocol.Connect;
  53. import org.mobicents.jcc.inap.protocol.Continue;
  54. import org.mobicents.jcc.inap.protocol.Operation;
  55. import org.mobicents.jcc.inap.protocol.RequestBCSMState;
  56. import org.mobicents.jcc.inap.protocol.parms.BCSMEvent;
  57. import org.mobicents.jcc.inap.protocol.parms.CalledPartyNumber;
  58. import org.mobicents.jcc.inap.protocol.parms.LegID;
  59. import org.mobicents.jcc.inap.protocol.parms.RequestedInformationType;
  60. import org.mobicents.jcc.inap.protocol.parms.RequestedInformationTypeList;
  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 TerminatingConnection extends AbstractConnection {
  73. private JccCalledPartyNumber destinationAddress;
  74. private String lastAddress;
  75. private String originalAddress;
  76. private String redirectedAddress;
  77. private JccAddress originatingAddress;
  78. private final static Logger logger = Logger.getLogger(TerminatingConnection.class);
  79. /** Creates a new instance of TerminatingConnection */
  80. public TerminatingConnection(ConnectionID connectionID, JccCallImpl call, JccAddress address, JccAddress originatingAddress,TCAPProvider tcapProvider,Dialog tcapDialog) {
  81. super(connectionID, call, address, tcapProvider, tcapDialog);
  82. this.originatingAddress = originatingAddress;
  83. JccCalledPartyNumber cpn = (JccCalledPartyNumber) address;
  84. this.destinationAddress = new JccCalledPartyNumber(
  85. (JccInapProviderImpl) cpn.getProvider(),
  86. cpn.getRouteAddress());
  87. }
  88. public void onAuthorizeCallAttempt() {
  89. logger.info(this + "AUTHORIZE_CALL_ATTEMPT, " + getCauseName(cause));
  90. timer.reset(AUTH_TIMEOUT);
  91. JccEvent evt = new JccConnectionEventImpl(JccConnectionEvent.CONNECTION_CALL_DELIVERY, this, cause);
  92. queueEvent(evt);
  93. }
  94. public void onAddressCollect() {
  95. //never happened for terminating connection
  96. }
  97. public void onAddressAnalyze(JccConnectionEventImpl evt) {
  98. //never happened for termminated connection
  99. }
  100. public void onCallDelivery() {
  101. logger.info(this + "CALL_DELIVERY, " + getCauseName(cause));
  102. if (logger.isDebugEnabled()) {
  103. logger.debug(this + "onCallDelivery(): reset timeout timer");
  104. }
  105. timer.reset(CALL_DELIVERY_TIMEOUT);
  106. if (logger.isDebugEnabled()) {
  107. logger.debug(this + "onCallDelivery(): sending signaling message to MSC");
  108. }
  109. CalledPartyNumber routeNumber = destinationAddress.getRouteAddress();
  110. if (logger.isDebugEnabled()) {
  111. logger.debug(this + "connecting to " + routeNumber);
  112. }
  113. Connect connect = new Connect(routeNumber);
  114. JccCallingPartyNumber cpn = (JccCallingPartyNumber) originatingAddress;
  115. if (cpn.getGenericNumber() != null) {
  116. connect.setGenericNumber(cpn.getGenericNumber());
  117. }
  118. RequestBCSMState bcsm = new RequestBCSMState();
  119. bcsm.add(new BCSMEvent(BCSMEvent.T_ANSWER));
  120. bcsm.add(new BCSMEvent(BCSMEvent.T_NO_ANSWER));
  121. bcsm.add(new BCSMEvent(BCSMEvent.T_BUSY));
  122. bcsm.add(new BCSMEvent(BCSMEvent.T_ABANDON));
  123. //Aply charging
  124. ApplyCharging applyCharging = new ApplyCharging(
  125. LegID.SENDING_SIDE_ID,
  126. LegID.FIRST_LEG);
  127. RequestedInformationTypeList list = new RequestedInformationTypeList();
  128. list.add(RequestedInformationType.CALL_STOP_TIME);
  129. list.add(RequestedInformationType.CALL_CONNECTED_ELAPSED_TIME);
  130. list.add(RequestedInformationType.RELEASE_CAUSE);
  131. LegID legID = new LegID(LegID.SENDING_SIDE_ID, LegID.SECOND_LEG);
  132. CallInformationRequest cir = new CallInformationRequest(list, legID);
  133. Continue cont = new Continue();
  134. try{
  135. Invoke invoke = super.tcapProvider.getComponentPrimitiveFactory().createTCInvokeRequest();
  136. invoke.setInvokeId(super.tcapDialog.getNewInvokeId());
  137. //components.add(new Invoke(1, applyCharging));
  138. OperationCode oc = super.tcapProvider.getComponentPrimitiveFactory().createOperationCode();
  139. oc.setLocalOperationCode( new Long(Operation.APPLY_CHARGING));
  140. invoke.setOperationCode(oc);
  141. //now set apply charging.
  142. Parameter parameter = super.tcapProvider.getComponentPrimitiveFactory().createParameter();
  143. parameter.setPrimitive(ApplyCharging._IS_PRIMITIVE);
  144. parameter.setTag(ApplyCharging._TAG);
  145. parameter.setTagClass(ApplyCharging._TAG_CLASS);
  146. parameter.setData(applyCharging.toByteArray());
  147. invoke.setParameter(parameter);
  148. tcapDialog.sendComponent(invoke);
  149. //components.add(new Invoke(2, bcsm));
  150. invoke = super.tcapProvider.getComponentPrimitiveFactory().createTCInvokeRequest();
  151. invoke.setInvokeId(super.tcapDialog.getNewInvokeId());
  152. oc = super.tcapProvider.getComponentPrimitiveFactory().createOperationCode( );
  153. oc.setLocalOperationCode(new Long(Operation.REQUEST_REPORT_BCSM_EVENT));
  154. invoke.setOperationCode(oc);
  155. parameter = super.tcapProvider.getComponentPrimitiveFactory().createParameter();
  156. parameter.setPrimitive(RequestBCSMState._IS_PRIMITIVE);
  157. parameter.setTag(RequestBCSMState._TAG);
  158. parameter.setTagClass(RequestBCSMState._TAG_CLASS);
  159. parameter.setData(bcsm.toByteArray());
  160. invoke.setParameter(parameter);
  161. tcapDialog.sendComponent(invoke);
  162. //components.add(new Invoke(3, cir));
  163. invoke = super.tcapProvider.getComponentPrimitiveFactory().createTCInvokeRequest();
  164. invoke.setInvokeId(super.tcapDialog.getNewInvokeId());
  165. oc = super.tcapProvider.getComponentPrimitiveFactory().createOperationCode( );
  166. oc.setLocalOperationCode(new Long(Operation.CALL_INFORMATION_REQUEST));
  167. invoke.setOperationCode(oc);
  168. parameter = super.tcapProvider.getComponentPrimitiveFactory().createParameter();
  169. parameter.setPrimitive(CallInformationRequest._IS_PRIMITIVE);
  170. parameter.setTag(CallInformationRequest._TAG);
  171. parameter.setTagClass(CallInformationRequest._TAG_CLASS);
  172. parameter.setData(cir.toByteArray());
  173. invoke.setParameter(parameter);
  174. tcapDialog.sendComponent(invoke);
  175. //components.add(new Invoke(4, connect));
  176. invoke = super.tcapProvider.getComponentPrimitiveFactory().createTCInvokeRequest();
  177. invoke.setInvokeId(super.tcapDialog.getNewInvokeId());
  178. oc = super.tcapProvider.getComponentPrimitiveFactory().createOperationCode();
  179. oc.setLocalOperationCode( new Long(Operation.CONNECT));
  180. invoke.setOperationCode(oc);
  181. parameter = super.tcapProvider.getComponentPrimitiveFactory().createParameter();
  182. parameter.setPrimitive(Connect._IS_PRIMITIVE);
  183. parameter.setTag(Connect._TAG);
  184. parameter.setTagClass( Connect._TAG_CLASS);
  185. parameter.setData(connect.toByteArray());
  186. invoke.setParameter(parameter);
  187. tcapDialog.sendComponent(invoke);
  188. //components.add(new Invoke(5, cont));
  189. TCContinueRequest continueRequest = this.tcapProvider.getDialogPrimitiveFactory().createContinue(this.tcapDialog);
  190. //add this, so dialog can create APDU with answer
  191. continueRequest.setApplicationContextName(super.tcapDialog.getApplicationContextName());
  192. continueRequest.setUserInformation(super.tcapDialog.getUserInformation());
  193. this.tcapDialog.send(continueRequest);
  194. //switch called and calling party addresses
  195. // SccpAddress calledPartyAddress = connectionID.getCallingPartyAddress();
  196. // SccpAddress callingPartyAddress = connectionID.getCalledPartyAddress();
  197. JccEvent evt = new JccConnectionEventImpl(
  198. JccConnectionEvent.CONNECTION_ALERTING,
  199. this,
  200. JccConnectionEvent.CAUSE_NORMAL);
  201. this.queueEvent(evt);
  202. } catch (Exception e) {
  203. logger.error("I/O Error", e);
  204. JccEvent evt = new JccConnectionEventImpl(
  205. JccConnectionEvent.CONNECTION_FAILED,
  206. this,
  207. JccEvent.CAUSE_GENERAL_FAILURE);
  208. queueEvent(evt);
  209. }
  210. }
  211. public void onAlerting() {
  212. logger.info(this + "ALERTING");
  213. timer.reset(ALERTING_TIMEOUT);
  214. }
  215. public void onConnected() {
  216. logger.info(this + "CONNECTED, " + getCauseName(cause));
  217. if (logger.isDebugEnabled()) {
  218. logger.debug(this + "onConnected(): reset timeout timer");
  219. }
  220. timer.reset(CONNECTED_TIMEOUT);
  221. if (logger.isDebugEnabled()) {
  222. logger.debug(this + "onConnected(): sending signaling message to MSC");
  223. }
  224. RequestBCSMState bcsm = new RequestBCSMState();
  225. bcsm.add(new BCSMEvent(BCSMEvent.T_DISCONNECT, new LegID(LegID.SENDING_SIDE_ID, LegID.FIRST_LEG)));
  226. bcsm.add(new BCSMEvent(BCSMEvent.T_DISCONNECT, new LegID(LegID.SENDING_SIDE_ID, LegID.SECOND_LEG)));
  227. try{
  228. Continue cont = new Continue();
  229. //Components components = new Components();
  230. //components.add(new Invoke(1, bcsm));
  231. org.mobicents.protocols.ss7.tcap.asn.comp.Invoke invoke = super.tcapProvider.getComponentPrimitiveFactory().createTCInvokeRequest();
  232. invoke.setInvokeId(super.tcapDialog.getNewInvokeId());
  233. OperationCode oc = super.tcapProvider.getComponentPrimitiveFactory().createOperationCode();
  234. oc.setLocalOperationCode(new Long(Operation.REQUEST_REPORT_BCSM_EVENT));
  235. invoke.setOperationCode(oc);
  236. Parameter parameter = super.tcapProvider.getComponentPrimitiveFactory().createParameter();
  237. parameter.setPrimitive(RequestBCSMState._IS_PRIMITIVE);
  238. parameter.setTag(RequestBCSMState._TAG);
  239. parameter.setTagClass(RequestBCSMState._TAG_CLASS);
  240. parameter.setData(bcsm.toByteArray());
  241. invoke.setParameter(parameter);
  242. tcapDialog.sendComponent(invoke);
  243. //components.add(new Invoke(2, cont));
  244. //continue does not have parameter
  245. invoke = super.tcapProvider.getComponentPrimitiveFactory().createTCInvokeRequest();
  246. invoke.setInvokeId(super.tcapDialog.getNewInvokeId());
  247. oc = super.tcapProvider.getComponentPrimitiveFactory().createOperationCode();
  248. oc.setLocalOperationCode( new Long(Operation.CONTINUE));
  249. invoke.setOperationCode(oc);
  250. tcapDialog.sendComponent(invoke);
  251. TCContinueRequest message = this.tcapProvider.getDialogPrimitiveFactory().createContinue(this.tcapDialog);
  252. this.tcapDialog.send(message);
  253. } catch (Exception e) {
  254. logger.error("I/O Error", e);
  255. JccEvent evt = new JccConnectionEventImpl(
  256. JccConnectionEvent.CONNECTION_FAILED,
  257. this,
  258. JccEvent.CAUSE_GENERAL_FAILURE);
  259. queueEvent(evt);
  260. }
  261. }
  262. public void selectRoute(String digits) throws MethodNotSupportedException, InvalidStateException, ResourceUnavailableException, PrivilegeViolationException, InvalidPartyException {
  263. //we assume that format of the digits may be as follows:
  264. //destination#genericNumber which can be used to represent callerID
  265. String tokens[] = digits.split("#");
  266. destinationAddress.setName(tokens[0]);
  267. if (tokens.length > 1) {
  268. ((JccCallingPartyNumber) this.originatingAddress).setCallerID(tokens[1]);
  269. }
  270. if (isBlocked()) {
  271. resume();
  272. }
  273. }
  274. public void answer() throws PrivilegeViolationException, ResourceUnavailableException, InvalidStateException, MethodNotSupportedException {
  275. }
  276. public void attachMedia() throws PrivilegeViolationException, ResourceUnavailableException, InvalidStateException {
  277. }
  278. public void detachMedia() throws PrivilegeViolationException, ResourceUnavailableException, InvalidStateException {
  279. }
  280. public String getLastAddress() {
  281. return address.getName();
  282. }
  283. public String getOriginalAddress() {
  284. return address.getName();
  285. }
  286. public String getDestinationAddress() {
  287. return null;
  288. }
  289. public JccAddress getOriginatingAddress() {
  290. return originatingAddress;
  291. }
  292. public String getRedirectedAddress() {
  293. return redirectedAddress;
  294. }
  295. public void routeConnection(boolean b) throws InvalidStateException, ResourceUnavailableException, PrivilegeViolationException, MethodNotSupportedException, InvalidPartyException, InvalidArgumentException {
  296. }
  297. public MidCallData getMidCallData() throws InvalidStateException, ResourceUnavailableException, MethodNotSupportedException {
  298. return null;
  299. }
  300. }