You're missing the commons-code jar, which you download separately from
HttpClient. Check this link:
http://jakarta.apache.org/commons/httpclient/dependencies.html


--Steve

-----Original Message-----
From: Veni Garg [mailto:[EMAIL PROTECTED] 
Sent: Friday, August 11, 2006 12:31 PM
To: [email protected]
Subject: Error in executing PostXML sample application

Hey there!

I am trying to execute one of the sample apps provided here
PostXML.java. My
goal is to transmit and XML file to a URL and get a response back from
the
site. This app pretty much covers it. I have had trouble compiling it
first
because, it could not find the HTTPClient classes though they were right
in
the Classpath.  Eventually got it to compile, but now I cannot execute
it. I
get the following error. Any ideas or recommendations? I have had a hard
time for it to find all the commons-httpclient & commons-logging jars
though
they were in the classpath. I had to unzip the jars and put the
necessary
classes local to the PostXML.java program for it to even compile. Could
this
be part of the problem??

The code and error are posted below.

Thanksfor any input.
VG

import java.io.File;

import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.methods.FileRequestEntity;
import org.apache.commons.httpclient.methods.PostMethod;
import org.apache.commons.httpclient.methods.RequestEntity;

/**
 *
 * This is a sample application that demonstrates
 * how to use the Jakarta HttpClient API.
 *
 * This application sends an XML document
 * to a remote web server using HTTP POST
 *
 * @author Sean C. Sullivan
 * @author Ortwin Glueck
 * @author Oleg Kalnichevski
 */
public class PostXML {

    /**
     *
     * Usage:
     *          java PostXML http://mywebserver:80/ c:\foo.xml
     *
     *  @param args command line arguments
     *                 Argument 0 is a URL to a web server
     *                 Argument 1 is a local filename
     *
     */
    public static void main(String[] args) throws Exception {
        if (args.length != 2) {
            System.out.println("Usage: java -classpath <classpath>
[-Dorg.apache.commons.logging.simplelog.defaultlog=<loglevel>] PostXML
<url>
<filename>]");
            System.out.println("<classpath> - must contain the
commons-httpclient.jar and commons-logging.jar");
            System.out.println("<loglevel> - one of error, warn, info,
debug, trace");
            System.out.println("<url> - the URL to post the file to");
            System.out.println("<filename> - file to post to the URL");
            System.out.println();
            System.exit(1);
        }
        // Get target URL
        String strURL = args[0];
        // Get file to be posted
        String strXMLFilename = args[1];
        File input = new File(strXMLFilename);
        // Prepare HTTP post
        PostMethod post = new PostMethod(strURL);
        // Request content will be retrieved directly
        // from the input stream
        RequestEntity entity = new FileRequestEntity(input, "text/xml;
charset=ISO-8859-1");
        post.setRequestEntity(entity);
        // Get HTTP client
        HttpClient httpclient = new HttpClient();
        // Execute request
        try {
            int result = httpclient.executeMethod(post);
            // Display status code
            System.out.println("Response status code: " + result);
            // Display response
            System.out.println("Response body: ");
            System.out.println(post.getResponseBodyAsString());
        } finally {
            // Release current connection to the connection pool once
you
are done
            post.releaseConnection();
        }
    }
}

------------------------------------------------------------------------
----
------------------------------------------------------------------------
----
------
ERROR


C:\Program Files\Java\jdk1.6.0\bin>java PostXML
http://1.2.3.4/abcd/crg.aspx
C:\abc.xml

Exception in thread "main" java.lang.NoClassDefFoundError:
org/apache/commons/co
dec/DecoderException
        at org.apache.commons.httpclient.HttpMethodBase.<init>(Unknown
Source)
        at
org.apache.commons.httpclient.methods.ExpectContinueMethod.<init>(Unk
nown Source)
        at
org.apache.commons.httpclient.methods.EntityEnclosingMethod.<init>(Un
known Source)
        at
org.apache.commons.httpclient.methods.PostMethod.<init>(Unknown
Sourc
e)
        at PostXML.main(PostXML.java:48)

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

Reply via email to