Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

replace clunky format override with a cleaner filter #14

Open
denevers opened this issue Dec 16, 2018 · 0 comments
Open

replace clunky format override with a cleaner filter #14

denevers opened this issue Dec 16, 2018 · 0 comments
Labels
Enhancement New feature or request Feature: Linked Data Broker URI resolver

Comments

@denevers
Copy link
Collaborator

denevers commented Dec 16, 2018

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

@jvanulde jvanulde added Enhancement New feature or request Feature: Linked Data Broker URI resolver labels May 29, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement New feature or request Feature: Linked Data Broker URI resolver
Projects
None yet
Development

No branches or pull requests

2 participants