JBoss fuse camel: Error when I evaluate a body - apache-camel

I am invoking a web service from the camel, and when I try to evaluate its response, I get an error. This is the camel code:
<!-- Transformatio to the ws backend -->
<process id="_transformToValidaAccesoUsuario" ref="transformToValidaAccesoUsuario"/>
<!-- Invoke the ws -->
<to id="invokeAutenticaSesion" uri="cxf:bean:autenticaSesionProxy?defaultOperationName=validarAccesoUsuario"/>
<!-- Validate the response -->
<choice id="validacionAutenticaUsuario">
<when id="validacionUsuarioOK">
<simple>${body.getResponseStatus.getDescripcionRespuesta} == 'OK'</simple>
<log id="logValidacionUsuario" message="validacionUsuario correcto"/>
</when>
<otherwise id="validacionUsuarioError">
<log id="logValidacionUsuario2" message="validacionUsuario incorrecto"/>
</otherwise>
</choice>
I have this error when I run the service:
<faultstring>Failed to invoke method: getResponseStatus on null due to: org.apache.camel.component.bean.MethodNotFoundException: Method with name: getResponseStatus not found on bean: [pe.gob.sis.esb.negocio.consultaafiliados.proxy.autenticasesion.ValidarAccesoUsuarioResponseType#f482049] of type: org.apache.cxf.message.MessageContentsList. Exchange[]</faultstring>
Edit:
The class already has the method getResponseStatus()
package pe.gob.sis.esb.negocio.consultaafiliados.proxy.autenticasesion;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlType;
#XmlAccessorType(XmlAccessType.FIELD)
#XmlType(name = "ValidarAccesoUsuarioResponseType", namespace = "http://sis.gob.pe/esb/tecnico/autenticaSesion/messages/validarAccesoUsuario/v1/", propOrder = {
"responseStatus",
"login"
})
public class ValidarAccesoUsuarioResponseType {
protected ResponseStatus responseStatus;
protected Login login;
public ResponseStatus getResponseStatus() {
return responseStatus;
}
public void setResponseStatus(ResponseStatus value) {
this.responseStatus = value;
}
public Login getLogin() {
return login;
}
public void setLogin(Login value) {
this.login = value;
}
}

Ah its maybe the crappy MessageContentsList from camel-cxf / CXF. Its a design fault in camel-cxf I think. So what you can do is to convert the message body to not include that, by
<setBody><simple>${body[0]}</simple></setBody>
Which will take the first element from that MessageContentsList and store that as the message body, which will be that POJO class.
It depends a bit how you configure camel-cxf / CXF and what is stored as the message body. But the MessageContentsList is a smell.

Related

How to map the response for the REST request by Apache camel HTTP component

