/protocols/jain-mgcp/stack/src/test/java/org/mobicents/protocols/mgcp/stack/test/endpointconfiguration/CA.java

http://mobicents.googlecode.com/ · Java · 112 lines · 64 code · 27 blank · 21 comment · 1 complexity · 3bded982321faf826ab26ba99fb868ea MD5 · raw file

  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. package org.mobicents.protocols.mgcp.stack.test.endpointconfiguration;
  23. import jain.protocol.ip.mgcp.JainMgcpCommandEvent;
  24. import jain.protocol.ip.mgcp.JainMgcpEvent;
  25. import jain.protocol.ip.mgcp.JainMgcpResponseEvent;
  26. import jain.protocol.ip.mgcp.message.Constants;
  27. import jain.protocol.ip.mgcp.message.EndpointConfiguration;
  28. import jain.protocol.ip.mgcp.message.parms.BearerInformation;
  29. import jain.protocol.ip.mgcp.message.parms.CallIdentifier;
  30. import jain.protocol.ip.mgcp.message.parms.EndpointIdentifier;
  31. import org.apache.log4j.Logger;
  32. import org.mobicents.protocols.mgcp.stack.JainMgcpExtendedListener;
  33. import org.mobicents.protocols.mgcp.stack.JainMgcpStackProviderImpl;
  34. import org.mobicents.protocols.mgcp.stack.test.createconnection.CreateConnectionTest;
  35. public class CA implements JainMgcpExtendedListener {
  36. private static Logger logger = Logger.getLogger(CA.class);
  37. private JainMgcpStackProviderImpl caProvider;
  38. private int mgStack = 0;
  39. private boolean responseReceived = false;
  40. public CA(JainMgcpStackProviderImpl caProvider, JainMgcpStackProviderImpl mgwProvider) {
  41. this.caProvider = caProvider;
  42. mgStack = mgwProvider.getJainMgcpStack().getPort();
  43. }
  44. public void sendEndpointConfiguration() {
  45. try {
  46. caProvider.addJainMgcpListener(this);
  47. CallIdentifier callID = caProvider.getUniqueCallIdentifier();
  48. EndpointIdentifier endpointID = new EndpointIdentifier("media/trunk/Announcement/", "127.0.0.1:" + mgStack);
  49. EndpointConfiguration endpointConfiguration = new EndpointConfiguration(this, endpointID, BearerInformation.EncMethod_A_Law );
  50. endpointConfiguration.setTransactionHandle(caProvider.getUniqueTransactionHandler());
  51. caProvider.sendMgcpEvents(new JainMgcpEvent[] { endpointConfiguration });
  52. logger.debug(" EndpointConfiguration command sent for TxId " + endpointConfiguration.getTransactionHandle()
  53. + " and CallId " + callID);
  54. } catch (Exception e) {
  55. e.printStackTrace();
  56. EndpointConfigurationTest.fail("Unexpected Exception");
  57. }
  58. }
  59. public void checkState() {
  60. CreateConnectionTest.assertTrue("Expect to receive EPCF Response", responseReceived);
  61. }
  62. public void transactionEnded(int handle) {
  63. logger.info("transactionEnded " + handle);
  64. }
  65. public void transactionRxTimedOut(JainMgcpCommandEvent command) {
  66. logger.info("transactionRxTimedOut " + command);
  67. }
  68. public void transactionTxTimedOut(JainMgcpCommandEvent command) {
  69. logger.info("transactionTxTimedOut " + command);
  70. }
  71. public void processMgcpCommandEvent(JainMgcpCommandEvent jainmgcpcommandevent) {
  72. logger.info("processMgcpCommandEvent " + jainmgcpcommandevent);
  73. }
  74. public void processMgcpResponseEvent(JainMgcpResponseEvent jainmgcpresponseevent) {
  75. logger.debug("processMgcpResponseEvent = " + jainmgcpresponseevent);
  76. switch (jainmgcpresponseevent.getObjectIdentifier()) {
  77. case Constants.RESP_ENDPOINT_CONFIGURATION:
  78. responseReceived = true;
  79. break;
  80. default:
  81. logger.warn("This RESPONSE is unexpected " + jainmgcpresponseevent);
  82. break;
  83. }
  84. }
  85. }