• 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
  • Tim Cooke
  • paul wheaton
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

HTTPURLConnection on HP Unix

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,
I am passing an XML String through HTTPURLConnection to the server which is an HP Unix machine. First time request and response goes through. For the second time when i access the server outputstream is posing a problem. A null pointer exception is thrown and the passed XML string length is zero.
Immediate response will be greatly appreciated.
Here is the code snippet.
try
{
URL url = new URL(url_resource);
con = (HttpURLConnection) url.openConnection();
con.setUseCaches( false );
con.setDoOutput(true);
con.setDoInput(true);
con.setRequestMethod("POST");
con.setRequestProperty( "Content-Length", String.valueOf( xml_string.length() ) );
con.setRequestProperty( "Content-Type", "multi-part/form-data");
}
catch(Exception exc)
{
String s = exc.getMessage();
}
try
{
// Write out the XML Contents
PrintWriter out = new PrintWriter(new OutputStreamWriter(con.getOutputStream() ));
out.println(xml_buff.toString());
out.close();
}
catch(Exception exc1)
{
String s = exc1.getMessage();
}
After this When I try to read the message from the input stream NullPointerException is thrown and the message is as "Did not meet stated content length of OutputStream: you wrote 0 bytes and I was expecting you to write exactly 252 bytes!!!"
Regards
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
We don't have many rules around these parts, but we do have our naming policy, which requires that you use both a first and last name. Please head over here and fix yours, pronto! Thanks, pardner, and see you around the Ranch!
 
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I can't figure out what's wrong with your code, but one thing I can suggest is to use a BufferedWriter instead of a PrintWriter. The reason for this is the PrintWriter class doesn't throw any exceptions. What this means is that all exceptions that occur while using the PrintWriter are never revealed to the surrounding java code.
~P.S. if you DO decide to use a BufferedWriter, don't forget to .flush()!
 
It means our mission is in jeapordy! Quick, read this tiny ad!
Clean our rivers and oceans from home
https://www.kickstarter.com/projects/paulwheaton/willow-feeders
reply
    Bookmark Topic Watch Topic
  • New Topic