|
CXF has been edited by willem jiang (May 23, 2008). Change summary: Added the discription of how to propagate camel-cxf endpoint's request and response context CXF ComponentThe cxf: component provides integration with Apache CXF Maven users will need to add the following dependency to their pom.xml for this component: <dependency> <groupId>org.apache.camel</groupId> <artifactId>camel-cxf</artifactId> <version>x.x.x</version> <!-- use the same version as your Camel core version --> </dependency>
The serviceName and portName are QNames The descriptions of the dataformats
Configure the CXF endpoints with springYou can configure the CXF endpoint with the below spring configuration file, and you can also embed the endpoint into the camelContext tags. <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:cxf="http://activemq.apache.org/camel/schema/cxfEndpoint" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd http://activemq.apache.org/camel/schema/cxfEndpoint http://activemq.apache.org/camel/schema/cxf/cxfEndpoint.xsd http://activemq.apache.org/camel/schema/spring http://activemq.apache.org/camel/schema/spring/camel-spring.xsd "> <cxf:cxfEndpoint id="routerEndpoint" address="http://localhost:9003/CamelContext/RouterPort" serviceClass="org.apache.hello_world_soap_http.GreeterImpl"/> <cxf:cxfEndpoint id="serviceEndpoint" address="http://localhost:9000/SoapContext/SoapPort" wsdlURL="testutils/hello_world.wsdl" serviceClass="org.apache.hello_world_soap_http.Greeter" endpointName="s:SoapPort" serviceName="s:SOAPService" xmlns:s="http://apache.org/hello_world_soap_http" /> <camelContext id="camel" xmlns="http://activemq.apache.org/camel/schema/spring"> <route> <from uri="cxf:bean:routerEndpoint" /> <to uri="cxf:bean:serviceEndpoint" /> </route> </camelContext> </beans> Be sure to include the JAX-WS schemaLocation attribute specified on the root beans element. This allows CXF to validate the file and is required. Also note the namespace declarations at the end of the <cxf:cxfEndpoint/> tag--these are required because the combined "{namespace}localName" syntax is presently not supported for this tag's attribute values. The jaxws:endpoint element supports many additional attributes:
It also supports many child elements:
You can find more advanced examples which show how to provide interceptors and properties here: How to consume the message from the camel-cxf endpoint in POJO data formatThe camel-cxf endpoint consumer POJO data format is based on the cxf invoker 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 formatThe camel-cxf endpoint producer is based on the cxf client API 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]); How to propagate camel-cxf endpoint's request and response contextcxf client API 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); // Set the request context to the inMessage Map<String, Object> requestContext = new HashMap<String, Object>(); requestContext.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, JAXWS_SERVER_ADDRESS); exchange.getIn().setBody(params); exchange.getIn().setHeader(Client.REQUEST_CONTEXT , requestContext); 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]); // Get the response context form outMessage Map<String, Object> responseContext = CastUtils.cast((Map)out.getHeader(Client.RESPONSE_CONTEXT)); assertNotNull(responseContext); assertEquals("Get the wrong wsdl opertion name", "{http://apache.org/hello_world_soap_http}greetMe", responseContext.get("javax.xml.ws.wsdl.operation").toString()); See Also |
Unsubscribe or edit your notifications preferences
