You are viewing a plain text version of this content. The canonical link for it is here.
Posted to httpclient-users@hc.apache.org by Wayne Richards <wa...@gmail.com> on 2008/03/15 18:00:27 UTC
Using HTTPClient to call Creative Commons Web Service
This is probably a newbie question, as I have just started working with
the HTTPClient.
The question is that I know that the following line placed in a browser
address line will return what I want.
http://api.creativecommons.org/rest/license/standard/issue?answers=%3Canswers%3E%0A%3Clicense-standard%3E%3Cderivatives%3Esa%3C%2Fderivatives%3E%0A%3Ccommercial%3Ey%3C%2Fcommercial%3E%0A%3Cjurisdiction%3Epl%3C%2Fjurisdiction%3E%0A%3C%2Flicense-standard%3E%0A%3C%2Fanswers%3E%0A
So I have created a simple HTTPClient app to call the web service. The
following is the code that I have generated using examples that I have
found that attempt to do what I was hoping would give me the results
that I wanted.
public class LicenseCCWebService implements Serializable {
/**
* @param args
*/
public static void main(String[] args) {
int serviceStatusCode;
String serviceAddress =
"http://api.creativecommons.org/rest/license/standard/issue";
String serviceParamaters =
("<license-standard><derivatives>sa</derivatives><commercial>y</commercial><jurisdiction>pl</jurisdiction></license-standard>");
HttpClient serviceClient = new HttpClient();
HttpMethod serviceMethod = new GetMethod(serviceAddress);
serviceClient.getParams().setParameter("<license-standard><derivatives>sa</derivatives><commercial>y</commercial><jurisdiction>pl</jurisdiction></license-standard>",
new DefaultHttpMethodRetryHandler());
System.out.println(serviceParamaters);
try {
serviceStatusCode = serviceClient.executeMethod(serviceMethod);
if (serviceStatusCode != HttpStatus.SC_OK) {
System.err.println("Method failed: " +
serviceMethod.getStatusLine());
}
} catch (HttpException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
System.out.println(serviceMethod.getResponseBodyAsString());
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
The result of running the application is:
Method failed: HTTP/1.1 500 Internal Server Error
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN"
"http://www.w3.org/TR/REC-html40/strict.dtd">
<html>
<head><title>Internal Server Error</title></head>
<body>
<h1>Internal Server Error</h1>
<p>An internal error occurred while handling your request.</p>
<p>The server administrator should have been notified of the problem.
You may wish to contact the server administrator ([no address given])
and inform them of
the time the error occurred, and anything you might have done to trigger
the error.</p>
<p>If you are the server administrator, more information may be
available in either the server's error log or Quixote's error log.</p>
</body>
</html>
I must be doing something wrong. The issue I have are:
I don't know enough to debug what is going wrong
I cannot figure out how to see what the actual method/parameters are
so that I can compare to the working method call.
I am using the HTTPClient to make the call to the web service because I
need to pass domain authentication a firewall to allow for the call to
pass-thru the firewall with authentication.
Help would be greatly appreciated and advice on how to best make this
type of service call is welcome.
Regards
Wayne
---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
For additional commands, e-mail: httpclient-users-help@hc.apache.org
Re: Using HTTPClient to call Creative Commons Web Service
Posted by Oleg Kalnichevski <ol...@apache.org>.
On Sat, 2008-03-15 at 10:00 -0700, Wayne Richards wrote:
> This is probably a newbie question, as I have just started working with
> the HTTPClient.
>
> The question is that I know that the following line placed in a browser
> address line will return what I want.
>
> http://api.creativecommons.org/rest/license/standard/issue?answers=%3Canswers%3E%0A%3Clicense-standard%3E%3Cderivatives%3Esa%3C%2Fderivatives%3E%0A%3Ccommercial%3Ey%3C%2Fcommercial%3E%0A%3Cjurisdiction%3Epl%3C%2Fjurisdiction%3E%0A%3C%2Flicense-standard%3E%0A%3C%2Fanswers%3E%0A
>
Wayne,
Use a traffic analyzer to capture packets generated by the browser and
then program HttpClient to generate identical / compatible packets.
Oleg
---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
For additional commands, e-mail: httpclient-users-help@hc.apache.org