You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by imranrazakhan <im...@gmail.com> on 2016/08/29 05:19:25 UTC

ERROR No message body reader has been found for class, ContentType: application/json' in CXF JAXRS - 2.17.3

HI,

I have developed Rest Service using cxfrs component in 2.17.3. GET services
are working fine but however when call POST service and error 415 (
Unsupported Media Type ) is returned. We have defined Media Type (
application/json ) 

Error Logs:

[                          main] DefaultCamelContext            INFO  Apache
Camel 2.17.3 (CamelContext: camel-1) started in 1.150 seconds
[               qtp792782299-19] JAXRSUtils                     ERROR No
message body reader has been found for class
com.warid.sns.service.subscriptionNotification, ContentType:
application/json
[               qtp792782299-19] WebApplicationExceptionMapper  WARN 
javax.ws.rs.WebApplicationException: HTTP 415 Unsupported Media Type
	at
org.apache.cxf.jaxrs.utils.JAXRSUtils.readFromMessageBody(JAXRSUtils.java:1313)
	at
org.apache.cxf.jaxrs.utils.JAXRSUtils.processParameter(JAXRSUtils.java:824)
	at
org.apache.cxf.jaxrs.utils.JAXRSUtils.processParameters(JAXRSUtils.java:787)
	at
org.apache.cxf.jaxrs.interceptor.JAXRSInInterceptor.processRequest(JAXRSInInterceptor.java:212)


Route:

from("cxfrs://http://localhost:9090/notify?resourceClasses=com.warid.sns.service.ServiceNotificationResource&bindingStyle=SimpleConsumer")
			.log( "The message body contains ${body}" )
			.log( "The message body contains ${headers}" )
			.process(new ServiceNotificationProcessor())
			.marshal().json(JsonLibrary.Jackson);

ResourceClass:

@Path("/")
public class ServiceNotificationResource {
	
	 @Context
	 private UriInfo uriInfo;
	 
	 public ServiceNotificationResource()
	 {}
	
	 @POST
	 @Path("/notifysubscription")
	 @Consumes(MediaType.APPLICATION_JSON)
	 public Response createSubscription(subscriptionNotification sn) {
		 return  Response.status(Response.Status.NO_CONTENT).build();
	 }
	 
	 @GET
	 @Path("/getSubscription")
	 @Produces(MediaType.APPLICATION_JSON)
	 public subscriptionNotification getSubscription() {
		 subscriptionNotification sn = new subscriptionNotification();
		 sn.setApplicationName("1");
		 sn.setSubscriberAddress("tel:12345678");
		 sn.setApplicationName("news");
		 sn.setOperation("sub");
		 return sn;
	 }
}

Processor:

Message inMessage = exchange.getIn();
				String operationName = inMessage.getHeader(CxfConstants.OPERATION_NAME,
String.class);
				System.out.println("operation name ==="+operationName);
			
				if ("getSubscription".equalsIgnoreCase(operationName)) {
					subscriptionNotification sn = new subscriptionNotification();
					sn.setApplicationName("1");
					sn.setSubscriberAddress("tel:12345678");
					sn.setApplicationName("news");
					sn.setOperation("sub");		
					exchange.getOut().setBody(sn);
				} else {
					
					exchange.getOut().setBody(
Response.status(Response.Status.NO_CONTENT).build() );
				}





--
View this message in context: http://camel.465427.n5.nabble.com/ERROR-No-message-body-reader-has-been-found-for-class-ContentType-application-json-in-CXF-JAXRS-2-173-tp5786940.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: ERROR No message body reader has been found for class, ContentType: application/json' in CXF JAXRS - 2.17.3

Posted by Brad Johnson <br...@mediadriver.com>.
Glad that you got it straightened out!

I've used Jackson and it worked well. I don't recall having problems with
Jettison but what the heck.

Unless I have a compelling need I usually just stick with the JAXB provider.


Brad

On Wed, Aug 31, 2016 at 3:56 AM, Sergey Beryozkin <sb...@gmail.com>
wrote:

> On 31/08/16 06:56, imranrazakhan wrote:
>
>>
>> @sergery/ranx,
>>
>> addition of jettision didn't resolve problem.
>>
> Default CXF JSONProvider is JAXB based but is optional, it is available in
> cxf-rt-rs-extensions-providers (alongside some other optional providers).
>
>>
>>
>> @cacert,
>>
>> Thanks, Your suggestion worked perfectly.
>>
>> Working with Jackson is often preferred by CXF users...
>
> Sergey
>
>>
>>
>>
>> --
>> View this message in context: http://camel.465427.n5.nabble.
>> com/ERROR-No-message-body-reader-has-been-found-for-class-
>> ContentType-application-json-in-CXF-JAXRS-2-173-tp5786940p5787019.html
>> Sent from the Camel - Users mailing list archive at Nabble.com.
>>
>>
>
> --
> Sergey Beryozkin
>
> Talend Community Coders
> http://coders.talend.com/
>

