Package com.sun.net.httpserver

Examples of com.sun.net.httpserver.HttpExchange


        handler = new JolokiaHttpHandler(getConfig());
    }

    @Test
    public void testCallbackGet() throws IOException, URISyntaxException {
        HttpExchange exchange = prepareExchange("http://localhost:8080/jolokia/read/java.lang:type=Memory/HeapMemoryUsage?callback=data");

        // Simple GET method
        expect(exchange.getRequestMethod()).andReturn("GET");


        Headers header = new Headers();
        ByteArrayOutputStream out = prepareResponse(handler, exchange, header);
View Full Code Here


        assertTrue(result.startsWith("data({"));
    }

    @Test
    public void testCallbackPost() throws URISyntaxException, IOException {
        HttpExchange exchange = prepareExchange("http://localhost:8080/jolokia?callback=data");

        // Simple GET method
        expect(exchange.getRequestMethod()).andReturn("POST");

        Headers reqHeaders = new Headers();
        reqHeaders.add("Content-Type","text/plain; charset=UTF-8");
        expect(exchange.getRequestHeaders()).andReturn(reqHeaders);
        String req = "{\"timestamp\":1287914327,\"status\":200," +
                "\"request\":{\"mbean\":\"java.lang:type=Memory\",\"attribute\":\"HeapMemoryUsage\",\"type\":\"read\"}," +
                "\"value\":{\"max\":\"129957888\",\"committed\":\"85000192\",\"init\":\"0\",\"used\":\"6813824\"}}";
        byte[] buf = req.getBytes("utf-8");
        InputStream is = new ByteArrayInputStream(buf);
        expect(exchange.getRequestBody()).andReturn(is);
        Headers header = new Headers();
        ByteArrayOutputStream out = prepareResponse(handler, exchange, header);

        handler.handle(exchange);
View Full Code Here

        assertTrue(result.endsWith("});"));
        assertTrue(result.startsWith("data({"));
    }

    private HttpExchange prepareExchange(String pUri) throws URISyntaxException {
        HttpExchange exchange = EasyMock.createMock(HttpExchange.class);
        URI uri = new URI(pUri);
        expect(exchange.getRequestURI()).andReturn(uri);
        expect(exchange.getRemoteAddress()).andReturn(new InetSocketAddress(8080));
        return exchange;
    }
View Full Code Here

        if (!target.startsWith(getContextPath()))
        {
            return;
        }

        HttpExchange jettyHttpExchange;
        if (baseRequest.isSecure())
        {
            jettyHttpExchange = new JettyHttpsExchange(_httpContext,req,resp);
        }
        else
        {
            jettyHttpExchange = new JettyHttpExchange(_httpContext,req,resp);
        }

        // TODO: add filters processing

        try
        {
            Authenticator auth = _httpContext.getAuthenticator();
            if (auth != null)
            {
                handleAuthentication(resp,jettyHttpExchange,auth);
            }
            else
            {
                _httpHandler.handle(jettyHttpExchange);
            }
        }
        catch (Exception ex)
        {
            PrintWriter writer = new PrintWriter(jettyHttpExchange.getResponseBody());

            resp.setStatus(500);
            writer.println("<h2>HTTP ERROR: 500</h2>");
            writer.println("<pre>INTERNAL_SERVER_ERROR</pre>");
            writer.println("<p>RequestURI=" + req.getRequestURI() + "</p>");
View Full Code Here

        handler.stop();
    }

    @Test
    public void testCallbackGet() throws IOException, URISyntaxException {
        HttpExchange exchange = prepareExchange("http://localhost:8080/jolokia/read/java.lang:type=Memory/HeapMemoryUsage?callback=data");

        // Simple GET method
        expect(exchange.getRequestMethod()).andReturn("GET");

        Headers header = new Headers();
        ByteArrayOutputStream out = prepareResponse(handler, exchange, header);

        handler.doHandle(exchange);
View Full Code Here

        assertTrue(result.startsWith("data({"));
    }

    @Test
    public void testCallbackPost() throws URISyntaxException, IOException, java.text.ParseException {
        HttpExchange exchange = prepareExchange("http://localhost:8080/jolokia?callback=data",
                                                "Content-Type","text/plain; charset=UTF-8",
                                                "Origin",null
                                               );

        // Simple GET method
View Full Code Here

        assertTrue(parsedExpires.before(now) || parsedExpires.equals(now));
    }

    @Test
    public void invalidMethod() throws URISyntaxException, IOException, ParseException {
        HttpExchange exchange = prepareExchange("http://localhost:8080/");

        // Simple GET method
        expect(exchange.getRequestMethod()).andReturn("PUT");
        Headers header = new Headers();
        ByteArrayOutputStream out = prepareResponse(handler, exchange, header);
        handler.doHandle(exchange);

        JSONObject resp = (JSONObject) new JSONParser().parse(out.toString());
View Full Code Here

                {"classpath:/${prop:jolokia.test1.policy.location}", "not allowed"},
                {"classpath:/${prop:jolokia.test2.policy.location}.xml", "not allowed"}
        }) {
            Configuration config = getConfig(ConfigKey.POLICY_LOCATION,params[0]);
            JolokiaHttpHandler newHandler = new JolokiaHttpHandler(config);
            HttpExchange exchange = prepareExchange("http://localhost:8080/jolokia/read/java.lang:type=Memory/HeapMemoryUsage");
            // Simple GET method
            expect(exchange.getRequestMethod()).andReturn("GET");
            Headers header = new Headers();
            ByteArrayOutputStream out = prepareResponse(handler, exchange, header);
            newHandler.start(false);
            try {
                newHandler.doHandle(exchange);
View Full Code Here

        JolokiaHttpHandler handler = new JolokiaHttpHandler(getConfig(ConfigKey.LOGHANDLER_CLASS,InvalidLogHandler.class.getName()));
    }

    @Test
    public void simlePostRequestWithCors() throws URISyntaxException, IOException {
        HttpExchange exchange = prepareExchange("http://localhost:8080/jolokia",
                                                "Content-Type","text/plain; charset=UTF-8",
                                                "Origin","http://localhost:8080/"
                                               );

        prepareMemoryPostReadRequest(exchange);
View Full Code Here

        expect(pExchange.getRequestBody()).andReturn(is);
    }

    @Test
    public void preflightCheck() throws URISyntaxException, IOException {
        HttpExchange exchange = prepareExchange("http://localhost:8080/",
                                                "Origin","http://localhost:8080/",
                                                "Access-Control-Request-Headers","X-Bla, X-Blub");
        expect(exchange.getRequestMethod()).andReturn("OPTIONS");

        Headers header = new Headers();
        ByteArrayOutputStream out = prepareResponse(handler, exchange, header);
        handler.doHandle(exchange);
        assertEquals(header.getFirst("Access-Control-Allow-Origin"),"http://localhost:8080/");
View Full Code Here

TOP

Related Classes of com.sun.net.httpserver.HttpExchange

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.