You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomee.apache.org by andyay <cs...@hotmail.com> on 2012/09/20 23:55:30 UTC

Simple MessageBodyWriter Testing with "No message body writer has been found for response class" error.

I just setup a simple test project to see how to implement MessageBodyWriter.
But I keep getting "No message body writer has been found for response class
Customer" error.

Can someone give me some help ?

These are what I have:

1. properties file
openejb.cxf.jax-rs.providers = com.mycompany.MyMessageBodyWriter
com.mycompany.Customer.providers = com.mycompany.MyMessageBodyWriter
openejb.jaxrs.providers.auto = true

2. Provider
package com.mycompany;
...
@Produces("my/type")
@Provider
public class MyMessageBodyWriter implements MessageBodyWriter<Customer> {
    @Override
    public long getSize(Customer obj, Class<?> type, Type genericType,
            Annotation[] annotations, MediaType mediaType) {    	
        return -1;
    }

    @Override
    public boolean isWriteable(Class<?> type, Type genericType,
            Annotation annotations[], MediaType mediaType) {
        return true;
    }

    @Override
    public void writeTo(Customer target, Class<?> type, Type genericType,
            Annotation[] annotations, MediaType mediaType,
            MultivaluedMap<String,Object> httpHeaders, OutputStream
outputStream)
            throws IOException {  
        outputStream.write("Test".getBytes());
        outputStream.flush();
    }
}

3. Rest service
@Path("/pojo3")
public class Test3 {
	 @GET
	 @Produces("my/type")
	    public Customer pojo3() {
		    Customer c = new Customer();
		   ...
		    return c;
	    }
}



--
View this message in context: http://openejb.979440.n4.nabble.com/Simple-MessageBodyWriter-Testing-with-No-message-body-writer-has-been-found-for-response-class-error-tp4657558.html
Sent from the OpenEJB User mailing list archive at Nabble.com.

Re: Simple MessageBodyWriter Testing with "No message body writer has been found for response class" error.

Posted by Romain Manni-Bucau <rm...@gmail.com>.
did you try with tomee snapshot?

*Romain Manni-Bucau*
*Twitter: @rmannibucau*
*Blog: http://rmannibucau.wordpress.com*
*LinkedIn: http://www.linkedin.com/pub/romain-manni-bucau/43/544/956*




2012/9/21 andyay <cs...@hotmail.com>

> Thanks for the help. But I am getting an error doing so.
> Any idea ?
>
> [severity=ERROR, message=unexpected element (uri:"",
> local:"pojo-deployment"). Expected elements are
> <{http://openejb.apache.org/xml/ns/openejb-jar-2.2}ejb-ql-compiler-factory
> >,<{http://openejb.apache.org/xml/ns/openejb-jar-2.2}properties>,<{
> http://geronimo.apache.org/xml/ns/deployment-1.2}service>,<{
> http://geronimo.apache.org/xml/ns/naming-1.2}message-destination>,<{
> http://openejb.apache.org/xml/ns/openejb-jar-2.2}db-syntax-factory>,<{
> http://geronimo.apache.org/xml/ns/security-2.0}security>,<{
> http://java.sun.com/xml/ns/persistence}persistence>,<{
> http://geronimo.apache.org/xml/ns/deployment-1.2}environment>,<{
> http://geronimo.apache.org/xml/ns/naming-1.2}cmp-connection-factory>,<{
> http://openejb.apache.org/xml/ns/openejb-jar-2.2}relationships>,<{
> http://geronimo.apache.org/xml/ns/deployment-1.2}gbean>,<{
> http://openejb.apache.org/xml/ns/openejb-jar-2.2}enterprise-beans>,<{
> http://openejb.apache.org/xml/ns/openejb-jar-2.2}enforce-foreign-key-constraints
> >,<{http://geronimo.apache.org/xml/ns/j2ee/application-1.2}security>,
> locator=[node=null, object=null, url=null, line=2,col=91,offset=-1]]
>
> SEVERE: Unable to deploy collapsed ear in war /DSTest: Exception: Cannot
> unmarshall the openejb-jar.xml. Xml content written to:
> C:\Users\WAG\AppData\Local\Temp\openejb-jar-1422988848215116310.xml:
> unexpected element (uri:"http://www.openejb.org/openejb-jar/1.1",
> local:"pojo-deployment"). Expected elements are
> <{http://www.openejb.org/openejb-jar/1.1}properties>,<{
> http://www.openejb.org/openejb-jar/1.1}ejb-deployment>,<{
> http://www.openejb.org/openejb-jar/1.1}module-name>
> org.apache.openejb.OpenEJBException: Cannot unmarshall the openejb-jar.xml.
> Xml content written to:
> C:\Users\WAG\AppData\Local\Temp\openejb-jar-1422988848215116310.xml:
> unexpected element (uri:"http://www.openejb.org/openejb-jar/1.1",
> local:"pojo-deployment"). Expected elements are
> <{http://www.openejb.org/openejb-jar/1.1}properties>,<{
> http://www.openejb.org/openejb-jar/1.1}ejb-deployment>,<{
> http://www.openejb.org/openejb-jar/1.1}module-name>
>
>
> This is what I put in WEB-INF\openejb-jar.xml
> <openejb-jar>
>   <pojo-deployment class="com.mycompany.Test3">
>     <properties>
>        cxf.jaxrs.providers = com.mycompany.MyMessageBodyWriter
>     </properties>
>   </pojo-deployment>
> </openejb-jar>
>
> This is what I put in WEB-INF\resources.xml
>  <resources>
>   <Resource id="my" class-name="com.mycompany.Test3" />
> </resources>
>
>
>
> --
> View this message in context:
> http://openejb.979440.n4.nabble.com/Simple-MessageBodyWriter-Testing-with-No-message-body-writer-has-been-found-for-response-class-error-tp4657558p4657585.html
> Sent from the OpenEJB User mailing list archive at Nabble.com.
>

Re: Simple MessageBodyWriter Testing with "No message body writer has been found for response class" error.

Posted by andyay <cs...@hotmail.com>.
I am not sure it is the right place to ask this question.
But I have this (jax-rs) rest service and its custom messageBodyWriter
working in TomEE+, and it is not working in Weblogic 12c. 
Anyone have an idea why and how to get it to work ?

Thanks,



--
View this message in context: http://openejb.979440.n4.nabble.com/Simple-MessageBodyWriter-Testing-with-No-message-body-writer-has-been-found-for-response-class-error-tp4657558p4658012.html
Sent from the OpenEJB User mailing list archive at Nabble.com.

Re: Simple MessageBodyWriter Testing with "No message body writer has been found for response class" error.

Posted by andyay <cs...@hotmail.com>.
I think it is a couple of misspell, e.g. resource vs resources, and name vs
class-name.

A working example worth a thousand words ! :o)



--
View this message in context: http://openejb.979440.n4.nabble.com/Simple-MessageBodyWriter-Testing-with-No-message-body-writer-has-been-found-for-response-class-error-tp4657558p4657655.html
Sent from the OpenEJB User mailing list archive at Nabble.com.

Re: Simple MessageBodyWriter Testing with "No message body writer has been found for response class" error.

Posted by Romain Manni-Bucau <rm...@gmail.com>.
Great!

Did you find your issue?

*Romain Manni-Bucau*
*Twitter: @rmannibucau*
*Blog: **http://rmannibucau.wordpress.com/*<http://rmannibucau.wordpress.com/>
*LinkedIn: **http://fr.linkedin.com/in/rmannibucau*




2012/9/25 andyay <cs...@hotmail.com>

> Yes, it works ! Thanks :)
>
>
>
> --
> View this message in context:
> http://openejb.979440.n4.nabble.com/Simple-MessageBodyWriter-Testing-with-No-message-body-writer-has-been-found-for-response-class-error-tp4657558p4657644.html
> Sent from the OpenEJB User mailing list archive at Nabble.com.
>

Re: Simple MessageBodyWriter Testing with "No message body writer has been found for response class" error.

Posted by andyay <cs...@hotmail.com>.
Yes, it works ! Thanks :)



--
View this message in context: http://openejb.979440.n4.nabble.com/Simple-MessageBodyWriter-Testing-with-No-message-body-writer-has-been-found-for-response-class-error-tp4657558p4657644.html
Sent from the OpenEJB User mailing list archive at Nabble.com.

Re: Simple MessageBodyWriter Testing with "No message body writer has been found for response class" error.

Posted by Romain Manni-Bucau <rm...@gmail.com>.
uploaded a sample here:  http://fr.packupload.com/HKR8HZEPQUK

the content type i used is test/tomee and it works (the method returns a
string = "ko" and the bodywriter returns "ok").

*Romain Manni-Bucau*
*Twitter: @rmannibucau*
*Blog: http://rmannibucau.wordpress.com*
*LinkedIn: http://www.linkedin.com/pub/romain-manni-bucau/43/544/956*




2012/9/22 Romain Manni-Bucau <rm...@gmail.com>

> Weird, can you share it please?
>
> On today snapshot you can try to add the providers in the classes set
> Le 22 sept. 2012 09:22, "andyay" <cs...@hotmail.com> a écrit :
>
> I have made the changes again. But I again am getting the same error.
>> Is there something missing in my ApplicationConfig.java ?
>>
>> WEB-INF/openejb-jar.xml:
>> <openejb-jar>
>>   <pojo-deployment class-name="com.mycompany.Test3">
>>     <properties>
>>        cxf.jaxrs.providers = MyMessageBodyWriter
>>     </properties>
>>   </pojo-deployment>
>> </openejb-jar>
>>
>> WEB-INF/resources.xml:
>> <resource>
>>   <Service id="MyMessageBodyWriter"
>> class-name="com.mycompany.MyMessageBodyWriter" />
>> </resource>
>>
>> ApplicationConfig.java:
>> package com.mycompany;
>> ...
>> @ApplicationPath("/rest-prefix")
>> public class ApplicationConfig extends Application {
>>     public Set<Class<?>> getClasses() {
>>         return new HashSet<Class<?>>(Arrays.asList(Test3.class));
>>     }
>> }
>>
>>
>>
>>
>> --
>> View this message in context:
>> http://openejb.979440.n4.nabble.com/Simple-MessageBodyWriter-Testing-with-No-message-body-writer-has-been-found-for-response-class-error-tp4657558p4657601.html
>> Sent from the OpenEJB User mailing list archive at Nabble.com.
>>
>

Re: Simple MessageBodyWriter Testing with "No message body writer has been found for response class" error.

Posted by Romain Manni-Bucau <rm...@gmail.com>.
Weird, can you share it please?

On today snapshot you can try to add the providers in the classes set
Le 22 sept. 2012 09:22, "andyay" <cs...@hotmail.com> a écrit :

> I have made the changes again. But I again am getting the same error.
> Is there something missing in my ApplicationConfig.java ?
>
> WEB-INF/openejb-jar.xml:
> <openejb-jar>
>   <pojo-deployment class-name="com.mycompany.Test3">
>     <properties>
>        cxf.jaxrs.providers = MyMessageBodyWriter
>     </properties>
>   </pojo-deployment>
> </openejb-jar>
>
> WEB-INF/resources.xml:
> <resource>
>   <Service id="MyMessageBodyWriter"
> class-name="com.mycompany.MyMessageBodyWriter" />
> </resource>
>
> ApplicationConfig.java:
> package com.mycompany;
> ...
> @ApplicationPath("/rest-prefix")
> public class ApplicationConfig extends Application {
>     public Set<Class<?>> getClasses() {
>         return new HashSet<Class<?>>(Arrays.asList(Test3.class));
>     }
> }
>
>
>
>
> --
> View this message in context:
> http://openejb.979440.n4.nabble.com/Simple-MessageBodyWriter-Testing-with-No-message-body-writer-has-been-found-for-response-class-error-tp4657558p4657601.html
> Sent from the OpenEJB User mailing list archive at Nabble.com.
>

Re: Simple MessageBodyWriter Testing with "No message body writer has been found for response class" error.

Posted by andyay <cs...@hotmail.com>.
I have made the changes again. But I again am getting the same error.
Is there something missing in my ApplicationConfig.java ?

WEB-INF/openejb-jar.xml: 
<openejb-jar>  
  <pojo-deployment class-name="com.mycompany.Test3">  
    <properties>  
       cxf.jaxrs.providers = MyMessageBodyWriter 
    </properties>  
  </pojo-deployment>  
</openejb-jar>  

WEB-INF/resources.xml: 
<resource>  
  <Service id="MyMessageBodyWriter"
class-name="com.mycompany.MyMessageBodyWriter" />  
</resource>  

ApplicationConfig.java: 
package com.mycompany;
...
@ApplicationPath("/rest-prefix")
public class ApplicationConfig extends Application {
    public Set<Class&lt;?>> getClasses() {
        return new HashSet<Class&lt;?>>(Arrays.asList(Test3.class));
    }
}




--
View this message in context: http://openejb.979440.n4.nabble.com/Simple-MessageBodyWriter-Testing-with-No-message-body-writer-has-been-found-for-response-class-error-tp4657558p4657601.html
Sent from the OpenEJB User mailing list archive at Nabble.com.

Re: Simple MessageBodyWriter Testing with "No message body writer has been found for response class" error.

Posted by Romain Manni-Bucau <rm...@gmail.com>.
just tried:

1) added WEB-INF/openejb-jar.xml:
<openejb-jar>
  <pojo-deployment class-name="org.Resource">
    <properties>
      cxf.jaxrs.providers = ip
    </properties>
  </pojo-deployment>
</openejb-jar>

2) added WEB-INF/resources.xml:
<resource>
  <Service id="ip" class-name="org.IP"/>
