|
1 | 1 | /*
|
2 |
| - * Copyright 2002-2014 the original author or authors. |
| 2 | + * Copyright 2002-2015 the original author or authors. |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
|
50 | 50 | */
|
51 | 51 | public class AbstractJettyServerTestCase {
|
52 | 52 |
|
53 |
| - protected static String helloWorld = "H\u00e9llo W\u00f6rld"; |
| 53 | + protected static final String helloWorld = "H\u00e9llo W\u00f6rld"; |
54 | 54 |
|
55 |
| - protected static int port; |
56 |
| - protected static String baseUrl; |
| 55 | + protected static final int port = SocketUtils.findAvailableTcpPort(); |
57 | 56 |
|
58 |
| - protected static MediaType textContentType; |
59 |
| - protected static MediaType jsonContentType; |
| 57 | + protected static final String baseUrl = "http://localhost:" + port; |
60 | 58 |
|
61 |
| - private static Server jettyServer; |
| 59 | + protected static final MediaType textContentType = new MediaType("text", "plain", Collections.singletonMap("charset", "utf-8")); |
| 60 | + |
| 61 | + protected static final MediaType jsonContentType = new MediaType("application", "json", Collections.singletonMap("charset", "utf-8")); |
| 62 | + |
| 63 | + private static final Server jettyServer = new Server(port); |
62 | 64 |
|
63 | 65 | @BeforeClass
|
64 | 66 | public static void startJettyServer() throws Exception {
|
65 |
| - port = SocketUtils.findAvailableTcpPort(); |
66 |
| - jettyServer = new Server(port); |
67 |
| - baseUrl = "http://localhost:" + port; |
68 | 67 | ServletContextHandler handler = new ServletContextHandler();
|
69 |
| - byte[] bytes = helloWorld.getBytes("UTF-8"); |
70 |
| - textContentType = new MediaType("text", "plain", Collections |
71 |
| - .singletonMap("charset", "UTF-8")); |
72 |
| - jsonContentType = new MediaType("application", "json", Collections |
73 |
| - .singletonMap("charset", "UTF-8")); |
| 68 | + byte[] bytes = helloWorld.getBytes("utf-8"); |
74 | 69 | handler.addServlet(new ServletHolder(new GetServlet(bytes, textContentType)), "/get");
|
75 | 70 | handler.addServlet(new ServletHolder(new GetServlet(new byte[0], textContentType)), "/get/nothing");
|
76 | 71 | handler.addServlet(new ServletHolder(new GetServlet(bytes, null)), "/get/nocontenttype");
|
@@ -212,7 +207,7 @@ protected void doPost(HttpServletRequest request, HttpServletResponse response)
|
212 | 207 | response.setStatus(HttpServletResponse.SC_CREATED);
|
213 | 208 | response.setHeader("Location", location);
|
214 | 209 | response.setContentType(contentType.toString());
|
215 |
| - byte[] bytes = body.getBytes("UTF-8"); |
| 210 | + byte[] bytes = body.getBytes("utf-8"); |
216 | 211 | response.setContentLength(bytes.length);;
|
217 | 212 | FileCopyUtils.copy(bytes, response.getOutputStream());
|
218 | 213 | }
|
@@ -244,7 +239,7 @@ private static class UriServlet extends HttpServlet {
|
244 | 239 | @Override
|
245 | 240 | protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
|
246 | 241 | resp.setContentType("text/plain");
|
247 |
| - resp.setCharacterEncoding("UTF-8"); |
| 242 | + resp.setCharacterEncoding("utf-8"); |
248 | 243 | resp.getWriter().write(req.getRequestURI());
|
249 | 244 | }
|
250 | 245 | }
|
|
0 commit comments