• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Bartender
Posts: 1971
17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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)
 
Ranch Hand
Posts: 282
Eclipse IDE PHP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Bartender
Posts: 1971
17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic