commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Rosa <rml...@terra.es>
Subject Re: HttpClient problem
Date Wed, 28 Sep 2005 08:01:51 GMT
Rosa wrote:

> Kedar Panse wrote:
>
>> If its a applet, are you including httpclient classes with it?  It 
>> seems from the error that its not able to load the claases
>>
>> Kedar
>>
>> Rosa wrote:
>>
>>> I am developing an applet that sends two byte arrays and two 
>>> parameters to the server. It uses the HttpClient library. The code 
>>> looks like this:
>>>                               ...
>>>                URL url = new URL(baseApp, "../guardaHr.do");
>>>                //HttpClient version 3.0-rc2
>>>                PostMethod pM = new PostMethod(url.getPath());
>>>                try {
>>>                    byte [] oA = UtilXML.creaFXML(docA);
>>>                    byte [] oP = UtilXML.creaFXML(docG);
>>>                    pM.addParameter("fI", fIniStr);
>>>                    pM.addParameter("fF", fFinStr);
>>>                    ByteArrayPartSource horA = new 
>>> ByteArrayPartSource("horA.xml", oA);
>>>                    ByteArrayPartSource horP = new 
>>> ByteArrayPartSource("horP.xml", oP);
>>>                    FilePart p1 = new FilePart("hA", horA);
>>>                    FilePart p2 = new FilePart("hP", horP);
>>>                    Part[] partes = {p1, p2};
>>>                    pM.setRequestEntity(new 
>>> MultipartRequestEntity(partes, pM.getParams()));
>>>                    HttpClient cliente = new HttpClient();
>>>                    
>>> cliente.getHttpConnectionManager().getParams().setConnectionTimeout(30000); 
>>>
>>>                    int estado = cliente.executeMethod(pM);
>>>                    if (estado == HttpStatus.SC_OK) {
>>>                        System.out.println(
>>>                            "Upload finished, response=" + 
>>> pM.getResponseBodyAsString()
>>>                        );
>>>                    } else {
>>>                        System.out.println(
>>>                            "Upload failed, response=" + 
>>> HttpStatus.getStatusText(estado)
>>>                        );
>>>                    }
>>>                    pM.releaseConnection();
>>>                }
>>>                catch (Exception ex) {
>>>                    ex.printStackTrace();
>>>                    pM.releaseConnection();
>>>                }                          ...
>>>
>>>
>>>
>>> The code compiles fine. The applet is not signed because I am not 
>>> accessing the file system at all. When I try to load the applet from 
>>> the web browser I get the following error
>>>
>>>    java.lang.NoClassDefFoundError: 
>>> org/apache/commons/httpclient/methods/multipart/PartSource
>>>
>>>        at java.lang.Class.getDeclaredConstructors0(Native Method)
>>>
>>>        at java.lang.Class.privateGetDeclaredConstructors(Unknown 
>>> Source)
>>>
>>>        at java.lang.Class.getConstructor0(Unknown Source)
>>>
>>>        at java.lang.Class.newInstance0(Unknown Source)
>>>
>>>        at java.lang.Class.newInstance(Unknown Source)
>>>
>>>        at sun.applet.AppletPanel.createApplet(Unknown Source)
>>>
>>>        at sun.plugin.AppletViewer.createApplet(Unknown Source)
>>>
>>>        at sun.applet.AppletPanel.runLoader(Unknown Source)
>>>
>>>        at sun.applet.AppletPanel.run(Unknown Source)
>>>
>>>        at java.lang.Thread.run(Unknown Source)
>>>
>>>
>>> Do somebody knows what is happening?
>>>
>>> Thanks in advance
>>>
>>> Rosa
>>>
>>>
>>>
>>>
>>>
>>> ---------------------------------------------------------------------
>>> 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
>>
>>
>
> Yes, I am including them. I put the same code in a standalone class 
> and I get a distinct error. The code of the class is
>
> import java.net.URL;
>
> import org.apache.commons.httpclient.HttpClient;
> import org.apache.commons.httpclient.HttpStatus;
> import org.apache.commons.httpclient.methods.PostMethod;
> import 
> org.apache.commons.httpclient.methods.multipart.ByteArrayPartSource;
> import org.apache.commons.httpclient.methods.multipart.FilePart;
> import 
> org.apache.commons.httpclient.methods.multipart.MultipartRequestEntity;
> import org.apache.commons.httpclient.methods.multipart.Part;
>
> /*
> * Created on 14-jun-2005
> *
> * TODO To change the template for this generated file go to
> * Window - Preferences - Java - Code Style - Code Templates
> */
>
> /**
> * @author Rosa
> *
> * TODO To change the template for this generated type comment go to
> * Window - Preferences - Java - Code Style - Code Templates
> */
> public class Cliente {
>
>    public static void main(String[] args) {
>        PostMethod pM =null;
>        try {
>        URL url = new URL("http://localhost:8085/sigp/guardaHr.do");
>                    //Asi se hace con la version 3.0 de la api
>            pM = new PostMethod(url.getPath());
>                            byte [] oA = "abc".getBytes();
>            byte [] oP = "def".getBytes();
>            pM.addParameter("fI", "12/31/2004");
>            pM.addParameter("fF", "12/31/2005");
>            ByteArrayPartSource horA = new 
> ByteArrayPartSource("horA.xml", oA);
>            ByteArrayPartSource horP = new 
> ByteArrayPartSource("horP.xml", oP);
>                          FilePart p1 = new FilePart("hA", horA);
>            FilePart p2 = new FilePart("hP", horP);
>            Part[] partes = {p1, p2};
>                      pM.setRequestEntity(new 
> MultipartRequestEntity(partes, pM.getParams()));
>            HttpClient cliente = new HttpClient();
>            
> cliente.getHttpConnectionManager().getParams().setConnectionTimeout(30000); 
>
>            int estado = cliente.executeMethod(pM);
>            if (estado == HttpStatus.SC_OK) {
>                System.out.println(
>                    "Upload finished, response=" + 
> pM.getResponseBodyAsString()
>                );
>            } else {
>                System.out.println(
>                    "Upload failed, response=" + 
> HttpStatus.getStatusText(estado)
>                );
>            }
>            pM.releaseConnection();
>        }
>        catch (Exception ex) {
>            ex.printStackTrace();
>            System.out.println("Exception "+ex.toString());
>            pM.releaseConnection();
>        }     }
> }
>
> and the error I get now is
>
>    java.lang.IllegalArgumentException: host parameter is null
>    at 
> org.apache.commons.httpclient.HttpConnection.<init>(HttpConnection.java:206) 
>
>    at 
> org.apache.commons.httpclient.HttpConnection.<init>(HttpConnection.java:155) 
>
>    at 
> org.apache.commons.httpclient.SimpleHttpConnectionManager.getConnectionWithTimeout(SimpleHttpConnectionManager.java:132)

>
>    at 
> org.apache.commons.httpclient.HttpMethodDirector.executeMethod(HttpMethodDirector.java:152)

>
>    at 
> org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:393) 
>
>    at 
> org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:324)Exception

> java.lang.IllegalArgumentException: host parameter is null
>
>    at Cliente.main(Cliente.java:50)
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-user-help@jakarta.apache.org
>
>
OK. The standalone class works fine if I replace url.getPath() with 
url.toString(), but the applet still doesn´t work.

---------------------------------------------------------------------
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