IOException Bogus Chunk Size
843834Feb 22 2004 — edited Jun 7 2004Hi All,
I am getting a IOException : bogus chunk size
java.io.IOException: Bogus chunk size
at sun.net.www.http.ChunkedInputStream.processRaw(ChunkedInputStream.java:292)
at sun.net.www.http.ChunkedInputStream.readAheadBlocking(ChunkedInputStream.java:545)
at sun.net.www.http.ChunkedInputStream.readAhead(ChunkedInputStream.java:582)
at sun.net.www.http.ChunkedInputStream.read(ChunkedInputStream.java:669)
My code does the following:
1) Open a httpURLConnection to a url and sends xml to create session.
2) Gets back a binary security token and builds an XML request for invoking a webservice.
3) Sends the request
4) I am getting IOException bogus chunk size here.
In what situations does one get bogus chunk size IOexception. Any comments/pointers are higly appreciated. I am pasting my code below .
Thank you.
Anand
public class SailAvailUSGClient
{
public String m_serverName = null;
public String m_createSessionFileName = null;
public String m_sailAvailReqFileName = null;
public SailAvailUSGClient(String serverName, String createSessionFileName,
String sailAvailReqFileName)
{
m_serverName = serverName;
m_createSessionFileName = createSessionFileName;
m_sailAvailReqFileName= sailAvailReqFileName;
}
private String createSession() throws Exception
{
String outputXML = sendXMLToCreateSession();
return getBinaryToken(outputXML);
}
private String getBinaryToken(String outputXML) throws Exception
{
//Here I just parse the outputXML to extract the binary token
}
private String sendXMLToCreateSession() throws Exception
{
HttpURLConnection con = setUpConnection();
PrintWriter printWriter = new PrintWriter(con.getOutputStream()) ;
// SessionCreateXML is the XML used to create a session.
printWriter.print(sessionCreateXML);
printWriter.close();
BufferedReader bufferedReader =
new BufferedReader(new InputStreamReader( con.getInputStream()));
String inputLine = null;
StringBuffer inputCache = new StringBuffer();
while ((inputLine = bufferedReader.readLine()) != null)
{
inputCache.append( inputLine + "\n" );
}
bufferedReader.close();
//System.out.println("Output XML: " + inputCache.toString());
return inputCache.toString();
}
private HttpURLConnection setUpConnection() throws Exception
{
URL url = new URL( m_serverName);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setDoOutput(true);
connection.setDoInput(true);
connection.setUseCaches (false);
connection.setRequestProperty ("Content-Type","text/xml; charset=utf-8");
connection.setRequestMethod("POST");
return connection;
}
public void sendRequestXML(String reqXML)throws Exception
{
HttpURLConnection con = setUpConnection();
PrintWriter printWriter = new PrintWriter(con.getOutputStream()) ;
printWriter.print(reqXML);
printWriter.close();
BufferedReader bufferedReader =
new BufferedReader(new InputStreamReader( con.getInputStream()));
String inputLine = null;
StringBuffer inputCache = new StringBuffer();
while ((inputLine = bufferedReader.readLine()) != null)
{
inputCache.append( inputLine + "\n" );
}
bufferedReader.close();
System.out.println("Output XML: " + inputCache.toString());
//return inputCache.toString();
}
public static void main(String[] args)
{
try
{
SailAvailUSGClient client = new SailAvailUSGClient( "http://myURL", "c:\\temp\\sessioncreate.txt" ,"");
String binaryToken = client.createSession();
System.out.println(binaryToken);
String reqXML = ClientUtils.buildRequestXML(binaryToken);
// reqXML is just the request to be sent to invoke the webservice.
client.sendRequestXML(reqXML);
}
catch (Exception e)
{
e.printStackTrace();
}
}
}