D
dave
I'm trying to write a string from URLConnection to a servlet. what I'm
trying to do is, get an XML file from client over URL so that the
servlet can get it and process it and send the response to the client.
The problem, here is I'm not getting the XMLstring to the servlet. I
do the
for details:
*********servlet side*********************
reader = new BufferedReader(new
InputStreamReader(httpRequest.getInputStream()));
String line = null;
int letter = 0;
while ((letter = reader.read()) != -1) {
buffer.append(letter);
//System.out.println(line);
}
} catch (Exception e) {
log(ERROR,"Cannot read from URL" + e.toString());
throw e;
} finally {
try {
reader.close();
} catch (IOException io) {
log(ERROR,"Error closing URLReader!");
throw io;
}
}
System.out.println("&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&");
SaxParser sp= new SaxParser(buffer.toString(), true);
**************client Side***********************
URL url = new URL("http://localhost/lkn?action=cartToCart");
HttpURLConnection connection = (HttpURLConnection)
url.openConnection();
connection.setDoOutput(true);
connection.setDoInput(true);
connection.setUseCaches(false);
connection.setDefaultUseCaches(false);
String queryString = buildXml().toString();
OutputStream out = connection.getOutputStream();
out.write(queryString.getBytes());
//out.write(queryString.getBytes());
out.flush();
out.close();
trying to do is, get an XML file from client over URL so that the
servlet can get it and process it and send the response to the client.
The problem, here is I'm not getting the XMLstring to the servlet. I
do the
following steps:
*client side*
1. create URL corresponding to the servlet
2. get URLConnection ( url.openConnection() )
3. enable output ( connection.setDoOutput(true) )
4. get output stream ( connection.getOutputStream() )
5. wrap the output stream into PrintWriter
6. println(string)
7. flush/close output stream
*server side*
1. get input stream for the servlet ( request.getInputStream() )
2. wrap it to BufferedReader
3. read the string
4. process it using SAX Parser
5. send the response to the client
It looks like the string has not come
through to the servlet.
for details:
*********servlet side*********************
reader = new BufferedReader(new
InputStreamReader(httpRequest.getInputStream()));
String line = null;
int letter = 0;
while ((letter = reader.read()) != -1) {
buffer.append(letter);
//System.out.println(line);
}
} catch (Exception e) {
log(ERROR,"Cannot read from URL" + e.toString());
throw e;
} finally {
try {
reader.close();
} catch (IOException io) {
log(ERROR,"Error closing URLReader!");
throw io;
}
}
System.out.println("&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&");
SaxParser sp= new SaxParser(buffer.toString(), true);
**************client Side***********************
URL url = new URL("http://localhost/lkn?action=cartToCart");
HttpURLConnection connection = (HttpURLConnection)
url.openConnection();
connection.setDoOutput(true);
connection.setDoInput(true);
connection.setUseCaches(false);
connection.setDefaultUseCaches(false);
String queryString = buildXml().toString();
OutputStream out = connection.getOutputStream();
out.write(queryString.getBytes());
//out.write(queryString.getBytes());
out.flush();
out.close();