Reputation: 267
I want to use the following type of URL in Restlet: http://url.com/http://www.anotherurl.com/path
As a result I want to get http://www.anotherurl.com/path
as a parameter.
However it does nothing.
Also, if I use http://url.com/path
, then I receive "path" without problems. http://url.com/www.anotherurl.com
gives me www.anotherurl.com
. However http://url.com/www.anotherurl.com/path
is 404.
Upvotes: 1
Views: 1860
Reputation: 202216
In fact, there are two parts here.
The URL building using the Reference
class:
Reference ref = new Reference();
ref.setScheme("http");
ref.setHostDomain("localhost");
ref.setHostPort(8182);
ref.addSegment("test");
ref.addSegment("http://test");
ClientResource cr = new ClientResource(ref);
cr.get();
Getting the value as a path parameter and decode it. Here is the routing configuration in the application class:
public Restlet createInboundRoot() {
Router router = new Router(getContext());
router.attach("/test/{id}", MyServerResource.class);
return router;
}
And the corresponding code in the server resource:
public class MyServerResource extends ServerResource {
@Get
public Representation get() {
String id = getAttribute("id");
// Prints http%3A%2F%2Ftest
System.out.println("id = "+id);
// Prints http://test
System.out.println("id = "+Reference.decode(id));
return new EmptyRepresentation();
}
}
Hope it helps you, Thierry
Upvotes: 0
Reputation: 18835
You need to encode the parameter special characters properly. Use URLEncoder to do so.
Upvotes: 4