The Source for Java Technology Collaboration

Home » java.net Forums » GlassFish » GlassFish

Thread: Glassfish+jersey+json+natural convention and new jaxb

Welcome, Guest Help
Login Login
Guest Settings Guest Settings
This question is not answered. Helpful answers available: 2. Correct answers available: 1.

Reply to this Thread Reply to this Thread Search Forum Search Forum Back to Thread List Back to Thread List

Permlink Replies: 10 - Last Post: Nov 18, 2009 4:25 PM by: hokusmokus Threads: [ Previous | Next ]
rafik777

Posts: 9
Glassfish+jersey+json+natural convention and new jaxb
Posted: Jun 29, 2009 8:25 AM
 
  Click to reply to this thread Reply

Hi,
I want to deploy jersey application on glassfish v3 Preview and I mainly use json provider with natural convention. When I try deploy my app I get error:

INFO: Initiating Jersey application, version 'Jersey: 1.1.0-ea 04/30/2009 06:59 PM'

SEVERE: [failed to localize] error.jaxb.ri.2.1.10.missing()
SEVERE: The provider class, class org.mycompany.core.rs.provider.CommonJaxbProvider, could not be instantiated. Processing will continue but the class will not be utilized
java.lang.RuntimeException: [failed to localize] error.jaxb.ri.2.1.10.missing()
at com.sun.jersey.api.json.JSONConfiguration.natural(JSONConfiguration.java:277)


My configuration is analogous to described in:
http://blogs.sun.com/japod/entry/configuring_json_for_restful_web

How can I run my app? How to update or override jaxb in glassfish.
I tried using lib/endorsed/ directory but it doesn't help.

Could you help me?

rafik777

Posts: 9
Re: Glassfish+jersey+json+natural convention and new jaxb
Posted: Jul 2, 2009 7:53 AM   in response to: rafik777
 
  Click to reply to this thread Reply

No one has idea how to update jaxb in glassfish v3 Preview???
G v3 is promoted as very modular architecture, so I belive that this must be possible.

Sahoo
Re: Glassfish+jersey+json+natural convention and new jaxb
Posted: Jul 2, 2009 8:02 AM   in response to: rafik777
  Click to reply to this thread Reply

Of course you can update. Just get hold of the new version of JAXB OSGi
bundle and replace the corresponding files found in modules and
modules/endorsed directory in glassfish installation.

Sahoo

glassfish@javadesktop.org wrote:
> No one has idea how to update jaxb in glassfish v3 Preview???
> G v3 is promoted as very modular architecture, so I belive that this must be possible.
> [Message sent by forum member 'rafik777' (rafik777)]
>
> http://forums.java.net/jive/thread.jspa?messageID=353936
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@glassfish.dev.java.net
> For additional commands, e-mail: users-help@glassfish.dev.java.net
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@glassfish.dev.java.net
For additional commands, e-mail: users-help@glassfish.dev.java.net


Jakub Podlesak
Re: Glassfish+jersey+json+natural convention and new jaxb
Posted: Jul 2, 2009 8:18 AM   in response to: Sahoo
  Click to reply to this thread Reply

On Thu, Jul 02, 2009 at 08:32:39PM +0530, Sahoo wrote:
> Of course you can update. Just get hold of the new version of JAXB OSGi
> bundle and replace the corresponding files found in modules and
> modules/endorsed directory in glassfish installation.

And what about two applications, which need two different versions of JAXB?
Is there a way, how one application can (either via bundling it's own jaxb jar,
or some other way) use a specifix jaxb version regardless the version
installed in GlassFish?

Thanks,

~Jakub

>
> Sahoo
>
> glassfish@javadesktop.org wrote:
> >No one has idea how to update jaxb in glassfish v3 Preview???
> >G v3 is promoted as very modular architecture, so I belive that this must
> >be possible.
> >[Message sent by forum member 'rafik777' (rafik777)]
> >
> >http://forums.java.net/jive/thread.jspa?messageID=353936
> >
> >---------------------------------------------------------------------
> >To unsubscribe, e-mail: users-unsubscribe@glassfish.dev.java.net
> >For additional commands, e-mail: users-help@glassfish.dev.java.net
> >
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@glassfish.dev.java.net
> For additional commands, e-mail: users-help@glassfish.dev.java.net
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@glassfish.dev.java.net
For additional commands, e-mail: users-help@glassfish.dev.java.net


Sahoo
Re: Glassfish+jersey+json+natural convention and new jaxb
Posted: Jul 2, 2009 8:31 AM   in response to: Jakub Podlesak
  Click to reply to this thread Reply

