我试图关注tutorial jersey 2,但我陷入了这个我无法摆脱的异常。该请求尚未到达服务器。
异常
http://localhost:8080/TBOAirAPIEndPoint/air/Consolidation Jul 09,2015 6:59:42 PM org.glassfish.jersey.message.internal.WriterInterceptorExecutor $ TerminalWriterInterceptor aroundWriteTo
严重:找不到媒体类型= application / json的MessageBodyWriter,类型=类com.mcruiseon.airapi.tunnel.common.UserNamePassword,genericType = class com.mcruiseon.airapi.tunnel.common.UserNamePassword。
@Test
public void test1PostSearch() throws Exception {
ClientConfig config = new ClientConfig();
Client client = ClientBuilder.newClient();
URI url = UriBuilder.fromUri(
"http://" + LOCALHOST + "/TBOAirAPIEndPoint/air/Consolidation")
.build();
WebTarget service = client.target(url);
Response response = (Response) service
.path("search")
.path("/BOM/BLR/" + FlightSearchType.OneWay.ordinal()
+ "/3/9/2015" + "/6/10/2015/"
+ CabinClass.Economy.ordinal() + "/1/1/1")
.request()
--exception--.post(Entity.entity(
new UserNamePassword("clientID", "password"),
MediaType.APPLICATION_JSON), Response.class);
assertNotNull(response);
}
发布电话
@POST
@Path("search/{origin}/{destination}/{flightSearchType}/{departureDayOfMonth}/{departureMonthOfYear}/{departureYear}/{returnDayOfMonth}/{returnMonthOfYear}/{returnYear}/{cabinClass}/{adultCount}/{childCount}/{infantCount}")
@Consumes({ MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_JSON })
public Response search(@PathParam("origin") String origin,
@PathParam("destination") String destination,
@PathParam("flightSearchType") int flightSearchType,
@PathParam("departureDayOfMonth") int departureDayOfMonth,
@PathParam("departureMonthOfYear") int departureMonthOfYear,
@PathParam("departureYear") int depatureYear,
@PathParam("returnDayOfMonth") int returnDayOfMonth,
@PathParam("returnMonthOfYear") int returnMonthOfYear,
@PathParam("returnYear") int returnYear,
@PathParam("cabinClass") int cabinClass,
@PathParam("adultCount") int adultCount,
@PathParam("childCount") int childCount,
@PathParam("infantCount") int infantCount,
JAXBElement<UserNamePassword> userNamePassword) {
修改
ClientConfig config = new ClientConfig();
config.property(MessageProperties.LEGACY_WORKERS_ORDERING, true);
Client client = ClientBuilder.newClient();
URI url = UriBuilder.fromUri(
"http://" + LOCALHOST + "/TBOAirAPIEndPoint/air/Consolidation")
.build();
WebTarget service = client.target(url);
Response response = (Response) service
.path("search")
.path("/BOM/BLR/" + FlightSearchType.OneWay.ordinal()
+ "/3/9/2015" + "/6/10/2015/"
+ CabinClass.Economy.ordinal() + "/1/1/1")
.request()
.post(Entity.entity(
new UserNamePassword("clientID", "password"),
MediaType.APPLICATION_JSON), Response.class);
assertNotNull(response);
修改
我找到了migration guide from 1.x to 2.x。坦率地说,我不在乎,我只是这样工作所以我很乐意设置"jersey.config.workers.legacyOrdering") to true in ResourceConfig or ClientConfig properties.
。但是我在哪里以及如何将此变量设置为true。 ClientConfig在哪里
我还将junit代码修改为
ClientConfig config = new ClientConfig();
config.property("jersey.config.workers.legacyOrdering", true);
NOR做了这项工作
ClientConfig config = new ClientConfig();
config.property(MessageProperties.LEGACY_WORKERS_ORDERING, true);
答案 0 :(得分:0)
我为此下载了Genson 1.3。版本0.94不起作用。