Saminda,
HttpClient has Commons-Codec as a dependency which must be present on
the classpath. Please see
http://jakarta.apache.org/commons/httpclient/dependencies.html
Not much wrong with your code, but I recommend you fix the encoding problem.
Odi
Saminda Abeyruwan wrote:
Hi,
I have a client which calls for a Axis2 service deployed in "localhost"
via following code
.....
public static void main(String[] args) throws Exception {
HttpClient client = new HttpClient();
String str = "<soapenv:Envelope
xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\"
xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"
xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"
xmlns:wsrm=\"http://schemas.xmlsoap.org/ws/2005/02/rm\"
xmlns:wsa=\"http://schemas.xmlsoap.org/ws/2004/08/addressing\">\n" +
" <soapenv:Body>\n" +
" <wsrm:CreateSequence>\n" +
" <wsrm:AcksTo>\n"
+
"
<wsa:Address>http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous</wsa:Address>\n"
+
" </wsrm:AcksTo>\n" +
" </wsrm:CreateSequence>\n" +
" </soapenv:Body></soapenv:Envelope>";
PostMethod httppost = new
PostMethod("http://localhost:8080/axis2/services/MyService/echo");
//
httppost.setRequestEntity(
new InputStreamRequestEntity(new
ByteArrayInputStream(str.getBytes())));
try {
client.executeMethod(httppost);
if (httppost.getStatusCode() == HttpStatus.SC_OK) {
System.out.println(httppost.getResponseBodyAsString());
} else {
System.out.println(
"Unexpected failure: "
+ httppost.getStatusLine().toString());
}
} finally {
httppost.releaseConnection();
}
}
......
PostMehod throws the following exception,
Exception in thread "main" java.lang.NoClassDefFoundError:
org/apache/commons/codec/DecoderException
at
org.apache.commons.httpclient.HttpMethodBase.<init>(HttpMethodBase.java:217)
at
org.apache.commons.httpclient.methods.ExpectContinueMethod.<init>(ExpectContinueMethod.java:92)
at
org.apache.commons.httpclient.methods.EntityEnclosingMethod.<init>(EntityEnclosingMethod.java:114)
at
org.apache.commons.httpclient.methods.PostMethod.<init>(PostMethod.java:105)
at userguide.clients.HttpClientTests.main(HttpClientTests.java:33)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:78)
==================================================
This sample being written following the examples of the httpclient. What
has gone worng with this code.
Saminda
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]