</resource>


and it worked

Note: values in properties can be qualified name too now
Note 2: i'm commiting code to be able to add providers in
Application.getClasses method


*Romain Manni-Bucau*
*Twitter: @rmannibucau*
*Blog: http://rmannibucau.wordpress.com*
*LinkedIn: http://www.linkedin.com/pub/romain-manni-bucau/43/544/956*




2012/9/21 andyay <cs...@hotmail.com>

> I have made the change, but I got the same error.
>
>  <resources>
>    <Service id="my" class-name="com.mycompany.Test3" />
>  </resources>
>
>
>
> --
> View this message in context:
> http://openejb.979440.n4.nabble.com/Simple-MessageBodyWriter-Testing-with-No-message-body-writer-has-been-found-for-response-class-error-tp4657558p4657594.html
> Sent from the OpenEJB User mailing list archive at Nabble.com.
>

Re: Simple MessageBodyWriter Testing with "No message body writer has been found for response class" error.

Posted by andyay <cs...@hotmail.com>.
I have made the change, but I got the same error.

 <resources> 
   <Service id="my" class-name="com.mycompany.Test3" /> 
 </resources> 



--
View this message in context: http://openejb.979440.n4.nabble.com/Simple-MessageBodyWriter-Testing-with-No-message-body-writer-has-been-found-for-response-class-error-tp4657558p4657594.html
Sent from the OpenEJB User mailing list archive at Nabble.com.

