Search in sources :

Example 6 with ExchangePattern

use of org.apache.camel.ExchangePattern in project camel by apache.

the class CamelTargetAdapter method send.

public boolean send(Message<?> message) throws Exception {
    boolean result = false;
    ExchangePattern pattern;
    if (isExpectReply()) {
        pattern = ExchangePattern.InOut;
    } else {
        pattern = ExchangePattern.InOnly;
    }
    Exchange inExchange = new DefaultExchange(getCamelContext(), pattern);
    SpringIntegrationBinding.storeToCamelMessage(message, inExchange.getIn());
    Exchange outExchange = getCamelTemplate().send(getCamelEndpointUri(), inExchange);
    org.apache.camel.Message camelMsg = outExchange.hasOut() ? outExchange.getOut() : outExchange.getIn();
    if (camelMsg.isFault()) {
        result = true;
    }
    Message<?> response;
    if (isExpectReply()) {
        //Check the message header for the return address
        response = SpringIntegrationBinding.storeToSpringIntegrationMessage(outExchange.getOut());
        if (replyChannel == null) {
            MessageChannel messageReplyChannel = (MessageChannel) message.getHeaders().get(MessageHeaders.REPLY_CHANNEL);
            if (messageReplyChannel != null) {
                result = messageReplyChannel.send(response);
            } else {
                throw new MessageDeliveryException(response, "Cannot resolve ReplyChannel from message: " + message);
            }
        } else {
            result = replyChannel.send(response);
        }
    }
    return result;
}
Also used : DefaultExchange(org.apache.camel.impl.DefaultExchange) Exchange(org.apache.camel.Exchange) DefaultExchange(org.apache.camel.impl.DefaultExchange) MessageChannel(org.springframework.messaging.MessageChannel) ExchangePattern(org.apache.camel.ExchangePattern) MessageDeliveryException(org.springframework.messaging.MessageDeliveryException)

Example 7 with ExchangePattern

use of org.apache.camel.ExchangePattern in project camel by apache.

the class SjmsComponent method validateMepAndReplyTo.

/**
     * Helper method used to verify that when there is a namedReplyTo value we
     * are using the InOut MEP. If namedReplyTo is defined and the MEP is InOnly
     * the endpoint won't be expecting a reply so throw an error to alert the
     * user.
     *
     * @param parameters {@link Endpoint} parameters
     * @throws Exception throws a {@link CamelException} when MEP equals InOnly
     *                   and namedReplyTo is defined.
     */
private static void validateMepAndReplyTo(Map<String, Object> parameters) throws Exception {
    boolean namedReplyToSet = parameters.containsKey("namedReplyTo");
    boolean mepSet = parameters.containsKey("exchangePattern");
    if (namedReplyToSet && mepSet) {
        if (!parameters.get("exchangePattern").equals(ExchangePattern.InOut.toString())) {
            String namedReplyTo = (String) parameters.get("namedReplyTo");
            ExchangePattern mep = ExchangePattern.valueOf((String) parameters.get("exchangePattern"));
            throw new CamelException("Setting parameter namedReplyTo=" + namedReplyTo + " requires a MEP of type InOut. Parameter exchangePattern is set to " + mep);
        }
    }
}
Also used : ExchangePattern(org.apache.camel.ExchangePattern) CamelException(org.apache.camel.CamelException)

Example 8 with ExchangePattern

use of org.apache.camel.ExchangePattern in project camel by apache.

the class SpringRemotingWithOneWayTest method testAsyncInvocation.

@Test
public void testAsyncInvocation() throws Exception {
    endpoint.expectedMessageCount(1);
    // we should not block even though there is no consumer on the endpoint!
    myService.doSomethingAsync("Hello");
    endpoint.assertIsSatisfied();
    List<Exchange> list = endpoint.getReceivedExchanges();
    for (Exchange exchange : list) {
        log.info("Received: " + exchange.getIn().getBody());
        ExchangePattern pattern = exchange.getPattern();
        assertEquals("Expected pattern on exchange: " + exchange, ExchangePattern.InOnly, pattern);
    }
}
Also used : Exchange(org.apache.camel.Exchange) ExchangePattern(org.apache.camel.ExchangePattern) Test(org.junit.Test)

