[
https://issues.apache.org/jira/browse/CXF-7860?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16640763#comment-16640763
]
ASF GitHub Bot commented on CXF-7860:
-------------------------------------
reta commented on issue #453: CXF-7860: Reprocess @FormParam parms so they
contain the latest data
URL: https://github.com/apache/cxf/pull/453#issuecomment-427585364
@andymc12 Thanks a lot for addressing this very edgy case. I was looking how
the current implementation works and basically I was trying to understand if we
could defer the evaluation of the HTTP parameters (like `@FormParam`) to a
later phase. In general, I think it would be feasible but would significantly
impact the existing design.
However, I think I found a simple trick to make it work: reordering
parameters initialization. Here is an interesting exercise:
- `Response processForm(@FormParam("value") String value, Form form)` ->
does not work
- `Response processForm(Form form, @FormParam("value") String value)` ->
works just fine
So the idea in the nutshell is to a modify `JAXRSUtils::processParameters`
to initialize parameters in a different order. In this case, the `Form` should
be initialized before any `@FormParam`, it triggers the reader interceptors and
the right values are propagated in `Form` and `@FromParam` arguments. It should
also work in case of constructors or class members.
What do you think?
Thanks!
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
> JAX-RS @FormParam parameters are not updated when form content is modified
> --------------------------------------------------------------------------
>
> Key: CXF-7860
> URL: https://issues.apache.org/jira/browse/CXF-7860
> Project: CXF
> Issue Type: Bug
> Components: JAX-RS
> Affects Versions: 3.2.6
> Reporter: Andy McCright
> Assignee: Andy McCright
> Priority: Major
>
> The JAX-RS community noticed a difference in behavior between CXF and
> Jersey/RESTEasy where form data in the HTTP body is modified prior to
> invoking the resource method. There are two differences noted:
> 1) CXF does not invoke a MessageBodyReader (or any ReaderInterceptors) when
> there is no entity parameter. I believe that this is proper behavior - or at
> least an appropriate optimization since there is no parameter, why bother
> creating one with a MBR (and it's associated ReaderInterceptors)?
> 2) When the resource method contains both a Form parameter (entity) _and_ a
> parameter annotated with `@FormParam`, and a Filter or interceptor, etc. has
> modified the content of of the HTTP body, the value injected for the
> `@FormParam` parameter does not reflect those modifications, but the Form
> entity parameter does. This seems inconsistent, and (IMO) violates the
> spirit of the spec - note that there is no TCK test for this case, so CXF is
> still compliant - but it differs from other implementations. Here is an
> example:
>
>
> {code:java}
> @Provider
> public class FormReaderInterceptor implements ReaderInterceptor {
> private static final Logger LOG =
> LogUtils.getL7dLogger(FormReaderInterceptor.class);
> @Override
> public Object aroundReadFrom(ReaderInterceptorContext ctx) throws
> IOException, WebApplicationException {
> BufferedReader br = new BufferedReader(new
> InputStreamReader(ctx.getInputStream()));
> String line;
> while ((line = br.readLine()) != null) {
> LOG.info("readLine: " + line);
> }
> ByteArrayInputStream bais = new
> ByteArrayInputStream("value=MODIFIED".getBytes());
> ctx.setInputStream(bais);
> return ctx.proceed();
> }
> }
> {code}
>
> {code:java}
> @POST
> public Response processForm(@FormParam("value") String value, Form form)
> {...
> {code}
>
> If the HTTP request body contains "value=ORIGINAL", then when CXF invokes the
> processForm method, it will pass "ORIGINAL" to the String value, but will
> pass a Form object that contains a MultivaluedMap with entry
> "value=MODIFIED". To be consistent with Jersey and RESTEasy, CXF should
> inject MODIFIED as the String value.
>
> See JAX-RS API [Issue
> 659|https://github.com/eclipse-ee4j/jaxrs-api/issues/659] for more details.
>
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)