Search in sources :

Example 56 with Message

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);
}
Also used : Response(javax.ws.rs.core.Response) Message(org.apache.camel.Message)

Example 57 with Message

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()));
}
Also used : DataSm(org.jsmpp.bean.DataSm) Message(org.apache.camel.Message) RegisteredDelivery(org.jsmpp.bean.RegisteredDelivery) ESMClass(org.jsmpp.bean.ESMClass) DataSmResult(org.jsmpp.session.DataSmResult)

Example 58 with Message

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);
}
Also used : Message(org.apache.camel.Message) IOException(java.io.IOException)

Example 59 with Message

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);
}
Also used : Exchange(org.apache.camel.Exchange) SessionStateListener(org.jsmpp.session.SessionStateListener) Message(org.apache.camel.Message) BindParameter(org.jsmpp.session.BindParameter) Test(org.junit.Test)

Example 60 with Message

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);
}
Also used : Exchange(org.apache.camel.Exchange) SessionStateListener(org.jsmpp.session.SessionStateListener) Message(org.apache.camel.Message) BindParameter(org.jsmpp.session.BindParameter) Test(org.junit.Test)

Aggregations

Message (org.apache.camel.Message)738 Exchange (org.apache.camel.Exchange)348 Test (org.junit.Test)223 Processor (org.apache.camel.Processor)118 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)104 DefaultMessage (org.apache.camel.impl.DefaultMessage)54 Endpoint (org.apache.camel.Endpoint)45 DefaultExchange (org.apache.camel.impl.DefaultExchange)44 InputStream (java.io.InputStream)38 HashMap (java.util.HashMap)38 Response (javax.ws.rs.core.Response)38 ArrayList (java.util.ArrayList)29 Map (java.util.Map)26 RouteBuilder (org.apache.camel.builder.RouteBuilder)25 Customer (org.apache.camel.component.cxf.jaxrs.testbean.Customer)25 ActionResponse (org.openstack4j.model.common.ActionResponse)25 IOException (java.io.IOException)24 DataHandler (javax.activation.DataHandler)21 Producer (org.apache.camel.Producer)21 List (java.util.List)20