Raw XML Push from input stream captures only the first line of XML
Posted
by
pqsk
on Stack Overflow
See other posts from Stack Overflow
or by pqsk
Published on 2010-12-17T04:49:26Z
Indexed on
2010/12/21
5:00 UTC
Read the original article
Hit count: 424
I'm trying to read XML that is being pushed to my java app. I originally had this in my glassfish server working. The working code in glassfish is as follows:
public class XMLPush implements Serializable
{
public void processXML()
{
StringBuilder sb = new StringBuilder();
BufferedReader br = null;
try
{
br = ((HttpServletRequest)FacesContext.getCurrentInstance().getExternalContext().getRequest()).getReader ();
String s = null;
while((s = br.readLine ()) != null)
{
sb.append ( s );
}
//other code to process xml
...........
.............................
}catch(Exception ex)
{
XMLCreator.exceptionOutput ( "processXML","Exception",ex);
}
....
.....
}//processXML
}//class
It works perfect, but my client is unable to have glassfish on their server. I tried grabbing the raw xml from php, but I couldn't get it to work. I decided to open up a socket and listen for the xml push manually. Here is my code for receiving the push:
public class ListenerService extends Thread
{
private BufferedReader reader = null;
private String line;
public ListenerService ( Socket connection )thows Exception
{
this.reader = new BufferedReader ( new InputStreamReader ( connection.getInputStream () ) );
this.line = null;
}//ListenerService
@Override
public void run ()
{
try
{
while ( (this.line = this.reader.readLine ()) != null)
{
System.out.println ( this.line );
........
}//while
} System.out.println ( ex.toString () );
}
} catch ( Exception ex )
{
...
}//catch
}//run
I haven't done much socket programing, but from what I read for the past week is that passing the xml into a string is bad. What am I doing wrong and why is it that in glassfish server it works, and when I just open a socket myself it doesn't?
this is all that I receive from the push:
PUT /?XML_EXPORT_REASON=ResponseLoop&TIMESTAMP=1292559547 HTTP/1.1
Host: ************************
Accept: */*
Content-Length: 470346
Expect: 100-continue
<?xml version="1.0" encoding="UTF-8" ?>
Where did the xml go? Is it because I am placing it in a string? I just need to grab the xml and save it into a file and then process it. Everything else works, but this.Any help would be greatly appreciated.
© Stack Overflow or respective owner