users@jersey.java.net

Re: [Jersey] I can't get a POST message to work

From: Jakub Podlesak <Jakub.Podlesak_at_Sun.COM>
Date: Mon, 19 Jan 2009 16:38:24 +0100

Hello Eric,

On Sun, Jan 18, 2009 at 10:12:55AM -0600, Marsh Eric wrote:
> Hello,
>
> I'm developing an iPhone application that needs to pass information between
> the iPhone and a remote database. Using web services seemed to be a good
> strategy so I downloaded the latest version of Netbeans, spent a day or two
> reading and working through the web services examples. Doing some web
> searches I found that most iPhone developers are using JSON so I downloaded
> an iPhone JSON library and went to work at developing a communications
> channel between the remote device and the database.
>
> I don't know if it makes any difference but I'm developing on a Mac.
>
> First of all, when I tried to deploy I was getting some errors related to
> JSON. They are:
>
> SEVERE: The provider class, class
> com.sun.jersey.impl.provider.entity.JSONJAXBElementProvider, could not be
> instantiated
> SEVERE: The provider class, class
> com.sun.jersey.impl.provider.entity.JSONListElementProvider, could not be
> instantiated
> SEVERE: The provider class, class
> com.sun.jersey.impl.provider.entity.JSONRootElementProvider, could not be
> instantiated
>
> I thought that I'd go back and look at those problems later as the app did
> seem to deploy even with the errors.

I would recommend you to try resolve the above errors in the first place
as it seems something is wrong with your configuration.
Are you using the latest NetBeans 6.5? If so,
could you try to create a new project with:
[New Project]->[Samples]->[WebServices]->[Customer Database (RESTful)]
then try to deploy. Same errors?
Then please try to submit a new bug report against NetBeans RESTful WS plugin at [1]
Another thing you may try is to run your NetBeans with a fresh userdir.
Then you need to use --userdir rest-app-nbdir command line option.


>
> It wasn't too tough getting the database to talk to the iPhone. However
> I've spent something like a week and a half trying to get the
> communications to work going the other way. Initially when I was getting
> errors and exceptions I thought that my problem was that I simply didn't
> understand the JSON protocol. Consequently I stopped trying to get the
> iPhone to talk to the web services and started to experiment with the
> netbeans "Test RESTful web services" web interface. I would do a get to
> grab some data from my database, tweak the results and try to POST them
> back to the database. I could never get this to work. I had a number of

The simplest test scenario to try out here is to

 - GET some data from a particular containee resource
 - POST the very same *unchanged* data to the corresponding container resource

Then, you should get something like
Entity already exists exception (coming from db layer)
Which in fact means, you entity gets unmarshalled all right.
Could you please try out something similar (without touching the data) at your application?


> returned error codes depending on what I would try to POST but I finally
> focused on the fact that I was getting messages similar to the following:
>
>
> javax.ws.rs.WebApplicationException: javax.xml.bind.UnmarshalException -
> with linked exception: [org.xml.sax.SAXParseException: Content is not
> allowed in prolog.] at converter.UriResolver.resolve(UriResolver.java:81)
>
> I've been doing some reading and it appears that in Jersey JSON is layered
> over XML. Since this exception appears to be coming from the XML layer it
> looks like I would have to step through the Jersey source to figure out
> what's going on. I suspect that the problem is related to the exceptions
> that were happening on deployment that I cited earlier.
>

I suspect that is the case. If the customer db application works for you,
you might want to check, you web app uses the same jersey related libraries.
(Please make sure you do not mix jersey jar versions)

If none of the above helps, would you be able to send out your project
files so that i could have a closer look?

~Jakub

[1]http://www.netbeans.org/community/issues.html

> I downloaded the source so that I could build and debug in the Jersey and
> Grizzly layers. This took a couple of hours. To my surprise there was a
> couple of places where the source wouldn't build as downloaded. One is in
> ContainerResponse.java where the compiler complained that at line 216 it
> couldn't find getMessageBodyWriterMediaTypes. Another problem is at line
> 292 in BasicValidator.java where it couldn't find
> ERROR_SUBRES_LOC_HAS_ENTITY_PARAM. I did some quick hacks just to get the
> application to build. However it wouldn't deploy and at that point I
> decided that I'd just spent too much time on this and decided to yell for
> help.
>
> I'd really like to be able to use Glassfish, Netbeans and Jersey but I
> really seem to be stuck. If I can't get this to fly I may have to backtrack
> and do something entirely different. It doesn't appear that I can do a
> remote database connection from the iPhone so web services looks like the
> best solution. The problem appears to be at the server end, not the iPhone
> end anyway. I'm really kind of surprised that I've had so much trouble.
> Regardless, I need to break through this roadblock and get this app done.
>
> Suggestions or help anyone?