Search in sources :

Example 11 with SMSMessage

use of org.apache.camel.component.cm.client.SMSMessage in project camel by apache.

the class CMProducer method process.

/**
     * Producer is a exchange processor. This process is built in several steps. 1. Validate message receive from client 2. Send validated message to CM endpoints. 3. Process response from CM
     * endpoints.
     */
@Override
public void process(final Exchange exchange) throws Exception {
    // Immutable message receive from clients. Throws camel ' s
    // InvalidPayloadException
    final SMSMessage smsMessage = exchange.getIn().getMandatoryBody(SMSMessage.class);
    // Validates Payload - SMSMessage
    log.trace("Validating SMSMessage instance provided: {}", smsMessage.toString());
    final Set<ConstraintViolation<SMSMessage>> constraintViolations = getValidator().validate(smsMessage);
    if (constraintViolations.size() > 0) {
        final StringBuffer msg = new StringBuffer();
        for (final ConstraintViolation<SMSMessage> cv : constraintViolations) {
            msg.append(String.format("- Invalid value for %s: %s", cv.getPropertyPath().toString(), cv.getMessage()));
        }
        log.debug(msg.toString());
        throw new InvalidPayloadRuntimeException(exchange, SMSMessage.class);
    }
    log.trace("SMSMessage instance is valid: {}", smsMessage.toString());
    // We have a valid (immutable) SMSMessage instance, lets extend to
    // CMMessage
    // This is the instance we will use to build the XML document to be
    // sent to CM SMS GW.
    final CMMessage cmMessage = new CMMessage(smsMessage.getPhoneNumber(), smsMessage.getMessage());
    log.debug("CMMessage instance build from valid SMSMessage instance");
    if (smsMessage.getFrom() == null || smsMessage.getFrom().isEmpty()) {
        String df = getConfiguration().getDefaultFrom();
        cmMessage.setSender(df);
        log.debug("Dynamic sender is set to default dynamic sender: {}", df);
    }
    // Remember, this can be null.
    cmMessage.setIdAsString(smsMessage.getId());
    // Unicode and multipart
    cmMessage.setUnicodeAndMultipart(getConfiguration().getDefaultMaxNumberOfParts());
    // 2. Send a validated sms message to CM endpoints
    //  for abnormal situations.
    sender.send(cmMessage);
    log.debug("Request accepted by CM Host: {}", cmMessage.toString());
}
Also used : SMSMessage(org.apache.camel.component.cm.client.SMSMessage) ConstraintViolation(javax.validation.ConstraintViolation) InvalidPayloadRuntimeException(org.apache.camel.InvalidPayloadRuntimeException)

Example 12 with SMSMessage

use of org.apache.camel.component.cm.client.SMSMessage in project camel by apache.

the class CMTest method testUnroutableMessageException.

@Test(expected = UnroutableMessageException.class)
public void testUnroutableMessageException() throws Exception {
    // Change sending strategy
    CMEndpoint endpoint = (CMEndpoint) camelContext.getEndpoint(applicationContext.getBean(CamelTestConfiguration.class).getUri());
    CMProducer producer = endpoint.createProducer();
    producer.setSender(new UnroutableMessageExceptionSender());
    // Body
    final SMSMessage smsMessage = new SMSMessage(generateIdAsString(), generateUnicodeMessage(), validNumber, null);
    send(producer, smsMessage);
}
Also used : CMEndpoint(org.apache.camel.component.cm.CMEndpoint) SMSMessage(org.apache.camel.component.cm.client.SMSMessage) UnroutableMessageExceptionSender(org.apache.camel.component.cm.test.mocks.cmsender.UnroutableMessageExceptionSender) CMProducer(org.apache.camel.component.cm.CMProducer) Test(org.junit.Test)

Example 13 with SMSMessage

use of org.apache.camel.component.cm.client.SMSMessage in project camel by apache.

the class CMTest method testCMResponseException.

/*
     * 3. CM Responses (Faking Exceptions)
     */
@Test(expected = CMResponseException.class)
public void testCMResponseException() throws Exception {
    // Change sending strategy
    CMEndpoint endpoint = (CMEndpoint) camelContext.getEndpoint(applicationContext.getBean(CamelTestConfiguration.class).getUri());
    CMProducer producer = endpoint.createProducer();
    producer.setSender(new CMResponseExceptionSender());
    // Body
    final SMSMessage smsMessage = new SMSMessage(generateIdAsString(), generateUnicodeMessage(), validNumber, null);
    send(producer, smsMessage);
}
Also used : CMEndpoint(org.apache.camel.component.cm.CMEndpoint) CMResponseExceptionSender(org.apache.camel.component.cm.test.mocks.cmsender.CMResponseExceptionSender) SMSMessage(org.apache.camel.component.cm.client.SMSMessage) CMProducer(org.apache.camel.component.cm.CMProducer) Test(org.junit.Test)

Example 14 with SMSMessage

use of org.apache.camel.component.cm.client.SMSMessage in project camel by apache.

the class CMTest method testNoAccountFoundForProductTokenException.

@Test(expected = NoAccountFoundForProductTokenException.class)
public void testNoAccountFoundForProductTokenException() throws Exception {
    // Change sending strategy
    CMEndpoint endpoint = (CMEndpoint) camelContext.getEndpoint(applicationContext.getBean(CamelTestConfiguration.class).getUri());
    CMProducer producer = endpoint.createProducer();
    producer.setSender(new NoAccountFoundForProductTokenExceptionSender());
    // Body
    final SMSMessage smsMessage = new SMSMessage(generateIdAsString(), generateGSM0338Message(), validNumber, null);
    send(producer, smsMessage);
}
Also used : CMEndpoint(org.apache.camel.component.cm.CMEndpoint) NoAccountFoundForProductTokenExceptionSender(org.apache.camel.component.cm.test.mocks.cmsender.NoAccountFoundForProductTokenExceptionSender) SMSMessage(org.apache.camel.component.cm.client.SMSMessage) CMProducer(org.apache.camel.component.cm.CMProducer) Test(org.junit.Test)

Example 15 with SMSMessage

use of org.apache.camel.component.cm.client.SMSMessage in project camel by apache.

the class CMTest method testNoMessageException.

@Test(expected = NoMessageException.class)
public void testNoMessageException() throws Exception {
    // Change sending strategy
    CMEndpoint endpoint = (CMEndpoint) camelContext.getEndpoint(applicationContext.getBean(CamelTestConfiguration.class).getUri());
    CMProducer producer = endpoint.createProducer();
    producer.setSender(new NoMessageExceptionSender());
    // Body
    final SMSMessage smsMessage = new SMSMessage(generateIdAsString(), generateGSM0338Message(), validNumber, null);
    send(producer, smsMessage);
}
Also used : CMEndpoint(org.apache.camel.component.cm.CMEndpoint) NoMessageExceptionSender(org.apache.camel.component.cm.test.mocks.cmsender.NoMessageExceptionSender) SMSMessage(org.apache.camel.component.cm.client.SMSMessage) CMProducer(org.apache.camel.component.cm.CMProducer) Test(org.junit.Test)

Aggregations

SMSMessage (org.apache.camel.component.cm.client.SMSMessage)24 Test (org.junit.Test)23 ConstraintViolation (javax.validation.ConstraintViolation)12 CMEndpoint (org.apache.camel.component.cm.CMEndpoint)9 CMProducer (org.apache.camel.component.cm.CMProducer)9 PhoneNumber (com.google.i18n.phonenumbers.Phonenumber.PhoneNumber)1 InvalidPayloadRuntimeException (org.apache.camel.InvalidPayloadRuntimeException)1 CMResponseExceptionSender (org.apache.camel.component.cm.test.mocks.cmsender.CMResponseExceptionSender)1 InsufficientBalanceExceptionSender (org.apache.camel.component.cm.test.mocks.cmsender.InsufficientBalanceExceptionSender)1 InvalidMSISDNExceptionSender (org.apache.camel.component.cm.test.mocks.cmsender.InvalidMSISDNExceptionSender)1 InvalidProductTokenExceptionSender (org.apache.camel.component.cm.test.mocks.cmsender.InvalidProductTokenExceptionSender)1 NoAccountFoundForProductTokenExceptionSender (org.apache.camel.component.cm.test.mocks.cmsender.NoAccountFoundForProductTokenExceptionSender)1 NoMessageExceptionSender (org.apache.camel.component.cm.test.mocks.cmsender.NoMessageExceptionSender)1 NotPhoneNumberFoundExceptionSender (org.apache.camel.component.cm.test.mocks.cmsender.NotPhoneNumberFoundExceptionSender)1 UnknownErrorExceptionSender (org.apache.camel.component.cm.test.mocks.cmsender.UnknownErrorExceptionSender)1 UnroutableMessageExceptionSender (org.apache.camel.component.cm.test.mocks.cmsender.UnroutableMessageExceptionSender)1