@Override public Response getListingJson(Application app, ServletConfig sc, HttpHeaders headers, UriInfo uriInfo) throws JsonProcessingException { Response response = getListingJsonResponse(app, context, sc, headers, uriInfo); response.getHeaders().add("Access-Control-Allow-Origin", "*"); response.getHeaders().add("Access-Control-Allow-Headers", "x-requested-with, ssi-token"); response.getHeaders().add("Access-Control-Max-Age", "3600"); response.getHeaders().add("Access-Control-Allow-Methods","GET,POST,PUT,DELETE,OPTIONS"); return response; } }
@Override public Response getListingJson(Application app, ServletConfig sc, HttpHeaders headers, UriInfo uriInfo) throws JsonProcessingException { Response response = getListingJsonResponse(app, context, sc, headers, uriInfo); response.getHeaders().add("Access-Control-Allow-Origin", "*"); response.getHeaders().add("Access-Control-Allow-Headers", "x-requested-with, ssi-token"); response.getHeaders().add("Access-Control-Max-Age", "3600"); response.getHeaders().add("Access-Control-Allow-Methods","GET,POST,PUT,DELETE,OPTIONS"); return response; } }
@Override public void filter(ContainerRequestContext requestContext, ContainerResponseContext responseContext) throws IOException { if (!cacheResponseHeader.isEmpty()) { responseContext.getHeaders().add(HttpHeaders.CACHE_CONTROL, cacheResponseHeader); } }
public static void encodeAttachments(MultivaluedMap<String, Object> headers, Map<String, String> attachments) { if (attachments == null || attachments.isEmpty()) return; StringBuilder value = new StringBuilder(); for (Map.Entry<String, String> entry : attachments.entrySet()) { value.append(StringTools.urlEncode(entry.getKey())).append("=") .append(StringTools.urlEncode(entry.getValue())).append(";"); } if (value.length() > 1) value.deleteCharAt(value.length() - 1); headers.add(ATTACHMENT_HEADER, value.toString()); }
/** * Add new cookie to the message headers. * * @param cookie cookie to be added. */ public void cookie(final Cookie cookie) { getHeaders().add(HttpHeaders.COOKIE, cookie); }
/** * Add new cache control entry to the message headers. * * @param cacheControl cache control entry to be added. */ public void cacheControl(final CacheControl cacheControl) { getHeaders().add(HttpHeaders.CACHE_CONTROL, cacheControl); }
/** * Add new cache control entry to the message headers. * * @param cacheControl cache control entry to be added. */ public void cacheControl(final CacheControl cacheControl) { getHeaders().add(HttpHeaders.CACHE_CONTROL, cacheControl); }
@Override public void filter(ClientRequestContext requestContext) throws IOException { int size = 0; for (Map.Entry<String, String> entry : RpcContext.getContext().getAttachments().entrySet()) { String key = entry.getKey(); String value = entry.getKey(); if (illegalForRest(key) || illegalForRest(value)) { throw new IllegalArgumentException("The attachments of " + RpcContext.class.getSimpleName() + " must not contain ',' or '=' when using rest protocol"); } // TODO for now we don't consider the differences of encoding and server limit if (value != null) { size += value.getBytes("UTF-8").length; } if (size > MAX_HEADER_SIZE) { throw new IllegalArgumentException("The attachments of " + RpcContext.class.getSimpleName() + " is too big"); } String attachments = key + "=" + value; requestContext.getHeaders().add(DUBBO_ATTACHMENT_HEADER, attachments); } }
@Override public void filter(ContainerRequestContext requestContext, ContainerResponseContext responseContext) throws IOException { final Timer.Context context = (Timer.Context) requestContext.getProperty("metricsTimerContext"); if (context == null) return; final long elapsedNanos = context.stop(); responseContext.getHeaders().add("X-Runtime-Microseconds", TimeUnit.NANOSECONDS.toMicros(elapsedNanos)); } }
@Override public void filter(ContainerRequestContext requestContext, ContainerResponseContext responseContext) throws IOException { // Add no-cache to XMLHttpRequests, to avoid browsers caching results String requestedWith = requestContext.getHeaders().getFirst("X-Requested-With"); if ("XMLHttpRequest".equals(requestedWith)) { responseContext.getHeaders().add("Cache-Control", "no-cache"); } } }
@Override public void filter(ClientRequestContext requestContext) throws IOException { int size = 0; for (Map.Entry<String, String> entry : RpcContext.getContext().getAttachments().entrySet()) { String key = entry.getKey(); String value = entry.getKey(); if (illegalForRest(key) || illegalForRest(value)) { throw new IllegalArgumentException("The attachments of " + RpcContext.class.getSimpleName() + " must not contain ',' or '=' when using rest protocol"); } // TODO for now we don't consider the differences of encoding and server limit if (value != null) { size += value.getBytes("UTF-8").length; } if (size > MAX_HEADER_SIZE) { throw new IllegalArgumentException("The attachments of " + RpcContext.class.getSimpleName() + " is too big"); } String attachments = key + "=" + value; requestContext.getHeaders().add(DUBBO_ATTACHMENT_HEADER, attachments); } }
@Override public void filter(ContainerRequestContext requestContext, ContainerResponseContext responseContext) throws IOException { if (responseContext.hasEntity()) { Exception e = (Exception) responseContext.getEntity(); if (exceptionClass.isAssignableFrom(e.getClass()) || (e.getCause() != null && exceptionClass.isAssignableFrom(e.getCause().getClass()))) { meter.mark(); } responseContext.setEntity(null); responseContext.getHeaders().add("X-Exceptions-Thrown", e.toString() + " : " + meter.getCount()); } } }
@Override public void filter(ContainerRequestContext requestContext, ContainerResponseContext responseContext) throws IOException { responseContext.getHeaders().add("X-Graylog-Node-ID", nodeId.toString()); } }
@Override public void filter(ClientRequestContext context) throws IOException { if (context.hasEntity() && context.getHeaders().getFirst(HttpHeaders.CONTENT_ENCODING) == null && this.forceEncoding) { context.getHeaders().add(HttpHeaders.CONTENT_ENCODING, "gzip"); } }
@Override public void filter(ClientRequestContext requestContext) throws IOException { if (!requestContext.getHeaders().containsKey(HttpHeaders.ACCEPT_ENCODING)) { requestContext.getHeaders().add(HttpHeaders.ACCEPT_ENCODING, "gzip"); } if (hasEntity(requestContext) && isCompressionEnabled()) { Object contentEncoding = requestContext.getHeaders().getFirst(HttpHeaders.CONTENT_ENCODING); if (!"gzip".equals(contentEncoding)) { requestContext.getHeaders().add(HttpHeaders.CONTENT_ENCODING, "gzip"); } } }
@Override public Object aroundReadFrom(ReaderInterceptorContext context) throws IOException { if (!context.getHeaders().containsKey(HttpHeaders.ACCEPT_ENCODING)) { context.getHeaders().add(HttpHeaders.ACCEPT_ENCODING, "gzip"); } final String contentEncoding = context.getHeaders().getFirst(HttpHeaders.CONTENT_ENCODING); if (contentEncoding != null && (contentEncoding.equals("gzip") || contentEncoding.equals("x-gzip"))) { context.setInputStream(new GZIPInputStream(context.getInputStream())); } return context.proceed(); }
/** * Add a new header value. * * @param name header name. * @param value header value. * @return updated context. */ public InboundMessageContext header(String name, Object value) { getHeaders().add(name, HeaderUtils.asString(value, RuntimeDelegate.getInstance())); return this; }
private javax.ws.rs.core.Response.ResponseBuilder header(String name, Object value, boolean single) { if (value != null) { if (single) { context.getHeaders().putSingle(name, value); } else { context.getHeaders().add(name, value); } } else { context.getHeaders().remove(name); } return this; }
/** * Add a new header value. * * @param name header name. * @param value header value. * @return updated context. */ public InboundMessageContext header(String name, Object value) { getHeaders().add(name, HeaderUtils.asString(value, RuntimeDelegate.getInstance())); return this; }