commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Adamowski, Marcin" <Marcin.Adamow...@turner.com>
Subject RE: [HttpClient] HttpClient with JRun Webserver
Date Wed, 11 Aug 2004 15:05:23 GMT
Ok it works.

I was returning EntityEnclosingMethod.CONTENT_LENGTH_CHUNKED; from getContentLenght() method
as suggested on the mailing list, and it worked with Tomcat but not with JRun, so I calculated
proper lenght of the stream + 1 (don't ask me why, but only then it worked).

Anyway the code is below..

This one enables to send any Object to the web server from the client




public class ObjectRequestEntity extends ByteArrayRequestEntity
{
   public static final org.apache.log4j.Logger log = org.apache.log4j.Logger.getLogger(ObjectRequestEntity.class);

   Object object = null;

   public ObjectRequestEntity(Object content){
     super("".getBytes());
     object = content;
   }

   public ObjectRequestEntity(Object content, String contentType){
     super("".getBytes(),contentType);
     object = content;
  }

  public void writeRequest(OutputStream out) throws IOException{
    ObjectOutputStream oos = new ObjectOutputStream(out);
    oos.reset();
    oos.writeObject(this.object);
    oos.flush();
  }

  public long getContentLength() {
//    return EntityEnclosingMethod.CONTENT_LENGTH_CHUNKED;
    long size = EntityEnclosingMethod.CONTENT_LENGTH_CHUNKED;
    try{
      ByteArrayOutputStream baos = new ByteArrayOutputStream();
      ObjectOutputStream oos = new ObjectOutputStream(baos);
      oos.writeObject(object);
      byte[] bytes = baos.toByteArray();
      oos.close();
      baos.close();
      size = bytes.length+1;
      log.debug("ContentLength : "+size);
    }catch(IOException ex){
      log.error("IOException",ex);
    }
    return size;
  }

}

-----Original Message-----
From: Adamowski, Marcin [mailto:Marcin.Adamowski@turner.com]
Sent: 11 August 2004 13:24
To: 'commons-user@jakarta.apache.org'
Subject: [HttpClient] HttpClient with JRun Webserver


Does anyone used HttpClient with JRun Webserver?

I'm trying to do something like that

Code from the client

String url = "http://localhost:8100/test.jsp";
HttpClient client = new HttpClient();
PostMethod post = new PostMethod(url);
post.setRequestEntity(new StringRequestEntity("sample String"));
client.executeMethod(post);

Code from the jsp page

ServletInputStream s = request.getInputStream();
java.io.ObjectInputStream ois = new java.io.ObjectInputStream(s);

When I'm using Tomcat, everything is fine, but on JRun when I'm trying to create ObjectInputStream
I've got an exception.

error 
java.io.EOFExceptionat java.io.ObjectInputStream$PeekInputStream.readFully(ObjectInputStream.java:2165)
...

Does onyone know what's wrong?

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org


Mime
View raw message