On Oct 10, 2008, at 5:40 PM, Paulo Cordeiro wrote:
> Hi,
>
> Thank you. I need access service
>
> @GET
> @Path("/list")
> @ProduceMime( { "application/json", "application/xml" })
> public DpReports getListOfReports() {....
>
> and others similar and secure services.
>
Secured in what way? https?
Client c = Client.create();
WebResource r = c.resource("
https://host/list");
// JAXB using XML serialization
DpReports dp = r.accept("application/xml").get(DpReports.class);
// JAXB using JSON serialization
DpReports dp = r.accept("application/json").get(DpReports.class);
// JSON as String serialization
String json = r.accept("application/json").get(String.class);
It you get fed up setting the accept header you can write a client
filter to add it and add the filter to the client or the Web resource.
// I prefer JSON over XML filter
ClientFilter cf = new ClientFilter() {
public ClientResponse handle(ClientRequest cr)
throws ClientHandlerException {
cr.getMetadata().add("Accept", "application/json, application/
xml;q=0.8");
return getNext().handle(cr);
}
}
c.addFilter(cf);
Paul.