1 package com.atlassian.plugins.rest.common.error.jersey;
2
3 import java.io.IOException;
4 import java.io.OutputStream;
5 import java.lang.annotation.Annotation;
6 import java.lang.reflect.Type;
7
8 import javax.ws.rs.Produces;
9 import javax.ws.rs.WebApplicationException;
10 import javax.ws.rs.core.MediaType;
11 import javax.ws.rs.core.MultivaluedMap;
12 import javax.ws.rs.ext.MessageBodyWriter;
13 import javax.ws.rs.ext.Provider;
14
15
16
17
18 @Provider
19 @Produces(MediaType.TEXT_PLAIN)
20 public class UncaughtExceptionEntityWriter implements MessageBodyWriter<UncaughtExceptionEntity> {
21 public long getSize(UncaughtExceptionEntity t, Class<?> type, Type genericType, Annotation[] annotations,
22 MediaType mediaType) {
23 return -1;
24 }
25
26 public boolean isWriteable(Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType) {
27 return UncaughtExceptionEntity.class.isAssignableFrom(type);
28 }
29
30 public void writeTo(UncaughtExceptionEntity t, Class<?> type, Type genericType, Annotation[] annotations,
31 MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream)
32 throws IOException, WebApplicationException {
33 entityStream.write(t.getStackTrace().getBytes("utf-8"));
34 }
35 }