You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by daranha3560 <da...@rogers.com> on 2004/03/05 19:53:38 UTC
commons-httpclient-2.0.jar - class not found: org\apache\commons\httpclient\HttpMethod
Problem: I am getting a runtime error when posting an XML file
via HTTP POST to a servlet running on Tomcat 5.0.18
Error: java.lang.NoClassDefFoundError: org\apache\commons\httpclient\HttpMethod
Environment:
WINNT 4.0
jdk : Java 2 standard edition version 1.4.2_03
Downloaded software (site : http://jakarta.apache.org/site/binindex.cgi):
(downloaded yesterday afternoon)
Commons FileUpload 1.0 zip; Commons Logging 1.0.3;
Commons HttpClient 2.0 zip
jar files copied to j2sdk1.4.2_03\jre\lib\ext:
1. commons-httpclient-2.0.jar
2. commons-logging.jar
3. commons-logging-api.jar
4. commons-fileupload-1.0.jar
Tomcat 5.0.18 and client program are on the same machine
Is any other package required? Is JSSE required for j2sdk 1.4.2_03?
Is there a site for commons-httpclient FAQ?
Your help is very much appreciated.
Thanks
Diana
Code is listed below for your convenience (HttpClient sample code: jakarta-comons/httpclient/src/examples) postXML.java:
import java.io.File;
import java.io.FileInputStream;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpException;
import org.apache.commons.httpclient.methods.EntityEnclosingMethod;
import org.apache.commons.httpclient.methods.*;
public class postXML {
public static void main(String[] args) throws Exception {
try {
String strURL = "http://test.ca:80/Test1/fileUpload";
String strXMLFilename = "D:\\testXML.xml";
File input = new File(strXMLFilename);
PostMethod post = new PostMethod(strURL);
post.setRequestBody(new FileInputStream(input));
if (input.length() < Integer.MAX_VALUE) {
post.setRequestContentLength((int)input.length());
} else {
post.setRequestContentLength(EntityEnclosingMethod.CONTENT_LENGTH_CHUNKED);
}
post.setRequestHeader("Content-type", "text/xml; charset=ISO-8859-1");
HttpClient httpclient = new HttpClient();
int result = httpclient.executeMethod(post);
System.out.println("Response status code: " + result);
System.out.println("Response body: ");
System.out.println(post.getResponseBodyAsString());
post.releaseConnection();
}
catch (Exception e)
{ e.getMessage(); }
} // end main
} // end postXML
Thanks for your help.