Jersey 2.x post 调用抛出 SEVERE:找不到媒体类型的 MessageBodyWriter=application/json
Jersey 2.x post call throws SEVERE: MessageBodyWriter not found for media type=application/json
我试着去关注tutorial jersey 2,但是我陷入了这个无法摆脱的异常。请求尚未到达服务器。
异常
http://localhost:8080/TBOAirAPIEndPoint/air/Consolidation
Jul 09, 2015 6:59:42 PM org.glassfish.jersey.message.internal.WriterInterceptorExecutor$TerminalWriterInterceptor aroundWriteTo
SEVERE: MessageBodyWriter not found for media type=application/json, type=class 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 通话
@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);
也没有这项工作
ClientConfig config = new ClientConfig();
config.property(MessageProperties.LEGACY_WORKERS_ORDERING, true);
我为此下载了 Genson 1.3。版本 0.94 不工作。
我试着去关注tutorial jersey 2,但是我陷入了这个无法摆脱的异常。请求尚未到达服务器。
异常
http://localhost:8080/TBOAirAPIEndPoint/air/Consolidation Jul 09, 2015 6:59:42 PM org.glassfish.jersey.message.internal.WriterInterceptorExecutor$TerminalWriterInterceptor aroundWriteTo
SEVERE: MessageBodyWriter not found for media type=application/json, type=class 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 通话
@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);
也没有这项工作
ClientConfig config = new ClientConfig();
config.property(MessageProperties.LEGACY_WORKERS_ORDERING, true);
我为此下载了 Genson 1.3。版本 0.94 不工作。