Jim,
This has to do with what I noticed about the Client eating exceptions.
Basically, what's happening is that some of the Client methods, like
handle(), wrap certain exceptions in order to log them. However, they
don't rethrow the exceptions.
So, if you pass in a dud URL like you suggest, the restlet client will
barf out a log message telling you an error occurred, but your method
will just continue running to the next line. Instead, what should be
happening is that you should be able to put your code in a try/catch
block and that way if you do pass in a bad url, the code will move into
the catch section.
I found two places where I had to patch the client code in order to get
to see these exceptions. I provided the patches to the bug list, but
haven't really heard any response yet (it's only been a couple of days).
Anyway, if you want, you could grab the patch files from the following
bug. Alternatively, if you don't want to patch the source code, I'd be
happy to send you the jars I compiled with these changes.
http://restlet.tigris.org/issues/show_bug.cgi?id=311
Once you have this, the client will throw a (runtime) exception which
you can use like this (using your code):
try {
Client client = new Client(Protocol.HTTP);
Response response = client.post(url, objrep);
} catch (Exception e) {
// notify your user of the bad url or other problems.
}
Ultimately, what needs to happen, is that these handle methods need to
throw checked exceptions so that you as an end user _must_ catch the
exceptions. That would make for a much nicer system, since wrapping
exceptions up into runtime exceptions just to get them out of a method
is bad api design.
Hope this helps.
Adam
Jim Alateras wrote:
Hi,
I seem to have stumbled across a problem with Client. I am using the
following code to talk to my restlet application
Client client = new Client(Protocol.HTTP);
Response response = client.post(url, objrep);
logger.info("The response from the post is " +
response.getStatus().getName());
If I pass through a dud url I get the following exception
28/05/2007 22:46:58 com.noelios.restlet.http.HttpClientHelper handle
WARNING: Error while handling an HTTP client call:
28/05/2007 22:46:58 com.noelios.restlet.http.HttpClientHelper handle
INFO: Error while handling an HTTP client call
java.lang.IllegalArgumentException: Only HTTP or HTTPS resource URIs are
allowed here
at
com.noelios.restlet.ext.httpclient.HttpMethodCall.<init>(HttpMethodCall.java:121)
at
com.noelios.restlet.ext.httpclient.HttpClientHelper.create(HttpClientHelper.java:148)
at
com.noelios.restlet.http.HttpClientConverter.toSpecific(HttpClientConverter.java:75)
at
com.noelios.restlet.http.HttpClientHelper.handle(HttpClientHelper.java:85)
at org.restlet.Client.handle(Client.java:110)
at org.restlet.Uniform.handle(Uniform.java:97)
at org.restlet.Uniform.post(Uniform.java:165)
at
au.com.observant.ringocore.client.http.HttpRingoCoreClient.post(HttpRingoCoreClient.java:85)
at
au.com.observant.ringocore.dispatcher.service.DispatcherConsumer.run(DispatcherConsumer.java:237)
at java.lang.Thread.run(Thread.java:595)
2007-05-28 22:46:58,269 [Thread-2] INFO - The response from the post is OK
but the response code returned form the post is set to Status.SUCCESS_OK
(200).
The issue is that in the Uniform class the org.restlet.data.Response is
initialized with a status of OK and the IllegalArgumentException at the
top of the stack is not propageted down.
I believe the resolution is to make some changes to
com.noelios.restlet.http.HttpClientHelper.handle
form
HttpClientCall httpCall = getConverter().toSpecific(this, request);
getConverter().commit(httpCall, request, response);
to
HttpClientCall httpCall = getConverter().toSpecific(this, request);
if (httpCall != null) {
getConverter().commit(httpCall, request, response);
} else {
response.setStatus(Status.CLIENT_ERROR_NOT_FOUND);
}
but I'm not sure whether i need to make the commit() call even if there
is an error.
Can you pls advice.
cheers
</jima>