@@ -54,11 +54,12 @@ public class AbstractJettyServerTestCase {
54
54
55
55
protected static final String helloWorld = "H\u00e9 llo W\u00f6 rld" ;
56
56
57
- protected static final MediaType textContentType = new MediaType ("text" , "plain" ,
58
- Collections .singletonMap ("charset" , "UTF-8" ));
57
+ protected static final MediaType textContentType =
58
+ new MediaType ("text" , "plain" , Collections .singletonMap ("charset" , "UTF-8" ));
59
+
60
+ protected static final MediaType jsonContentType =
61
+ new MediaType ("application" , "json" , Collections .singletonMap ("charset" , "UTF-8" ));
59
62
60
- protected static final MediaType jsonContentType = new MediaType ("application" ,
61
- "json" , Collections .singletonMap ("charset" , "utf-8" ));
62
63
63
64
private static Server jettyServer ;
64
65
@@ -69,7 +70,6 @@ public class AbstractJettyServerTestCase {
69
70
70
71
@ BeforeClass
71
72
public static void startJettyServer () throws Exception {
72
-
73
73
// Let server pick its own random, available port.
74
74
jettyServer = new Server (0 );
75
75
@@ -119,13 +119,12 @@ private static class StatusCodeServlet extends GenericServlet {
119
119
120
120
private final int sc ;
121
121
122
- private StatusCodeServlet (int sc ) {
122
+ public StatusCodeServlet (int sc ) {
123
123
this .sc = sc ;
124
124
}
125
125
126
126
@ Override
127
- public void service (ServletRequest request , ServletResponse response ) throws
128
- ServletException , IOException {
127
+ public void service (ServletRequest request , ServletResponse response ) throws IOException {
129
128
((HttpServletResponse ) response ).setStatus (sc );
130
129
}
131
130
}
@@ -137,12 +136,12 @@ private static class ErrorServlet extends GenericServlet {
137
136
138
137
private final int sc ;
139
138
140
- private ErrorServlet (int sc ) {
139
+ public ErrorServlet (int sc ) {
141
140
this .sc = sc ;
142
141
}
143
142
144
143
@ Override
145
- public void service (ServletRequest request , ServletResponse response ) throws ServletException , IOException {
144
+ public void service (ServletRequest request , ServletResponse response ) throws IOException {
146
145
((HttpServletResponse ) response ).sendError (sc );
147
146
}
148
147
}
@@ -155,14 +154,13 @@ private static class GetServlet extends HttpServlet {
155
154
156
155
private final MediaType contentType ;
157
156
158
- private GetServlet (byte [] buf , MediaType contentType ) {
157
+ public GetServlet (byte [] buf , MediaType contentType ) {
159
158
this .buf = buf ;
160
159
this .contentType = contentType ;
161
160
}
162
161
163
162
@ Override
164
- protected void doGet (HttpServletRequest request , HttpServletResponse response )
165
- throws ServletException , IOException {
163
+ protected void doGet (HttpServletRequest request , HttpServletResponse response ) throws IOException {
166
164
if (contentType != null ) {
167
165
response .setContentType (contentType .toString ());
168
166
}
@@ -175,28 +173,27 @@ protected void doGet(HttpServletRequest request, HttpServletResponse response)
175
173
@ SuppressWarnings ("serial" )
176
174
private static class PostServlet extends HttpServlet {
177
175
178
- private final String s ;
176
+ private final String content ;
179
177
180
178
private final String location ;
181
179
182
180
private final byte [] buf ;
183
181
184
182
private final MediaType contentType ;
185
183
186
- private PostServlet (String s , String location , byte [] buf , MediaType contentType ) {
187
- this .s = s ;
184
+ public PostServlet (String content , String location , byte [] buf , MediaType contentType ) {
185
+ this .content = content ;
188
186
this .location = location ;
189
187
this .buf = buf ;
190
188
this .contentType = contentType ;
191
189
}
192
190
193
191
@ Override
194
- protected void doPost (HttpServletRequest request , HttpServletResponse response )
195
- throws ServletException , IOException {
192
+ protected void doPost (HttpServletRequest request , HttpServletResponse response ) throws IOException {
196
193
assertTrue ("Invalid request content-length" , request .getContentLength () > 0 );
197
194
assertNotNull ("No content-type" , request .getContentType ());
198
195
String body = FileCopyUtils .copyToString (request .getReader ());
199
- assertEquals ("Invalid request body" , s , body );
196
+ assertEquals ("Invalid request body" , content , body );
200
197
response .setStatus (HttpServletResponse .SC_CREATED );
201
198
response .setHeader ("Location" , baseUrl + location );
202
199
response .setContentLength (buf .length );
@@ -213,14 +210,13 @@ private static class JsonPostServlet extends HttpServlet {
213
210
214
211
private final MediaType contentType ;
215
212
216
- private JsonPostServlet (String location , MediaType contentType ) {
213
+ public JsonPostServlet (String location , MediaType contentType ) {
217
214
this .location = location ;
218
215
this .contentType = contentType ;
219
216
}
220
217
221
218
@ Override
222
- protected void doPost (HttpServletRequest request , HttpServletResponse response )
223
- throws ServletException , IOException {
219
+ protected void doPost (HttpServletRequest request , HttpServletResponse response ) throws IOException {
224
220
assertTrue ("Invalid request content-length" , request .getContentLength () > 0 );
225
221
assertNotNull ("No content-type" , request .getContentType ());
226
222
String body = FileCopyUtils .copyToString (request .getReader ());
@@ -239,13 +235,12 @@ private static class PutServlet extends HttpServlet {
239
235
240
236
private final String s ;
241
237
242
- private PutServlet (String s , byte [] buf , MediaType contentType ) {
238
+ public PutServlet (String s , byte [] buf , MediaType contentType ) {
243
239
this .s = s ;
244
240
}
245
241
246
242
@ Override
247
- protected void doPut (HttpServletRequest request , HttpServletResponse response )
248
- throws ServletException , IOException {
243
+ protected void doPut (HttpServletRequest request , HttpServletResponse response ) throws IOException {
249
244
assertTrue ("Invalid request content-length" , request .getContentLength () > 0 );
250
245
assertNotNull ("No content-type" , request .getContentType ());
251
246
String body = FileCopyUtils .copyToString (request .getReader ());
@@ -259,7 +254,7 @@ protected void doPut(HttpServletRequest request, HttpServletResponse response)
259
254
private static class UriServlet extends HttpServlet {
260
255
261
256
@ Override
262
- protected void doGet (HttpServletRequest req , HttpServletResponse resp ) throws ServletException , IOException {
257
+ protected void doGet (HttpServletRequest req , HttpServletResponse resp ) throws IOException {
263
258
resp .setContentType ("text/plain" );
264
259
resp .setCharacterEncoding ("utf-8" );
265
260
resp .getWriter ().write (req .getRequestURI ());
@@ -311,9 +306,8 @@ protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws S
311
306
private static class FormServlet extends HttpServlet {
312
307
313
308
@ Override
314
- protected void doPost (HttpServletRequest req , HttpServletResponse resp ) throws ServletException , IOException {
315
- assertEquals (MediaType .APPLICATION_FORM_URLENCODED_VALUE ,
316
- req .getContentType ());
309
+ protected void doPost (HttpServletRequest req , HttpServletResponse resp ) throws IOException {
310
+ assertEquals (MediaType .APPLICATION_FORM_URLENCODED_VALUE , req .getContentType ());
317
311
318
312
Map <String , String []> parameters = req .getParameterMap ();
319
313
assertEquals (2 , parameters .size ());
@@ -334,7 +328,7 @@ protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws S
334
328
private static class DeleteServlet extends HttpServlet {
335
329
336
330
@ Override
337
- protected void doDelete (HttpServletRequest req , HttpServletResponse resp ) throws ServletException , IOException {
331
+ protected void doDelete (HttpServletRequest req , HttpServletResponse resp ) throws IOException {
338
332
resp .setStatus (200 );
339
333
}
340
334
}
0 commit comments