Search in sources :

Example 56 with Headers

use of com.sun.net.httpserver.Headers in project spf4j by zolyfarkas.

the class TcpServerTest method createHttpServer.

@BeforeClass
public static void createHttpServer() throws IOException {
    server = HttpServer.create(new InetSocketAddress(TEST_PORT), 0);
    server.createContext("/", new HttpHandler() {

        @Override
        public void handle(final HttpExchange he) throws IOException {
            Headers respHeaders = he.getResponseHeaders();
            respHeaders.add("testheader", "testValue");
            he.sendResponseHeaders(200, 0);
            OutputStream responseBody = he.getResponseBody();
            responseBody.write("Some Body".getBytes(StandardCharsets.UTF_8));
            responseBody.close();
        }
    });
    server.start();
}
Also used : HttpHandler(com.sun.net.httpserver.HttpHandler) InetSocketAddress(java.net.InetSocketAddress) Headers(com.sun.net.httpserver.Headers) ByteArrayOutputStream(java.io.ByteArrayOutputStream) OutputStream(java.io.OutputStream) HttpExchange(com.sun.net.httpserver.HttpExchange) IOException(java.io.IOException) BeforeClass(org.junit.BeforeClass)

Aggregations

Headers (com.sun.net.httpserver.Headers)56 OutputStream (java.io.OutputStream)23 IOException (java.io.IOException)17 InetSocketAddress (java.net.InetSocketAddress)12 InputStream (java.io.InputStream)10 HttpExchange (com.sun.net.httpserver.HttpExchange)9 Test (org.junit.Test)9 Test (org.junit.jupiter.api.Test)8 ByteArrayInputStream (java.io.ByteArrayInputStream)7 HttpServer (com.sun.net.httpserver.HttpServer)6 ByteArrayOutputStream (java.io.ByteArrayOutputStream)6 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)6 BufferedImage (java.awt.image.BufferedImage)5 BufferedReader (java.io.BufferedReader)5 InputStreamReader (java.io.InputStreamReader)5 Path (java.nio.file.Path)5 HashMap (java.util.HashMap)5 BeforeClass (org.junit.BeforeClass)5 Graphics2D (java.awt.Graphics2D)4 Image (java.awt.Image)4