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

The following examples show how to use javax.ws.rs.ext.WriterInterceptorContext#setMediaType() . 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: CaptchaWriterInterceptor.java    From ameba with MIT License 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void aroundWriteTo(WriterInterceptorContext context) throws IOException, WebApplicationException {
    Object entity = context.getEntity();
    if (entity instanceof Images.Captcha || entity instanceof Captcha) {
        context.setMediaType(IMG_TYPE);
        context.getHeaders().putSingle(HttpHeaders.CONTENT_TYPE, IMG_TYPE);
        if (entity instanceof Captcha) {
            Captcha captcha = (Captcha) entity;
            context.setType(BufferedImage.class);
            context.setEntity(captcha.getImage());
        }
    }
    context.proceed();
}
 
Example 2
Source File: BookServer20.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Override
public void aroundWriteTo(WriterInterceptorContext context) throws IOException, WebApplicationException {
    context.getHeaders().add("ServerWriterInterceptor", "serverWrite");
    context.getHeaders().putSingle("ServerWriterInterceptor2", "serverWrite2");
    response.addHeader("ServerWriterInterceptorHttpResponse", "serverWriteHttpResponse");
    String ct = context.getHeaders().getFirst("Content-Type").toString();
    if (!ct.endsWith("ISO-8859-1")) {
        ct += "us-ascii";
    }
    context.setMediaType(MediaType.valueOf(ct));
    context.proceed();
}
 
Example 3
Source File: JsonpPreStreamInterceptor.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Override
public void aroundWriteTo(WriterInterceptorContext context) throws IOException, WebApplicationException {
    handleMessage(PhaseInterceptorChain.getCurrentMessage());
    context.setMediaType(MediaType.APPLICATION_JSON_TYPE);
    context.proceed();
    context.setMediaType(JAXRSUtils.toMediaType(getMediaType()));
}
 
Example 4
Source File: JweWriterInterceptor.java    From cxf with Apache License 2.0 4 votes vote down vote up
private void setJoseMediaType(WriterInterceptorContext ctx) {
    MediaType joseMediaType = JAXRSUtils.toMediaType(JoseConstants.MEDIA_TYPE_JOSE);
    ctx.setMediaType(joseMediaType);
}
 
Example 5
Source File: JweJsonWriterInterceptor.java    From cxf with Apache License 2.0 4 votes vote down vote up
private void setJoseMediaType(WriterInterceptorContext ctx) {
    MediaType joseMediaType = JAXRSUtils.toMediaType(JoseConstants.MEDIA_TYPE_JOSE_JSON);
    ctx.setMediaType(joseMediaType);
}
 
Example 6
Source File: JwsWriterInterceptor.java    From cxf with Apache License 2.0 4 votes vote down vote up
private void setJoseMediaType(WriterInterceptorContext ctx) {
    MediaType joseMediaType = JAXRSUtils.toMediaType(JoseConstants.MEDIA_TYPE_JOSE);
    ctx.setMediaType(joseMediaType);
}