PageRenderTime 35ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

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

http://mobicents.googlecode.com/
Java | 115 lines | 67 code | 26 blank | 22 comment | 5 complexity | 65993c96c2c37862d18a8f27595fe3ba 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. package org.mobicents.protocols.mgcp.stack.test.notificationrequest;
  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.NotificationRequest;
  28. import jain.protocol.ip.mgcp.message.parms.EndpointIdentifier;
  29. import jain.protocol.ip.mgcp.message.parms.ReturnCode;
  30. import org.apache.log4j.Logger;
  31. import org.mobicents.protocols.mgcp.stack.JainMgcpExtendedListener;
  32. import org.mobicents.protocols.mgcp.stack.JainMgcpStackProviderImpl;
  33. public class CA implements JainMgcpExtendedListener {
  34. private static Logger logger = Logger.getLogger(CA.class);
  35. private JainMgcpStackProviderImpl caProvider;
  36. private int mgStack = 0;
  37. private boolean responseReceived = false;
  38. public CA(JainMgcpStackProviderImpl caProvider, JainMgcpStackProviderImpl mgwProvider) {
  39. this.caProvider = caProvider;
  40. mgStack = mgwProvider.getJainMgcpStack().getPort();
  41. }
  42. public void sendNotificationRequest() {
  43. try {
  44. caProvider.addJainMgcpListener(this);
  45. EndpointIdentifier endpointID = new EndpointIdentifier("media/trunk/Announcement/enp4", "127.0.0.1:"
  46. + mgStack);
  47. NotificationRequest notificationRequest = new NotificationRequest(this, endpointID, caProvider
  48. .getUniqueRequestIdentifier());
  49. notificationRequest.setTransactionHandle(caProvider.getUniqueTransactionHandler());
  50. caProvider.sendMgcpEvents(new JainMgcpEvent[] { notificationRequest });
  51. logger.debug(" NotificationRequest command sent for TxId " + notificationRequest.getTransactionHandle());
  52. } catch (Exception e) {
  53. // TODO Auto-generated catch block
  54. e.printStackTrace();
  55. NotificationRequestTest.fail("Unexpected Exception");
  56. }
  57. }
  58. public void checkState() {
  59. NotificationRequestTest.assertTrue("Expect to receive RQNT Response", responseReceived);
  60. }
  61. public void transactionEnded(int handle) {
  62. logger.info("transactionEnded " + handle);
  63. }
  64. public void transactionRxTimedOut(JainMgcpCommandEvent command) {
  65. logger.info("transactionRxTimedOut " + command);
  66. }
  67. public void transactionTxTimedOut(JainMgcpCommandEvent command) {
  68. logger.info("transactionTxTimedOut " + command);
  69. }
  70. public void processMgcpCommandEvent(JainMgcpCommandEvent jainmgcpcommandevent) {
  71. logger.info("processMgcpCommandEvent " + jainmgcpcommandevent);
  72. }
  73. public void processMgcpResponseEvent(JainMgcpResponseEvent jainmgcpresponseevent) {
  74. logger.debug("processMgcpResponseEvent = " + jainmgcpresponseevent);
  75. switch (jainmgcpresponseevent.getObjectIdentifier()) {
  76. case Constants.RESP_NOTIFICATION_REQUEST:
  77. if (jainmgcpresponseevent.getReturnCode().getValue() == ReturnCode.PROTOCOL_ERROR
  78. || jainmgcpresponseevent.getReturnCode().getValue() == ReturnCode.TRANSACTION_EXECUTED_NORMALLY) {
  79. responseReceived = true;
  80. }
  81. break;
  82. default:
  83. logger.warn("This RESPONSE is unexpected " + jainmgcpresponseevent);
  84. NotificationRequestTest.fail("Incorrect response for RQNT command ");
  85. responseReceived = false;
  86. break;
  87. }
  88. }
  89. }