/protocols/jain-mgcp/stack/src/test/java/org/mobicents/protocols/mgcp/stack/test/modifyconnection/MGW.java

http://mobicents.googlecode.com/ · Java · 112 lines · 66 code · 25 blank · 21 comment · 3 complexity · 9088b1a60aad53c2d0abd27fd7de3e75 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.modifyconnection;
  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.ModifyConnectionResponse;
  28. import jain.protocol.ip.mgcp.message.parms.ReturnCode;
  29. import java.util.TooManyListenersException;
  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 MGW implements JainMgcpExtendedListener {
  34. private static Logger logger = Logger.getLogger(MGW.class);
  35. private boolean responseSent = false;
  36. JainMgcpStackProviderImpl mgwProvider;
  37. private boolean sendFailedResponse = false;
  38. public MGW(JainMgcpStackProviderImpl mgwProvider, boolean sendFailedResponse) {
  39. this(mgwProvider);
  40. this.sendFailedResponse = sendFailedResponse;
  41. }
  42. public MGW(JainMgcpStackProviderImpl mgwProvider) {
  43. this.mgwProvider = mgwProvider;
  44. try {
  45. this.mgwProvider.addJainMgcpListener(this);
  46. } catch (TooManyListenersException e) {
  47. e.printStackTrace();
  48. ModifyConnectionTest.fail("Unexpected Exception");
  49. }
  50. }
  51. public void checkState() {
  52. ModifyConnectionTest.assertTrue("Expect to sent MDCX Response", responseSent);
  53. }
  54. public void transactionEnded(int handle) {
  55. logger.info("transactionEnded " + handle);
  56. }
  57. public void transactionRxTimedOut(JainMgcpCommandEvent command) {
  58. logger.info("transactionRxTimedOut " + command);
  59. }
  60. public void transactionTxTimedOut(JainMgcpCommandEvent command) {
  61. logger.info("transactionTxTimedOut " + command);
  62. }
  63. public void processMgcpCommandEvent(JainMgcpCommandEvent jainmgcpcommandevent) {
  64. logger.info("processMgcpCommandEvent \n" + jainmgcpcommandevent);
  65. switch (jainmgcpcommandevent.getObjectIdentifier()) {
  66. case Constants.CMD_MODIFY_CONNECTION:
  67. ModifyConnectionResponse response = null;
  68. if (this.sendFailedResponse) {
  69. response = new ModifyConnectionResponse(jainmgcpcommandevent.getSource(),
  70. ReturnCode.Endpoint_Insufficient_Resources);
  71. } else {
  72. response = new ModifyConnectionResponse(jainmgcpcommandevent.getSource(),
  73. ReturnCode.Transaction_Executed_Normally);
  74. }
  75. response.setTransactionHandle(jainmgcpcommandevent.getTransactionHandle());
  76. mgwProvider.sendMgcpEvents(new JainMgcpEvent[] { response });
  77. responseSent = true;
  78. break;
  79. default:
  80. logger.warn("This REQUEST is unexpected " + jainmgcpcommandevent);
  81. break;
  82. }
  83. }
  84. public void processMgcpResponseEvent(JainMgcpResponseEvent jainmgcpresponseevent) {
  85. logger.info("processMgcpResponseEvent " + jainmgcpresponseevent);
  86. }
  87. }