Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Calling webservice: works from standalone app but not from weblogic

 
Simone Battagliero
Greenhorn
Posts: 1
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I'm calling a SOAP 1.1 webservice which use basic HTTP authentication. All works well in a standalone class, but if I put the same code into a web application, for example in an Action class, it doesn't work. I receive a 500 response code, and an empty body. Can you help me?
My code looks like this, using the Apache Commons libraries:

...
HttpClient client = new HttpClient();
client.getState().setCredentials(
new AuthScope("<webservice_server>", 80),
new UsernamePasswordCredentials("<username>", "<password>")
);
PostMethod post = new PostMethod("<webservice_url>");
post.setRequestHeader("SOAPAction", "<webservice_url>#<method>");
post.setRequestBody(new StringBufferInputStream(input)); //input previously defined
post.setDoAuthentication(true);
try {
int status = client.executeMethod( post );
String body = post.getResponseBodyAsString();
if(status == 200){
return body;
}else{
throw new Exception("status: " + status + " body: " + body);
}
} finally {
post.releaseConnection();
}

Thank you

Simone
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic