Package org.apache.camel

Examples of org.apache.camel.Exchange


       
    }
   
    @Test
    public void testGetCustomerExceptionWithCxfRsEndpoint() {
        Exchange exchange
            = template.send("cxfrs://http://localhost:" + getPort1() + "/" + getClass().getSimpleName() + "/?httpClientAPI=true", new Processor() {
                public void process(Exchange exchange) throws Exception {
                    exchange.setPattern(ExchangePattern.InOut);
                    Message message = exchange.getIn();
                    // set the Http method
                    message.setHeader(Exchange.HTTP_METHOD, "PUT");
                    // set the relative path
                    message.setHeader(Exchange.HTTP_PATH, "/customerservice/customers");
                    // we just setup the customer with a wrong id
                    Customer customer = new Customer();
                    customer.setId(222);
                    customer.setName("user");
                    message.setBody(customer);               
                }
            });
        // we should get the exception here
        assertNotNull("Expect the exception here", exchange.getException());
        CxfOperationException exception = (CxfOperationException)exchange.getException();
       
        assertEquals("Get a wrong response body", "Cannot find the customer!", exception.getResponseBody());
       
    }
View Full Code Here


       
    }
   
    @Test
    public void testGetCustomerWithCxfRsEndpoint() {
        Exchange exchange
            = template.send("cxfrs://http://localhost:" + getPort1() + "/" + getClass().getSimpleName() + "/?httpClientAPI=true", new Processor() {
                public void process(Exchange exchange) throws Exception {
                    exchange.setPattern(ExchangePattern.InOut);
                    Message inMessage = exchange.getIn();
                    // set the Http method
                    inMessage.setHeader(Exchange.HTTP_METHOD, "GET");
                    // set the relative path
                    inMessage.setHeader(Exchange.HTTP_PATH, "/customerservice/customers/123");               
                    // Specify the response class , cxfrs will use InputStream as the response object type
                    inMessage.setHeader(CxfConstants.CAMEL_CXF_RS_RESPONSE_CLASS, Customer.class);
                    // since we use the Get method, so we don't need to set the message body
                    inMessage.setBody(null);               
                }
            });
    
        // get the response message
        Customer response = (Customer) exchange.getOut().getBody();
        assertNotNull("The response should not be null ", response);
        assertEquals("Get a wrong customer id ", String.valueOf(response.getId()), "123");
        assertEquals("Get a wrong customer name", response.getName(), "John");
        assertEquals("Get a wrong response code", 200, exchange.getOut().getHeader(Exchange.HTTP_RESPONSE_CODE));
    }
View Full Code Here

    protected int poll() throws Exception {
        Stack<BasicIssue> newIssues = new Stack<BasicIssue>();
        getNewIssues(0, newIssues);
        while (!newIssues.empty()) {
            BasicIssue newIssue = newIssues.pop();
            Exchange e = getEndpoint().createExchange();
            e.getIn().setBody(newIssue);
            getProcessor().process(e);
        }
        return newIssues.size();
    }
View Full Code Here

        assertEquals("Get a wrong response code", 200, exchange.getOut().getHeader(Exchange.HTTP_RESPONSE_CODE));
    }

    @Test
    public void testGetCustomerWithVariableReplacementAndCxfRsEndpoint() {
        Exchange exchange = template.send("cxfrs://http://localhost:" + getPort1() + "/" + getClass().getSimpleName() + "/?httpClientAPI=true", new Processor() {
            public void process(Exchange exchange) throws Exception {
                exchange.setPattern(ExchangePattern.InOut);
                Message inMessage = exchange.getIn();
                // set the Http method
                inMessage.setHeader(Exchange.HTTP_METHOD, "GET");
                // set the relative path
                inMessage.setHeader(Exchange.HTTP_PATH, "/customerservice/customers/{customerId}");
                // Set variables for replacement
                inMessage.setHeader(CxfConstants.CAMEL_CXF_RS_VAR_VALUES, new String[] {"123"});
                // Specify the response class , cxfrs will use InputStream as the response object type
                inMessage.setHeader(CxfConstants.CAMEL_CXF_RS_RESPONSE_CLASS, Customer.class);
                // since we use the Get method, so we don't need to set the message body
                inMessage.setBody(null);
            }
        });

        // get the response message
        Customer response = (Customer) exchange.getOut().getBody();
        assertNotNull("The response should not be null ", response);
        assertEquals("Get a wrong customer id ", String.valueOf(response.getId()), "123");
        assertEquals("Get a wrong customer name", response.getName(), "John");
        assertEquals("Get a wrong response code", 200, exchange.getOut().getHeader(Exchange.HTTP_RESPONSE_CODE));
    }
