This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Servlets and the fly likes Issue with sending xml jaxb object to servlet body Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Issue with sending xml jaxb object to servlet body" Watch "Issue with sending xml jaxb object to servlet body" New topic
Author

Issue with sending xml jaxb object to servlet body

Julien Raynal
Greenhorn

Joined: Apr 06, 2009
Posts: 2
I have been working on this simple call to a servlet that reads the xml passed to it but keep getting a 500 error. Could anyone point me in the right direction?

Here is the client code:



I cannot figure out what is wrong... Going crazy. I am simply creating a jaxb object and marshalling it to the servlet output stream.

Here is the servlet code:



Thanks for the help...

jaydev

jaydev
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Is there nothing in the server logs, like a stack trace?
Bauke Scholtz
Ranch Hand

Joined: Oct 08, 2006
Posts: 2458
A HTTP 500 error means that there is a serious and unhandled problem in the server side code.

In case of a Java webapplication, this generally means that there's an exception been thrown. If you don't see it (fully) in the error page itself (read the response), you normally can find the complete exception details and the trace back in the appserver's logs. This information should be enough to solve the problem yourself.
Julien Raynal
Greenhorn

Joined: Apr 06, 2009
Posts: 2
Thanks for the reply. I finally found some hint on Tomcat that indicates a "Premature enf of file" SAXParseException, which allowed me to figure out that when the servlet reads:



No data is being read, which means that for some reason, the jaxb object that is supposed to be written to the ouput stream on the client is not written. I am not sure why. Any suggestions would be great. I deugged the jaxb object and I know that it is not null and has data. Am I not writing correctly on the client?
Bauke Scholtz
Ranch Hand

Joined: Oct 08, 2006
Posts: 2458
You need to flush and close the outputstream. It's apparently buffered.
If that doesn't help, try invoking URLConnection#getInputStream().
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Issue with sending xml jaxb object to servlet body
 
Similar Threads
Clarification Requested - XML recordset & JAXB classes
Communication between a Swing Client and a Servlet via HttpURLConnection
how to get XML form javaobject using JAXB
JAXB namespace
JAXB Custom Validation Handler is not receiving control during Exception