Refine search
@Override public final Object aroundReadFrom(ReaderInterceptorContext context) throws IOException, WebApplicationException { String contentEncoding = context.getHeaders().getFirst(HttpHeaders.CONTENT_ENCODING); if (contentEncoding != null && getSupportedEncodings().contains(contentEncoding)) { context.setInputStream(decode(contentEncoding, context.getInputStream())); } return context.proceed(); }
if (tracingLogger.isLogEnabled(MsgTraceEvent.MBR_FIND)) { tracingLogger.log(MsgTraceEvent.MBR_FIND, context.getType().getName(), (context.getGenericType() instanceof Class ? ((Class) context.getGenericType()).getName() : context.getGenericType()), String.valueOf(context.getMediaType()), java.util.Arrays.toString(context.getAnnotations())); context.getType(), context.getGenericType(), context.getAnnotations(), context.getMediaType(), ReaderInterceptorExecutor.this); final EntityInputStream input = new EntityInputStream(context.getInputStream()); if (input.isEmpty() && !context.getHeaders().containsKey(HttpHeaders.CONTENT_TYPE)) { return null; } else { LOGGER.log(Level.FINE, LocalizationMessages.ERROR_NOTFOUND_MESSAGEBODYREADER(context.getMediaType(), context.getType(), context.getGenericType())); throw new MessageBodyProviderNotFoundException(LocalizationMessages.ERROR_NOTFOUND_MESSAGEBODYREADER( context.getMediaType(), context.getType(), context.getGenericType()));
@Override public Object aroundReadFrom(ReaderInterceptorContext context) throws IOException, WebApplicationException { byte[] buffer = IOUtils.toByteArray(context.getInputStream()); logger.info("The contents of request body is: \n" + new String(buffer, "UTF-8") + "\n"); context.setInputStream(new ByteArrayInputStream(buffer)); return context.proceed(); }
@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(); }
@Override public Object aroundReadFrom(ReaderInterceptorContext context) throws IOException, WebApplicationException { if (ri.getResourceClass() == BookStore.class) { String serverRead = context.getHeaders().getFirst("ServerReaderInterceptor"); if (serverRead == null || !"serverRead".equals(serverRead)) { throw new RuntimeException(); } if (ui.getPath().endsWith("/async")) { context.getHeaders().putSingle("ServerReaderInterceptor", "serverReadAsync"); } } return context.proceed(); }
Verifier verifier = (Verifier) context.getProperty(Verifier.class.getName()); if (verifier == null) return context.proceed(); MultivaluedMap<String, String> headers = context.getHeaders(); List<String> strings = headers.get(DKIMSignature.DKIM_SIGNATURE); if (strings == null) InputStream old = context.getInputStream(); try context.setInputStream(stream); Object rtn = context.proceed(); byte[] body = stream.toByteArray(); KeyRepository repository = (KeyRepository) context.getProperty(KeyRepository.class.getName()); if (repository == null) context.setInputStream(old);
@Override public Object aroundReadFrom(ReaderInterceptorContext context) throws IOException, WebApplicationException { if (context.getInputStream() != null) { context.getHeaders().add("ClientReaderInterceptor", "clientRead"); } return context.proceed(); }
@Override public Object aroundReadFrom(ReaderInterceptorContext context) throws IOException, WebApplicationException { if (ri.getResourceClass() == BookStore.class) { context.getHeaders().add("ServerReaderInterceptor", "serverRead"); } return context.proceed(); }
@SuppressWarnings("unchecked") private Object invokeReadFrom(final ReaderInterceptorContext context, final MessageBodyReader reader, final EntityInputStream input) throws WebApplicationException, IOException { final TracingLogger tracingLogger = getTracingLogger(); final long timestamp = tracingLogger.timestamp(MsgTraceEvent.MBR_READ_FROM); final InputStream stream = new UnCloseableInputStream(input, reader); try { return reader.readFrom(context.getType(), context.getGenericType(), context.getAnnotations(), context.getMediaType(), context.getHeaders(), stream); } catch (final NoContentException ex) { if (translateNce) { throw new BadRequestException(ex); } else { throw ex; } } finally { tracingLogger.logDuration(MsgTraceEvent.MBR_READ_FROM, timestamp, reader); } } }
@Override public Object aroundReadFrom(final ReaderInterceptorContext context) throws IOException, WebApplicationException { try { return context.proceed(); } catch (final WebApplicationException | MappableException | MessageBodyProviderNotFoundException e) { throw e; } catch (final Exception e) { throw new MappableException(e); } }
@Override public Object aroundReadFrom(ReaderInterceptorContext context) throws IOException, WebApplicationException { if (!enabled) { LOG.fine("Verify signature reader interceptor is disabled"); return context.proceed(); } LOG.fine("Starting interceptor message verification process"); Map<String, List<String>> responseHeaders = context.getHeaders(); byte[] messageBody = extractMessageBody(context); digestVerifier.inspectDigest(messageBody, responseHeaders); context.setInputStream(new ByteArrayInputStream(messageBody)); LOG.fine("Finished interceptor message verification process"); return context.proceed(); }
public void testWrapsInputStream(String contentType) throws WebApplicationException, IOException { ReaderInterceptorContext context = mockContext(contentType); InputStream is = mock(InputStream.class); when(context.getInputStream()).thenReturn(is); readInterceptor.aroundReadFrom(context); verifyZeroInteractions(is); ArgumentCaptor<InputStream> updatedIsCapture = ArgumentCaptor.forClass(InputStream.class); verify(context).setInputStream(updatedIsCapture.capture()); verify(context).getMediaType(); verify(context).getInputStream(); verify(context).proceed(); verifyNoMoreInteractions(context); InputStream updatedIs = updatedIsCapture.getValue(); // just make sure we have some wrapper assertNotSame(is, updatedIs); updatedIs.close(); verify(is).close(); }
@SuppressWarnings({ "unchecked", "rawtypes" }) @Override public Object aroundReadFrom(ReaderInterceptorContext c) throws IOException, WebApplicationException { Class entityCls = (Class)c.getType(); Type entityType = c.getGenericType(); MediaType entityMt = c.getMediaType(); Annotation[] entityAnns = c.getAnnotations(); if (m.get(ProviderFactory.PROVIDER_SELECTION_PROPERTY_CHANGED) == Boolean.TRUE && !reader.isReadable(entityCls, entityType, entityAnns, entityMt)) { reader = ProviderFactory.getInstance(m) .createMessageBodyReader(entityCls, entityType, entityAnns, entityMt, m); if (reader == null) { throw new RuntimeException("No reader available"); } } return reader.readFrom(entityCls, entityType, entityAnns, entityMt, new HttpHeadersImpl(m).getRequestHeaders(), c.getInputStream()); }
public class CallbackStripInterceptor implements ReaderInterceptor { private final static byte[] bytes = "callback(".getBytes(); @Override public Object aroundReadFrom(ReaderInterceptorContext context) throws IOException, WebApplicationException { int howMany = bytes.length; InputStream x = context.getInputStream(); if( !(x.available() >= howMany) ) { return context.proceed(); } x.mark( howMany ); byte[] preamble = new byte[ howMany ]; x.read( preamble ); // In case the first part of our entity doesn't have the callback String, reset the stream so downstream exploiters get the full entity. if( !Arrays.equals( preamble, callbackBytes ) ) { x.reset(); } return context.proceed(); }
public void testDoesNotWrapInputStream(String contentType) throws WebApplicationException, IOException { ReaderInterceptorContext context = mockContext(contentType); InputStream is = mock(InputStream.class); when(context.getInputStream()).thenReturn(is); readInterceptor.aroundReadFrom(context); verifyZeroInteractions(is); verify(context).getMediaType(); verify(context).proceed(); verifyNoMoreInteractions(context); }
private InputStream fetchWrappedInputStream(String base64InputString) throws WebApplicationException, IOException { ReaderInterceptorContext context = mock(ReaderInterceptorContext.class); ByteArrayInputStream bais = new ByteArrayInputStream(base64InputString.getBytes()); when(context.getInputStream()).thenReturn(bais); ArgumentCaptor<InputStream> updatesIsCapture = ArgumentCaptor.forClass(InputStream.class); alwaysBase64ReadInterceptor.aroundReadFrom(context); verify(context).setInputStream(updatesIsCapture.capture()); return updatesIsCapture.getValue(); }
@Override public InputStream getInputStream() { return readerInterceptorContext.getInputStream(); }
public Object aroundReadFrom(ReaderInterceptorContext readerContext) throws IOException, WebApplicationException { String requestLength = readerContext.getHeaders().getFirst(HttpHeaders.CONTENT_LENGTH); readerContext.setProperty(REQUEST_LENGTH_PROPERTY, requestLength); return readerContext.proceed();
@Override public void setInputStream(InputStream is) { readerInterceptorContext.setInputStream(is); }
@Override public MultivaluedMap<String, String> getHeaders() { return readerInterceptorContext.getHeaders(); }