Jakub Podlesak wrote:
> On Thu, Jul 02, 2009 at 08:32:39PM +0530, Sahoo wrote:
>
>> Of course you can update. Just get hold of the new version of JAXB OSGi
>> bundle and replace the corresponding files found in modules and
>> modules/endorsed directory in glassfish installation.
>>
>
> And what about two applications, which need two different versions of JAXB?
> Is there a way, how one application can (either via bundling it's own jaxb jar,
> or some other way) use a specifix jaxb version regardless the version
> installed in GlassFish?
>
>
You probably have to develop your application as an OSGi bundle to do
something like this.

Thanks,
Sahoo
> Thanks,
>
> ~Jakub
>
>
>> Sahoo
>>
>> glassfish@javadesktop.org wrote:
>>
>>> No one has idea how to update jaxb in glassfish v3 Preview???
>>> G v3 is promoted as very modular architecture, so I belive that this must
>>> be possible.
>>> [Message sent by forum member 'rafik777' (rafik777)]
>>>
>>> http://forums.java.net/jive/thread.jspa?messageID=353936
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: users-unsubscribe@glassfish.dev.java.net
>>> For additional commands, e-mail: users-help@glassfish.dev.java.net
>>>
>>>
>>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@glassfish.dev.java.net
>> For additional commands, e-mail: users-help@glassfish.dev.java.net
>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@glassfish.dev.java.net
> For additional commands, e-mail: users-help@glassfish.dev.java.net
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@glassfish.dev.java.net
For additional commands, e-mail: users-help@glassfish.dev.java.net


rafik777

Posts: 9
Re: Glassfish+jersey+json+natural convention and new jaxb
Posted: Jul 2, 2009 10:12 AM   in response to: Sahoo
 
  Click to reply to this thread Reply

Thanks for reply
But, there is something wrong, because I downloaded latest night build of glassfish v3 preview and it has new version of jaxb I think.

jersey (json) required min jaxb v 2.1.10 but now is 2.2 already

I looked to jersey code and there is something like:

public static Builder natural() {
// this is to make sure people trying to use NATURAL notation will get clear message what is missing, when an old JAXB RI version is used
try {
Class.forName("com.sun.xml.bind.annotation.OverrideAnnotationOf");
} catch (ClassNotFoundException ex) {
Logger.getLogger(JSONConfiguration.class.getName()).log(Level.SEVERE, ImplMessages.ERROR_JAXB_RI_2_1_10_MISSING());
throw new RuntimeException(ImplMessages.ERROR_JAXB_RI_2_1_10_MISSING());
}
return new Builder(Notation.NATURAL);
}


so i greped glassfish directories by OverrideAnnotationOf file and i found:

glassfishv3\glassfish\modules\jaxb-osgi.jar\com\sun\xml\bind\annotation\OverrideAnnotationOf .class

I tried put jaxb-osgi-2.2-promoted-b36.jar in modeules/endorsed/ but it doesn't help.
jersey still doesn't see this anotation.

?

rafik777

Posts: 9
Re: Glassfish+jersey+json+natural convention and new jaxb
Posted: Jul 6, 2009 3:44 AM   in response to: rafik777
 
  Click to reply to this thread Reply

Some ideas?
How can I check wchich jar (jaxb) is loaded by glassfish and visible for my app and why?

Jakub Podlesak
Re: Glassfish+jersey+json+natural convention and new jaxb
Posted: Jul 9, 2009 8:42 AM   in response to: rafik777
  Click to reply to this thread Reply


Hi,

could you try to bundle jaxb-2.1.12 jar with your war file
and set the following in the WEB-INF/sun-web.xml descriptor?

<class-loader delegate="false"/>

Does it help?

~Jakub

P.S. Attaching a sample sun-web.xml, so that you can just
update the context root there and reuse

On Mon, Jun 29, 2009 at 08:25:37AM -0700, glassfish@javadesktop.org wrote:
> Hi,
> I want to deploy jersey application on glassfish v3 Preview and I mainly use json provider with natural convention. When I try deploy my app I get error:
>
> INFO: Initiating Jersey application, version 'Jersey: 1.1.0-ea 04/30/2009 06:59 PM'
>
> SEVERE: [failed to localize] error.jaxb.ri.2.1.10.missing()
> SEVERE: The provider class, class org.mycompany.core.rs.provider.CommonJaxbProvider, could not be instantiated. Processing will continue but the class will not be utilized
> java.lang.RuntimeException: [failed to localize] error.jaxb.ri.2.1.10.missing()
> at com.sun.jersey.api.json.JSONConfiguration.natural(JSONConfiguration.java:277)
>
>
> My configuration is analogous to described in:
> http://blogs.sun.com/japod/entry/configuring_json_for_restful_web
>
> How can I run my app? How to update or override jaxb in glassfish.
> I tried using lib/endorsed/ directory but it doesn't help.
>
> Could you help me?
> [Message sent by forum member 'rafik777' (rafik777)]
>
> http://forums.java.net/jive/thread.jspa?messageID=353422
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@glassfish.dev.java.net
> For additional commands, e-mail: users-help@glassfish.dev.java.net
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@glassfish.dev.java.net
For additional commands, e-mail: users-help@glassfish.dev.java.net