Re: ERROR No message body reader has been found for class, ContentType: application/json' in CXF JAXRS - 2.17.3

Posted by Sergey Beryozkin <sb...@gmail.com>.
On 31/08/16 06:56, imranrazakhan wrote:
>
> @sergery/ranx,
>
> addition of jettision didn't resolve problem.
Default CXF JSONProvider is JAXB based but is optional, it is available 
in cxf-rt-rs-extensions-providers (alongside some other optional 
providers).
>
>
> @cacert,
>
> Thanks, Your suggestion worked perfectly.
>
Working with Jackson is often preferred by CXF users...

Sergey
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/ERROR-No-message-body-reader-has-been-found-for-class-ContentType-application-json-in-CXF-JAXRS-2-173-tp5786940p5787019.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>


-- 
Sergey Beryozkin

Talend Community Coders
http://coders.talend.com/

Re: ERROR No message body reader has been found for class, ContentType: application/json' in CXF JAXRS - 2.17.3

Posted by imranrazakhan <im...@gmail.com>.
@sergery/ranx,

addition of jettision didn't resolve problem.


@cacert,

Thanks, Your suggestion worked perfectly. 




--
View this message in context: http://camel.465427.n5.nabble.com/ERROR-No-message-body-reader-has-been-found-for-class-ContentType-application-json-in-CXF-JAXRS-2-173-tp5786940p5787019.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: ERROR No message body reader has been found for class, ContentType: application/json' in CXF JAXRS - 2.17.3

Posted by cacert <ka...@gmail.com>.
Hi,

As far as I understand this is because of there is no default json provider
for jaxrs in cxf. (for xml messages there is jaxb as default)
I could be able to solve this issue by defining a provider for json, and
giving this definition on my rest endpoint.

in maven:

	    <dependency>
	        <groupId>org.codehaus.jackson</groupId>
	        <artifactId>jackson-jaxrs</artifactId>
	        <version>1.9.13</version>
	    </dependency>

and if you use spring boot define a bean as follows,

	@Bean
	public org.codehaus.jackson.jaxrs.JacksonJsonProvider jsonProvider(){
		JacksonJsonProvider jsonProvider = new JacksonJsonProvider();
		return jsonProvider;
	}

and then you can define your rest endpoint as follow,

private static final String REST_ENDPOINT_URI =
"cxfrs:///servlet/rest?resourceClasses=com.example.CustomerOperations&*providers=#jsonProvider
*



--
View this message in context: http://camel.465427.n5.nabble.com/ERROR-No-message-body-reader-has-been-found-for-class-ContentType-application-json-in-CXF-JAXRS-2-173-tp5786940p5787008.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: ERROR No message body reader has been found for class, ContentType: application/json' in CXF JAXRS - 2.17.3

Posted by Brad Johnson <br...@mediadriver.com>.
What Sergey suggested is what I've used in the past.  I don't recall if
that's the version with my BOM but you're using the latest version of Camel

<!-- https://mvnrepository.com/artifact/org.codehaus.jettison/jettison -->
<dependency>
    <groupId>org.codehaus.jettison</groupId>
    <artifactId>jettison</artifactId>
    <version>1.3.8</version>
</dependency>


On Tue, Aug 30, 2016 at 2:51 AM, Sergey Beryozkin <sb...@gmail.com>
wrote:

> If so - do you have a jettison dependency on the classpath ?
>
> Sergey
>
>
> On 30/08/16 05:23, imranrazakhan wrote:
>
>> HI,
>>
>> Yes it has @XmlRootElement annotation.
>>
>> Regards,
>>
>>
>>
>> --
>> View this message in context: http://camel.465427.n5.nabble.
>> com/ERROR-No-message-body-reader-has-been-found-for-class-
>> ContentType-application-json-in-CXF-JAXRS-2-173-tp5786940p5786968.html
>> Sent from the Camel - Users mailing list archive at Nabble.com.
>>
>>
>
> --
> Sergey Beryozkin
>
> Talend Community Coders
> http://coders.talend.com/
>

Re: ERROR No message body reader has been found for class, ContentType: application/json' in CXF JAXRS - 2.17.3

Posted by Sergey Beryozkin <sb...@gmail.com>.
If so - do you have a jettison dependency on the classpath ?

Sergey

On 30/08/16 05:23, imranrazakhan wrote:
> HI,
>
> Yes it has @XmlRootElement annotation.
>
> Regards,
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/ERROR-No-message-body-reader-has-been-found-for-class-ContentType-application-json-in-CXF-JAXRS-2-173-tp5786940p5786968.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>


