1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package de.smartics.resteasy.hypermedia.renderer;
17
18 import java.util.Locale;
19
20 import javax.servlet.http.HttpServletRequest;
21 import javax.servlet.http.HttpServletResponse;
22 import javax.ws.rs.core.Context;
23 import javax.ws.rs.core.Response;
24 import javax.ws.rs.core.UriInfo;
25 import javax.ws.rs.ext.ExceptionMapper;
26
27 import org.jboss.resteasy.spi.HttpRequest;
28 import org.jboss.resteasy.spi.HttpResponse;
29
30 import de.smartics.resteasy.hypermedia.resources.ResourceDiscovery;
31 import de.smartics.resteasy.hypermedia.resources.Resources;
32
33
34
35
36 public abstract class AbstractExceptionHandler implements
37 ExceptionMapper<Throwable>
38 {
39
40
41
42
43
44
45
46
47
48 @Context
49 protected HttpResponse response;
50
51
52
53
54 @Context
55 protected HttpRequest request;
56
57
58
59
60 @Context
61 protected HttpServletRequest servletRequest;
62
63
64
65
66 @Context
67 protected HttpServletResponse servletResponse;
68
69
70
71
72 @Context
73 protected UriInfo uriInfo;
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94 protected abstract I18nProvider getI18nProvider();
95
96
97
98
99
100
101 protected ResourceContext createContext()
102 {
103 final LocalizationProvider l7nProvider = fetchLocalizationProvider();
104 final Resources resources = ResourceDiscovery.createDiscovery();
105 final ResourceContext context =
106 new ResourceContext.Builder().with(servletRequest)
107 .with(servletResponse).with(uriInfo).with(l7nProvider)
108 .with(resources).build();
109 return context;
110 }
111
112 private LocalizationProvider fetchLocalizationProvider()
113 {
114 final Locale locale = servletRequest.getLocale();
115 final LocalizationProvider l7nProvider =
116 getI18nProvider().getProvider(locale);
117 return l7nProvider;
118 }
119
120 @Override
121 public Response toResponse(final Throwable exception)
122 {
123 return null;
124 }
125
126
127 }