public static WebResource createWebResource()
{
final ClientConfig cc = new DefaultClientConfig();
final Client c = Client.create(cc);
final WebResource wr = c.resource("http://localhost:19801/wtg_inventory_war/wtg/rest")
.path(inv);
return wr;
}
public void tester()
{
final WebResource wr = JaxrsClientUtil.createWebResource()
.path("wtg-service");
wr.accept(MediaType.APPLICATION_XML);
String response = wr.path("get-services")
.type(MediaType.APPLICATION_XML)
.get(String.class);
System.out.println(response);
}
服務器端:Jersey客戶端API WebResource accept()沒有正確設置MIME頭?
@Path("get-services")
@GET
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
public Response handleFindInventoryServices(
@Context WtgSpringContainer ioc // Spring config for service operations
)
{
System.out.println("Got a service listing request...");
LOGGER.info("Got a service listing request");
Get the app specific data formatted in JAXB XML or JSON...
.
.
.
return Response.ok(msg).build();
}
無論什麼樣的客戶端集接受媒體類型,JSON回來?使用curl和-HAccept:application/json或application/xml可以正常工作。我想在不更改服務器端的情況下測試我的服務器。
任何指針,爲什麼我不能強制服務器作爲我的首選MIME類型的XML?
運行到此以及嘗試使用Jersey Client API與CouchDB安裝進行通信時,text/plain始終會發送,而不管我使用accept()設置的內容,因此CouchDB始終以text/plain方式響應,並且沒有任何POJO映射的東西最終在澤西客戶端發射,因爲它從來沒有看到「應用程序/ json」 - 我實際上是通過ClientFilter修改頭部,但事實證明這些頭部映射是不可變的,只是在訪問時引發異常一個寫。讓我知道你是否找到了答案。 –