Java Code Examples for javax.ws.rs.ext.WriterInterceptorContext#proceed()

The following examples show how to use javax.ws.rs.ext.WriterInterceptorContext#proceed() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LoggingFilter.java    From ameba with MIT License 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void aroundWriteTo(final WriterInterceptorContext writerInterceptorContext)
        throws IOException, WebApplicationException {
    final LoggingStream stream = (LoggingStream) writerInterceptorContext.getProperty(ENTITY_LOGGER_PROPERTY);
    writerInterceptorContext.proceed();

    final Object requestId = Requests.getProperty(LOGGING_ID_PROPERTY);
    final long id = requestId != null ? (Long) requestId : _id.incrementAndGet();
    StringBuilder b = (StringBuilder) writerInterceptorContext.getProperty(LOGGER_BUFFER_PROPERTY);
    if (b == null) {
        b = new StringBuilder();
        writerInterceptorContext.setProperty(LOGGER_BUFFER_PROPERTY, b);
    }
    printPrefixedHeaders(b, id, RESPONSE_PREFIX, HeaderUtils.asStringHeaders(writerInterceptorContext.getHeaders()));

    if (stream != null) {
        log(stream.getStringBuilder(MessageUtils.getCharset(writerInterceptorContext.getMediaType())));
    } else {
        log(b);
    }
}
 
Example 2
Source File: BaseMethodStatsInterceptor.java    From datawave with Apache License 2.0 5 votes vote down vote up
protected ResponseMethodStats doWrite(WriterInterceptorContext context) throws IOException, WebApplicationException {
    ResponseMethodStats stats;
    long start = System.nanoTime();
    OutputStream originalOutputStream = context.getOutputStream();
    CountingOutputStream countingStream = new CountingOutputStream(originalOutputStream);
    context.setOutputStream(countingStream);
    try {
        context.proceed();
    } finally {
        long stop = System.nanoTime();
        long time = TimeUnit.NANOSECONDS.toMillis(stop - start);
        
        context.setOutputStream(originalOutputStream);
        
        stats = (ResponseMethodStats) context.getProperty(RESPONSE_STATS_NAME);
        if (stats == null) {
            log.warn("No response stats found for " + getClass() + ". Using default.");
            stats = new ResponseMethodStats();
        }
        
        RequestMethodStats requestStats = (RequestMethodStats) context.getProperty(REQUEST_STATS_NAME);
        if (requestStats == null) {
            log.warn("No request method stats found for " + getClass() + ". Using default.");
            requestStats = new RequestMethodStats();
            requestStats.callStartTime = stop + TimeUnit.MILLISECONDS.toNanos(1);
        }
        
        stats.serializationTime = time;
        stats.loginTime = requestStats.getLoginTime();
        stats.callTime = TimeUnit.NANOSECONDS.toMillis(stop - requestStats.getCallStartTime());
        stats.bytesWritten = countingStream.getCount();
        // Merge in the headers we saved in the postProcess call, if any.
        putNew(stats.responseHeaders, context.getHeaders());
    }
    
    return stats;
}
 
Example 3
Source File: LogbookServerFilter.java    From logbook with MIT License 5 votes vote down vote up
@Override
public void aroundWriteTo(final WriterInterceptorContext context) throws IOException {
    context.proceed();

    read(context::getProperty, "write-response", ResponseWritingStage.class)
            .ifPresent(throwingConsumer(ResponseWritingStage::write));
}
 
Example 4
Source File: CreateSignatureInterceptor.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Override
public void aroundWriteTo(WriterInterceptorContext context) throws IOException {
    // Only sign the request if we have a Body.
    if (context.getEntity() != null) {
        // skip digest if already set
        if (addDigest
            && context.getHeaders().keySet().stream().noneMatch(DIGEST_HEADER_NAME::equalsIgnoreCase)) {
            addDigest(context);
        } else {
            sign(context);
            context.proceed();
        }
    }
}
 
Example 5
Source File: StreamingWriterInterceptor.java    From ameba with MIT License 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void aroundWriteTo(WriterInterceptorContext context) throws IOException, WebApplicationException {
    if (isWritable(context)) {
        MultivaluedMap<String, Object> respHeaders = context.getHeaders();
        ContainerRequestContext requestContext = requestProvider.get();
        MultivaluedMap<String, String> reqHeaders = requestContext.getHeaders();
        if (reqHeaders.containsKey(MediaStreaming.RANGE)) {
            if (reqHeaders.containsKey(IF_RANGE)) {
                String ifRangeHeader = reqHeaders.getFirst(IF_RANGE);
                if (StringUtils.isBlank(ifRangeHeader)) {
                    return;
                }
                if (respHeaders.containsKey(HttpHeaders.ETAG)) {
                    if (MessageHelper.getHeaderString(respHeaders, HttpHeaders.ETAG)
                            .equals(ifRangeHeader)) {
                        applyStreaming(requestContext, context);
                        return;
                    }
                }
                if (respHeaders.containsKey(HttpHeaders.LAST_MODIFIED)) {
                    if (MessageHelper.getHeaderString(respHeaders, HttpHeaders.LAST_MODIFIED)
                            .equals(ifRangeHeader)) {
                        applyStreaming(requestContext, context);
                    }
                }
            } else {
                applyStreaming(requestContext, context);
            }
        }
    }
    context.proceed();
}
 
Example 6
Source File: HttpHeaderStatisticInjector.java    From porcupine with Apache License 2.0 5 votes vote down vote up
@Override
public void aroundWriteTo(WriterInterceptorContext context) throws IOException, WebApplicationException {
    List<Statistics> pipelines = statistics.get();
    MultivaluedMap<String, Object> headers = context.getHeaders();
    pipelines.forEach(s -> headers.add("x-porcupine-statistics-" + s.getPipelineName(), serializeStatistics(s)));
    context.proceed();
}
 