I have implemented following route with Apache camel XML mode.
<restConfiguration component="servlet" bindingMode="json" contextPath="/abc-esb/rest" port="8181">
<dataFormatProperty key="prettyPrint" value="true" />
<dataFormatProperty key="json.in.disableFeatures" value="FAIL_ON_EMPTY_BEANS,FAIL_ON_UNKNOWN_PROPERTIES" />
</restConfiguration>
<rest path="/service-http" consumes="application/json" produces="application/json">
<put type="com.abc.abcd.esb.models.UserServiceMapping" uri="/create">
<route>
<setHeader headerName="Authorization">
<simple>Basic YWRtaW46YWRtaW4=</simple>
</setHeader>
<setHeader headerName="CamelHttpMethod">
<constant>POST</constant>
</setHeader>
<setBody>
<simple>
{"SystemUserDetails":{"userName":"${body.objectDetails.userName}",
"password": "${body.objectDetails.password}"}}
</simple>
</setBody>
<to uri="http://192.168.1.20:8081/abcd/services/UserServiceRest/V1.0/users/create?bridgeEndpoint=true" />
</route>
</put>
</rest>
Functionality happens as expected. But camel returns HTTP 500 mentioning following error.
com.fasterxml.jackson.databind.JsonMappingException: No serializer
found for class
org.apache.camel.converter.stream.CachedOutputStream$WrappedInputStream
and no properties discovered to create BeanSerializer (to avoid
exception, disable SerializationFeature.FAIL_ON_EMPTY_BEANS) ) at
com.fasterxml.jackson.databind.ser.impl.UnknownSerializer.failForEmpty(UnknownSerializer.java:69)
at
com.fasterxml.jackson.databind.ser.impl.UnknownSerializer.serialize(UnknownSerializer.java:32)
at
com.fasterxml.jackson.databind.ser.DefaultSerializerProvider.serializeValue(DefaultSerializerProvider.java:130)
When I analyze a tcp dump related to this scenario, I found this HTTP 500 occurred when trying to mapping the {"status" : "Success"} response from the external webservice.
Content of the UserServiceMapping class
private String serviceName;
private String serviceMethod;
private String mappedServiceObject;
private SystemUserDetails objectDetails;
// private StatusDetails statusDetails;
public String getMappedServiceObject() {
return mappedServiceObject;
}
public void setMappedServiceObject(String mappedServiceObject) {
this.mappedServiceObject = mappedServiceObject;
}
public String getServiceName() {
return serviceName;
}
public void setServiceName(String serviceName) {
this.serviceName = serviceName;
}
public String getServiceMethod() {
return serviceMethod;
}
public void setServiceMethod(String serviceMethod) {
this.serviceMethod = serviceMethod;
}
public SystemUserDetails getObjectDetails() {
return objectDetails;
}
public void setObjectDetails(SystemUserDetails objectDetails) {
this.objectDetails = objectDetails;
}
/*
* public StatusDetails getStatusDetails() { return statusDetails; }
*
* public void setStatusDetails(StatusDetails statusDetails) {
* this.statusDetails = statusDetails; }
*/
Request response flow of the scenario
How ever up to now I couldn't find an exact reason for this issue but I could by-pass the problem by setting Accept: application/xml other than Accept: application/json in my external REST client which makes the initial REST request. (REST service endpoint in other end configured to produce both json and xml)

Best way to write a Camel Test on a Content Based Routing

I'm a bit stuck on how to proceed in writing a Simple Camel Test case for a CBR. Say I have this simple route:
<route id="_route1">
<from id="_to1" uri="file:/home/user/data/eip-demo/in?noop=true"/>
<choice id="_choice1">
<when id="_when1">
<simple>${header.CamelFileName} regex '^.*xml$'</simple>
<to id="_to2" uri="file:/home/user/data/eip-demo/xml"/>
</when>
<when id="_when2">
<simple>${header.CamelFileName} regex '^.*txt$'</simple>
<to id="_to3" uri="file:/home/user/data/eip-demo/txt"/>
</when>
<otherwise id="_otherwise1">
<log id="_log1" message="File unknown!"/>
<to id="_to2" uri="file:/tmp"/>
</otherwise>
</choice>
</route>
What is the most correct way to test this route? I think I could replace the file: component with a direct: component and Produce the files in the Test Case. However, then I will not be able to run the route directly from the IDE (Jboss Developer Studio). What is the most correct approach to coding a route like that which needs to be tested?
UPDATE: I've refined a bit the Camel Test created by JBoss Developer Studio:
public class CamelContextXmlTest extends CamelSpringTestSupport {
// TODO Create test message bodies that work for the route(s) being tested
// Expected message bodies
protected Object[] expectedBodies = { "<something id='1'>expectedBody1</something>",
"textfile" };
protected Object[] name = { "test.xml",
"test.txt" };
// Templates to send to input endpoints
#Produce(uri = "file:/home/data/eip-demo/in?noop=true")
protected ProducerTemplate inputEndpoint;
// Mock endpoints used to consume messages from the output endpoints and then perform assertions
#EndpointInject(uri = "mock:output")
protected MockEndpoint outputEndpoint;
#EndpointInject(uri = "mock:output2")
protected MockEndpoint output2Endpoint;
#EndpointInject(uri = "mock:output3")
protected MockEndpoint output3Endpoint;
#Test
public void testCamelRoute() throws Exception {
// Create routes from the output endpoints to our mock endpoints so we can assert expectations
context.addRoutes(new RouteBuilder() {
#Override
public void configure() throws Exception {
from("file:/home/user/data/eip-demo/xml").to(outputEndpoint);
from("file:/home/user/data/eip-demo/txt").to(output2Endpoint);
}
});
// Define some expectations
// TODO Ensure expectations make sense for the route(s) we're testing
//outputEndpoint.expectedBodiesReceivedInAnyOrder(expectedBodies);
// Send some messages to input endpoints
int index=0;
for (Object expectedBody : expectedBodies) {
inputEndpoint.sendBodyAndHeader(expectedBody,"CamelFileName",name[index]);
index++;
}
outputEndpoint.expectedMessageCount(1);
output2Endpoint.expectedMessageCount(1);
// Validate our expectations
assertMockEndpointsSatisfied();
}
#Override
protected ClassPathXmlApplicationContext createApplicationContext() {
return new ClassPathXmlApplicationContext("META-INF/spring/camel-context.xml");
}
}
Is it a good solution or can it be improved?
What you need here is AdviseWith:
http://camel.apache.org/advicewith.html
You simply need to replace/modify your endpoints on the fly OR simply add a mock on the fly after each condition of your CBR. If you couldn't do it, let me know and I will help with with some actual code that does this job for you.
R.

