Search in sources :

Example 1 with DefaultProducer

use of org.apache.camel.impl.DefaultProducer in project camel by apache.

the class RetryRouteScopedUntilRecipientListIssueTest method createCamelContext.

@Override
protected CamelContext createCamelContext() throws Exception {
    CamelContext context = super.createCamelContext();
    context.addEndpoint("fail", new DefaultEndpoint() {

        public Producer createProducer() throws Exception {
            return new DefaultProducer(this) {

                public void process(Exchange exchange) throws Exception {
                    exchange.setException(new IllegalArgumentException("Damn"));
                }
            };
        }

        public Consumer createConsumer(Processor processor) throws Exception {
            return null;
        }

        @Override
        protected String createEndpointUri() {
            return "fail";
        }

        public boolean isSingleton() {
            return true;
        }
    });
    context.addEndpoint("not-fail", new DefaultEndpoint() {

        public Producer createProducer() throws Exception {
            return new DefaultProducer(this) {

                public void process(Exchange exchange) throws Exception {
                // noop
                }
            };
        }

        public Consumer createConsumer(Processor processor) throws Exception {
            return null;
        }

        @Override
        protected String createEndpointUri() {
            return "not-fail";
        }

        public boolean isSingleton() {
            return true;
        }
    });
    return context;
}
Also used : CamelContext(org.apache.camel.CamelContext) Exchange(org.apache.camel.Exchange) Processor(org.apache.camel.Processor) DefaultEndpoint(org.apache.camel.impl.DefaultEndpoint) DefaultProducer(org.apache.camel.impl.DefaultProducer) Producer(org.apache.camel.Producer) Consumer(org.apache.camel.Consumer) DefaultProducer(org.apache.camel.impl.DefaultProducer) ExchangeException(org.apache.camel.ExchangeException)

Example 2 with DefaultProducer

use of org.apache.camel.impl.DefaultProducer in project camel by apache.

the class DummyRestProducerFactory method createProducer.

@Override
public Producer createProducer(CamelContext camelContext, String host, String verb, String basePath, final String uriTemplate, String queryParameters, String consumes, String produces, Map<String, Object> parameters) throws Exception {
    // use a dummy endpoint
    Endpoint endpoint = camelContext.getEndpoint("stub:dummy");
    return new DefaultProducer(endpoint) {

        @Override
        public void process(Exchange exchange) throws Exception {
            String query = exchange.getIn().getHeader(Exchange.REST_HTTP_QUERY, String.class);
            if (query != null) {
                String name = ObjectHelper.after(query, "name=");
                exchange.getIn().setBody("Bye " + name);
            }
            String uri = exchange.getIn().getHeader(Exchange.REST_HTTP_URI, String.class);
            if (uri != null) {
                int pos = uri.lastIndexOf('/');
                String name = uri.substring(pos + 1);
                exchange.getIn().setBody("Hello " + name);
            }
        }
    };
}
Also used : Exchange(org.apache.camel.Exchange) Endpoint(org.apache.camel.Endpoint) DefaultProducer(org.apache.camel.impl.DefaultProducer) Endpoint(org.apache.camel.Endpoint)

Example 3 with DefaultProducer

use of org.apache.camel.impl.DefaultProducer in project camel by apache.

the class EventEndpoint method createProducer.

public Producer createProducer() throws Exception {
    ObjectHelper.notNull(applicationContext, "applicationContext");
    return new DefaultProducer(this) {

        public void process(Exchange exchange) throws Exception {
            ApplicationEvent event = toApplicationEvent(exchange);
            applicationContext.publishEvent(event);
        }
    };
}
Also used : Exchange(org.apache.camel.Exchange) DefaultProducer(org.apache.camel.impl.DefaultProducer) ApplicationEvent(org.springframework.context.ApplicationEvent)

Aggregations

Exchange (org.apache.camel.Exchange)3 DefaultProducer (org.apache.camel.impl.DefaultProducer)3 CamelContext (org.apache.camel.CamelContext)1 Consumer (org.apache.camel.Consumer)1 Endpoint (org.apache.camel.Endpoint)1 ExchangeException (org.apache.camel.ExchangeException)1 Processor (org.apache.camel.Processor)1 Producer (org.apache.camel.Producer)1 DefaultEndpoint (org.apache.camel.impl.DefaultEndpoint)1 ApplicationEvent (org.springframework.context.ApplicationEvent)1