在JAXRS MessageBodyWriter中更改http状态

时间:2018-01-25 23:20:44

标签: java web-services java-ee jax-rs

我的服务返回响应对象基于writeTo方法中的计算我想要设置http状态。能否请你帮忙我如何设置http状态。

@Provider
    @Produces(MediaType.APPLICATION_XML)
    public class ResponseWriter implements MessageBodyWriter<RespObject> {


        @Override
        public long getSize(RespObject resp, Class<?> type, Type genericType, Annotation[] annotations,
                MediaType mediaType) {
            return -1;
        }

        @Override
        public void writeTo(RespObject resp, Class<?> type, Type genericType, Annotation[] annotations,
                MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream)
                throws IOException, WebApplicationException {
                // Based on resp type object i want set http status here
        }

        @Override
        public boolean isWriteable(Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType) {
            return true;
        }

    }

0 个答案:

没有答案