Re: Simple MessageBodyWriter Testing with "No message body writer has been found for response class" error.

Posted by Romain Manni-Bucau <rm...@gmail.com>.
Maybe i wrote too quickly. Can you replace Resource by Service please
(sorry again)
Le 21 sept. 2012 18:45, "andyay" <cs...@hotmail.com> a écrit :

> Just replaced my Tomee with apache-tomee-1.1.1-20120919.130758-4-plus. The
> error goes away. But the problem is the same. (i.e. WARNING: No message
> body
> writer has been found for response class Customer.)
>
> Is there a problem in my xml files ?
>
> This is what I put in WEB-INF\openejb-jar.xml
> <openejb-jar>
>   <pojo-deployment class="com.mycompany.Test3">
>     <properties>
>        cxf.jaxrs.providers = com.mycompany.MyMessageBodyWriter
>     </properties>
>   </pojo-deployment>
> </openejb-jar>
>
> This is what I put in WEB-INF\resources.xml
>  <resources>
>   <Resource id="my" class-name="com.mycompany.Test3" />
> </resources>
>
>
>
>
> --
> View this message in context:
> http://openejb.979440.n4.nabble.com/Simple-MessageBodyWriter-Testing-with-No-message-body-writer-has-been-found-for-response-class-error-tp4657558p4657588.html
> Sent from the OpenEJB User mailing list archive at Nabble.com.
>