Example 7
Source File: LogbookClientFilter.java    From logbook with MIT License 5 votes vote down vote up
@Override
public void aroundWriteTo(final WriterInterceptorContext context) throws IOException, WebApplicationException {
    context.proceed();

    read(context::getProperty, "write-request", RequestWritingStage.class)
            .ifPresent(throwingConsumer(stage ->
                    context.setProperty("process-response", stage.write())));
}
 
Example 8
Source File: JAXRSHTTPSignatureTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Override
public void aroundWriteTo(WriterInterceptorContext context) throws IOException {
    // skip digest if already set or we actually don't have a body
    if (shouldAddDigest(context)) {
        addDigest(context);
    } else {
        sign(context);
        context.proceed();
    }
}
 
Example 9
Source File: TraceInterceptor.java    From dubbox-hystrix with Apache License 2.0 4 votes vote down vote up
public void aroundWriteTo(WriterInterceptorContext writerInterceptorContext) throws IOException, WebApplicationException {
    System.out.println("Writer interceptor invoked");
    writerInterceptorContext.proceed();
}
 
Example 10
Source File: LoggingFilter.java    From dubbox-hystrix with Apache License 2.0 4 votes vote down vote up
public void aroundWriteTo(WriterInterceptorContext context) throws IOException, WebApplicationException {
    OutputStreamWrapper wrapper = new OutputStreamWrapper(context.getOutputStream());
    context.setOutputStream(wrapper);
    context.proceed();
    logger.info("The contents of response body is: \n" + new String(wrapper.getBytes(), "UTF-8") + "\n");
}
 
Example 11
Source File: TraceInterceptor.java    From dubbox with Apache License 2.0 4 votes vote down vote up
public void aroundWriteTo(WriterInterceptorContext writerInterceptorContext) throws IOException, WebApplicationException {
    System.out.println("Writer interceptor invoked");
    writerInterceptorContext.proceed();
}
 
Example 12
Source File: TraceInterceptor.java    From dubbox with Apache License 2.0 4 votes vote down vote up
public void aroundWriteTo(WriterInterceptorContext writerInterceptorContext) throws IOException, WebApplicationException {
    System.out.println("Writer interceptor invoked");
    writerInterceptorContext.proceed();
}
 
Example 13
Source File: JAXRS20ClientServerBookTest.java    From cxf with Apache License 2.0 4 votes vote down vote up
@Override
public void aroundWriteTo(WriterInterceptorContext context) throws IOException, WebApplicationException {
    context.getHeaders().add("ClientWriterInterceptor", "clientWrite");
    context.proceed();
}
 
Example 14
Source File: TraceInterceptor.java    From dubbox with Apache License 2.0 4 votes vote down vote up
public void aroundWriteTo(WriterInterceptorContext writerInterceptorContext) throws IOException, WebApplicationException {
    System.out.println("Writer interceptor invoked");
    writerInterceptorContext.proceed();
}
 
Example 15
Source File: LoggingFilter.java    From dubbox with Apache License 2.0 4 votes vote down vote up
public void aroundWriteTo(WriterInterceptorContext context) throws IOException, WebApplicationException {
    OutputStreamWrapper wrapper = new OutputStreamWrapper(context.getOutputStream());
    context.setOutputStream(wrapper);
    context.proceed();
    logger.info("The contents of response body is: \n" + new String(wrapper.getBytes(), "UTF-8") + "\n");
}
 
Example 16
Source File: LoggingFilter.java    From dubbox with Apache License 2.0 4 votes vote down vote up
public void aroundWriteTo(WriterInterceptorContext context) throws IOException, WebApplicationException {
    OutputStreamWrapper wrapper = new OutputStreamWrapper(context.getOutputStream());
    context.setOutputStream(wrapper);
    context.proceed();
    logger.info("The contents of response body is: \n" + new String(wrapper.getBytes(), "UTF-8") + "\n");
}
 
Example 17
Source File: TestWriterInterceptor.java    From microprofile-rest-client with Apache License 2.0 4 votes vote down vote up
@Override
public void aroundWriteTo(WriterInterceptorContext writerInterceptorContext) throws IOException, WebApplicationException {
    invocations.incrementAndGet();
    writerInterceptorContext.proceed();
}
 
Example 18
Source File: LoggingFilter.java    From dubbox with Apache License 2.0 4 votes vote down vote up
public void aroundWriteTo(WriterInterceptorContext context) throws IOException, WebApplicationException {
    OutputStreamWrapper wrapper = new OutputStreamWrapper(context.getOutputStream());
    context.setOutputStream(wrapper);
    context.proceed();
    logger.info("The contents of response body is: \n" + new String(wrapper.getBytes(), "UTF-8") + "\n");
}
 
Example 19
Source File: DynamicTraceInterceptor.java    From dubbo-2.6.5 with Apache License 2.0 4 votes vote down vote up
@Override
public void aroundWriteTo(WriterInterceptorContext writerInterceptorContext) throws IOException, WebApplicationException {
    System.out.println("Dynamic writer interceptor invoked");
    writerInterceptorContext.proceed();
}
 
Example 20
Source File: DynamicTraceInterceptor.java    From dubbox with Apache License 2.0 4 votes vote down vote up
public void aroundWriteTo(WriterInterceptorContext writerInterceptorContext) throws IOException, WebApplicationException {
    System.out.println("Dynamic writer interceptor invoked");
    writerInterceptorContext.proceed();
}