This week's book giveaway is in the Jython/Python forum.
We're giving away four copies of Murach's Python Programming and have Michael Urban and Joel Murach on-line!
See this thread for details.
Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Non-browser Java app - posting to a URL  RSS feed

Rox Rox
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Obj: Program for Posting a XML file to a listener URL and get back the XML response after processing.
Constraint: That listener is protected by a thirdparty SSO tool and so a credential cookie needs to be built. this is simple and was acheived, like the the program first talks to the SSO server, establishes a session and obtains a cookie whic can be inserted to the ensuing posts to the URL.
Problem: Unable to post the file ..for details pls look at the code that i am trying ..ALL SUGGESTIONS welcome!!
public void processRequest(HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException
SMJavaAgent smja = new SMJavaAgent();
smtoken = smja.retSSOToken();
Cookie cSMSession = new Cookie("SMSESSION", smtoken);


URL u = new URL(urlString);
//IS there a way of achieving the below functionality using
//servlet's forms posting to a non-browser URL browsers are involved here
HttpURLConnection conn = (HttpURLConnection) u.openConnection();
conn.setRequestProperty("Cookie", cSMSession.getName()+"="+cSMSession.getValue());
OutputStream out = conn.getOutputStream();

//posting hte fie to the output stream
BufferedReader in = new BufferedReader(new FileReader(file));
while((s = in.readLine())!= null)
xml_line = xml_line+s;

writer.println("The XML file is ..\n");

//getting back the response from the URL
InputStream ins = conn.getInputStream();

int i = ins.available();
if ( i <= 0) break;
byte b[] = new byte[i];;
String tmp = new String(b);

//close all the open resources and disconnect
William Brogden
Author and all-around good cowpoke
Posts: 13078
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That looks pretty reasonable, but I think you need to flush that output stream. Probably the other end is waiting for the last bit of XML that is stuck in the buffer.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!