resteasy/Resteasy — pull request #238 by liweinan (2013-01-19 06:21:45+00:00)
Title: RESTEASY-796

The patch is for this in MessageBodyParameterInjector:

```java
// We have to do this isFormData() hack because of servlets and servlet filters
// A filter that does getParameter() will screw up the input stream which will screw up the
// provider. We do it here rather than hack the provider as the provider is reused for client side
// and also, the server may be using the client framework to make another remote call.
if (isFormData(type, genericType, annotations, mediaType)) {
...
}
else {
...
}
```

We could uniform the "if...else" logic here, and make form data also pass through the ReaderInterceptor(JAXRS 2.0)/MessageBodyReaderInterceptor(JAXRS 1.0).

First we could save the original form data:

```java
MultivaluedMap origFormData = null;
if (isFormData(type, genericType, annotations, mediaType)) {
boolean encoded = FindAnnotation.findAnnotation(annotations, Encoded.class) != null;
if (encoded)
origFormData = request.getFormParameters();
else
origFormData = request.getDecodedFormParameters();
}
```

Then we let the data go through the MBR, no matter it's form data or not. After we get the data from context:

```java
final Object obj = messageBodyReaderContext.proceed();
We can judge whether obj is form data or not:
if (isFormData(obj)) {...}
```

If the return obj is form data and origFormData is not null, we could assume that the obj returned from interceptor is the modified copy and let's use it. If returned obj is not form data but origFormData exists, we can say the interceptor has ruined the data, so we'll just return origFormData:

```java
if (origFormData != null) {
if (isFormData(obj)) {
return obj;
} else {
return origFormData;
}
}
```

This could provide the uniform behavior no matter user use MultivaluedMap or primitive type as their API parameters, and it won't break the backward compatibility.