HTTP Post 中的 Rest 变量 api returns 0
HTTP Post Rest variable in the api returns 0
免责声明:我可能缺少一些 J2ee/Jersey 编程的基础知识。
出于某种原因,出发年份变为 0
。我想知道为什么。
请求
http://localhost:8080/myendpoint/api/BOM/BLR/0/3/9/2015/6/10/2015/1/1/1/1
请求 Junit 代码
@Test
public void test1PostSearch() throws Exception {
ClientConfig config = new DefaultClientConfig();
Client client = Client.create(config);
URI url = UriBuilder
.fromUri(
"http://"
+ LOCALHOST
+ "/myendpoint/api/BOM/BLR/"
+ FlightSearchType.OneWay.ordinal()
+ "/3/9/2015" + "/6/10/2015/"
+ CabinClass.Economy.ordinal() + "/1/1/1")
.build();
WebResource service = client.resource(url);
System.out.println(url);
String status = (String) service.type(MediaType.APPLICATION_JSON).post(
String.class, new UserNamePassword("clientID", "password"));
assertNotNull(status);
}
** 服务器端(泽西 2.x)**
@POST
@Path("api/{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("depatureYear") 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) {
log.debug("EndPointConsolidation " + depatureYear + ":" + returnYear);
输出日志
0 [http-bio-8080-exec-6] DEBUG com.EndPointConsolidation - EndPointConsolidation 0:2015
问题
为什么出发年份是 0?
愚蠢的错误,我从
@PathParam("departureMonthOfYear") int departureMonthOfYear,
@PathParam("depatureYear") int depatureYear,
@PathParam("returnDayOfMonth") int returnDayOfMonth,
至
@PathParam("departureMonthOfYear") int departureMonthOfYear,
@PathParam("depa**r**tureYear") int depa**r**tureYear,
@PathParam("returnDayOfMonth") int returnDayOfMonth,
错过了 r
:)。
免责声明:我可能缺少一些 J2ee/Jersey 编程的基础知识。
出于某种原因,出发年份变为 0
。我想知道为什么。
请求
http://localhost:8080/myendpoint/api/BOM/BLR/0/3/9/2015/6/10/2015/1/1/1/1
请求 Junit 代码
@Test
public void test1PostSearch() throws Exception {
ClientConfig config = new DefaultClientConfig();
Client client = Client.create(config);
URI url = UriBuilder
.fromUri(
"http://"
+ LOCALHOST
+ "/myendpoint/api/BOM/BLR/"
+ FlightSearchType.OneWay.ordinal()
+ "/3/9/2015" + "/6/10/2015/"
+ CabinClass.Economy.ordinal() + "/1/1/1")
.build();
WebResource service = client.resource(url);
System.out.println(url);
String status = (String) service.type(MediaType.APPLICATION_JSON).post(
String.class, new UserNamePassword("clientID", "password"));
assertNotNull(status);
}
** 服务器端(泽西 2.x)**
@POST
@Path("api/{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("depatureYear") 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) {
log.debug("EndPointConsolidation " + depatureYear + ":" + returnYear);
输出日志
0 [http-bio-8080-exec-6] DEBUG com.EndPointConsolidation - EndPointConsolidation 0:2015
问题
为什么出发年份是 0?
愚蠢的错误,我从
@PathParam("departureMonthOfYear") int departureMonthOfYear,
@PathParam("depatureYear") int depatureYear,
@PathParam("returnDayOfMonth") int returnDayOfMonth,
至
@PathParam("departureMonthOfYear") int departureMonthOfYear,
@PathParam("depa**r**tureYear") int depa**r**tureYear,
@PathParam("returnDayOfMonth") int returnDayOfMonth,
错过了 r
:)。