Re: Simple MessageBodyWriter Testing with "No message body writer has been found for response class" error.

Posted by andyay <cs...@hotmail.com>.
Just replaced my Tomee with apache-tomee-1.1.1-20120919.130758-4-plus. The
error goes away. But the problem is the same. (i.e. WARNING: No message body
writer has been found for response class Customer.)

Is there a problem in my xml files ?

This is what I put in WEB-INF\openejb-jar.xml 
<openejb-jar>  
  <pojo-deployment class="com.mycompany.Test3">  
    <properties>  
       cxf.jaxrs.providers = com.mycompany.MyMessageBodyWriter 
    </properties>  
  </pojo-deployment>  
</openejb-jar>  

This is what I put in WEB-INF\resources.xml 
 <resources>  
  <Resource id="my" class-name="com.mycompany.Test3" />  
</resources> 




--
View this message in context: http://openejb.979440.n4.nabble.com/Simple-MessageBodyWriter-Testing-with-No-message-body-writer-has-been-found-for-response-class-error-tp4657558p4657588.html
Sent from the OpenEJB User mailing list archive at Nabble.com.

Re: Simple MessageBodyWriter Testing with "No message body writer has been found for response class" error.

Posted by andyay <cs...@hotmail.com>.
Thanks for the help. But I am getting an error doing so.
Any idea ?

[severity=ERROR, message=unexpected element (uri:"",
local:"pojo-deployment"). Expected elements are
<{http://openejb.apache.org/xml/ns/openejb-jar-2.2}ejb-ql-compiler-factory>,<{http://openejb.apache.org/xml/ns/openejb-jar-2.2}properties>,<{http://geronimo.apache.org/xml/ns/deployment-1.2}service>,<{http://geronimo.apache.org/xml/ns/naming-1.2}message-destination>,<{http://openejb.apache.org/xml/ns/openejb-jar-2.2}db-syntax-factory>,<{http://geronimo.apache.org/xml/ns/security-2.0}security>,<{http://java.sun.com/xml/ns/persistence}persistence>,<{http://geronimo.apache.org/xml/ns/deployment-1.2}environment>,<{http://geronimo.apache.org/xml/ns/naming-1.2}cmp-connection-factory>,<{http://openejb.apache.org/xml/ns/openejb-jar-2.2}relationships>,<{http://geronimo.apache.org/xml/ns/deployment-1.2}gbean>,<{http://openejb.apache.org/xml/ns/openejb-jar-2.2}enterprise-beans>,<{http://openejb.apache.org/xml/ns/openejb-jar-2.2}enforce-foreign-key-constraints>,<{http://geronimo.apache.org/xml/ns/j2ee/application-1.2}security>,
locator=[node=null, object=null, url=null, line=2,col=91,offset=-1]]

SEVERE: Unable to deploy collapsed ear in war /DSTest: Exception: Cannot
unmarshall the openejb-jar.xml. Xml content written to:
C:\Users\WAG\AppData\Local\Temp\openejb-jar-1422988848215116310.xml:
unexpected element (uri:"http://www.openejb.org/openejb-jar/1.1",
local:"pojo-deployment"). Expected elements are
<{http://www.openejb.org/openejb-jar/1.1}properties>,<{http://www.openejb.org/openejb-jar/1.1}ejb-deployment>,<{http://www.openejb.org/openejb-jar/1.1}module-name>
org.apache.openejb.OpenEJBException: Cannot unmarshall the openejb-jar.xml.
Xml content written to:
C:\Users\WAG\AppData\Local\Temp\openejb-jar-1422988848215116310.xml:
unexpected element (uri:"http://www.openejb.org/openejb-jar/1.1",
local:"pojo-deployment"). Expected elements are
<{http://www.openejb.org/openejb-jar/1.1}properties>,<{http://www.openejb.org/openejb-jar/1.1}ejb-deployment>,<{http://www.openejb.org/openejb-jar/1.1}module-name>


This is what I put in WEB-INF\openejb-jar.xml
<openejb-jar> 
  <pojo-deployment class="com.mycompany.Test3"> 
    <properties> 
       cxf.jaxrs.providers = com.mycompany.MyMessageBodyWriter 
    </properties> 
  </pojo-deployment> 
</openejb-jar> 

This is what I put in WEB-INF\resources.xml
 <resources> 
  <Resource id="my" class-name="com.mycompany.Test3" /> 
</resources> 



--
View this message in context: http://openejb.979440.n4.nabble.com/Simple-MessageBodyWriter-Testing-with-No-message-body-writer-has-been-found-for-response-class-error-tp4657558p4657585.html
Sent from the OpenEJB User mailing list archive at Nabble.com.

Re: Simple MessageBodyWriter Testing with "No message body writer has been found for response class" error.

Posted by Romain Manni-Bucau <rm...@gmail.com>.
try this:

1) in META-INF/openejb-jar.xml -or WEB-INF for webapps ;))

