You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomee.apache.org by netname <al...@gmail.com> on 2012/10/04 08:28:44 UTC

TomEE 1.5 and Jackson

I am trying to move a JAX-RS application from 1.0 to 1.5 but I am getting all
sort of errors. The first error I got was: "No message body writer has been
found for response class". So I came to the forum and read that setting the
providers in system.properties and putting the Jackson jars in TomEE/lib is
not the appropiate way anymore. Below are the steps that I am following,
please let me know where is my error:

Setup Jackson in TomEE 1.5


1)  Copy jackson-mapper-asl-1.9.9.jar, jackson-core-asl-1.9.9.jar,
jackson-jaxrs-1.9.9.jar in MyWebApp/lib folder

2) Under the WEB-INF folder add the following files:

resources.xml
-------------
<resources>
    <Service id="jsonProvider"
             class-name="org.codehaus.jackson.jaxrs.JacksonJsonProvider" />
    <Service id="jaxbProvider"
             class-name="org.codehaus.jackson.jaxrs.JacksonJaxbJsonProvider"
/>
</resources>


openejb-jar.xml
---------------
<openejb-jar xmlns="http://www.openejb.org/xml/ns/openejb-jar-1.1">
    <pojo-deployment
class-name="com.palda.faclpt.util.JacksonContextResolver">
        <properties>
            cxf.jax-rs.providers = jsonProvider, jaxbProvider
        </properties>
    </pojo-deployment>
</openejb-jar>

Questions


*1) Which namespace for openejb-jar-1.1 should I use?*
    I found that newer versions do not support the pojo-deployment element

*2) Which is the use of the class specified in the pojo-deployment?*
  In TomEE I did not have to implement a Provider class. I did do it,
though, in order to customize the date format on the generated JSON. I am
not sure if this is the class that should be used for the pojo-deployment
element

The class that I am using as Provider is:

@Provider
@Produces(MediaType.APPLICATION_JSON)
public class JacksonContextResolver implements ContextResolver<ObjectMapper>
{
    private ObjectMapper objectMapper;

    public JacksonContextResolver() throws Exception {
        this.objectMapper = new
ObjectMapper().configure(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES,
false);
    }
    public ObjectMapper getContext(Class<?> objectType) {
       
objectMapper.configure(SerializationConfig.Feature.WRITE_DATES_AS_TIMESTAMPS,
false);
        return objectMapper;
    }
}


Thanks,

Alberto




--
View this message in context: http://openejb.979440.n4.nabble.com/TomEE-1-5-and-Jackson-tp4657777.html
Sent from the OpenEJB User mailing list archive at Nabble.com.

Re: TomEE 1.5 and Jackson

Posted by Romain Manni-Bucau <rm...@gmail.com>.
hmm not sure if we publish any xsd or "single page doc" about
openejb-jar.xml

i have to write a lot of doc but for some weeks it will be hard to find
"cool time" to do so but that's on my todo list

about the sample it is a great idea, do you want to contribute it? (just
need to create a jira, and attach a patch - the only constraint on sample
is the pom.xml which should define a distribution management but simply
start from this pom for instance:
http://svn.apache.org/repos/asf/openejb/trunk/openejb/examples/cdi-basic/pom.xml
)

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




2012/10/5 netname <al...@gmail.com>

> Nothing beats working code !
>
> You get the error: "The number of beans deployed (3) does not match the
> number of beans actually in the jar (2).  Please redeploy this jar." If you
> do not change the attribute from "class-name" to "ejb-name" or if you do
> not
> change the value to the EJB name and leave the full class name.
>
> Here is the working example including the change to the cxf.jaxrs.providers
> property in openejb-jar.xml in order to eliminate resource.xml  fooEjb.zip
> <http://openejb.979440.n4.nabble.com/file/n4657789/fooEjb.zip>
>
> Do you know if there is any type of documentation for openejb-jar.xml?
>
> Also, it might be a good idea to add the setup of Jackson to the list of
> provided examples.
>
> Thanks a lot for your help!
>
>
>
>
>
> --
> View this message in context:
> http://openejb.979440.n4.nabble.com/TomEE-1-5-and-Jackson-tp4657777p4657789.html
> Sent from the OpenEJB User mailing list archive at Nabble.com.
>

Re: TomEE 1.5 and Jackson

Posted by netname <al...@gmail.com>.
Nothing beats working code !

You get the error: "The number of beans deployed (3) does not match the
number of beans actually in the jar (2).  Please redeploy this jar." If you
do not change the attribute from "class-name" to "ejb-name" or if you do not
change the value to the EJB name and leave the full class name.

