Exemplo n.º 1
0
    @Override
    public long perform() {
      code = ((MgcpCommandException) transaction().getLastError()).getCode();
      message = ((MgcpCommandException) transaction().getLastError()).getErrorMessage();

      MgcpEvent evt =
          transaction().getProvider().createEvent(MgcpEvent.RESPONSE, getEvent().getAddress());
      MgcpResponse response = (MgcpResponse) evt.getMessage();
      response.setResponseCode(code);
      response.setResponseString(message);
      response.setTxID(transaction().getId());

      if (connectionID != null) {
        response.setParameter(Parameter.CONNECTION_ID, connectionID.getValue());
      }

      try {
        transaction().getProvider().send(evt);
      } catch (IOException e) {
        logger.error(e);
      } finally {
        evt.recycle();
      }

      return 0;
    }
Exemplo n.º 2
0
    @Override
    public long perform() {
      MgcpEvent evt =
          transaction().getProvider().createEvent(MgcpEvent.RESPONSE, getEvent().getAddress());
      MgcpResponse response = (MgcpResponse) evt.getMessage();
      response.setResponseCode(MgcpResponseCode.TRANSACTION_WAS_EXECUTED);
      response.setResponseString(SUCCESS);
      response.setTxID(transaction().getId());

      if (connectionID != null) {
        response.setParameter(Parameter.CONNECTION_ID, connectionID.getValue());
      }
      response.setParameter(Parameter.CONNECTION_PARAMETERS, new Text("PS=" + tx + ", PR=" + rx));

      try {
        transaction().getProvider().send(evt);
      } catch (IOException e) {
        logger.error(e);
      } finally {
        evt.recycle();
      }

      return 0;
    }
Exemplo n.º 3
0
    @Override
    public long perform() {
      request = (MgcpRequest) getEvent().getMessage();

      Parameter callID = request.getParameter(Parameter.CALL_ID);
      if (callID == null) {
        throw new MgcpCommandException(MgcpResponseCode.PROTOCOL_ERROR, CALLID_MISSING);
      }

      // modify local connection options
      Parameter l = request.getParameter(Parameter.LOCAL_CONNECTION_OPTIONS);
      if (l != null) {
        lcOptions.setValue(l.getValue());
      } else {
        lcOptions.setValue(null);
      }

      // getting call
      MgcpCall call = transaction().getCall(callID.getValue().hexToInteger(), false);
      if (call == null) {
        throw new MgcpCommandException(MgcpResponseCode.INCORRECT_CALL_ID, UNKNOWN_CALL_IDENTIFIER);
      }

      connectionID = request.getParameter(Parameter.CONNECTION_ID);
      if (connectionID == null) {
        throw new MgcpCommandException(MgcpResponseCode.PROTOCOL_ERROR, CONNECTIONID_EXPECTED);
      }

      try {
        mgcpConnection = call.getMgcpConnection(connectionID.getValue().hexToInteger());
      } catch (Exception e) {
        throw new MgcpCommandException(
            MgcpResponseCode.CONNECTION_WAS_DELETED,
            new Text("Unknown connectionidentifier, probably it was deleted"));
      }

      if (mgcpConnection == null)
        throw new MgcpCommandException(
            MgcpResponseCode.CONNECTION_WAS_DELETED,
            new Text("Unknown connectionidentifier, probably it was deleted"));

      // set SDP if requested
      Parameter sdp = request.getParameter(Parameter.SDP);
      Parameter mode = request.getParameter(Parameter.MODE);

      if (sdp != null) {
        try {
          mgcpConnection.setOtherParty(sdp.getValue());
        } catch (IOException e) {
          logger.error("Could not set remote peer", e);
          throw new MgcpCommandException(MgcpResponseCode.UNSUPPORTED_SDP, SDP_NEGOTIATION_FAILED);
        }
      }

      if (mode != null) {
        try {
          mgcpConnection.setMode(mode.getValue());
        } catch (ModeNotSupportedException e) {
          throw new MgcpCommandException(
              MgcpResponseCode.INVALID_OR_UNSUPPORTED_MODE, new Text("problem with mode"));
        }
      }

      mgcpConnection.setDtmfClamp(lcOptions.getDtmfClamp());

      MgcpEvent evt =
          transaction().getProvider().createEvent(MgcpEvent.RESPONSE, getEvent().getAddress());
      MgcpResponse response = (MgcpResponse) evt.getMessage();
      response.setResponseCode(MgcpResponseCode.TRANSACTION_WAS_EXECUTED);
      response.setResponseString(SUCCESS);
      response.setTxID(transaction().getId());

      if (connectionID != null) {
        response.setParameter(Parameter.CONNECTION_ID, connectionID.getValue());
      }

      Text descriptor = mgcpConnection.getDescriptor();
      if (descriptor != null) response.setParameter(Parameter.SDP, mgcpConnection.getDescriptor());

      try {
        transaction().getProvider().send(evt);
      } catch (IOException e) {
        logger.error(e);
      } finally {
        evt.recycle();
      }

      return 0;
    }