This week's book giveaway is in the General Computing forum.
We're giving away four copies of Emmy in the Key of Code and have Aimee Lucido on-line!
See this thread for details.
Win a copy of Emmy in the Key of Code this week in the General Computing forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Paweł Baczyński
  • Piet Souris
  • Vijitha Kumara

Using Commons to access URL

 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Anyone feeling generous and like to read the below?

It's throwing a "java.lang.NoClassDefFoundError: org/apache/commons/codec/DecoderException" error?

/**
* @ejb.interface-method
* view-type="remote"
*
*/
public String sendMessage(String sender, String recipient, String text){
HttpClient client = new HttpClient();
String url = "http://myapi.com/http/sendmsg";
String username = "aaa";
String password = "bbb";
String api_id = "ccc";
String status = "";
String responseBody = "";
PostMethod method = new PostMethod(url);
NameValuePair[] data = {
new NameValuePair("user",username),
new NameValuePair("password",password),
new NameValuePair("api_id",api_id),
new NameValuePair("from",sender),
new NameValuePair("to",recipient),
new NameValuePair("text",text)
};

method.addParameters(data);

DefaultMethodRetryHandler retryhandler = new DefaultMethodRetryHandler();
retryhandler.setRequestSentRetryEnabled(false);
retryhandler.setRetryCount(3);
method.setMethodRetryHandler(retryhandler);

try {
// Execute the method.
int statusCode = client.executeMethod(method);
if (statusCode != HttpStatus.SC_OK) {
System.err.println("Method failed: " + method.getStatusLine());
}

// Read the response body.
responseBody = method.getResponseBodyAsString();

// Deal with the response.
// Use caution: ensure correct character encoding and is not binary data
//status = new String(responseBody);

} catch (IOException e) {
System.err.println("Failed to download file.");
e.printStackTrace();
} finally {
// Release the connection.
method.releaseConnection();
}
return responseBody;
}
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Make sure org/apache/commons/codec/DecoderException is in your classpath.
 
Stephen Hanley
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nearly two weeks this has been wrecking the proverbial head.

Finally working perfectly. Thanks all at Javaranch for your help.
 
Catch Ernie! Catch the egg! And catch this tiny ad too:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!