Here is the working example including the change to the cxf.jaxrs.providers
property in openejb-jar.xml in order to eliminate resource.xml  fooEjb.zip
<http://openejb.979440.n4.nabble.com/file/n4657789/fooEjb.zip>  

Do you know if there is any type of documentation for openejb-jar.xml?

Also, it might be a good idea to add the setup of Jackson to the list of
provided examples.

Thanks a lot for your help!





--
View this message in context: http://openejb.979440.n4.nabble.com/TomEE-1-5-and-Jackson-tp4657777p4657789.html
Sent from the OpenEJB User mailing list archive at Nabble.com.

Re: TomEE 1.5 and Jackson

Posted by Romain Manni-Bucau <rm...@gmail.com>.
Hi,

first side note: i think you can get rid of resources.xml since
cxf.jaxrs.providers=org.codehaus.jackson.jaxrs.JacksonJsonProvider should
work too (you dont need to configure the provider so no need of
resources.xml)

about your error it should be elsewhere since updating your sample to use
an EJB i managed to make it working with:

<openejb-jar>
  <ejb-deployment ejb-name="Resource">
    <properties>
      cxf.jaxrs.providers = bw
    </properties>
  </ejb-deployment>
</openejb-jar>



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




2012/10/5 netname <al...@gmail.com>

> Thanks a lot Romain !  With your post and an example I found that you
> wrote a
> while ago (foo) I was able to make it work.  The only issue that I have is
> that if my service is an EJB I get the following error: *"number of beans
> deployed (11) does not match the number of beans actually in the jar
> (12)"*.
> I have other EJBs that are not endpoints in JAX-RS. It seems that once I
> define an EJB in openejb-jar.xml I have to define them all in
> openejb-jar.xml.
>
> I am attaching the Foo project modified to register Jackson.
>
> The steps to setup Jackson in TomEE (as it is my understanding) are:
>
> *Setup Jackson in TomEE 1.5*
>
> 1)  Copy jackson-mapper-asl-1.9.9.jar, jackson-core-asl-1.9.9.jar,
> jackson-jaxrs-1.9.9.jar into WEB-INF/lib folder
>
> 2) Under the WEB-INF folder add the following files:
>
> resources.xml
> -------------
> <resources>
>     <Service id="jsonProvider"
>              class-name="org.codehaus.jackson.jaxrs.JacksonJsonProvider" />
>     <Service id="jaxbProvider"
>
>  class-name="org.codehaus.jackson.jaxrs.JacksonJaxbJsonProvider"
> />
> </resources>
>
>
> openejb-jar.xml
> ---------------
> <openejb-jar>
>     <pojo-deployment class-name="com.example.MyJaxRSService">
>         <properties>
>             cxf.jax-rs.providers = jsonProvider, jaxbProvider
>         </properties>
>     </pojo-deployment>
> </openejb-jar>
>
> Note: make sure that MyJaxRSService is a POJO, if it were an EJB then you
> should use ejb-deployment
>
>
> --------------------------------------------------------------------------------------------------
>
> *Questions:*
>
> 1) Could someone please point me to instructions on how to register EJBs in
> openejb-jar.xml.
> 2) How can I avoid the error: "number of beans deployed (11) does not match
> the number of beans actually in the jar (12)"
>
>
>
>
> --
> View this message in context:
> http://openejb.979440.n4.nabble.com/TomEE-1-5-and-Jackson-tp4657777p4657786.html
> Sent from the OpenEJB User mailing list archive at Nabble.com.
>

Re: TomEE 1.5 and Jackson

Posted by netname <al...@gmail.com>.
Thanks a lot Romain !  With your post and an example I found that you wrote a
while ago (foo) I was able to make it work.  The only issue that I have is
that if my service is an EJB I get the following error: *"number of beans
deployed (11) does not match the number of beans actually in the jar (12)"*.
I have other EJBs that are not endpoints in JAX-RS. It seems that once I
define an EJB in openejb-jar.xml I have to define them all in
openejb-jar.xml.

I am attaching the Foo project modified to register Jackson. 

The steps to setup Jackson in TomEE (as it is my understanding) are:

*Setup Jackson in TomEE 1.5*

1)  Copy jackson-mapper-asl-1.9.9.jar, jackson-core-asl-1.9.9.jar,
jackson-jaxrs-1.9.9.jar into WEB-INF/lib folder 

2) Under the WEB-INF folder add the following files: 

resources.xml 
------------- 
<resources>
    <Service id="jsonProvider" 
             class-name="org.codehaus.jackson.jaxrs.JacksonJsonProvider" />
    <Service id="jaxbProvider" 
             class-name="org.codehaus.jackson.jaxrs.JacksonJaxbJsonProvider"
