-
1. Re: Exposing REST interface using Camel and SMX
davsclaus Sep 28, 2010 12:23 AM (in response to ramesh.ramakrishnan)Is this the right approach?
Yes the message to send back to the client after step 6.
See unit tests in the camel-cxf component for the cxfrs for examples
https://svn.apache.org/repos/asf/camel/trunk/components/camel-cxf/
-
2. Re: Exposing REST interface using Camel and SMX
davsclaus Sep 28, 2010 12:26 AM (in response to davsclaus)I also created a ticket at Apache so we will add a REST based example in a future release
-
3. Re: Exposing REST interface using Camel and SMX
ramesh.ramakrishnan Sep 28, 2010 5:57 AM (in response to davsclaus)Hello Claus, thanks for your quick response. However, I still have issue as the incoming XML (or JSON) isn't getting converted in to the JAXB custom pojo.
If i do,
from("cxfrs://bean://myService").process(new Processor() {
@Override
public void process(Exchange exchange) throws Exception {
Message inMessage = exchange.getIn();
MyJaxBPojoClass myPojo= inMessage.getBody(MyJaxBPojoClass .class);
}}).convertBodyTo(MyJaxBPojoClass .class)
I get the following exception, Caused by: org.apache.camel.NoTypeConversionAvailableException: No type converter available to convert from type: java.lang.Object[] to the required type:test.package.MyJaxBPojoClass. Also, myPojo object is null.
Do I need to have custom type converter that transforms incoming generic object to custom JaxB object?
Many thanks.
-
4. Re: Exposing REST interface using Camel and SMX
davsclaus Sep 28, 2010 7:31 AM (in response to ramesh.ramakrishnan)Yeah could be.
I bet CXF-RS may store the incoming message in some CXF specific way which may not be easily converted using JAXB.
Use a Camel Processor and see what Exchange contains.
We can maybe do some improvement in CXF-RS. I think we did that for CXF-WS so it had a fallback type converter feature. Most likely CXF-RS needs something similar.
You are welcome to create a small project and ZIP it we can use as an example to improve CXF-RS. If needed.
-
5. Re: Exposing REST interface using Camel and SMX
ramesh.ramakrishnan Sep 28, 2010 12:53 PM (in response to davsclaus)Hello Claus,
Thanks for the response. If not for your response, would have spent sometime thinking that something wrong with my configuration. I did a quick workaround by creating a custom Processor and retrieved 0th element from the Object array and converted it to the JAXB object. This worked like magic
My CustomProcessor code is,
public class MyCustomProcessor implements Processor {
@Override
public void process(Exchange exchange) throws Exception {
/* Extract the incoming Object[] and get the 0th element from it.
* This 0th element should be then set to the Body of IN Message */
ObjectArray objects = (Object[]) exchange.getIn().getBody();
exchange.getIn().setBody(objects[0]); }}
Note: ObjectArray is actually array of Object. Since there arent any
markup to post, its interpreting array notation as URL.
My final route,
from("cxfrs://bean://myRESTService").process(new MyCustomProcessor())
.to("xslt:convertCustomOrderToSOAP.xsl) // Perform XSLT
.to("jbi:servce:WSDL_LOCATION?mep=In-OUT") // Call SOAP endpoint
.convertBodyTo(String.class) // transform response to String
.to("xslt:convertSOAPToCustomOrder.xsl") // Perform XSLT to get SOAP body
.convertBodyTo(CustomOrderPojo.class) // Final conversion before sending it back to caller
-
6. Re: Exposing REST interface using Camel and SMX
davsclaus Sep 29, 2010 2:53 AM (in response to ramesh.ramakrishnan)Thanks for reporting that you found a solution.
I have created a ticket to improve CXF-RS in the future so you most likely don't need your custom processor workaround