Ok, that is a enough about the motivation and usage. I thought I'd share the few lines of Java code needed to support this in JAX-RS 2.0 based implementations. Since I want the HTTP response header Accept-Post to be returned for a variety of use scenarios such as: when JAX-RS returns a 415, on OPTIONS and HEAD requests, and so on, I decided to always return the header. To do this, I implemented the ContainerResponseFilter with a simple Class and
filter()
method as:import javax.ws.rs.container.ContainerRequestContext;
import javax.ws.rs.container.ContainerResponseContext;
import javax.ws.rs.container.ContainerResponseFilter;
import javax.ws.rs.ext.Provider;
public class AcceptPostResponseFilter
implements ContainerResponseFilter {
@Override
public void filter(ContainerRequestContext requestContext,
ContainerResponseContext responseContext)
throws IOException {
responseContext.getHeaders().putSingle(
"Accept-Post",
"text/turtle", "application/ld+json", "image/png");
}
}
That is about it, except of course you needs to register this filter with your JAX-RS Application, such as:
import java.util.HashSet;
import java.util.Set;
import javax.ws.rs.core.Application;
public class MyApplication extends Application {
@Override
public Set<Class<?>> getClasses() {
Set<Class<?>> classes = new HashSet<Class<?>>();
classes.add(AcceptPostResponseFilter.class);
return classes;
}
}
I've made this change for the in-progress LDP reference implementation occurring at Eclipse Lyo.