@Test public void testValidateRequestWithUnknownSecondaryEndpoint() throws MgcpException { final StringBuilder builder = new StringBuilder(); builder.append("CRCX 147483655 mobicents/bridge/$@127.0.0.1:2427 MGCP 1.0").append(System.lineSeparator()); builder.append("C:1").append(System.lineSeparator()); builder.append("M:sendrecv").append(System.lineSeparator()); builder.append("N:restcomm@127.0.0.1:2727").append(System.lineSeparator()); builder.append("Z2:mobicents/ivr/$@127.0.0.1:2427"); final int transactionId = 147483655; final MgcpRequest request = new MgcpMessageParser().parseRequest(builder.toString()); final MgcpEndpointManager endpointManager = mock(MgcpEndpointManager.class); final MgcpEndpoint bridgeEndpoint = mock(MgcpEndpoint.class); final EndpointIdentifier bridgeEndpointId = new EndpointIdentifier("mobicents/bridge/1", "127.0.0.1:2427"); final CreateConnectionCommand crcx = new CreateConnectionCommand(transactionId, request.getParameters(), endpointManager); when(endpointManager.registerEndpoint("mobicents/bridge/")).thenReturn(bridgeEndpoint); when(endpointManager.registerEndpoint("mobicents/ivr/")).thenThrow(new UnrecognizedMgcpNamespaceException("")); when(bridgeEndpoint.getEndpointId()).thenReturn(bridgeEndpointId); MgcpCommandResult result = crcx.call(); assertNotNull(result); assertEquals(MgcpResponseCode.ENDPOINT_NOT_AVAILABLE.code(), result.getCode()); assertEquals(0, result.getParameters().size()); }
@Override public MgcpCommandResult call() { CrcxContext context = new CrcxContext(); try { validateParameters(this.requestParameters, context); executeCommand(context); context.setCode(MgcpResponseCode.TRANSACTION_WAS_EXECUTED.code()); context.setMessage(MgcpResponseCode.TRANSACTION_WAS_EXECUTED.message()); } catch (RuntimeException | MgcpConnectionException e) { log.error("Unexpected error occurred during tx=" + this.transactionId + " execution. Reason: " + e.getMessage() + ". Rolling back."); rollback(context); context.setCode(MgcpResponseCode.PROTOCOL_ERROR.code()); context.setMessage(MgcpResponseCode.PROTOCOL_ERROR.message()); } catch (MgcpCommandException e) { log.error("Protocol error occurred during tx=" + this.transactionId + " execution. Reason: " + e.getMessage()); context.setCode(e.getCode()); context.setMessage(e.getMessage()); } return respond(context); }
CreateConnectionCommand extends AbstractMgcpCommand { @Override public MgcpCommandResult call() { CrcxContext context = new CrcxContext(); try { validateParameters(this.requestParameters, context); executeCommand(context); context.setCode(MgcpResponseCode.TRANSACTION_WAS_EXECUTED.code()); context.setMessage(MgcpResponseCode.TRANSACTION_WAS_EXECUTED.message()); } catch (RuntimeException | MgcpConnectionException e) { log.error("Unexpected error occurred during tx=" + this.transactionId + " execution. Reason: " + e.getMessage() + ". Rolling back."); rollback(context); context.setCode(MgcpResponseCode.PROTOCOL_ERROR.code()); context.setMessage(MgcpResponseCode.PROTOCOL_ERROR.message()); } catch (MgcpCommandException e) { log.error("Protocol error occurred during tx=" + this.transactionId + " execution. Reason: " + e.getMessage()); context.setCode(e.getCode()); context.setMessage(e.getMessage()); } return respond(context); } }
CreateConnectionCommand extends AbstractMgcpCommand { @Override public MgcpCommandResult call() { CrcxContext context = new CrcxContext(); try { validateParameters(this.requestParameters, context); executeCommand(context); context.setCode(MgcpResponseCode.TRANSACTION_WAS_EXECUTED.code()); context.setMessage(MgcpResponseCode.TRANSACTION_WAS_EXECUTED.message()); } catch (RuntimeException | MgcpConnectionException e) { log.error("Unexpected error occurred during tx=" + this.transactionId + " execution. Reason: " + e.getMessage() + ". Rolling back."); rollback(context); context.setCode(MgcpResponseCode.PROTOCOL_ERROR.code()); context.setMessage(MgcpResponseCode.PROTOCOL_ERROR.message()); } catch (MgcpCommandException e) { log.error("Protocol error occurred during tx=" + this.transactionId + " execution. Reason: " + e.getMessage()); context.setCode(e.getCode()); context.setMessage(e.getMessage()); } return respond(context); } CreateConnectionCommand(int transactionId, Parameters<MgcpParameterType> parameters, MgcpEndpointManager endpointManager); }
CreateConnectionCommand extends AbstractMgcpCommand { @Override public MgcpCommandResult call() { CrcxContext context = new CrcxContext(); try { validateParameters(this.requestParameters, context); executeCommand(context); context.setCode(MgcpResponseCode.TRANSACTION_WAS_EXECUTED.code()); context.setMessage(MgcpResponseCode.TRANSACTION_WAS_EXECUTED.message()); } catch (RuntimeException | MgcpConnectionException e) { log.error("Unexpected error occurred during tx=" + this.transactionId + " execution. Reason: " + e.getMessage() + ". Rolling back."); rollback(context); context.setCode(MgcpResponseCode.PROTOCOL_ERROR.code()); context.setMessage(MgcpResponseCode.PROTOCOL_ERROR.message()); } catch (MgcpCommandException e) { log.error("Protocol error occurred during tx=" + this.transactionId + " execution. Reason: " + e.getMessage()); context.setCode(e.getCode()); context.setMessage(e.getMessage()); } return respond(context); } CreateConnectionCommand(int transactionId, Parameters<MgcpParameterType> parameters, MgcpEndpointManager endpointManager); @Override MgcpCommandResult call(); }
CreateConnectionCommand extends AbstractMgcpCommand { @Override public MgcpCommandResult call() { CrcxContext context = new CrcxContext(); try { validateParameters(this.requestParameters, context); executeCommand(context); context.setCode(MgcpResponseCode.TRANSACTION_WAS_EXECUTED.code()); context.setMessage(MgcpResponseCode.TRANSACTION_WAS_EXECUTED.message()); } catch (RuntimeException | MgcpConnectionException e) { log.error("Unexpected error occurred during tx=" + this.transactionId + " execution. Reason: " + e.getMessage() + ". Rolling back."); rollback(context); context.setCode(MgcpResponseCode.PROTOCOL_ERROR.code()); context.setMessage(MgcpResponseCode.PROTOCOL_ERROR.message()); } catch (MgcpCommandException e) { log.error("Protocol error occurred during tx=" + this.transactionId + " execution. Reason: " + e.getMessage()); context.setCode(e.getCode()); context.setMessage(e.getMessage()); } return respond(context); } CreateConnectionCommand(int transactionId, Parameters<MgcpParameterType> parameters, MgcpEndpointManager endpointManager); @Override MgcpCommandResult call();  }