Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Added the document to show how to consume and prepare message for the camel-cxf endpoint

...

You can find more advanced examples which show how to provide interceptors and properties here: http://cwiki.apache.org/CXF20DOC/jax-ws-configuration.html

How to consume the message from the camel-cxf endpoint in POJO data format

The camel-cxf endpoint consumer POJO data format is based on the cxf invoker, so the message header has a property with the name of CxfConstants.OPERATION_NAME and the message body is a list of the SEI method parameters.

Code Block
java
java

               from(SIMPLE_ENDPOINT_URI).process(new Processor() {
                    public void process(final Exchange exchange) {
                        Message request = exchange.getIn();
                        // Get the parameter list
                        List parameter = in.getBody(List.class);
                        // Get the operation name
                        String operation = (String)in.getHeader(CxfConstants.OPERATION_NAME);
                        Object result = null;
                        if (operation.equals(ECHO_OPERATION)) {
                            result = operation + " " + (String)parameter.get(0);
                        }                        
                        // Put the result back
                        exchange.getOut().setBody(result);
                    }
                });

How to prepare the message for the camel-cxf endpoint in POJO data format

The camel-cxf endpoint producer is based on the cxf client API. First you need to specify the operation name in the message header , then add the method parameters into a list and set the message with this parameter list will be ok. The response message's body is an object array, you can get the result from that array.

Code Block
java
java

        CxfExchange exchange = (CxfExchange)template.send(getJaxwsEndpointUri(), new Processor() {
            public void process(final Exchange exchange) {
                final List<String> params = new ArrayList<String>();
                params.add(TEST_MESSAGE);
                exchange.getIn().setBody(params);
                exchange.getIn().setHeader(CxfConstants.OPERATION_NAME, GREET_ME_OPERATION);
            }
        });

        org.apache.camel.Message out = exchange.getOut();
        Object[] output = (Object[])out.getBody();
        LOG.info("Received output text: " + output[0]);
        assertEquals("reply body on Camel", "Hello " + TEST_MESSAGE, output[0]);
Include Page
CAMEL:Endpoint See Also
CAMEL:Endpoint See Also