use of org.apache.camel.Message in project camel by apache.
the class HelsinkiServiceNowServiceCatalogItemsProcessor method submitItemProducer.
/*
* This method creates a record and returns the Table API relative path and
* redirect url to access the created record.
*
* Method:
* - POST
*
* URL Format:
* - /sn_sc/servicecatalog/items/{sys_id}/submit_producer
*/
private void submitItemProducer(Exchange exchange) throws Exception {
final Message in = exchange.getIn();
final Class<?> responseModel = getResponseModel(in);
final String sysId = getSysID(in);
final String apiVersion = getApiVersion(in);
Response response = client.reset().types(MediaType.APPLICATION_JSON_TYPE).path("sn_sc").path(apiVersion).path("servicecatalog").path("items").path(ObjectHelper.notNull(sysId, "sysId")).path("submit_producer").query(ServiceNowParams.SYSPARM_VIEW, in).invoke(HttpMethod.POST, in.getMandatoryBody());
setBodyAndHeaders(in, responseModel, response);
}
use of org.apache.camel.Message in project camel by apache.
the class SmppDataSmCommand method execute.
@Override
public void execute(Exchange exchange) throws SmppException {
DataSm dataSm = createDataSm(exchange);
if (log.isDebugEnabled()) {
log.debug("Sending a data short message for exchange id '{}'...", exchange.getExchangeId());
}
DataSmResult result;
try {
result = session.dataShortMessage(dataSm.getServiceType(), TypeOfNumber.valueOf(dataSm.getSourceAddrTon()), NumberingPlanIndicator.valueOf(dataSm.getSourceAddrNpi()), dataSm.getSourceAddr(), TypeOfNumber.valueOf(dataSm.getDestAddrTon()), NumberingPlanIndicator.valueOf(dataSm.getDestAddrNpi()), dataSm.getDestAddress(), new ESMClass(dataSm.getEsmClass()), new RegisteredDelivery(dataSm.getRegisteredDelivery()), DataCodings.newInstance(dataSm.getDataCoding()), dataSm.getOptionalParameters());
} catch (Exception e) {
throw new SmppException(e);
}
if (log.isDebugEnabled()) {
log.debug("Sent a data short message for exchange id '{}' and message id '{}'", exchange.getExchangeId(), result.getMessageId());
}
Message message = getResponseMessage(exchange);
message.setHeader(SmppConstants.ID, result.getMessageId());
message.setHeader(SmppConstants.OPTIONAL_PARAMETERS, createOptionalParameterByName(result.getOptionalParameters()));
message.setHeader(SmppConstants.OPTIONAL_PARAMETER, createOptionalParameterByCode(result.getOptionalParameters()));
}
use of org.apache.camel.Message in project camel by apache.
the class SmppProducer method process.
public void process(Exchange exchange) throws Exception {
if (session == null) {
if (this.configuration.isLazySessionCreation()) {
if (connectLock.tryLock()) {
try {
if (session == null) {
// set the system id and password with which we will try to connect to the SMSC
Message in = exchange.getIn();
String systemId = in.getHeader(SmppConstants.SYSTEM_ID, String.class);
String password = in.getHeader(SmppConstants.PASSWORD, String.class);
if (systemId != null && password != null) {
log.info("using the system id '{}' to connect to the SMSC...", systemId);
this.configuration.setSystemId(systemId);
this.configuration.setPassword(password);
}
session = createSession();
}
} finally {
connectLock.unlock();
}
}
}
}
// only possible by trying to reconnect
if (this.session == null) {
throw new IOException("Lost connection to " + getEndpoint().getConnectionString() + " and yet not reconnected");
}
SmppCommand command = getEndpoint().getBinding().createSmppCommand(session, exchange);
command.execute(exchange);
}
use of org.apache.camel.Message in project camel by apache.
the class SmppProducerLazySessionCreationTest method processShouldCreateTheSmppSession.
@Test
public void processShouldCreateTheSmppSession() throws Exception {
expect(endpoint.getConnectionString()).andReturn("smpp://smppclient@localhost:2775").times(2);
//expectation
session.setEnquireLinkTimer(5000);
//expectation
session.setTransactionTimer(10000);
session.addSessionStateListener(isA(SessionStateListener.class));
expect(session.connectAndBind("localhost", new Integer(2775), new BindParameter(BindType.BIND_TX, "smppclient", "password", "cp", TypeOfNumber.UNKNOWN, NumberingPlanIndicator.UNKNOWN, ""))).andReturn("1");
expect(endpoint.getConnectionString()).andReturn("smpp://smppclient@localhost:2775");
expect(endpoint.isSingleton()).andReturn(true);
SmppBinding binding = createMock(SmppBinding.class);
Exchange exchange = createMock(Exchange.class);
Message in = createMock(Message.class);
SmppCommand command = createMock(SmppCommand.class);
expect(endpoint.getBinding()).andReturn(binding);
expect(binding.createSmppCommand(session, exchange)).andReturn(command);
expect(exchange.getIn()).andReturn(in);
expect(in.getHeader("CamelSmppSystemId", String.class)).andReturn(null);
expect(in.getHeader("CamelSmppPassword", String.class)).andReturn(null);
command.execute(exchange);
replay(session, endpoint, binding, exchange, in, command);
producer.doStart();
producer.process(exchange);
verify(session, endpoint, binding, exchange, in, command);
}
use of org.apache.camel.Message in project camel by apache.
the class SmppProducerLazySessionCreationTest method processShouldCreateTheSmppSessionWithTheSystemIdAndPasswordFromTheExchange.
@Test
public void processShouldCreateTheSmppSessionWithTheSystemIdAndPasswordFromTheExchange() throws Exception {
expect(endpoint.getConnectionString()).andReturn("smpp://localhost:2775").times(2);
//expectation
session.setEnquireLinkTimer(5000);
//expectation
session.setTransactionTimer(10000);
session.addSessionStateListener(isA(SessionStateListener.class));
expect(session.connectAndBind("localhost", new Integer(2775), new BindParameter(BindType.BIND_TX, "smppclient2", "password2", "cp", TypeOfNumber.UNKNOWN, NumberingPlanIndicator.UNKNOWN, ""))).andReturn("1");
expect(endpoint.getConnectionString()).andReturn("smpp://localhost:2775");
SmppBinding binding = createMock(SmppBinding.class);
Exchange exchange = createMock(Exchange.class);
Message in = createMock(Message.class);
SmppCommand command = createMock(SmppCommand.class);
expect(endpoint.getBinding()).andReturn(binding);
expect(endpoint.isSingleton()).andReturn(true);
expect(binding.createSmppCommand(session, exchange)).andReturn(command);
expect(exchange.getIn()).andReturn(in);
expect(in.getHeader("CamelSmppSystemId", String.class)).andReturn("smppclient2");
expect(in.getHeader("CamelSmppPassword", String.class)).andReturn("password2");
command.execute(exchange);
replay(session, endpoint, binding, exchange, in, command);
producer.doStart();
producer.process(exchange);
verify(session, endpoint, binding, exchange, in, command);
}
Aggregations