rafik777

Posts: 9
Re: Glassfish+jersey+json+natural convention and new jaxb
Posted: Jul 9, 2009 10:17 AM   in response to: Jakub Podlesak
 
  Click to reply to this thread Reply

Hey,
thanks for reply
I tried quickly change classloading delegate to false in sun-web.xml, but then I had smth errors with eclipselink. I will try see it closer later.

But did you read my yesterday post?:
http://forums.java.net/jive/thread.jspa?threadID=64062&tstart=30

some ideas?
Why in the same application in one servlet jaxb class is visible and in other servlet not.
I have no idea.

hokusmokus

Posts: 2
Jersey + JSON + JAXB + Natural
Posted: Nov 17, 2009 3:43 PM   in response to: rafik777
 
  Click to reply to this thread Reply

Hi Java Community--

I have a problem with Jersey & JSON Notation...


I have a working Jersey prototype project that uses the default "mapping" notation.

I have about 8 tests that do the ususal POST, GET, PUT, and DELETE-- works great! (thank you jersey team for this great framework)


There is however one gripe: the JSON Notation

Let me give you some background about how I do things:


1) I generate my jaxb objects using an XSD file-- so i declare my XSD file.

2) I use of "XML Attributes" in my XSD file-- this cuts down on the XML payload size--

for ex:

this:
<config pollingInterval="100" />

is ALOT smaller than:

<config><pollingInterval>100</pollingInterval></config>

so I generally see XML attributes as more effecient (my perspective)


Given #1 and #2 the default JSON "mapping" notation produces JSON that is littered with "@".

Right now the "@" is the bane of my existence-- cause the javascript world does not like it at all.


So there are two straitfoward solutions-- either i have the client deal with the "@" or I have the server not send the "@"


Client Side Solution:

find and replace the "@ with an empty sting ('')-- yuck, this does not feel clean.

Server Side Solution:

Use a "JSONConfiguration" with NATURAL notation-- I have this halfway working.

The NATURAL notation is not (i am guessing) able to bind back into the JAXB Object.

The reason I say this is because:

I have a working Jersey Client that uses JAXB objects fine with the mapping notation, but fails with the natrual notation.

There is no "exception being thrown" its just that when I use the client to "GET" a jaxb object from the RESTful server,

it reterns an empty JAXB object with all hte members null and not set.


My prototype project is "maven-ized" and I am willing to post the entire project or code snippets as requested... for not I will post my JSONConfiguration


So in a nutshell:


@Provider
public class JAXBContextResolver implements ContextResolver<JAXBContext> {

private JAXBContext context;
private Class[] types = { Coupon.class, Coupons.class, Comment.class, Comments.class };

public JAXBContextResolver() throws Exception {
//this.context = new JSONJAXBContext(JSONConfiguration.mapped().build(), types); (THIS WORKS)
this.context = new JSONJAXBContext(JSONConfiguration.natural().build(), types); // THIS DOES NOT WORK)
}

public JAXBContext getContext(Class<?> objectType) {
for (Class type : types) {
if (type == objectType) {
return context;
}
}
return null;
}

}


Again, there is no exception being thrown, the issue is: If I use the Jersey Client to "GET" a JAXB object (that i know exists) -- it returns a JAXB object that has none of the members set/injected.

Please keep in mind that my JAXB Object members are annotated with "XMLAttribute" because I generate them from an XSD where I use alot of XML Attributes.

hokusmokus

Posts: 2
Re: Jersey + JSON + JAXB + Natural
Posted: Nov 18, 2009 4:25 PM   in response to: hokusmokus
 
  Click to reply to this thread Reply

Here is the solution:

You only need to change the configure method in your "JerseyTest" like this:

@Override
protected AppDescriptor configure() {
setTestContainerFactory(new JettyWebTestContainerFactory("./src/main/webapp"));

ClientConfig cc = new DefaultClientConfig();

// IMPORTANT
cc.getClasses().add(JAXBContextResolver.class);

return new WebAppDescriptor.Builder("com.prototype.resources").clientConfig(cc).build();
}

And that should be it.


so to be clear:

the jersey-server automatically register the ContextResolver found inside the resources package

however, for the jersey-client you MUST explicitly register the ContextResolver as shown above.


Many thanks to Jakub Podlesak for helping me understand this.




 XML java.net RSS