Example 9 with ExchangePattern

use of org.apache.camel.ExchangePattern in project camel by apache.

the class CxfRsInvoker method prepareExchange.

private org.apache.camel.Exchange prepareExchange(Exchange cxfExchange, Method method, Object[] paramArray, Object response) {
    ExchangePattern ep = ExchangePattern.InOut;
    if (method.getReturnType() == Void.class) {
        ep = ExchangePattern.InOnly;
    }
    final org.apache.camel.Exchange camelExchange = endpoint.createExchange(ep);
    if (response != null) {
        camelExchange.getOut().setBody(response);
    }
    CxfRsBinding binding = endpoint.getBinding();
    binding.populateExchangeFromCxfRsRequest(cxfExchange, camelExchange, method, paramArray);
    // the CXF in message property. Question: where should this property name be set up ? 
    if (endpoint.isPropagateContexts()) {
        camelExchange.setProperty(UriInfo.class.getName(), new UriInfoImpl(cxfExchange.getInMessage()));
        camelExchange.setProperty(Request.class.getName(), new RequestImpl(cxfExchange.getInMessage()));
        camelExchange.setProperty(HttpHeaders.class.getName(), new HttpHeadersImpl(cxfExchange.getInMessage()));
        camelExchange.setProperty(SecurityContext.class.getName(), new SecurityContextImpl(cxfExchange.getInMessage()));
    }
    return camelExchange;
}
Also used : HttpHeaders(javax.ws.rs.core.HttpHeaders) SecurityContextImpl(org.apache.cxf.jaxrs.impl.SecurityContextImpl) Request(javax.ws.rs.core.Request) HttpHeadersImpl(org.apache.cxf.jaxrs.impl.HttpHeadersImpl) ExchangePattern(org.apache.camel.ExchangePattern) SecurityContext(javax.ws.rs.core.SecurityContext) UriInfo(javax.ws.rs.core.UriInfo) RequestImpl(org.apache.cxf.jaxrs.impl.RequestImpl) UriInfoImpl(org.apache.cxf.jaxrs.impl.UriInfoImpl)

Example 10 with ExchangePattern

use of org.apache.camel.ExchangePattern in project camel by apache.

the class BeanInfoTest method assertMethodPattern.

protected void assertMethodPattern(BeanInfo info, String methodName, ExchangePattern expectedPattern) throws NoSuchMethodException {
    Class<?> type = info.getType();
    Method method = type.getMethod(methodName);
    assertNotNull("Could not find method: " + methodName, method);
    MethodInfo methodInfo = info.getMethodInfo(method);
    assertNotNull("Could not find methodInfo for: " + method, methodInfo);
    ExchangePattern actualPattern = methodInfo.getPattern();
    assertEquals("Pattern for: " + method, expectedPattern, actualPattern);
    LOG.info("Method: " + method + " has pattern: " + actualPattern);
}
Also used : ExchangePattern(org.apache.camel.ExchangePattern) Method(java.lang.reflect.Method)

Aggregations

ExchangePattern (org.apache.camel.ExchangePattern)16 Exchange (org.apache.camel.Exchange)8 AsyncCallback (org.apache.camel.AsyncCallback)4 AsyncProcessor (org.apache.camel.AsyncProcessor)4 Endpoint (org.apache.camel.Endpoint)4 Producer (org.apache.camel.Producer)4 AsyncProducerCallback (org.apache.camel.AsyncProducerCallback)3 Method (java.lang.reflect.Method)2 DefaultExchange (org.apache.camel.impl.DefaultExchange)2 OutputStream (java.io.OutputStream)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 MalformedURLException (java.net.MalformedURLException)1 URISyntaxException (java.net.URISyntaxException)1 Principal (java.security.Principal)1 ArrayList (java.util.ArrayList)1 Subject (javax.security.auth.Subject)1 HttpHeaders (javax.ws.rs.core.HttpHeaders)1 Request (javax.ws.rs.core.Request)1 SecurityContext (javax.ws.rs.core.SecurityContext)1 UriInfo (javax.ws.rs.core.UriInfo)1