• Post Reply Bookmark Topic Watch Topic
  • New Topic

Occasional Connection Reset (IO Exception) Errors when POSTing to Servlet  RSS feed

 
Mike London
Ranch Hand
Posts: 1476
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a small .NET class that I'm using to POST an XML string to my Java Servlet.

The Servlet writes the XML file to disk from the POSTed string data it gets.

I've noticed that running the .NET "EXE" doesn't always result in an XML file being created, though most of the time, it does work.

For those times, often the first time I run it, the Tomcat error log says that the Servlet has an IO Exception and with:

e.getCause="null", and
e.getMessage="connection reset".

Not sure what's causing this.

Any ideas?

-- Mike

The .NET class is simple and similar to this:
// Create a request using a URL that can receive a post.

WebRequest request = WebRequest.Create ("http://myServletAddressHere");

// Set the Method property of the request to POST.
request.Method = "POST";
// Create POST data and convert it to a byte array.

string postData = // call to .NET Web Service goes here to get XML String

byte[] byteArray = Encoding.UTF8.GetBytes (postData);
// Set the ContentType property of the WebRequest.
request.ContentType = "application/x-www-form-urlencoded";
// Set the ContentLength property of the WebRequest.
request.ContentLength = byteArray.Length;
// Get the request stream.
Stream dataStream = request.GetRequestStream ();
// Write the data to the request stream.
dataStream.Write (byteArray, 0, byteArray.Length);
// Close the Stream object.
dataStream.Close ();

(http://msdn.microsoft.com/en-us/library/debx8sh9.aspx)
 
Michael Angstadt
Ranch Hand
Posts: 278
Eclipse IDE Java PHP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why are you setting the content type to "application/x-www-form-urlencoded"? If you're sending XML, shouldn't it be "text/xml"?

Maybe the .NET web service you are using to get the XML is returning an empty response? Maybe this would cause problems?
 
Mike London
Ranch Hand
Posts: 1476
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Michael Angstadt wrote:Why are you setting the content type to "application/x-www-form-urlencoded"? If you're sending XML, shouldn't it be "text/xml"?

Maybe the .NET web service you are using to get the XML is returning an empty response? Maybe this would cause problems?


Good point.

In any case, I got the Java version of the client working and there are zero problems now.

Turned out that the "Service" class that .NET generated had, in the comments, instructions how to call the .NET WS. That was a nice touch.

Thanks for your reply.

- mike
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!