[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
Re: [ecf-dev] ECF making rest sync calls and HTTP error status codes and message
|
Hi Veselin,
On 10/19/2011 6:51 AM, Veselin Vasilev wrote:
Hi all,
sorry if this is not the right mailing list for technical questions
but I am a first time user so do not be so mad :)
This is the right list for technical questions...you've got it right.
Even if it weren't, we wouldn't be mad :).
I need to ask a couple of questions to understand what's going wrong for
you...see below.
I am using IRemoteServiceClientContainerAdapter to make a sync rest
call like this :
....
IRemoteCallable callable =
RestCallableFactory.createCallable(resource, resource, rcp,
request.getRequestType(),
IRestCall.DEFAULT_TIMEOUT);
IRemoteServiceRegistration registration =
adapter.registerCallables(new IRemoteCallable[] { callable }, null);
IRemoteService restClientService =
adapter.getRemoteService(registration.getReference());
....
Object result =
restClientService.callSync(RestCallFactory.createRestCall(resource,
request.getBody()));
The problem is that in case of expected server error (HTTP Status is
not 200 (OK)) I get RestException with the proper status code and this
text :
"Http response not OK. URL=http://.......... responseCode=505"
Restful Server Resource implementation is also mine so I control HTTP
response status and messages.
According to
http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.5.1
"User agents SHOULD display any included entity to the user"
When I looked at the spec (thanks for the ref), it's section 10.4
(Client Error 4xx) that says that User Agent SHOULD display any included
entity to the user...while section 10.5.5 (505) says that the response
SHOULD contain an entity describing why that version is not
supported...and what other protocols are supported.
So my first question...are your response codes (in error situations)
corresponding to the intended http situations (e.g. 4xx and/or 505), or
are you using these for something app-specific?
My question is if there is a way to get the Original Error Message or
the so called server's entity containing an explanation of the error
situation because no
matter what status codes I use and response messages I set, I always
get RestException with this predefined text "Http response not OK"
Yes, there is a way to get the response and handle it in any way you
chose, but it currently involves some additional code. The code
responsible for the current behavior is in this class:
http://git.eclipse.org/c/ecf/org.eclipse.ecf.git/tree/framework/bundles/org.eclipse.ecf.remoteservice.rest/src/org/eclipse/ecf/remoteservice/rest/client/RestClientService.java
See the method invokeRemoteCall on line 65. And particularly line
83...which is where non-ok response codes are handled.
You can create a subclass of RestClientService and override
invokeRemoteCall, handleException and/or other methods...to define the
behavior you wish...for handling the response codes, etc. Also, I'm
open to making changes to this code (i.e.
RestClientService.invokeRemoteCall so as to implement all of the SHOULD
behavior as specified in the w3c spec...so if you open a bug request (at
http://bugs.eclipse.org, project: rt/ecf) and attach a code contribution
and attach it to the bug, I will make the changes as quickly as possible
(perhaps not immediately, but as quickly as I can).
Note that if you choose to define a subclass of RestClientService, you
also need to create a new ECF container class (probably subclass of
RestClientContainer would do fine...and override
RestClientContainer.createRemoteService to create the appropriate
instance of your RestClientService subclass. If you need/want info on
how to create and declare an ECF container type, please just let us know.
Thanks,
Scott