Search in sources :

Example 1 with ExchangePattern

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

the class CamelOutputStream method commitOutputMessage.

private void commitOutputMessage() throws IOException {
    ExchangePattern pattern;
    if (isOneWay) {
        pattern = ExchangePattern.InOnly;
    } else {
        pattern = ExchangePattern.InOut;
    }
    LOG.debug("send the message to endpoint {}", this.targetCamelEndpointUri);
    final org.apache.camel.Exchange exchange = this.producer.createExchange(pattern);
    exchange.setProperty(Exchange.TO_ENDPOINT, this.targetCamelEndpointUri);
    CachedOutputStream outputStream = (CachedOutputStream) outMessage.getContent(OutputStream.class);
    // Send out the request message here, copy the protocolHeader back
    CxfHeaderHelper.propagateCxfToCamel(this.headerFilterStrategy, outMessage, exchange.getIn(), exchange);
    // TODO support different encoding
    exchange.getIn().setBody(outputStream.getInputStream());
    LOG.debug("template sending request: ", exchange.getIn());
    if (outMessage.getExchange().isSynchronous()) {
        syncInvoke(exchange);
    } else {
        // submit the request to the work queue
        asyncInvokeFromWorkQueue(exchange);
    }
}
Also used : ExchangePattern(org.apache.camel.ExchangePattern) OutputStream(java.io.OutputStream) CachedOutputStream(org.apache.cxf.io.CachedOutputStream) Exchange(org.apache.camel.Exchange) CachedOutputStream(org.apache.cxf.io.CachedOutputStream)

Example 2 with ExchangePattern

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

the class SetExchangePatternTest method assertMessageReceivedWithPattern.

protected void assertMessageReceivedWithPattern(String sendUri, ExchangePattern expectedPattern) throws InterruptedException {
    ExchangePattern sendPattern;
    switch(expectedPattern) {
        case InOut:
            sendPattern = ExchangePattern.InOnly;
            break;
        case InOnly:
        case RobustInOnly:
            sendPattern = ExchangePattern.InOut;
            break;
        default:
            sendPattern = ExchangePattern.InOnly;
    }
    MockEndpoint resultEndpoint = getMockEndpoint("mock:result");
    String expectedBody = "InOnlyMessage";
    resultEndpoint.expectedBodiesReceived(expectedBody);
    resultEndpoint.expectedHeaderReceived("foo", "bar");
    template.sendBodyAndHeader(sendUri, sendPattern, expectedBody, "foo", "bar");
    resultEndpoint.assertIsSatisfied();
    ExchangePattern actualPattern = resultEndpoint.getExchanges().get(0).getPattern();
    assertEquals("received exchange pattern", actualPattern, expectedPattern);
}
Also used : ExchangePattern(org.apache.camel.ExchangePattern) MockEndpoint(org.apache.camel.component.mock.MockEndpoint)

Example 3 with ExchangePattern

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

the class CamelInvocationHandler method doInvokeProxy.

@Override
public Object doInvokeProxy(Object proxy, Method method, Object[] args) throws Throwable {
    MethodInfo methodInfo = methodInfoCache.getMethodInfo(method);
    final ExchangePattern pattern = methodInfo != null ? methodInfo.getPattern() : ExchangePattern.InOut;
    return invokeProxy(method, pattern, args, binding);
}
Also used : ExchangePattern(org.apache.camel.ExchangePattern)

Example 4 with ExchangePattern

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

the class PojoMessageInvocationHandler method doInvokeProxy.

@Override
public Object doInvokeProxy(Object proxy, Method method, Object[] args) throws Throwable {
    int argsLength = (args == null) ? 0 : args.length;
    if (argsLength != 1) {
        throw new RuntimeCamelException(String.format("Error creating proxy for %s.%s Number of arguments must be 1 but is %d", method.getDeclaringClass().getName(), method.getName(), argsLength));
    }
    final ExchangePattern pattern = method.getReturnType() != Void.TYPE ? ExchangePattern.InOut : ExchangePattern.InOnly;
    return invokeWithBody(method, args[0], pattern);
}
Also used : ExchangePattern(org.apache.camel.ExchangePattern) RuntimeCamelException(org.apache.camel.RuntimeCamelException) Endpoint(org.apache.camel.Endpoint)

Example 5 with ExchangePattern

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

the class SendDynamicProcessor method process.

public boolean process(Exchange exchange, final AsyncCallback callback) {
    if (!isStarted()) {
        exchange.setException(new IllegalStateException("SendProcessor has not been started: " + this));
        callback.done(true);
        return true;
    }
    // we should preserve existing MEP so remember old MEP
    // if you want to permanently to change the MEP then use .setExchangePattern in the DSL
    final ExchangePattern existingPattern = exchange.getPattern();
    // which endpoint to send to
    final Endpoint endpoint;
    final ExchangePattern destinationExchangePattern;
    // use dynamic endpoint so calculate the endpoint to use
    Object recipient = null;
    try {
        recipient = expression.evaluate(exchange, Object.class);
        endpoint = resolveEndpoint(exchange, recipient);
        destinationExchangePattern = EndpointHelper.resolveExchangePatternFromUrl(endpoint.getEndpointUri());
    } catch (Throwable e) {
        if (isIgnoreInvalidEndpoint()) {
            if (LOG.isDebugEnabled()) {
                LOG.debug("Endpoint uri is invalid: " + recipient + ". This exception will be ignored.", e);
            }
        } else {
            exchange.setException(e);
        }
        callback.done(true);
        return true;
    }
    // send the exchange to the destination using the producer cache
    return producerCache.doInAsyncProducer(endpoint, exchange, pattern, callback, new AsyncProducerCallback() {

        public boolean doInAsyncProducer(Producer producer, AsyncProcessor asyncProducer, final Exchange exchange, ExchangePattern pattern, final AsyncCallback callback) {
            final Exchange target = configureExchange(exchange, pattern, destinationExchangePattern, endpoint);
            LOG.debug(">>>> {} {}", endpoint, exchange);
            return asyncProducer.process(target, new AsyncCallback() {

                public void done(boolean doneSync) {
                    // restore previous MEP
                    target.setPattern(existingPattern);
                    // signal we are done
                    callback.done(doneSync);
                }
            });
        }
    });
}
Also used : Exchange(org.apache.camel.Exchange) AsyncProducerCallback(org.apache.camel.AsyncProducerCallback) Endpoint(org.apache.camel.Endpoint) Producer(org.apache.camel.Producer) ExchangePattern(org.apache.camel.ExchangePattern) AsyncProcessor(org.apache.camel.AsyncProcessor) AsyncCallback(org.apache.camel.AsyncCallback)

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