users@jersey.java.net

Re: [Jersey] Conflict when using Jersey and Jackson json

From: Beatriz Nombela <beaotx_at_gmail.com>
Date: Thu, 22 Apr 2010 16:50:35 +0200

Hi Paul,

It is specified at the end of the following link:
http://docs.sun.com/app/docs/doc/819-3659/beadf?a=view :

"The default value is delegate="true", which causes the Web class
loader to delegate in the same manner as the other class loaders. You
must use delegate="true" for a web application that accesses EJB
components or that acts as a web service client or endpoint."

I've attached another sample closer to my application. There are two
more modules: ejb and ear. The way to test it is the same than before.
You will see that if delegate="true", the EJB's will be created, but
version of Jackson library would be incorrect. If delegate="false", my
application will use Jackson 1.5, but there will be a lot of
exceptions due to errors creating the EJB.

Thanks.



On Thu, Apr 22, 2010 at 3:16 PM, Paul Sandoz <Paul.Sandoz_at_sun.com> wrote:
>
> On Apr 22, 2010, at 3:12 PM, Beatriz Nombela wrote:
>
>> Hi Paul,
>>
>> Thanks for give me a solution. I've tried it in the sample and it
>> works, but when I've tested it in my project I have found a problem
>> :-(, and it is that my war accesses EJB components, and the class
>> loader delegation must be true when using EJB's.
>
> Why?
>
> Any details on errors, another zipped test case :-)
>
> Paul.
>
>> I'm not sure if
>> there'll be another solution besides that.
>>
>> Respecting the time of deployment in the embedded GF, it is true that
>> it takes a while. In the case of my .ear it takes more time, but I
>> configure realm authentication and my connection pool in the custom
>> domain.xml, so I find logical the stating time. However in my sample
>> app hardly exists configuration.
>>
>> In any case, thanks for your help. I will considerate any other
>> solution or proposition.
>>
>> Best regards.
>>
>> On Thu, Apr 22, 2010 at 12:45 PM, Paul Sandoz <Paul.Sandoz_at_sun.com> wrote:
>>>
>>> Hi Beatriz,
>>>
>>> Thanks for the test case. The solution is simple, but would have been
>>> hard
>>> to diagnose without it.
>>>
>>> In the sun-web.xml set class loader delegation to false:
>>>
>>> <sun-web-app error-url="">
>>>  <context-root>/sample-web</context-root>
>>>  <class-loader delegate="false"/>
>>>  <jsp-config>
>>>   <property name="keepgenerated" value="true">
>>>     <description>Keep a copy of the generated servlet class' java
>>> code.</description>
>>>   </property>
>>>  </jsp-config>
>>> </sun-web-app>
>>>
>>> then your integration test will pass, including the test using the Jersey
>>> client.
>>>
>>> BTW nice use of the GF plugin here. I noticed it seems to take quite a
>>> while
>>> for deployment to occur, i wonder if that is a bug in GF embedded?
>>>
>>> Paul.
>>>
>>> On Apr 20, 2010, at 1:59 PM, Beatriz Nombela wrote:
>>>
>>>> Hi,
>>>>
>>>> Sorry for the delay. I've attached a sample application with my
>>>> problem. There is a maven project with two modules: war and tests.
>>>> Tests are in a separate module as they are integration tests that run
>>>> against an embedded Glassfish with my war deployed. All the dependency
>>>> versions are in the parent pom.
>>>> In the tests module, you will see two tests that perform a GET HTTP
>>>> method but with different libraries: jersey-client and http-client.
>>>> This is to prove that without jersey-client (and without any
>>>> dependency of Jackson in tests), the error does continue.
>>>> The application works in a Glassfish v3.
>>>> To execute the tests, type from the parent directory:  mvn -Pit clean
>>>> install
>>>>
>>>> Before I was getting this errors, when I des/serialized with JAXB
>>>> instead of Jackson, the tests were executed correctly.
>>>>
>>>> Thanks for your help.
>>>>
>>>>
>>>>
>>>> On Tue, Apr 20, 2010 at 1:17 PM, Franz Wong <franzwong_at_gmail.com> wrote:
>>>>>
>>>>> It would be easier for us to trace if you can provide the content of
>>>>> pom.xml
>>>>> about the dependencies of jersey and jackson.
>>>>>
>>>>> Franz
>>>>>
>>>>> On Tue, Apr 20, 2010 at 5:43 PM, Beatriz Nombela <beaotx_at_gmail.com>
>>>>> wrote:
>>>>>>
>>>>>> Hi,
>>>>>>
>>>>>> I'm using the glassfish-embedded-all that ships with
>>>>>> maven-embedded-glassfish-plugin, version 3.0. As you've said, that GF
>>>>>> ships with Jersey (1.1.4.1), accordingly it comes with the Jackson
>>>>>> core library. I specified the Jersey dependency as provided, but it's
>>>>>> the same.
>>>>>>
>>>>>> Thanks for your attention.
>>>>>>
>>>>>>
>>>>>>
>>>>>> On Tue, Apr 20, 2010 at 11:29 AM, Paul Sandoz <Paul.Sandoz_at_sun.com>
>>>>>> wrote:
>>>>>>>
>>>>>>> Hi,
>>>>>>>
>>>>>>> What is your pom? a simple test executable test case may help.
>>>>>>>
>>>>>>> If you are using the jersey-test-framework then it does declare some
>>>>>>> unwanted dependencies (this has been fixed for 1.2-SNAPSHOT).
>>>>>>>
>>>>>>> What version of embedded GF are you using? Jersey is shipped with GF
>>>>>>> v3
>>>>>>> and
>>>>>>> GF v3 embedded and that does ship with jersey json stuff which in
>>>>>>> turn
>>>>>>> ships
>>>>>>> with the jackson core library.
>>>>>>>
>>>>>>> Paul.
>>>>>>>
>>>>>>> On Apr 20, 2010, at 11:18 AM, Beatriz Nombela wrote:
>>>>>>>
>>>>>>>> Hi,
>>>>>>>>
>>>>>>>> Thanks for your answers. I've specified version 1.5 of Jackson with
>>>>>>>> my
>>>>>>>> tests, but I'm getting the same error. Also, I've looked through the
>>>>>>>> output maven with -X parameter, but I don't see any other version of
>>>>>>>> Jackson as 1.5.
>>>>>>>>
>>>>>>>> I've changed Jackson version to the previous that I was using,
>>>>>>>> 1.4.3.
>>>>>>>> If in my test I do a GET to a resource, it works, but doing a POST I
>>>>>>>> get the following error:
>>>>>>>>
>>>>>>>> java.lang.NoSuchMethodError:
>>>>>>>> org.codehaus.jackson.type.JavaType.isConcrete()Z
>>>>>>>>     at
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>> org.codehaus.jackson.map.deser.BeanDeserializerFactory.createBeanDeserializer(BeanDeserializerFactory.java:80)
>>>>>>>>     at
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>> org.codehaus.jackson.map.deser.StdDeserializerProvider._createDeserializer(StdDeserializerProvider.java:315)
>>>>>>>>     at
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>> org.codehaus.jackson.map.deser.StdDeserializerProvider._createAndCache2(StdDeserializerProvider.java:246)
>>>>>>>>     at
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>> org.codehaus.jackson.map.deser.StdDeserializerProvider._createAndCacheValueDeserializer(StdDeserializerProvider.java:226)
>>>>>>>>     at
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>> org.codehaus.jackson.map.deser.StdDeserializerProvider.findValueDeserializer(StdDeserializerProvider.java:110)
>>>>>>>>     at
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>> org.codehaus.jackson.map.ObjectMapper._findRootDeserializer(ObjectMapper.java:1349)
>>>>>>>>     at
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>> org.codehaus.jackson.map.ObjectMapper._readMapAndClose(ObjectMapper.java:1282)
>>>>>>>>     at
>>>>>>>>
>>>>>>>> org.codehaus.jackson.map.ObjectMapper.readValue(ObjectMapper.java:927)
>>>>>>>> ......
>>>>>>>>
>>>>>>>> I don't understand what's going on, maybe the embedded Glassfish
>>>>>>>> overrides any library? I'll continue with it.
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>> On Tue, Apr 20, 2010 at 1:21 AM, Franz Wong <franzwong_at_gmail.com>
>>>>>>>> wrote:
>>>>>>>>>
>>>>>>>>> I used maven 's -X parameter to trace for dependency resolving.
>>>>>>>>> That
>>>>>>>>> may
>>>>>>>>> be
>>>>>>>>> useful.
>>>>>>>>> Franz
>>>>>>>>> On Tue, Apr 20, 2010 at 6:55 AM, Tatu Saloranta
>>>>>>>>> <tsaloranta_at_gmail.com>
>>>>>>>>> wrote:
>>>>>>>>>>
>>>>>>>>>> On Mon, Apr 19, 2010 at 3:51 PM, Beatriz Nombela
>>>>>>>>>> <beaotx_at_gmail.com>
>>>>>>>>>> wrote:
>>>>>>>>>>>
>>>>>>>>>>> Hi all,
>>>>>>>>>>>
>>>>>>>>>>> I'm having the same error:
>>>>>>>>>>>
>>>>>>>>>>> java.lang.VerifyError: (class:
>>>>>>>>>>> org/codehaus/jackson/map/ObjectMapper,
>>>>>>>>>>> method: writeValueAsBytes signature: (Ljava/lang/Object;)[B)…
>>>>>>>>>>>
>>>>>>>>>>> I have an .ear application, with a war module that uses Jersey
>>>>>>>>>>> (v.
>>>>>>>>>>> 1.1.5.1). I'm des/serializing with Jackson (v. 1.5.1),
>>>>>>>>>>> registering
>>>>>>>>>>> the
>>>>>>>>>>> JacksonJsonProviders provided with jackson-jaxrs in my class
>>>>>>>>>>> extending
>>>>>>>>>>> javax.ws.rs.Application. I have a @Provider class that configures
>>>>>>>>>>> ObjectMapper for that purpose. If I deploy my .ear in a Glassfish
>>>>>>>>>>> v3,
>>>>>>>>>>> my application works perferctly, but when I execute my tests in
>>>>>>>>>>> an
>>>>>>>>>>> embedded Glassfish (through maven-embedded-glassfish-plugin), I
>>>>>>>>>>> get
>>>>>>>>>>> the VeriryError exception. The error occurs just when I try to
>>>>>>>>>>> instantiate ObjectMapper in the provider.
>>>>>>>>>>>
>>>>>>>>>>> My tests are executed with jersey-client, but I've runned them
>>>>>>>>>>> with
>>>>>>>>>>> http-client to see if there was a conflict with jersey-client's
>>>>>>>>>>> jackson version. Anyway, I get the same error.
>>>>>>>>>>>
>>>>>>>>>>> Do you know what happens? Why my application fails only in tests
>>>>>>>>>>> phase?
>>>>>>>>>>
>>>>>>>>>> It sounds like test-only maven dependencies are resolved
>>>>>>>>>> differently
>>>>>>>>>> from compile/runtime dependencies. Specifically, compilation seems
>>>>>>>>>> to
>>>>>>>>>> refer to newer version: writeValueAsBytes was added in Jackson
>>>>>>>>>> 1.5,
>>>>>>>>>> and for some reason tests are running with an earlier version that
>>>>>>>>>> do
>>>>>>>>>> not include this method. It is bit odd that exception does claim
>>>>>>>>>> there
>>>>>>>>>> is a missing method.
>>>>>>>>>>
>>>>>>>>>> I don't know what is the right way to override test dependencies,
>>>>>>>>>> but
>>>>>>>>>> using 1.5 version for tests should resolve the issue.
>>>>>>>>>>
>>>>>>>>>> -+ Tatu +-
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>> ---------------------------------------------------------------------
>>>>>>>>>> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
>>>>>>>>>> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>> --
>>>>>>>> Beatriz Nombela Escobar
>>>>>>>> beaotx_at_gmail.com
>>>>>>>>
>>>>>>>>
>>>>>>>> ---------------------------------------------------------------------
>>>>>>>> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
>>>>>>>> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> ---------------------------------------------------------------------
>>>>>>> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
>>>>>>> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>>>>>>>
>>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>> --
>>>>>> Beatriz Nombela Escobar
>>>>>> beaotx_at_gmail.com
>>>>>>
>>>>>> ---------------------------------------------------------------------
>>>>>> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
>>>>>> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>>>>>>
>>>>>
>>>>>
>>>>
>>>>
>>>>
>>>> --
>>>> Beatriz Nombela Escobar
>>>> beaotx_at_gmail.com
>>>>
>>>>
>>>> <sample-parent.zip>---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
>>>> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
>>> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>>>
>>>
>>
>>
>>
>> --
>> Beatriz Nombela Escobar
>> beaotx_at_gmail.com
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
>> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>
>



-- 
Beatriz Nombela Escobar
beaotx_at_gmail.com