/* * (non-Javadoc) * * @see * com.sun.jersey.spi.container.ContainerRequestFilter#filter(com.sun.jersey * .spi.container.ContainerRequest) */ @Override public ContainerRequest filter(ContainerRequest request) { if (!initDone) { init(); } if (logStdOut) { String path = request.getRequestUri().getPath(); // mediaType=multipart/form-data;boundary=----WebKitFormBoundaryTHan76r5AkgpAuVG if (request.getMediaType() != null) { // logger.info("DELETE ME: mediaType=" + request.getMediaType() // + ", getType()" + request.getMediaType().getType() // + ", getSubType()=" // + request.getMediaType().getSubtype()); } else { logger.info("DELETE ME: mediaType is null. path=" + path); } if ((request.getMediaType() == null || !request.getMediaType().getType().equals("multipart")) && !path.endsWith("/service/general/logs")) { try { request = super.filter(request); } catch (Throwable t) { logger.error("Error FILTER logging. path=" + path, t); } } } return request; }
@Override public ContainerRequest filter(final ContainerRequest request) { if (this.forceSSL && (!request.isSecure())) { throw new PermanentRedirectException( UriBuilder.fromUri(request.getRequestUri()).scheme("https").build()); } return request; }
@Override public ContainerRequest filter(ContainerRequest containerRequest) { try { // Calling setURIs method clears the cached method, path etc. containerRequest.setUris( containerRequest.getBaseUri(), new URI(containerRequest.getRequestUri().toString().replace("/ws/", "/"))); } catch (URISyntaxException e) { e.printStackTrace(); } return containerRequest; }
public static CacheRequestContext build( ContainerRequest request, Set<String> vary, boolean includeBody) { try { MessageDigest digest = MessageDigest.getInstance("SHA-1"); for (String header : vary) { List<String> headerValues = request.getRequestHeader(header); if (headerValues != null && headerValues.size() > 0) { digest.update(header.getBytes(Charsets.UTF_8)); digest.update((byte) 0xFD); for (String value : headerValues) { digest.update(value.getBytes(Charsets.UTF_8)); digest.update((byte) 0xFE); } digest.update((byte) 0xFF); } } if (includeBody) { byte[] requestBody = request.getEntity(byte[].class); if (requestBody == null) { requestBody = new byte[0]; } if (requestBody.length > 0) { digest.update("Body".getBytes(Charsets.UTF_8)); digest.update((byte) 0xFD); digest.update(requestBody); digest.update((byte) 0xFF); } request.setEntityInputStream(new ByteArrayInputStream(requestBody)); } String hash = new String(Base64.encode(digest.digest()), Charsets.US_ASCII); return new CacheRequestContext( request.getMethod(), request.getRequestUri(), request.getRequestHeaders(), hash); } catch (NoSuchAlgorithmException ex) { // This error should not occur since SHA-1 must be included with every java distribution throw Throwables.propagate(ex); } }