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());
}
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);
}
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);
}
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);
}
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);
}
Aggregations