View Full Code Here

    public void testJcrProducer() throws Exception {
        result.expectedMessageCount(1);
        result.expectedHeaderReceived("my.contents.property", CONTENT);
        result.expectedHeaderReceived("content.approved", APPROVED);

        Exchange exchange = createExchangeWithBody(identifier);
        template.send("direct:a", exchange);
        assertMockEndpointsSatisfied();
    }
View Full Code Here

public class CamelJob implements Job {
    private static final Logger LOG = LoggerFactory.getLogger(CamelJob.class);

    @Override
    public void execute(JobExecutionContext context) throws JobExecutionException {
        Exchange exchange = null;
        try {
            if (LOG.isDebugEnabled()) {
                LOG.debug("Running CamelJob jobExecutionContext={}", context);
            }

            CamelContext camelContext = getCamelContext(context);
            QuartzEndpoint endpoint = lookupQuartzEndpoint(camelContext, context);
            exchange = endpoint.createExchange();
            exchange.setIn(new QuartzMessage(exchange, context));
            endpoint.getConsumerLoadBalancer().process(exchange);

            if (exchange.getException() != null) {
                throw new JobExecutionException(exchange.getException());
            }
        } catch (Exception e) {
            if (exchange != null) {
                LOG.error(CamelExchangeException.createExceptionMessage("Error processing exchange", exchange, e));
            } else {
View Full Code Here

        session.logout();
    }

    @Test
    public void testJcrNodePathCreation() throws Exception {
        Exchange exchange = createExchangeWithBody("<body/>");
        Exchange out = template.send("direct:a", exchange);
        assertNotNull(out);
        String uuid = out.getOut().getBody(String.class);
        assertNotNull("Out body was null; expected JCR node UUID", uuid);
        Session session = openSession();
        try {
            Node node = session.getNodeByIdentifier(uuid);
            assertNotNull(node);
View Full Code Here

        }
    }

    @Test
    public void testJcrNodePathCreationMultiValued() throws Exception {
        Exchange exchange = createExchangeWithBody(multiValued);
        Exchange out = template.send("direct:a", exchange);
        assertNotNull(out);
        String uuid = out.getOut().getBody(String.class);
        assertNotNull("Out body was null; expected JCR node UUID", uuid);
        Session session = openSession();
        try {
            Node node = session.getNodeByIdentifier(uuid);
            assertNotNull(node);
View Full Code Here

            if (!lines.isEmpty() && (lines.size() >= endpoint.getGroupLines() || last)) {
                // spit out lines as we hit the size, or it was the last
                List<String> copy = new ArrayList<String>(lines);
                Object body = endpoint.getGroupStrategy().groupLines(copy);
                // remember to inc index when we create an exchange
                Exchange exchange = endpoint.createExchange(body, index++, last);

                // clear lines
                lines.clear();

                getProcessor().process(exchange);
            }
        } else if (line != null) {
            // single line
            // remember to inc index when we create an exchange
            Exchange exchange = endpoint.createExchange(line, index++, last);
            getProcessor().process(exchange);
        }

        return index;
    }
View Full Code Here

        sendTimeOutMessage("cxf://bean:springEndpoint");
    }
   
    @Test
    public void testInvokingJaxWsServerWithCxfEndpointWithConfigurer() throws Exception {
        Exchange reply = sendJaxWsMessage("cxf://bean:springEndpoint?cxfEndpointConfigurer=#myConfigurer");
        // we don't expect the exception here
        assertFalse("We don't expect the exception here", reply.isFailed());
        assertEquals("Get a wrong response", "Greet Hello World!", reply.getOut().getBody(String.class));
    }
View Full Code Here

TOP

Related Classes of org.apache.camel.Exchange

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.