From: Andrew N. <AN...@fa...> - 2008-12-08 09:53:09
|
Regardless of the root cause behind the issues in my post below, for future reference we have found a solution, or work around, which consisted of placing the Form consuming method first and annotating it with: @Consumes("application/x-www-form-urlencoded") The code is then like: @POST @Path("/meetings") @Consumes("application/x-www-form-urlencoded") @Produces("application/xml") public MeetingWrapper createMeetingFromForm(@FormParam("institution" ) Long institutionId, ....etc). @POST @Path("/meetings") @Produces("application/xml") public MeetingWrapper createMeeting(@QueryParam("institution") Long institutionId, ....etc). And the result is what we need: form submission to "/meetings" is handled successfully by the createMeetingFromForm() method whilst a query encoded submission is handled by createMeeting(). Andy Andrew Newton Research Management Engineering (AlphaMetrics) FactSet Limited Broadgate West II, 1 Snowden Street, London EC2A 2DQ * And...@fa... | ( +44 (0)20 3009 7053 Andrew Newton/FactSet wrote on 01/12/2008 13:47:03: > problem using @QueryParam annotation with POST and form parameter injection > > Andrew Newton > > to: > > resteasy-developers > > 01/12/2008 13:47 > > Hi, > > We're developing some internal integration interfaces using RESTEasy > 1.0-beta-8 and its cool - thank you. > > However we are experiencing the following difficulty. Our app. > manages meetings, so I'll refer to that type here. > > We have two methods annotated to create meetings, the first with @QueryParam: > > @POST > @Path("/meetings") > @Produces("application/xml") > public MeetingWrapper createMeeting(@QueryParam("institution") Long > institutionId, ....etc). > > And the second with @FormParam: > > @POST > @Path("/meetingsForm") > @Produces("application/xml") > public MeetingWrapper createMeetingFromForm(@FormParam("institution" > ) Long institutionId, ....etc). > > Of course, what we'd like to have is just one such method. The > above are working for test requests such as: > > MockHttpRequest request = MockHttpRequest > .post("/meetingtracker/meetings?institution=" + institutionId, ....etc). > > And, invoking the second, "meetingsForm", method: > > MockHttpRequest request = MockHttpRequest > .post("/meetingtracker/meetingsForm"); > request.addFormHeader("institution", institutionId.toString()); > ....etc > > So the above examples seem fine. The problem is that we want to > support both query string and URL form parameter injection from > POSTed requests with a single signature. > > As I understand the documentation (for example RESTEasy doc. section > 5) this should be possible using the @QueryParam annotation alone. > So using the above examples, the following should work: > > MockHttpRequest request = MockHttpRequest > .post("/meetingtracker/meetings"); > request.addFormHeader("institution", institutionId.toString()); > ....etc > > In other words a single method with @QueryParam annotation should > work for both query string and URL form parameter injection from the POST. > > When we execute the above the method invocation occurs but the > parameter injection fails for every parameter: they all have the value null. > > Any assistance with this will be greatly appreciated. > > Thanks, > > Andy Newton > Andrew Newton > Research Management Engineering (AlphaMetrics) > FactSet Limited > Broadgate West II, 1 Snowden Street, London EC2A 2DQ > * And...@fa... | ( +44 (0)20 3009 7053 |