Win a copy of Five Lines of Code this week in the OO, Patterns, UML and Refactoring 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 ...
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Using Commons to access URL

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 = "";
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)


DefaultMethodRetryHandler retryhandler = new DefaultMethodRetryHandler();

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.");
} finally {
// Release the connection.
return responseBody;
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
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.
Everybody's invited. Except this tiny ad:
Thread Boost feature
    Bookmark Topic Watch Topic
  • New Topic