• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

Using Commons to access URL

 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic