0

I am trying to integrate CXF restful web services with Apache Camel. I am getting the following exception when I send a request to my web service:

Caused by: org.apache.camel.NoTypeConversionAvailableException: No type converter available to convert from type: org.apache.cxf.message.MessageContentsList to the required type: java.io.InputStream with value [null]
    at org.apache.camel.impl.converter.BaseTypeConverterRegistry.mandatoryConvertTo(BaseTypeConverterRegistry.java:147)
    at org.apache.camel.impl.MessageSupport.getMandatoryBody(MessageSupport.java:100)
    ... 68 more

I am pasting a section of my config xml for review:

<jaxrs:server id="restContainer" address="/" staticSubresourceResolution="true">

<jaxrs:serviceBeans>
    <ref bean="FooBar"/>
</jaxrs:serviceBeans>

<jaxrs:providers>
    <bean class="org.apache.cxf.jaxrs.provider.JSONProvider">
    <property name="dropRootElement" value="true"/>
    <property name="supportUnwrapped" value="true"/>
</jaxrs:providers>

<camelcxf:rsServer id="rsServer" address="http://localhost:port/MyApplication/rest/foobar" serviceClass="com.camel.example.FooBar"/>

<camel:camelContext id="camelContext-1">
    <camel:route>
        <camel:from uri="cxfrs:bean:rsServer"/>
        <camel:to uri="http://www.google.com"/>
    </camel:route>
</camel:camelContext> 
Pavel
  • 4,912
  • 7
  • 49
  • 69
Sikorski
  • 2,653
  • 3
  • 25
  • 46
  • Try adding this in your spring config somewhere. – Petter Nordlander Apr 21 '12 at 20:42
  • I already have this in myconfig xml – Sikorski Apr 22 '12 at 06:08
  • What version of Camel and CXF are you using? It seems the message from CXF is empty (null) and thus a type conversion fails. What do you post to your RS service? – Claus Ibsen Apr 22 '12 at 06:45
  • Camel version -2.9.0 CXF version 2.5.2.. this is null because i didnt posted anything to my server. ideally i need to post a json to my server which should be converted to a POJO automatically(This happened when i had only cxf not camel in my configuration). now if i post json it gives my the same error except for the null it shows the POJO name. Also please tell me when i hit my server with a simple rest url, what actually is being hit.. jaxrs:server tag or camelcxf:server tag?? – Sikorski Apr 23 '12 at 04:47
  • Also there is a problem when i am hiting my server by get method lets say i have server service class Demo which is mapped to the url "http://localhost:8080/MyProject/rest/demo" and it takes a username (String) as get parameter... so when i hit this with url :http://localhost:8080/MyProject/rest/demo?username=Sikorski it gives me following error: java.lang.IllegalArgumentException: Invalid uri: /MyProject/rest/demo/demo. If you are forwarding/bridging http endpoints, then enable the bridgeEndpoint option on the endpoint "\\{http://www.google.com}"... – Sikorski Apr 23 '12 at 06:05
  • resolved the issue with GET method,added a convertbodyto tag and some processing with CamelHttpUri etc. But when i Post JSON to server then getting the same exception: org.apache.camel.InvalidPayloadException: No body available of type: java.io.InputStream but has value: com.camel.model.PoiDetailsRequest@229b4 of type: com.camel.model.PoiDetailsRequest on: Message: com.camel.model.PoiDetailsRequest@229b4. Caused by: No type converter available to convert from type: com.camel.model.PoiDetailsRequest to the required type: java.io.InputStream with value com.camel.model.PoiDetailsRequest@229b4. – Sikorski Apr 23 '12 at 10:32

1 Answers1

2

solved all the errors.. actually the problem was not when my cxf server was getting hit, it comes out to be when the exchange was in the "to" part... i had to add a processor in between from and to and override all the CamelHttpUri , CamelHttpMethod etc .... to make it work.

<camelcxf:rsServer id="rsServer" address="http://localhost:port/MyApplication/rest/foobar serviceClass="com.camel.example.FooBar" />  <camel:camelContext id="camelContext-1">  <camel:route>  
<camel:from uri="cxfrs:bean:rsServer" />  
<camel:process ref="customInProcessor" />
<camel:to uri="http://www.google.com" /> 
 </camel:route>
  </camel:camelContext> 

<bean id="customInProcessor" class="com.camel.MyInProcessor" />
Sikorski
  • 2,653
  • 3
  • 25
  • 46