Hi,
I am trying to use HttpClient.
I am trying HttpConnection for persistent connection
between a standalone client and a servlet. I am
pasting the code here. Though I could send data using
multiple postMethod.execute(), and receive them in
servlet, I could not do with streams got from
HttpConnection object.
SendChunks.java :
=================
public class SendChunks{
public static void main(String a[]){
try{
HttpConnection con = new
HttpConnection("127.0.0.1",8080);
con.open();
PostMethod pm = new PostMethod("/");
Header hdr = new
Header("Transfer-Encoding","chunked");
pm.addRequestHeader("Content-type",
"text/html; charset=\"utf-8\"");
pm.addRequestHeader("Connection","Keep-Alive");
pm.addRequestHeader("Transfer-Encoding","chunked");
pm.addRequestHeader("Host","192.168.150.109");
pm.setUseDisk(false);
pm.setRequestHeader(hdr);
RequestOutputStream rs =
(RequestOutputStream)con.getRequestOutputStream(true);
rs.println("chunked line 1");
rs.println("chunked line 2");
con.close();
}catch(Exception e){
e.printStackTrace();
}
}
}
ServerServlet.java :
===================
public class ServerServlet extends HttpServlet {
private static String[] buf = new String[1000];
private static int readIndex = 0;
private static int writeIndex = 0;
protected void genericService(HttpServletRequest
request,
HttpServletResponse response){
try{
//check header
System.out.println("chunked : " +
request.getHeader("Transfer-Encoding"));
//read chunked data
StringBuffer bufInput = new StringBuffer();
ServletInputStream in =
request.getInputStream();
for(int c = in.read(); c != -1; c =
in.read()) {
if(c == -1) {
break;
} else {
System.out.println("char :" + c);
bufInput.append((char)c);
}
}
System.out.println("bufInput : " +
bufInput.toString());
}catch(Exception e){
e.printStackTrace();
}
}
Any sample code/pointers will be of great help. (As I
could not get any resource in net, I am posting it
here. And the code in test/ in cvs does not serve
this particular purpose.)
Regards,
Uma
__________________________________________________
Do You Yahoo!?
LAUNCH - Your Yahoo! Music Experience
http://launch.yahoo.com
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>