You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
GSIP content negotiation can override the Accept header by passing a f= parameter using a list of well known format key (stored in the configuration). right now, it's clunky code in each handler that tests this override before invoking the code.
A cleaner way to do this is to implement a PreMarcher change the Accept header
import java.io.IOException;
import java.util.ArrayList;
import javax.ws.rs.container.ContainerRequestContext;
import javax.ws.rs.container.ContainerRequestFilter;
import javax.ws.rs.container.PreMatching;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.ext.Provider;
@Provider
@PreMatching
public class FormatRequestFilter implements ContainerRequestFilter {
@Override
public void filter(ContainerRequestContext requestContext) throws IOException {
String format = requestContext.getUriInfo().getQueryParameters().getFirst("f");
ArrayList<String> mediaTypes = new ArrayList<>();
if ("application/json".equals(format) || "json".equals(format))
mediaTypes.add(MediaType.APPLICATION_JSON);
if ("text/html".equals(format) || "html".equals(format))
mediaTypes.add(MediaType.TEXT_HTML);
if (mediaTypes.size() > 0)
requestContext.getHeaders().put("Accept", mediaTypes);
}
}
this will override the header before routing the call to the right handler
The text was updated successfully, but these errors were encountered:
GSIP content negotiation can override the Accept header by passing a
f=
parameter using a list of well known format key (stored in the configuration). right now, it's clunky code in each handler that tests this override before invoking the code.A cleaner way to do this is to implement a PreMarcher change the Accept header
this will override the header before routing the call to the right handler
The text was updated successfully, but these errors were encountered: