hc-httpclient-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Veni Garg" <Veni.G...@clcsiii.com>
Subject Error in executing PostXML sample application
Date Fri, 11 Aug 2006 16:30:54 GMT
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.

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>
            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");
        // 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;
        // 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: ");
        } finally {
            // Release current connection to the connection pool once you
are done


C:\Program Files\Java\jdk1.6.0\bin>java PostXML

Exception in thread "main" java.lang.NoClassDefFoundError:
        at org.apache.commons.httpclient.HttpMethodBase.<init>(Unknown
nown Source)
known Source)
        at org.apache.commons.httpclient.methods.PostMethod.<init>(Unknown
        at PostXML.main(PostXML.java:48)

  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message