1 package org.kuali.student.enrollment.registration.client.service.impl; 2 3 import org.codehaus.jackson.jaxrs.JacksonJsonProvider; 4 5 import javax.ws.rs.Consumes; 6 import javax.ws.rs.Produces; 7 import javax.ws.rs.WebApplicationException; 8 import javax.ws.rs.core.MediaType; 9 import javax.ws.rs.core.MultivaluedMap; 10 import javax.ws.rs.ext.Provider; 11 import java.io.IOException; 12 import java.io.OutputStream; 13 import java.lang.annotation.Annotation; 14 import java.lang.reflect.Type; 15 import java.util.Map; 16 17 @Provider 18 @Consumes({MediaType.APPLICATION_JSON, "text/json"}) 19 @Produces({MediaType.APPLICATION_JSON, "text/json"}) 20 public class CustomHeaderJacksonJsonProvider extends JacksonJsonProvider { 21 private Map<String, String> headers; 22 23 @Override 24 public void writeTo(Object o, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream) throws IOException, WebApplicationException { 25 for (Map.Entry<String, String> entry : headers.entrySet()) { 26 httpHeaders.putSingle(entry.getKey(), entry.getValue()); 27 } 28 super.writeTo(o, type, genericType, annotations, mediaType, httpHeaders, entityStream); 29 } 30 31 public void setHeaders(Map<String, String> headers) { 32 this.headers = headers; 33 } 34 }