Skip to main content

Get full path in filter at RESTful Web Services (Jersey)

Please note these java.net forums are being decommissioned and use the new and improved forums at https://community.oracle.com/community/java.
2 replies [Last post]
JackNet
Offline
Joined: 2011-09-15
Points: 0

Dear experts,

I have a question that, how can I get the full path.
eg. http://abc:8080/ContextPath/resources/abcconnect/abc
Where
abcconnect is the resources
abc is the sub-resource

In code,

String response = client.resource("http://localhost:8080/ContextPath/resources").path("abcconncet").path('abc").accept("text/html").get(String.class);

But when using filter to get the uri,
public ClientResponse handle(ClientRequest cr) throws ClientHandlerException {
ClientResponse response = null;
System.out.println(cr.getURI()); // only the "http://localhost:8080/ContextPath/resources")
response = getNext().handle(cr);
return response
}

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
JackNet
Offline
Joined: 2011-09-15
Points: 0

I want to implement "retry mechanism" to request the site with resource when it is read timeout. Since that for some reason that I cannot use try catch to do retry when throw ClientHandlerException at the request. For example,
try {
ClientResponse response = resource.path("abcconnect").path("abc").accept("text/xml").get(ClientResponse.class);
} catch (ClientHandlerException ex) {
ex.printStackTrace();
}
(Cannot use it).

So I apply the ClientFilter to add to DefaultClientConfig - client.addFilter(new HandlingTimeout());
For coding,

public class HandlingTimeout() {
private WebResource resource;

public HandlingTimeout(WebResource resource) {
this.resource = resource;
}

public ClientResponse handle(ClientRequest cr) throws ClientHandlerException {
ClientResponse response = null;
try {
response = getNext().handle(cr);
} catch (ClientHandlerException ex) {
try {
if (cr.getMethod().equals("GET")) {
response = resource.path(cr.getURI().toString()).....get(ClientResponse.class);
}
} catch (Exception e) {
e.printStackTrace();
}
}
return response;
}

JackNet
Offline
Joined: 2011-09-15
Points: 0

Can any expert help me?