-- 
Sergey Beryozkin

Talend Community Coders
http://coders.talend.com/

Re: ERROR No message body reader has been found for class, ContentType: application/json' in CXF JAXRS - 2.17.3

Posted by imranrazakhan <im...@gmail.com>.
HI,

Yes it has @XmlRootElement annotation.

Regards,



--
View this message in context: http://camel.465427.n5.nabble.com/ERROR-No-message-body-reader-has-been-found-for-class-ContentType-application-json-in-CXF-JAXRS-2-173-tp5786940p5786968.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: ERROR No message body reader has been found for class, ContentType: application/json' in CXF JAXRS - 2.17.3

Posted by Brad Johnson <br...@mediadriver.com>.
Does your subscriptionNotification object have the XmlRootElement
annotation? While that might seem strange it is required for the JSON
marshal/unmarshal.

By the way, why are you lower casing your class names?

Brad

On Mon, Aug 29, 2016 at 12:19 AM, imranrazakhan <im...@gmail.com>
wrote:

> HI,
>
> I have developed Rest Service using cxfrs component in 2.17.3. GET services
> are working fine but however when call POST service and error 415 (
> Unsupported Media Type ) is returned. We have defined Media Type (
> application/json )
>
> Error Logs:
>
> [                          main] DefaultCamelContext            INFO
> Apache
> Camel 2.17.3 (CamelContext: camel-1) started in 1.150 seconds
> [               qtp792782299-19] JAXRSUtils                     ERROR No
> message body reader has been found for class
> com.warid.sns.service.subscriptionNotification, ContentType:
> application/json
> [               qtp792782299-19] WebApplicationExceptionMapper  WARN
> javax.ws.rs.WebApplicationException: HTTP 415 Unsupported Media Type
>         at
> org.apache.cxf.jaxrs.utils.JAXRSUtils.readFromMessageBody(
> JAXRSUtils.java:1313)
>         at
> org.apache.cxf.jaxrs.utils.JAXRSUtils.processParameter(
> JAXRSUtils.java:824)
>         at
> org.apache.cxf.jaxrs.utils.JAXRSUtils.processParameters(
> JAXRSUtils.java:787)
>         at
> org.apache.cxf.jaxrs.interceptor.JAXRSInInterceptor.processRequest(
> JAXRSInInterceptor.java:212)
>
>
> Route:
>
> from("cxfrs://http://localhost:9090/notify?resourceClasses=com.warid.sns.
> service.ServiceNotificationResource&bindingStyle=SimpleConsumer")
>                         .log( "The message body contains ${body}" )
>                         .log( "The message body contains ${headers}" )
>                         .process(new ServiceNotificationProcessor())
>                         .marshal().json(JsonLibrary.Jackson);
>
> ResourceClass:
>
> @Path("/")
> public class ServiceNotificationResource {
>
>          @Context
>          private UriInfo uriInfo;
>
>          public ServiceNotificationResource()
>          {}
>
>          @POST
>          @Path("/notifysubscription")
>          @Consumes(MediaType.APPLICATION_JSON)
>          public Response createSubscription(subscriptionNotification sn) {
>                  return  Response.status(Response.
> Status.NO_CONTENT).build();
>          }
>
>          @GET
>          @Path("/getSubscription")
>          @Produces(MediaType.APPLICATION_JSON)
>          public subscriptionNotification getSubscription() {
>                  subscriptionNotification sn = new
> subscriptionNotification();
>                  sn.setApplicationName("1");
>                  sn.setSubscriberAddress("tel:12345678");
>                  sn.setApplicationName("news");
>                  sn.setOperation("sub");
>                  return sn;
>          }
> }
>
> Processor:
>
> Message inMessage = exchange.getIn();
>                                 String operationName = inMessage.getHeader(
> CxfConstants.OPERATION_NAME,
> String.class);
>                                 System.out.println("operation name
> ==="+operationName);
>
>                                 if ("getSubscription".equalsIgnoreCase(operationName))
> {
>                                         subscriptionNotification sn = new
> subscriptionNotification();
>                                         sn.setApplicationName("1");
>                                         sn.setSubscriberAddress("tel:
> 12345678");
>                                         sn.setApplicationName("news");
>                                         sn.setOperation("sub");
>                                         exchange.getOut().setBody(sn);
>                                 } else {
>
>                                         exchange.getOut().setBody(
> Response.status(Response.Status.NO_CONTENT).build() );
>                                 }
>
>
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.
> com/ERROR-No-message-body-reader-has-been-found-for-
> class-ContentType-application-json-in-CXF-JAXRS-2-173-tp5786940.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>