com.sun.net.httpserver.Headers Java Examples
The following examples show how to use
com.sun.net.httpserver.Headers.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: HttpServer.java From hsac-fitnesse-fixtures with Apache License 2.0 | 7 votes |
protected Charset getCharSet(Headers heHeaders) { Charset charset = UTF8; String contentTypeHeader = heHeaders.getFirst(HTTP.CONTENT_TYPE); if (contentTypeHeader != null) { try { ContentType contentType = ContentType.parse(contentTypeHeader); Charset contentTypeCharset = contentType.getCharset(); if (contentTypeCharset != null) { charset = contentTypeCharset; } } catch (ParseException | UnsupportedCharsetException e) { // ignore, use default charset UTF8 } } return charset; }
Example #2
Source File: Deadlock.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 6 votes |
@Override public void handle (HttpExchange t) throws IOException { InputStream is = t.getRequestBody(); Headers map = t.getRequestHeaders(); Headers rmap = t.getResponseHeaders(); while (is.read() != -1); is.close(); t.sendResponseHeaders(200, -1); HttpPrincipal p = t.getPrincipal(); if (!p.getUsername().equals("fred")) { error = true; } if (!p.getRealm().equals("[email protected]")) { error = true; } t.close(); }
Example #3
Source File: SmokeTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
@Override public synchronized void handle (HttpExchange t) throws IOException { byte[] buf = new byte[2048]; try (InputStream is = t.getRequestBody()) { while (is.read(buf) != -1) ; } Headers map = t.getResponseHeaders(); String redirect = root + "/foo/" + Integer.toString(count); increment(); map.add("Location", redirect); t.sendResponseHeaders(301, -1); t.close(); }
Example #4
Source File: ActionHttp_PDI208_Test.java From hop with Apache License 2.0 | 6 votes |
private static void startHttpServer() throws IOException { httpServer = HttpServer.create( new InetSocketAddress( ActionHttp_PDI208_Test.HTTP_HOST, ActionHttp_PDI208_Test.HTTP_PORT ), 10 ); httpServer.createContext( "/uploadFile", new HttpHandler() { @Override public void handle( HttpExchange httpExchange ) throws IOException { Headers h = httpExchange.getResponseHeaders(); h.add( "Content-Type", "application/octet-stream" ); httpExchange.sendResponseHeaders( 200, 0 ); InputStream is = httpExchange.getRequestBody(); OutputStream os = httpExchange.getResponseBody(); int inputChar = -1; while ( ( inputChar = is.read() ) >= 0 ) { os.write( inputChar ); } is.close(); os.flush(); os.close(); httpExchange.close(); } } ); httpServer.start(); }
Example #5
Source File: JobEntryHTTP_PDI208_Test.java From pentaho-kettle with Apache License 2.0 | 6 votes |
private static void startHTTPServer() throws IOException { httpServer = HttpServer.create( new InetSocketAddress( JobEntryHTTP_PDI208_Test.HTTP_HOST, JobEntryHTTP_PDI208_Test.HTTP_PORT ), 10 ); httpServer.createContext( "/uploadFile", new HttpHandler() { @Override public void handle( HttpExchange httpExchange ) throws IOException { Headers h = httpExchange.getResponseHeaders(); h.add( "Content-Type", "application/octet-stream" ); httpExchange.sendResponseHeaders( 200, 0 ); InputStream is = httpExchange.getRequestBody(); OutputStream os = httpExchange.getResponseBody(); int inputChar = -1; while ( ( inputChar = is.read() ) >= 0 ) { os.write( inputChar ); } is.close(); os.flush(); os.close(); httpExchange.close(); } } ); httpServer.start(); }
Example #6
Source File: BPMNRestTaskJsonMappingTest.java From product-ei with Apache License 2.0 | 6 votes |
@Override public void handle(HttpExchange httpExchange) throws IOException { Headers headers = httpExchange.getResponseHeaders(); headers.add("Content-Type", "application/json"); //response payload String response = "{\"user\":null, \"id\":123}"; httpExchange.sendResponseHeaders(200, response.length()); OutputStream responseStream = httpExchange.getResponseBody(); try { responseStream.write(response.getBytes(Charset.defaultCharset())); } finally { responseStream.close(); } }
Example #7
Source File: Security.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
@Override public synchronized void handle(HttpExchange t) throws IOException { byte[] buf = new byte[2048]; System.out.println("Server: " + t.getRequestURI()); try (InputStream is = t.getRequestBody()) { while (is.read(buf) != -1) ; } increment(); if (count() == 1) { Headers map = t.getResponseHeaders(); String redirect = "/redirect/bar.txt"; map.add("Location", redirect); t.sendResponseHeaders(301, -1); t.close(); } else { String response = "Hello world"; t.sendResponseHeaders(200, response.length()); OutputStream os = t.getResponseBody(); os.write(response.getBytes(StandardCharsets.ISO_8859_1)); t.close(); } }
Example #8
Source File: ConsoleProxyAjaxHandler.java From cosmic with Apache License 2.0 | 6 votes |
@Override public void handle(final HttpExchange t) throws IOException { try { if (s_logger.isTraceEnabled()) { s_logger.trace("AjaxHandler " + t.getRequestURI()); } final long startTick = System.currentTimeMillis(); doHandle(t); if (s_logger.isTraceEnabled()) { s_logger.trace(t.getRequestURI() + " process time " + (System.currentTimeMillis() - startTick) + " ms"); } } catch (final IllegalArgumentException e) { s_logger.warn("Exception, ", e); final Headers hds = t.getResponseHeaders(); hds.set("Strict-Transport-Security", "max-age=31536000; includeSubDomains"); t.sendResponseHeaders(400, -1); // bad request } finally { t.close(); } }
Example #9
Source File: Deadlock.java From jdk8u_jdk with GNU General Public License v2.0 | 6 votes |
@Override public void handle (HttpExchange t) throws IOException { InputStream is = t.getRequestBody(); Headers map = t.getRequestHeaders(); Headers rmap = t.getResponseHeaders(); while (is.read() != -1); is.close(); t.sendResponseHeaders(200, -1); HttpPrincipal p = t.getPrincipal(); if (!p.getUsername().equals("fred")) { error = true; } if (!p.getRealm().equals("[email protected]")) { error = true; } t.close(); }
Example #10
Source File: InternalHttpServer.java From zxpoly with GNU General Public License v3.0 | 6 votes |
private void handleMainPage(final HttpExchange exchange) throws IOException { final String linkToVideoStream = "http://" + this.getHttpAddress() + "/" + STREAM_RESOURCE; final String page = HTML_TEMPLATE.replace("${video.link}", linkToVideoStream) .replace("${video.mime}", this.mime); final Headers headers = exchange.getResponseHeaders(); headers.add("Content-Type", "text/html"); final byte[] content = page.getBytes(StandardCharsets.UTF_8); exchange.sendResponseHeaders(200, content.length); final OutputStream out = exchange.getResponseBody(); out.write(content); out.flush(); out.close(); }
Example #11
Source File: AzureHttpHandler.java From crate with Apache License 2.0 | 6 votes |
public static void sendError(final HttpExchange exchange, final RestStatus status) throws IOException { final Headers headers = exchange.getResponseHeaders(); headers.add("Content-Type", "application/xml"); // see Constants.HeaderConstants.CLIENT_REQUEST_ID_HEADER final String requestId = exchange.getRequestHeaders().getFirst("x-ms-client-request-id"); if (requestId != null) { // see Constants.HeaderConstants.STORAGE_RANGE_HEADER headers.add("x-ms-request-id", requestId); } final String errorCode = toAzureErrorCode(status); // see Constants.HeaderConstants.ERROR_CODE headers.add("x-ms-error-code", errorCode); if ("HEAD".equals(exchange.getRequestMethod())) { exchange.sendResponseHeaders(status.getStatus(), -1L); } else { final byte[] response = ("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Error><Code>" + errorCode + "</Code><Message>" + status + "</Message></Error>").getBytes(StandardCharsets.UTF_8); exchange.sendResponseHeaders(status.getStatus(), response.length); exchange.getResponseBody().write(response); } }
Example #12
Source File: Deadlock.java From openjdk-8 with GNU General Public License v2.0 | 6 votes |
@Override public void handle (HttpExchange t) throws IOException { InputStream is = t.getRequestBody(); Headers map = t.getRequestHeaders(); Headers rmap = t.getResponseHeaders(); while (is.read() != -1); is.close(); t.sendResponseHeaders(200, -1); HttpPrincipal p = t.getPrincipal(); if (!p.getUsername().equals("fred")) { error = true; } if (!p.getRealm().equals("[email protected]")) { error = true; } t.close(); }
Example #13
Source File: LightWeightHttpServer.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
@Override public synchronized void handle(HttpExchange t) throws IOException { byte[] buf = new byte[2048]; try (InputStream is = t.getRequestBody()) { while (is.read(buf) != -1) ; } Headers map = t.getResponseHeaders(); if (count++ < 1) { map.add("Location", root + "/foo/" + count); } else { map.add("Location", SmokeTest.midSizedFilename); } t.sendResponseHeaders(301, -1); t.close(); }
Example #14
Source File: Deadlock.java From jdk8u60 with GNU General Public License v2.0 | 6 votes |
@Override public void handle (HttpExchange t) throws IOException { InputStream is = t.getRequestBody(); Headers map = t.getRequestHeaders(); Headers rmap = t.getResponseHeaders(); while (is.read() != -1); is.close(); t.sendResponseHeaders(200, -1); HttpPrincipal p = t.getPrincipal(); if (!p.getUsername().equals("fred")) { error = true; } if (!p.getRealm().equals("[email protected]")) { error = true; } t.close(); }
Example #15
Source File: NetworkUtilsTest.java From incubator-heron with Apache License 2.0 | 6 votes |
@Test public void testReadHttpRequestBodyFail() throws Exception { HttpExchange exchange = Mockito.mock(HttpExchange.class); Headers headers = Mockito.mock(Headers.class); Mockito.doReturn(headers).when(exchange).getRequestHeaders(); Mockito.doReturn("-1"). when(headers).getFirst(Matchers.anyString()); Assert.assertArrayEquals(new byte[0], NetworkUtils.readHttpRequestBody(exchange)); Mockito.doReturn("10"). when(headers).getFirst(Matchers.anyString()); InputStream inputStream = Mockito.mock(InputStream.class); Mockito.doReturn(inputStream).when(exchange).getRequestBody(); Mockito.doThrow(new IOException("Designed IO exception for testing")) .when(inputStream).read(Matchers.any(byte[].class), Matchers.anyInt(), Matchers.anyInt()); Assert.assertArrayEquals(new byte[0], NetworkUtils.readHttpRequestBody(exchange)); Mockito.verify(inputStream, Mockito.atLeastOnce()).close(); }
Example #16
Source File: NetworkUtilsTest.java From incubator-heron with Apache License 2.0 | 6 votes |
@Test public void testReadHttpRequestBody() throws Exception { byte[] expectedBytes = "TO READ".getBytes(); InputStream is = Mockito.spy(new ByteArrayInputStream(expectedBytes)); HttpExchange exchange = Mockito.mock(HttpExchange.class); Headers headers = Mockito.mock(Headers.class); Mockito.doReturn(Integer.toString(expectedBytes.length)). when(headers).getFirst(Matchers.anyString()); Mockito.doReturn(headers).when(exchange).getRequestHeaders(); Mockito.doReturn(is).when(exchange).getRequestBody(); Assert.assertArrayEquals(expectedBytes, NetworkUtils.readHttpRequestBody(exchange)); Mockito.verify(is, Mockito.atLeastOnce()).close(); }
Example #17
Source File: MindInspectorWebImpl.java From jason with GNU Lesser General Public License v3.0 | 5 votes |
public synchronized void registerCentRunner(RuntimeServices rs) { if (rs == null) return; this.runner = rs; httpServer.createContext("/df", new HttpHandler() { public void handle(HttpExchange exchange) throws IOException { String requestMethod = exchange.getRequestMethod(); Headers responseHeaders = exchange.getResponseHeaders(); responseHeaders.set("Content-Type", "text/html"); exchange.sendResponseHeaders(200, 0); OutputStream responseBody = exchange.getResponseBody(); if (requestMethod.equalsIgnoreCase("GET")) { responseBody.write(("<html><head><title>Directory Facilitator State</title></head><body>").getBytes()); responseBody.write(("<font size=\"+2\"><p style='color: red; font-family: arial;'>Directory Facilitator State</p></font>").getBytes()); responseBody.write("<table border=\"0\" cellspacing=\"3\" cellpadding=\"6\" >".getBytes()); responseBody.write("<tr style='background-color: #ece7e6; font-family: arial;'><td><b>Agent</b></td><td><b>Services</b></td></tr>".getBytes()); Map<String, Set<String>> df = runner.getDF(); for (String a: df.keySet()) { responseBody.write(("<tr style='font-family: arial;'><td>"+a+"</td>").getBytes()); for (String s: df.get(a)) { responseBody.write(("<td>"+s+"<br/></td>").getBytes()); } responseBody.write("</tr>".getBytes()); } responseBody.write("</table>".getBytes()); } responseBody.write("</body></html>".getBytes()); responseBody.close(); } }); }
Example #18
Source File: Basic.java From openjdk-8-source with GNU General Public License v2.0 | 5 votes |
public void handle(HttpExchange t) throws IOException { InputStream is = t.getRequestBody(); Headers map = t.getRequestHeaders(); Headers rmap = t.getResponseHeaders(); URI uri = t.getRequestURI(); debug("Server: received request for " + uri); String path = uri.getPath(); if (path.endsWith("a.jar")) aDotJar++; else if (path.endsWith("b.jar")) bDotJar++; else if (path.endsWith("c.jar")) cDotJar++; else System.out.println("Unexpected resource request" + path); while (is.read() != -1); is.close(); File file = new File(docsDir, path); if (!file.exists()) throw new RuntimeException("Error: request for " + file); long clen = file.length(); t.sendResponseHeaders (200, clen); OutputStream os = t.getResponseBody(); FileInputStream fis = new FileInputStream(file); try { byte[] buf = new byte [16 * 1024]; int len; while ((len=fis.read(buf)) != -1) { os.write (buf, 0, len); } } catch (IOException e) { e.printStackTrace(); } fis.close(); os.close(); }
Example #19
Source File: RegExp.java From V8LogScanner with MIT License | 5 votes |
private void buildVRSREQUEST() { rgxNode.add(PropTypes.Process); rgxNode.add(PropTypes.Method); rgxNode.add(PropTypes.URI); rgxNode.add(PropTypes.Headers); rgxNode.add(PropTypes.Body); rgxNode.add(PropTypes.Context); Filter filter = getFilter(PropTypes.Event); filter.add("VRSREQUEST"); }
Example #20
Source File: ResponseBuilder.java From james with Apache License 2.0 | 5 votes |
public void sendResponse(HTTPStatus responseStatus) throws IOException { Headers headers = exchange.getResponseHeaders(); headers.add(HTTP_HEADER_SERVER, "James HTTP Server"); if (contentType != null) { headers.add(HTTP_HEADER_CONTENT_TYPE, contentType.toString()); } exchange.sendResponseHeaders(responseStatus.getCode(), responseBody != null ? responseBody.length : -1L); if (responseBody != null) { try (OutputStream outputStream = exchange.getResponseBody()) { outputStream.write(responseBody); } } }
Example #21
Source File: HttpClientFactoryImplTest.java From component-runtime with Apache License 2.0 | 5 votes |
@Test void requestWithJSON() throws IOException { final HttpServer server = HttpServer.create(new InetSocketAddress(0), 0); server.createContext("/").setHandler(httpExchange -> { final Headers headers = httpExchange.getResponseHeaders(); headers.set("content-type", "application/json;charset=UTF-8"); final byte[] bytes; try (final BufferedReader in = new BufferedReader(new InputStreamReader(httpExchange.getRequestBody(), StandardCharsets.UTF_8))) { bytes = in.lines().collect(joining("\n")).getBytes(StandardCharsets.UTF_8); } httpExchange.sendResponseHeaders(HttpURLConnection.HTTP_OK, bytes.length); httpExchange.getResponseBody().write(bytes); httpExchange.close(); }); try { server.start(); final ResponseJson client = newDefaultFactory().create(ResponseJson.class, null); client.base("http://localhost:" + server.getAddress().getPort() + "/api"); final Response<Sample> result = client.main("application/json", new Sample(singletonList(new Foo("testJSON")))); assertEquals(1, result.body().getFoos().size()); assertEquals("testJSON", result.body().getFoos().iterator().next().getName()); assertEquals(HttpURLConnection.HTTP_OK, result.status()); assertEquals("30", result.headers().get("content-length").iterator().next()); } finally { server.stop(0); } }
Example #22
Source File: HTTPServer.java From learnjavabug with MIT License | 5 votes |
@Override public void handle(HttpExchange he) throws IOException { String requestMethod = he.getRequestMethod(); System.out.println(requestMethod + " " + he.getRequestURI().getPath() + ( StringUtils.isEmpty(he.getRequestURI().getRawQuery()) ? "" : "?" + he.getRequestURI().getRawQuery()) + " " + he.getProtocol()); if (requestMethod.equalsIgnoreCase("GET")) { Headers responseHeaders = he.getResponseHeaders(); responseHeaders.set("Content-Type", contentType == null ? "application/json" : contentType); he.sendResponseHeaders(200, 0); // parse request OutputStream responseBody = he.getResponseBody(); Headers requestHeaders = he.getRequestHeaders(); Set<String> keySet = requestHeaders.keySet(); Iterator<String> iter = keySet.iterator(); while (iter.hasNext()) { String key = iter.next(); List values = requestHeaders.get(key); String s = key + ": " + values.toString(); System.out.println(s); } System.out.println(); BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(he.getRequestBody())); StringBuilder stringBuilder = new StringBuilder(); String line; for (;(line = bufferedReader.readLine()) != null;) { stringBuilder.append(line); } System.out.println(stringBuilder.toString()); byte[] bytes = Files.toByteArray(new File(filePath == null ? HTTPServer.class.getClassLoader().getResource(clazz).getPath() : filePath)); // send response responseBody.write(bytes); responseBody.close(); } }
Example #23
Source File: Basic.java From openjdk-8 with GNU General Public License v2.0 | 5 votes |
public void handle(HttpExchange t) throws IOException { InputStream is = t.getRequestBody(); Headers map = t.getRequestHeaders(); Headers rmap = t.getResponseHeaders(); URI uri = t.getRequestURI(); debug("Server: received request for " + uri); String path = uri.getPath(); if (path.endsWith("a.jar")) aDotJar++; else if (path.endsWith("b.jar")) bDotJar++; else if (path.endsWith("c.jar")) cDotJar++; else System.out.println("Unexpected resource request" + path); while (is.read() != -1); is.close(); File file = new File(docsDir, path); if (!file.exists()) throw new RuntimeException("Error: request for " + file); long clen = file.length(); t.sendResponseHeaders (200, clen); OutputStream os = t.getResponseBody(); FileInputStream fis = new FileInputStream(file); try { byte[] buf = new byte [16 * 1024]; int len; while ((len=fis.read(buf)) != -1) { os.write (buf, 0, len); } } catch (IOException e) { e.printStackTrace(); } fis.close(); os.close(); }
Example #24
Source File: MindInspectorWebImpl.java From jason with GNU Lesser General Public License v3.0 | 5 votes |
private void registerAgentsBrowserView() { if (httpServer == null) return; try { httpServer.createContext("/agents", new HttpHandler() { public void handle(HttpExchange exchange) throws IOException { String requestMethod = exchange.getRequestMethod(); Headers responseHeaders = exchange.getResponseHeaders(); responseHeaders.set("Content-Type", "text/html"); exchange.sendResponseHeaders(200, 0); OutputStream responseBody = exchange.getResponseBody(); if (requestMethod.equalsIgnoreCase("GET")) { responseBody.write(("<html><head><title>Jason (list of agents)</title></head><body>").getBytes()); responseBody.write(("<font size=\"+2\"><p style='color: red; font-family: arial;'>Agents</p></font>").getBytes()); for (String a: histories.keySet()) { responseBody.write( ("- <a href=\"/agent-mind/"+a+"/latest\" target=\"am\" style=\"font-family: arial; text-decoration: none\">"+a+"</a><br/>").getBytes()); } if (runner != null && !runner.getDF().isEmpty()) { responseBody.write( ("<br/><a href=\"/df\" target=\"am\" style=\"font-family: arial; text-decoration: none\">DF</a><br/>").getBytes()); } } responseBody.write("<hr/>by <a href=\"http://jason.sf.net\" target=\"_blank\">Jason</a>".getBytes()); responseBody.write("</body></html>".getBytes()); responseBody.close(); } }); } catch (Exception e) { e.printStackTrace(); } }
Example #25
Source File: Basic.java From jdk8u60 with GNU General Public License v2.0 | 5 votes |
public void handle(HttpExchange t) throws IOException { InputStream is = t.getRequestBody(); Headers map = t.getRequestHeaders(); Headers rmap = t.getResponseHeaders(); URI uri = t.getRequestURI(); debug("Server: received request for " + uri); String path = uri.getPath(); if (path.endsWith("a.jar")) aDotJar++; else if (path.endsWith("b.jar")) bDotJar++; else if (path.endsWith("c.jar")) cDotJar++; else System.out.println("Unexpected resource request" + path); while (is.read() != -1); is.close(); File file = new File(docsDir, path); if (!file.exists()) throw new RuntimeException("Error: request for " + file); long clen = file.length(); t.sendResponseHeaders (200, clen); OutputStream os = t.getResponseBody(); FileInputStream fis = new FileInputStream(file); try { byte[] buf = new byte [16 * 1024]; int len; while ((len=fis.read(buf)) != -1) { os.write (buf, 0, len); } } catch (IOException e) { e.printStackTrace(); } fis.close(); os.close(); }
Example #26
Source File: HttpClientFactoryImplTest.java From component-runtime with Apache License 2.0 | 5 votes |
@Request @UseConfigurer(value = MonConfigurer.class) Response<byte[]> execute(@ConfigurerOption("readTimeout") Integer readTimeout, @ConfigurerOption("connectionTimeout") Integer connectionTimeout, @Url String url, @HttpMethod String method, @org.talend.sdk.component.api.service.http.Headers Map<String, String> headers, @QueryParams Map<String, String> queryParams, String payload);
Example #27
Source File: ResponseSender.java From Plan with GNU Lesser General Public License v3.0 | 5 votes |
private void setResponseHeaders() { Headers headers = exchange.getResponseHeaders(); Map<String, String> responseHeaders = response.getHeaders(); correctRedirect(responseHeaders); for (Map.Entry<String, String> header : responseHeaders.entrySet()) { headers.set(header.getKey(), header.getValue()); } }
Example #28
Source File: ServerConnectionImpl.java From openjdk-8 with GNU General Public License v2.0 | 5 votes |
@Override public void setResponseHeaders(Map<String,List<String>> headers) { Headers r = httpExchange.getResponseHeaders(); r.clear(); for(Map.Entry <String, List<String>> entry : headers.entrySet()) { String name = entry.getKey(); List<String> values = entry.getValue(); // ignore headers that interfere with our correct operations if (!"Content-Length".equalsIgnoreCase(name) && !"Content-Type".equalsIgnoreCase(name)) { r.put(name,new ArrayList<String>(values)); } } }
Example #29
Source File: HttpOnly.java From openjdk-8 with GNU General Public License v2.0 | 5 votes |
@Override public void handle(HttpExchange t) throws IOException { Headers reqHeaders = t.getRequestHeaders(); // some small sanity check List<String> cookies = reqHeaders.get("Cookie"); for (String cookie : cookies) { if (!cookie.contains("JSESSIONID") || !cookie.contains("WILE_E_COYOTE")) t.sendResponseHeaders(400, -1); } // return some cookies so we can check getHeaderField(s) Headers respHeaders = t.getResponseHeaders(); List<String> values = new ArrayList<>(); values.add("ID=JOEBLOGGS; version=1; Path=" + URI_PATH); values.add("NEW_JSESSIONID=" + (SESSION_ID+1) + "; version=1; Path=" + URI_PATH +"; HttpOnly"); values.add("NEW_CUSTOMER=WILE_E_COYOTE2; version=1; Path=" + URI_PATH); respHeaders.put("Set-Cookie", values); values = new ArrayList<>(); values.add("COOKIE2_CUSTOMER=WILE_E_COYOTE2; version=1; Path=" + URI_PATH); respHeaders.put("Set-Cookie2", values); values.add("COOKIE2_JSESSIONID=" + (SESSION_ID+100) + "; version=1; Path=" + URI_PATH +"; HttpOnly"); respHeaders.put("Set-Cookie2", values); t.sendResponseHeaders(200, -1); t.close(); }
Example #30
Source File: ContentTypeTestCase.java From product-ei with Apache License 2.0 | 5 votes |
public void handle(HttpExchange t) throws IOException { Headers h = t.getResponseHeaders(); h.add("Content-Type", contentType); String response = "This Content type test case"; t.sendResponseHeaders(HTTP_STATUS_OK, response.length()); OutputStream os = t.getResponseBody(); os.write(response.getBytes()); os.close(); }