get exchange related properties like ExchangePattern ID and BodyType in message

I'm new to Camel. I'm trying to read a file from one location, making some change in the file content and sending the file to another location. I trying to get exchange related information added in the file like the following:
Exchange[ExchangePattern: InOnly, BodyType: String, Body:
Test Message from custom processor:
Text from input file.
First line in the above sample is not coming. So far I wrote the following code:
applicationContext.xml:
<bean id="customProcessor" class="com.javacodegeeks.camel.CustomProcessor"/>
<camelContext xmlns="http://camel.apache.org/schema/spring">
<route>
<from uri="file:C:\\inputdir\\" />
<process ref="customProcessor"/>
<to uri="file:C:\\outputdir\\" />
</route>
CustomProcessor.java:
public class CustomProcessor implements Processor {
public void process(Exchange exchange) throws Exception {
String msgBody = exchange.getIn().getBody(String.class);
exchange.getIn().setBody("Test Message from custom processor: " + msgBody);
}
}
Main class:
public static final void main(String[] args) throws Exception {
ApplicationContext appContext = new ClassPathXmlApplicationContext(
"applicationContext.xml");
CamelContext camelContext = SpringCamelContext.springCamelContext(
appContext, false);
try {
camelContext.start();
Thread.sleep(200000);
} finally {
camelContext.stop();
}
}
You can access all the properties of Camel Exchange using Exchanges' method getProperties() i.e. exchange.getProperties() which return Map, so using this you can get the information and save it into the file using your CustomProcessor Camel processor.
For more information have a look on:
http://camel.apache.org/maven/current/camel-core/apidocs/org/apache/camel/Exchange.html

How do I properly use Mocks when testing Camel routes?

I am trying to write a Camel test that checks to ensure a content based router is routing XML files correctly. Here are the enpoints and the route in my blueprint.xml:
<endpoint uri="activemq:queue:INPUTQUEUE" id="jms.queue.input" />
<endpoint uri="activemq:queue:QUEUE1" id="jms.queue.1" />
<endpoint uri="activemq:queue:QUEUE2" id="jms.queue.2" />
<route id="general-jms.to.specific-jms">
<from ref="jms.queue.input" />
<choice>
<when>
<xpath>//object-type = '1'</xpath>
<log message="Sending message to queue: QUEUE1" />
<to ref="jms.queue.1" />
</when>
<when>
<xpath>//object-type = '2'</xpath>
<log message="Sending message to queue: QUEUE2" />
<to ref="jms.queue.2" />
</when>
<otherwise>
<log message="No output was able to be determined based on the input." />
</otherwise>
</choice>
</route>
Right now, all I am trying to do is send in a sample source file that has an <object-type> of 1 and verify that is it routed to the correct queue (QUEUE1) and is the correct data (should just send the entire XML file to QUEUE1). Here is my test code:
public class RouteTest extends CamelBlueprintTestSupport {
#Override
protected String getBlueprintDescriptor() {
return "/OSGI-INF/blueprint/blueprint.xml";
}
#Override
public String isMockEndpointsAndSkip() {
return "activemq:queue:QUEUE1";
}
#Test
public void testQueue1Route() throws Exception {
getMockEndpoint("mock:activemq:queue:QUEUE1").expectedBodiesReceived(context.getTypeConverter().convertTo(String.class, new File("src/test/resources/queue1-test.xml")));
template.sendBody("activemq:queue:INPUTQUEUE", context.getTypeConverter().convertTo(String.class, new File("src/test/resources/queue1-test.xml")));
assertMockEndpointsSatisfied();
}
}
When I run this test, I see the log message that I put in the route definition that says it is sending it to QUEUE1, but the JUnit test fails with this error message: java.lang.AssertionError: mock://activemq:queue:QUEUE1 Received message count. Expected: <1> but was: <0>.
Can someone help me understand what I am doing wrong?
My understanding is that Camel will automatically mock the QUEUE1 endpoint since I overrode the isMockEndpointsAndSkip() and provided the QUEUE1 endpoint uri. I thought this meant I should be able to use that endpoint in the getMockEnpoint() method just by appending "mock:" to the beginning of the uri. Then I should have a mocked endpoint of which I can set expections on (i.e. that is has to have the input file).
If I am unclear on something please let me know and any help is greatly appreciated!
The solution is to use CamelTestSupport.replaceRouteFromWith.
This method is completely lacking any documentation, but it works for me when invoking it like this:
public class FooTest extends CamelTestSupport {
#Override
public void setUp() throws Exception {
replaceRouteFromWith("route-id", "direct:route-input-replaced");
super.setUp();
}
// other stuff ...
}
This will also prevent the starting of the original consumer of the from destination of the route. For example that means it isn't necessary anymore to have a activemq instance running when a route with an activemq consumer is to be tested.
After working on this for quite some time, the only solution I came up with that actaully worked for me was to use the createRouteBuilder() method in my test class to add a route to a mocked endpoint at the end of the route defined in my blueprint.xml file. Then I can check that mocked endpoint for my expectations. Below is my final code for the test class. The blueprint XML remained the same.
public class RouteTest extends CamelBlueprintTestSupport {
#Override
protected String getBlueprintDescriptor() {
return "/OSGI-INF/blueprint/blueprint.xml";
}
#Test
public void testQueue1Route() throws Exception {
getMockEndpoint("mock:QUEUE1").expectedBodiesReceived(context.getTypeConverter().convertTo(String.class, new File("src/test/resources/queue1-test.xml")));
template.sendBody("activemq:queue:INPUTQUEUE", context.getTypeConverter().convertTo(String.class, new File("src/test/resources/queue1-test.xml")));
assertMockEndpointsSatisfied();
}
#Test
public void testQueue2Route() throws Exception {
getMockEndpoint("mock:QUEUE2").expectedBodiesReceived(context.getTypeConverter().convertTo(String.class, new File("src/test/resources/queue2-test.xml")));
template.sendBody("activemq:queue:INPUTQUEUE", context.getTypeConverter().convertTo(String.class, new File("src/test/resources/queue2-test.xml")));
assertMockEndpointsSatisfied();
}
#Override
protected RouteBuilder createRouteBuilder() throws Exception {
return new RouteBuilder() {
public void configure() throws Exception {
from("activemq:queue:QUEUE1").to("mock:QUEUE1");
from("activemq:queue:QUEUE2").to("mock:QUEUE2");
}
};
}
}
While this solution works, I don't fully understand why I can't just use isMockEndpointsAndSkip() instead of having to manually define a new route at the end of my existing blueprint.xml route. It is my understanding that defining isMockEndpointsAndSkip() with return "*"; will inject mocked endpoints for all of your endpoints defined in your blueprint.xml file. Then you can check for your expections on those mocked endpoints. But for some reason, this does not work for me.

Can anyone point me to a working example Camel route using a cxfrs client/producer?

I am having trouble getting my Camel route to successfully POST a message to an existing RESTful web service. I have tried all the examples in the camel cxf package but none of them produce a web service call (they are consumers). I would love to find a working example for this so I can step through the CxfRsProducer execution to hopefully discover why my route is not posting correctly to the web service.
Here is my RouteBuilder's configuration:
public void configure()
{
//errorHandler(deadLetterChannel(String.format("file:%s/../errors", sourceFolder)).useOriginalMessage().retriesExhaustedLogLevel(LoggingLevel.DEBUG));
errorHandler(loggingErrorHandler());
/*
* JMS to WS route for some of the events broadcast to the jms topic
*/
Endpoint eventTopic = getContext().getEndpoint(String.format("activemq:topic:%s?clientId=%s&durableSubscriptionName=%s", eventTopicName, durableClientId, durableSubscriptionName));
from(eventTopic) // listening on the jms topic
.process(eventProcessor) // translate event into a Notifications object (JAX-RS annotated class)
.choice() // gracefully end the route if there is no translator for the event type
.when(header("hasTranslator").isEqualTo(false)).stop() // no translator stops the route
.otherwise() // send the notification to the web service
.to("cxfrs:bean:rsClient");
}
Here is the rsClientBean:
<cxf:rsClient id="rsClient"
address="http://localhost/ws"
serviceClass="com.foo.notifications.NotificationsResource"
loggingFeatureEnabled="true" />
I'm pretty new to REST and I don't really understand what the serviceClass does for the rsClient because it looks to me like the definition of the exposed web service on the server.
The NotificationsResource class:
#Path("/notifications/")
public class NotificationManagerResource
{
// NOTE: The instance member variables will not be available to the
// Camel Exchange. They must be used as method parameters for them to
// be made available
#Context
private UriInfo uriInfo;
public NotificationManagerResource()
{
}
#POST
public Response postNotification(Notifications notifications)
{
return null;
}
}
The processor creates a Notifications object to put in the exechange message body:
private class EventProcessor implements Processor
{
#Override
public void process(Exchange exchange) throws Exception
{
Message in = exchange.getIn();
IEvent event = (IEvent) in.getBody();
Notifications notifications = null;
in.setHeader("hasTranslator", false);
in.setHeader("Content-Type", "application/xml");
in.setHeader(CxfConstants.CAMEL_CXF_RS_USING_HTTP_API, false);
// I've tried using the HTTP API as 'true', and that results in a 405 error instead of the null ptr.
INotificationTranslator translator = findTranslator(event);
if (translator != null)
{
notifications = translator.build(event);
in.setHeader("hasTranslator", true);
}
// replace the IEvent in the body with the translation
in.setBody(notifications);
exchange.setOut(in);
}
}
The Notifications class is annotated with JAXB for serialization
#XmlRootElement(name = "ArrayOfnotification")
#XmlType
public class Notifications
{
private List<Notification> notifications = new ArrayList<>();
#XmlElement(name="notification")
public List<Notification> getNotifications()
{
return notifications;
}
public void setNotifications(List<Notification> notifications)
{
this.notifications = notifications;
}
public void addNotification(Notification notification)
{
this.notifications.add(notification);
}
}
The error that is returned from the web service:
Exchange
---------------------------------------------------------------------------------------------------------------------------------------
Exchange[
Id ID-PWY-EHANSEN-01-62376-1407805689371-0-50
ExchangePattern InOnly
Headers {breadcrumbId=ID:EHANSEN-01-62388-1407805714469-3:1:1:1:47, CamelCxfRsUsingHttpAPI=false, CamelRedelivered=false, CamelRedeliveryCounter=0, Content-Type=application/xml, hasTranslator=true, JMSCorrelationID=null, JMSDeliveryMode=2, JMSDestination=topic://SysManEvents, JMSExpiration=1407805812574, JMSMessageID=ID:EHANSEN-01-62388-1407805714469-3:1:1:1:47, JMSPriority=4, JMSRedelivered=false, JMSReplyTo=null, JMSTimestamp=1407805782574, JMSType=null, JMSXGroupID=null, JMSXUserID=null}
BodyType com.ehansen.notification.types.v2.Notifications
Body <?xml version="1.0" encoding="UTF-8"?><ArrayOfnotification xmlns="http://schemas.datacontract.org/2004/07/ehansen.Notifications.Dto"> <notification> <causeType>EVENT_NAME</causeType> <causeValue>DeviceEvent</causeValue> <details> <notificationDetail> <name>BUSY</name> <value>false</value> <unit>boolean</unit> </notificationDetail> <notificationDetail> <name>DESCRIPTION</name> <value>Software Computer UPS Unit</value> <unit>name</unit> </notificationDetail> <notificationDetail> <name>DEVICE_NUMBER</name> <value>1</value> <unit>number</unit> </notificationDetail> <notificationDetail> <name>DEVICE_SUB_TYPE</name> <value>1</value> <unit>type</unit> </notificationDetail> <notificationDetail> <name>DEVICE_TYPE</name> <value>UPS</value> <unit>type</unit> </notificationDetail> <notificationDetail> <name>FAULTED</name> <value>false</value> <unit>boolean</unit> </notificationDetail> <notificationDetail> <name>RESPONDING</name> <value>true</value> <unit>boolean</unit> </notificationDetail> <notificationDetail> <name>STORAGE_UNIT_NUMBER</name> <value>1</value> <unit>number</unit> </notificationDetail> </details> <sourceType>DEVICE_ID</sourceType> <sourceValue>1:UPS:1</sourceValue> <time>2014-08-11T18:09:42.571-07:00</time> </notification></ArrayOfnotification>
]
Stacktrace
---------------------------------------------------------------------------------------------------------------------------------------
java.lang.NullPointerException
at java.lang.Class.searchMethods(Class.java:2670)
at java.lang.Class.getMethod0(Class.java:2694)
at java.lang.Class.getMethod(Class.java:1622)
at org.apache.camel.component.cxf.jaxrs.CxfRsProducer.findRightMethod(CxfRsProducer.java:266)
at org.apache.camel.component.cxf.jaxrs.CxfRsProducer.invokeProxyClient(CxfRsProducer.java:222)
at org.apache.camel.component.cxf.jaxrs.CxfRsProducer.process(CxfRsProducer.java:90)
at org.apache.camel.util.AsyncProcessorConverterHelper$ProcessorToAsyncProcessorBridge.process(AsyncProcessorConverterHelper.java:61)
at org.apache.camel.processor.SendProcessor$2.doInAsyncProducer(SendProcessor.java:143)
at org.apache.camel.impl.ProducerCache.doInAsyncProducer(ProducerCache.java:307)
at org.apache.camel.processor.SendProcessor.process(SendProcessor.java:138)
It is the methodName parameter in the following method from CxfRsProducer class that is null... so I assume there is something about my rsClient that is not configured correctly.
private Method findRightMethod(List<Class<?>> resourceClasses, String methodName, Class<?>[] parameterTypes) throws NoSuchMethodException {
Method answer = null;
for (Class<?> clazz : resourceClasses) {
try {
answer = clazz.getMethod(methodName, parameterTypes);
} catch (NoSuchMethodException ex) {
// keep looking
} catch (SecurityException ex) {
// keep looking
}
if (answer != null) {
return answer;
}
}
throw new NoSuchMethodException("Cannot find method with name: " + methodName + " having parameters: " + arrayToString(parameterTypes));
}
Thanks for any help anyone can provide!
The serviceClass is a JAX-RS annotated Java class that defines the operations of a REST web service.
When configuring a CXF REST client, you must specify and address and a serviceClass. By inspecting the annotations found on the serviceClass, the CXF client proxy knows which REST operations are supposed to be available on the REST service published on the specified address.
So in your case, you need to add in.setHeader.setHeader(CxfConstants.OPERATION_NAME, "postNotification"); to the EventProcessor to tell camel which method of the service class you want to call.
Alright then. Here is the camel configuration xml file.
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://w3.org/2001/XMLSchema-instance"
xmlns:cxf="http://camel.apache.org/schema/cxf"
xmlns:jaxrs="http://cxf.apache.org/jaxrs"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://camel.apache.org/schema/cxf
http://camel.apache.org/schema/cxf/camel-cxf.xsd
http://cxf.apache.org/jaxrs
http://cxf.apache.org/schemas/jaxrs.xsd
http://camel.apache.org/schema/spring
http://camel.apache.org/schema/spring/camel-spring.xsd
>
<import resource="classpath:META-INF/cxf/cxf.xml" />
<import resource="classpath:META-INF/cxf/cxf-servlet.xml" />
<bean id="helloBean" class="com.examples.camel.cxf.rest.resource.HelloWorldResource" />
<cxf:rsServer id="helloServer" address="/helloapp" loggingFeatureEnabled="true">
<cxf:serviceBeans>
<ref bean="helloBean" />
</cxf:serviceBeans>
<cxf:providers>
<bean class="org.codehaus.jackson.jaxrs.JacksonJsonProvider" />
</cxf:providers>
</cxf:rsServer>
<camelContext id="context" xmlns="http://camel.apache.org/schema/spring">
<route>
<from uri="cxfrs:bean:helloServer />
<log message="Processing CXF route....http method ${header.CamelHttpMethod}" />
<log message="Processing CXF route....path is ${header.CamelHttpPath}" />
<log message="Processing CXF route....body is ${body}" />
<choice>
<when>
<simple>${header.operationName} == 'sayHello'</simple>
<to uri="direct:invokeSayHello" />
</when>
<when>
<simple>${header.operationName} == 'greet'</simple>
<to uri="direct:invokeGreet" />
</when>
</choice>
</route>
<route id="invokeSayHello">
<from uri="direct:invokeSayHello" />
<bean ref="helloBean" method="sayHello" />
</route>
<route id="invokeGreet">
<from uri="direct:invokeGreet" />
<bean ref="helloBean" method="greet" />
</route>
</camelContext>
</beans>
The actual resource implementation class looks like below.
package com.examples.camel.cxf.rest.resource;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status;
public class HelloWorldResource implements HelloWorldIntf
{
public Response greet() {
return Response.status(Status.OK).
entity("Hi There!!").
build();
}
public Response sayHello(String input) {
Hello hello = new Hello();
hello.setHello("Hello");
hello.setName("Default User");
if(input != null)
hello.setName(input);
return Response.
status(Status.OK).
entity(hello).
build();
}
}
class Hello {
private String hello;
private String name;
public String getHello() { return hello; }
public void setHello(String hello) { this.hello = hello; }
public String getName() { return name; }
public void setName(String name) { this.name = name; }
}
You don't need , and cxf:rsServer> to be provided.
The tag alone will suffice to handle a web service request and invoke a route.
In case you have both and the then invoking the former will not help you in executing a route. For a route to get invoked, the request must reach to the address published by .
Hope this helps.

Resources