users@jersey.java.net

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

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Mon, 19 Jan 2009 11:35:30 +0100

Hi Eric,

In relation to JAXB and JSON i will let Jakub respond to the specifics
of that.

IMHO i suspect it might be easier for you to use XML directly if the
iPhone APIs have good support. Are there tools to generate code
artifacts from XML schema? if so you could generate XML schema from
the JAXB beans.


On Jan 18, 2009, at 5:12 PM, 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.
>

What version of NetBeans are you using? the errors above indicate that
you do not have the right jar fikes in the class path of your web app,
can you list what you have?


> 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 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)
>

Were you POSTing JSON or XML content. The above error indicates that
the server received XML it could not parse, i suspect because the
Content-Type of the request was "application/xml" rather than
"application/json".


> 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 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.
>

How did you obtain the source. From SVN? or from the maven jars files,
if the latter what did you download? Note that Jersey is built from a
number of maven modules. The source in jar form is supplied really for
debugging and viewing purposes and is not intended for compiling
purposes. To compile and build you need to use the the code from the
SVN repo. We continuously build Jersey from the trunk, using Hudson,
for every commit that occurs. Hudson informs us of any build errors
and it will not deploy artifacts to the maven repository if errors are
found (compile or test errors).

Sorry you are having such a hard time, hopefully we can come to some
resolution reasonably quickly,
Paul.

> 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?