Hello to all!
Forgive me, if I have made a mistake, by posting my question to an
irrelevant list, but this is my first try to use the benefits of the mailing
list.

I have just downloaded (from http://jakarta.apache.org/site/binindex.cgi)
version  2 (final) of httpclient and I am trying to create a small tester,
trying to post an xml, that I have read from a file.

I am pasting the test code that mades the post (in the code, I am creating
the test string ,  that I am willing to send, with a specific length of
10000 . The results are also the same, in case I am reading the input xml
from a file ) :

package com.intralot.melisa.bae.utils;

import com.intralot.melisa.bae.agents.agentBase;
import java.io.ByteArrayOutputStream;
import com.intralot.melisa.exceptions.iLotException;
import java.io.UnsupportedEncodingException;
import org.exolab.castor.xml.Marshaller;
import java.io.OutputStreamWriter;
import org.exolab.castor.xml.CastorException;
import java.io.ByteArrayInputStream;
import java.io.InputStreamReader;
import org.exolab.castor.types.Date;
import java.io.FileOutputStream;
import  java.io.InputStream;

import java.io.File;
import java.io.FileInputStream;

import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.methods.EntityEnclosingMethod;
import org.apache.commons.httpclient.methods.PostMethod;


public class test_post_mailinglist {
  public test_post_mailinglist() {
  }

  public static void main(String[] args) {
    test_post_mailinglist test_post1 = new test_post_mailinglist();
    System.out.println("POST");
    try {
      ///////////////////////////
      System.setProperty("org.apache.commons.logging.Log",
                         "org.apache.commons.logging.impl.SimpleLog");
 
System.setProperty("org.apache.commons.logging.simplelog.showdatetime",
                         "true");
      System.setProperty(
          "org.apache.commons.logging.simplelog.log.httpclient.wire",
"debug");
      System.setProperty(
 
"org.apache.commons.logging.simplelog.log.org.apache.commons.httpclient",
          "debug");
      String stringtosend = "";
      for (int kl = 0;kl<10000;kl++){
        stringtosend = stringtosend + "c" ;
      }
 
test_post1.SendTo("http://localhost:8080/MELISAdummy/receiver",stringtosend)
;

    }
    catch (Exception e) {
      System.out.println(e.toString());
    }

  }

  public String SendTo(String URL, String XmlStringToSend) throws Exception
{
     try {

       String strURL = URL;
       String input = XmlStringToSend ;
       PostMethod post = new PostMethod(strURL);
       //post.setRequestBody(new FileInputStream(new File("./input.xml")));
       post.setRequestBody(input);
       System.out.println(
           "--------------------------------------------------------");
       System.out.println("----------------- input.length() = " +
input.length());
       post.setRequestContentLength( post.CONTENT_LENGTH_AUTO );
       // post.setRequestContentLength( (int) input.length()
       //
post.setRequestContentLength(EntityEnclosingMethod.CONTENT_LENGTH_CHUNKED)
       post.setRequestHeader("Content-type", "text/xml; charset=UTF-8");
       HttpClient httpclient = new HttpClient();
       // Execute request
       httpclient.setConnectionTimeout(20000);
       httpclient.setTimeout(20000);
       int result = httpclient.executeMethod(post);
       System.out.println(" Response status code: " + result);
       System.out.print("Response CharSet--> ");
       System.out.println(post.getResponseCharSet());
       System.out.print("Response body--> ");
       System.out.println(post.getResponseBodyAsString());
       post.releaseConnection();
       return post.getResponseBodyAsString() ;
     }
 
catch(org.apache.commons.httpclient.HttpConnection$ConnectionTimeoutExceptio
n e){
       System.out.println("--- ConnectionTimeoutException ---");
       throw e;
     }
     catch(org.apache.commons.httpclient.HttpRecoverableException e){
       System.out.println("--- TimeoutException, ---");
       throw e;
     }
     catch (Exception exc) {
       throw exc;
     }
   }


}

The strange thing is that if I print  the results on server side, which is a
servlet (I am reading the results as :
          ServletInputStream servInStream = null;
       ByteArrayOutputStream baos = null;
       ByteArrayInputStream bais = null;
       byte[] bufByteArray = null;
       String msgIN = null;
       servInStream = request.getInputStream();
        System.out.println("--->request.getContentLength() = "
+request.getContentLength());
        bufByteArray = new byte[request.getContentLength()];
        servInStream.read(bufByteArray);
        msgIN = new String(bufByteArray, "UTF-8");
        bais = new ByteArrayInputStream(bufByteArray);
      
      System.out.println("--->bufByteArray.length = " +bufByteArray.length);
      System.out.println("--->msgIN.length()      = " +msgIN.length());
      for (int gg=0;gg<bufByteArray.length;gg++) {
        if (bufByteArray[gg]==0) break;
        System.out.print("--->byte("+gg+") = " + msgIN.charAt(gg));
      }


) 
only first 4319 bytes include a value, although the length of received data
is the same as the length of sent data (I can see these values in
system.out).
Any help would be useful,

Tassos















---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to