I'm using Restlet 2.0.0. I have a web service implemented using Restlet and the
digest authentication add-on. Everything works fine, I can write functioning
clients with Restlet.
Problem is, I need this to work with a webpage client, which communicates with
the server with AJAX. It seems that the AJAX implementation of many browsers
cannot properly deal with digest authentication, so I have tried to write a
workaround by creating a ServerResource called "AjaxDispatcher" that takes
incoming requests, modifies them to contain authentication data, and forward
them to corresponding ServerResources. That is, when I receive a request (A) to
URI "/ajax/do/this", I handle it, and make another request (B) to URI
"/do/this" with authentication taken in mind, and try to set the response to A
to whatever the response to B is.
(Another) problem is - I can't. After creating the ClientResource to
"/do/this", setting its request, and calling its get() method, whatever
response I try to give to A is seemingly ignored. A 200 OK and empty entity is
always returned. Also I keep being told something like the HTTP protocol isn't
supported.
I'm not good at describing things and may have made a mess above; anyway,
here's part of the (simplified) problematic code.
class AjaxDispatcher extends ServerResource {
@Get
public void handleGet() {
ClientResource client = new
ClientResource("http://localhost:31416/do/this");
System.out.println("trying to get " + client.getReference().toString());
client.get();
System.out.println(client.getResponse().getStatus());
setResponse(client.getResponse());
System.out.println(getStatus());
}
}
I get the following output when I GET http://localhost:31416/ajax/do/this:
trying to get http://localhost:31416/do/this
Jul 27, 2010 12:45:29 PM org.restlet.engine.component.ClientRouter getNext
WARNING: The protocol used by this request is not declared in the list of
client connectors. (HTTP/1.1)
Not Found (404) - The server has not found anything matching the request URI
Not Found (404) - The server has not found anything matching the request URI
Jul 27, 2010 12:45:29 PM org.restlet.engine.log.LogFilter afterHandle
INFO: 2010-07-27 12:45:29 127.0.0.1 - -
31416 GET /ajax/do/this - 200 0 0
260 http://localhost:31416 Mozilla/5.0 (X11; U; Linux i686;
en-US) AppleWebKit/534.3 (KHTML, like Gecko) Chrome/6.0.472.0 Safari/534.3
-
Jul 27, 2010 12:45:29 PM org.restlet.engine.http.connector.ServerConnection
writeMessage
WARNING: A response with a 200 (Ok) status should have an entity. Make sure
that resource "http://localhost:31416/ajax/do/this" returns one or sets the
status to 204 (No content).
Another strange thing is that it says GETting /do/this results in a 404. That's
weird since GETting it outside the ServerResource, in a standalone client,
works just fine.
Any help would be most appreciated.
------------------------------------------------------
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=2638482