<openejb-jar>
  <pojo-deployment class="...">
    <properties>
       cxf.jaxrs.providers = mine
    </properties>
  </pojo-deployment>
</openejb-jar>

2) in META-INF/resources.xml

<resources>
  <Resource id="mine" class-name="..." />
</resources>

*Romain Manni-Bucau*
*Twitter: @rmannibucau*
*Blog: http://rmannibucau.wordpress.com*
*LinkedIn: http://www.linkedin.com/pub/romain-manni-bucau/43/544/956*




2012/9/20 andyay <cs...@hotmail.com>

> I just setup a simple test project to see how to implement
> MessageBodyWriter.
> But I keep getting "No message body writer has been found for response
> class
> Customer" error.
>
> Can someone give me some help ?
>
> These are what I have:
>
> 1. properties file
> openejb.cxf.jax-rs.providers = com.mycompany.MyMessageBodyWriter
> com.mycompany.Customer.providers = com.mycompany.MyMessageBodyWriter
> openejb.jaxrs.providers.auto = true
>
> 2. Provider
> package com.mycompany;
> ...
> @Produces("my/type")
> @Provider
> public class MyMessageBodyWriter implements MessageBodyWriter<Customer> {
>     @Override
>     public long getSize(Customer obj, Class<?> type, Type genericType,
>             Annotation[] annotations, MediaType mediaType) {
>         return -1;
>     }
>
>     @Override
>     public boolean isWriteable(Class<?> type, Type genericType,
>             Annotation annotations[], MediaType mediaType) {
>         return true;
>     }
>
>     @Override
>     public void writeTo(Customer target, Class<?> type, Type genericType,
>             Annotation[] annotations, MediaType mediaType,
>             MultivaluedMap<String,Object> httpHeaders, OutputStream
> outputStream)
>             throws IOException {
>         outputStream.write("Test".getBytes());
>         outputStream.flush();
>     }
> }
>
> 3. Rest service
> @Path("/pojo3")
> public class Test3 {
>          @GET
>          @Produces("my/type")
>             public Customer pojo3() {
>                     Customer c = new Customer();
>                    ...
>                     return c;
>             }
> }
>
>
>
> --
> View this message in context:
> http://openejb.979440.n4.nabble.com/Simple-MessageBodyWriter-Testing-with-No-message-body-writer-has-been-found-for-response-class-error-tp4657558.html
> Sent from the OpenEJB User mailing list archive at Nabble.com.
>