You are viewing a plain text version of this content. The canonical link for it is here.
Posted to httpclient-users@hc.apache.org by Veni Garg <Ve...@clcsiii.com> on 2006/08/11 18:30:54 UTC
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)
Re: Error in executing PostXML sample application
Posted by Roland Weber <ht...@dubioso.net>.
Hello Veni Garg,
> I tried " javac -classpath C:\cld\myJava PostXML.java " from the command
RTFM on javac! An entry in the classpath is either a JAR, or the root
directory of a tree with .class files. It is NOT a directory in which
to look for JARs.
set CLASSPATH=c:\wherever\MyJar1.jar;c:\wherever\MyJar2.jar
cheers,
Roland
---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: httpclient-user-help@jakarta.apache.org
RE: Error in executing PostXML sample application
Posted by leung cc <dk...@hotmail.com>.
> ....
>I have the C:\Cld\myJava in my classpath. i have downloaded the following
>dependencies -
>
>commons-codec-1.3.zip
>commons-logging1.1.zip
>commons-httpclient-3.1-alpha1.zip
>
>Unzipped them and have the folders in my C:\Cld\myJava folder.
>
>However now I cannot even compile the PostXML.java. I get an error message
>saying it cannot find the Httpclient classes.
>
>I tried " javac -classpath C:\cld\myJava PostXML.java " from the command
>prompt and get the following errors. Nothing I do will find these classes.
Well, if you had simply unzipped those zip's, you are likely to have
directories named <package>-<version> under c:\cld\myjava and that won't do
you good if javac only tried to find org/apache/commons/httpclient/.... in
c:\cld\myjava. Anyway, unless you absolutely must have it that way, why not
make the jar's available somewhere in the CLASSPATH or even
$java_home/lib/ext and $java_home/jre/lib/ext (sorry, I hate to write
%java_home%... :) ?
---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: httpclient-user-help@jakarta.apache.org
RE: Error in executing PostXML sample application
Posted by Veni Garg <Ve...@clcsiii.com>.
Roland,
I did have all the dependencies in the classpath as well. Then I went and
did somehting a little silly. I had multiple versions of JDK & JRE on my
machine. So I decided to clean them up.
Now all I have is JDK1.5.0_08 and its corresponding JRE. These are both
installed by default in C:\Program Files\Java\jdk1.5.0_08
C:\Program Files\Java\jre1.5.0_08
On my C:\ I have another folder set C:\Cld\myJava which contains my
PostXML.java source.
I have the C:\Cld\myJava in my classpath. i have downloaded the following
dependencies -
commons-codec-1.3.zip
commons-logging1.1.zip
commons-httpclient-3.1-alpha1.zip
Unzipped them and have the folders in my C:\Cld\myJava folder.
However now I cannot even compile the PostXML.java. I get an error message
saying it cannot find the Httpclient classes.
I tried " javac -classpath C:\cld\myJava PostXML.java " from the command
prompt and get the following errors. Nothing I do will find these classes.
Here is the error-
C:\CLD\myJava>javac -classpath C:\Cld\myJava PostXML.java
PostXML.java:3: package org.apache.commons.httpclient does not exist
import org.apache.commons.httpclient.HttpClient;
^
PostXML.java:4: package org.apache.commons.httpclient.methods does not exist
import org.apache.commons.httpclient.methods.FileRequestEntity;
^
PostXML.java:5: package org.apache.commons.httpclient.methods does not exist
import org.apache.commons.httpclient.methods.PostMethod;
^
PostXML.java:6: package org.apache.commons.httpclient.methods does not exist
import org.apache.commons.httpclient.methods.RequestEntity;
^
PostXML.java:48: cannot find symbol
symbol : class PostMethod
location: class PostXML
PostMethod post = new PostMethod(strURL);
^
PostXML.java:48: cannot find symbol
symbol : class PostMethod
location: class PostXML
PostMethod post = new PostMethod(strURL);
^
PostXML.java:51: cannot find symbol
symbol : class RequestEntity
location: class PostXML
RequestEntity entity = new FileRequestEntity(input, "text/xml;
charset=I
SO-8859-1");
^
PostXML.java:51: cannot find symbol
symbol : class FileRequestEntity
location: class PostXML
RequestEntity entity = new FileRequestEntity(input, "text/xml;
charset=I
SO-8859-1");
^
PostXML.java:54: cannot find symbol
symbol : class HttpClient
location: class PostXML
HttpClient httpclient = new HttpClient();
^
PostXML.java:54: cannot find symbol
symbol : class HttpClient
location: class PostXML
HttpClient httpclient = new HttpClient();
^
10 errors
Any advice?
Thanks
Veni
-----Original Message-----
From: Roland Weber [mailto:http-async@dubioso.net]
Sent: Friday, August 11, 2006 10:38 AM
To: HttpClient User Discussion
Subject: Re: Error in executing PostXML sample application
Hello Veni Garg,
> Exception in thread "main" java.lang.NoClassDefFoundError:
> org/apache/commons/codec/DecoderException
the dependencies for HttpClient are listed on our website:
http://jakarta.apache.org/commons/httpclient/dependencies.html
You don't need junit at runtime, but you do need commons-codec,
as I have already told you in my last mail.
cheers,
Roland
---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: httpclient-user-help@jakarta.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: httpclient-user-help@jakarta.apache.org
Re: Error in executing PostXML sample application
Posted by Roland Weber <ht...@dubioso.net>.
Hello Veni Garg,
> Exception in thread "main" java.lang.NoClassDefFoundError:
> org/apache/commons/codec/DecoderException
the dependencies for HttpClient are listed on our website:
http://jakarta.apache.org/commons/httpclient/dependencies.html
You don't need junit at runtime, but you do need commons-codec,
as I have already told you in my last mail.
cheers,
Roland
---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: httpclient-user-help@jakarta.apache.org
RE: Error in executing PostXML sample application
Posted by Steve Terrell <St...@guideworkstv.com>.
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:Veni.Garg@clcsiii.com]
Sent: Friday, August 11, 2006 12:31 PM
To: httpclient-user@jakarta.apache.org
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: httpclient-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: httpclient-user-help@jakarta.apache.org