/>
</resources>


openejb-jar.xml 
--------------- 
<openejb-jar>
    <pojo-deployment class-name="com.example.MyJaxRSService">
        <properties>
            cxf.jax-rs.providers = jsonProvider, jaxbProvider 
        </properties>
    </pojo-deployment>
</openejb-jar>

Note: make sure that MyJaxRSService is a POJO, if it were an EJB then you
should use ejb-deployment

--------------------------------------------------------------------------------------------------

*Questions:*

1) Could someone please point me to instructions on how to register EJBs in
openejb-jar.xml.
2) How can I avoid the error: "number of beans deployed (11) does not match
the number of beans actually in the jar (12)"




--
View this message in context: http://openejb.979440.n4.nabble.com/TomEE-1-5-and-Jackson-tp4657777p4657786.html
Sent from the OpenEJB User mailing list archive at Nabble.com.

Re: TomEE 1.5 and Jackson

Posted by Romain Manni-Bucau <rm...@gmail.com>.
hmm, the class name should match the rest service

Note: funny but i scheduled last week a post about it ->
http://rmannibucau.wordpress.com/2012/10/04/jax-rsjax-ws-configuration-for-tomee-1-5-0/

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




2012/10/4 netname <al...@gmail.com>

> >> if you manage to share some maven war project (github or sthg else) i
> could
> >> give it a look (but i'm a bit time boxed these days)
>
> Thanks !!
>
>   The project is: https://github.com/netname/FacLpt
>
>   One of the beans that I am having problems converting to JSON is:
>
> https://github.com/netname/FacLpt/blob/master/src/main/java/com/palda/faclpt/model/FacLptConfiguration.java
>
> My openejb-jar.xml is:
> <openejb-jar>
>     <pojo-deployment class-name="com.palda.faclpt.FacLptConfiguration">
>         <properties>
>             cxf.jax-rs.providers = jsonProvider, jaxbProvider
>         </properties>
>     </pojo-deployment>
> </openejb-jar>
>
> and the resources.xml file is:
> <resources>
>     <Service id="jsonProvider"
>              class-name="org.codehaus.jackson.jaxrs.JacksonJsonProvider" />
>     <Service id="jaxbProvider"
>
>  class-name="org.codehaus.jackson.jaxrs.JacksonJaxbJsonProvider"
> />
> </resources>
>
> It is not clear to me what should I put in the pojo-deployment element. As
> of now, I am putting one of the beans to convert.
>
> The error I get is:
> Oct 04, 2012 4:10:51 AM
> org.apache.cxf.jaxrs.interceptor.JAXRSOutInterceptor
> writeResponseErrorMessage
> WARNING: No message body writer has been found for response class
> FacLptConfiguration.
>
> So it seems that I am failing to indicate TomEE to use Jackson.
>
> Thanks again.
>
>
>
> --
> View this message in context:
> http://openejb.979440.n4.nabble.com/TomEE-1-5-and-Jackson-tp4657777p4657782.html
> Sent from the OpenEJB User mailing list archive at Nabble.com.
>

Re: TomEE 1.5 and Jackson

Posted by netname <al...@gmail.com>.
>> if you manage to share some maven war project (github or sthg else) i
could 
>> give it a look (but i'm a bit time boxed these days) 

Thanks !!

  The project is: https://github.com/netname/FacLpt
  
  One of the beans that I am having problems converting to JSON is:
https://github.com/netname/FacLpt/blob/master/src/main/java/com/palda/faclpt/model/FacLptConfiguration.java

My openejb-jar.xml is:
<openejb-jar>
    <pojo-deployment class-name="com.palda.faclpt.FacLptConfiguration">
        <properties>
            cxf.jax-rs.providers = jsonProvider, jaxbProvider
        </properties>
    </pojo-deployment>
</openejb-jar>

and the resources.xml file is:
<resources>
    <Service id="jsonProvider"
             class-name="org.codehaus.jackson.jaxrs.JacksonJsonProvider" />
    <Service id="jaxbProvider"
             class-name="org.codehaus.jackson.jaxrs.JacksonJaxbJsonProvider"
/>
</resources>

It is not clear to me what should I put in the pojo-deployment element. As
of now, I am putting one of the beans to convert.

The error I get is:
Oct 04, 2012 4:10:51 AM org.apache.cxf.jaxrs.interceptor.JAXRSOutInterceptor
writeResponseErrorMessage
WARNING: No message body writer has been found for response class
FacLptConfiguration.

So it seems that I am failing to indicate TomEE to use Jackson.

Thanks again.



--
View this message in context: http://openejb.979440.n4.nabble.com/TomEE-1-5-and-Jackson-tp4657777p4657782.html
Sent from the OpenEJB User mailing list archive at Nabble.com.

Re: TomEE 1.5 and Jackson

Posted by Romain Manni-Bucau <rm...@gmail.com>.
if you manage to share some maven war project (github or sthg else) i could
give it a look (but i'm a bit time boxed these days)

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




2012/10/4 netname <al...@gmail.com>

> >> Maybe put it in web-inf/lib
>
> That is where I am putting them. I meant writing MyWebApp/web-inf/lib.
>
> Do you have any pointers in the setup of openejb-jar.xml? I have gone
> through all the forum posts for Jackson and I do not see an explanation of
> what is the class that is put there supposed to achieve.
>
> Thanks,
>
>
>
>
>
> --
> View this message in context:
> http://openejb.979440.n4.nabble.com/TomEE-1-5-and-Jackson-tp4657777p4657779.html
> Sent from the OpenEJB User mailing list archive at Nabble.com.
>

Re: TomEE 1.5 and Jackson

Posted by netname <al...@gmail.com>.
>> Maybe put it in web-inf/lib 

That is where I am putting them. I meant writing MyWebApp/web-inf/lib. 

Do you have any pointers in the setup of openejb-jar.xml? I have gone
through all the forum posts for Jackson and I do not see an explanation of
what is the class that is put there supposed to achieve.

Thanks,





--
View this message in context: http://openejb.979440.n4.nabble.com/TomEE-1-5-and-Jackson-tp4657777p4657779.html
Sent from the OpenEJB User mailing list archive at Nabble.com.

Re: TomEE 1.5 and Jackson

Posted by Romain Manni-Bucau <rm...@gmail.com>.
Maybe put it in web-inf/lib

Other parts sounds fine
Le 4 oct. 2012 08:29, "netname" <al...@gmail.com> a écrit :

> I am trying to move a JAX-RS application from 1.0 to 1.5 but I am getting
> all
> sort of errors. The first error I got was: "No message body writer has been
> found for response class". So I came to the forum and read that setting the
> providers in system.properties and putting the Jackson jars in TomEE/lib is
> not the appropiate way anymore. Below are the steps that I am following,
> please let me know where is my error:
>
> Setup Jackson in TomEE 1.5
>
>
> 1)  Copy jackson-mapper-asl-1.9.9.jar, jackson-core-asl-1.9.9.jar,
> jackson-jaxrs-1.9.9.jar in MyWebApp/lib folder
>
> 2) Under the WEB-INF folder add the following files:
>
> resources.xml
> -------------
> <resources>
>     <Service id="jsonProvider"
>              class-name="org.codehaus.jackson.jaxrs.JacksonJsonProvider" />
>     <Service id="jaxbProvider"
>
>  class-name="org.codehaus.jackson.jaxrs.JacksonJaxbJsonProvider"
> />
> </resources>
>
>
> openejb-jar.xml
> ---------------
> <openejb-jar xmlns="http://www.openejb.org/xml/ns/openejb-jar-1.1">
>     <pojo-deployment
> class-name="com.palda.faclpt.util.JacksonContextResolver">
>         <properties>
>             cxf.jax-rs.providers = jsonProvider, jaxbProvider
>         </properties>
>     </pojo-deployment>
> </openejb-jar>
>
> Questions
>
>
> *1) Which namespace for openejb-jar-1.1 should I use?*
>     I found that newer versions do not support the pojo-deployment element
>
> *2) Which is the use of the class specified in the pojo-deployment?*
>   In TomEE I did not have to implement a Provider class. I did do it,
> though, in order to customize the date format on the generated JSON. I am
> not sure if this is the class that should be used for the pojo-deployment
> element
>
> The class that I am using as Provider is:
>
> @Provider
> @Produces(MediaType.APPLICATION_JSON)
> public class JacksonContextResolver implements
> ContextResolver<ObjectMapper>
> {
>     private ObjectMapper objectMapper;
>
>     public JacksonContextResolver() throws Exception {
>         this.objectMapper = new
>
> ObjectMapper().configure(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES,
> false);
>     }
>     public ObjectMapper getContext(Class<?> objectType) {
>
>
> objectMapper.configure(SerializationConfig.Feature.WRITE_DATES_AS_TIMESTAMPS,
> false);
>         return objectMapper;
>     }
> }
>
>
> Thanks,
>
> Alberto
>
>
>
>
> --
> View this message in context:
> http://openejb.979440.n4.nabble.com/TomEE-1-5-and-Jackson-tp4657777.html
> Sent from the OpenEJB User mailing list archive at Nabble.com.
>