Package com.sun.net.httpserver

Examples of com.sun.net.httpserver.Headers


     * Returns the String value of the specified cookie.
     * @param name a String specifying the cookie name.
     */
    public String getCookie(final String name)
    {
        Headers headers = _exchange.getRequestHeaders();
        if (!headers.containsKey("Cookie"))
        {
            return null;
        }

        List<String> values = headers.get("cookie");
        for (String value : values)
        {
            String[] cookies = value.split(";");
            for (String cookie : cookies)
            {
View Full Code Here


    ExchangeImpl (
        String m, URI u, Request req, long len, HttpConnection connection
    ) throws IOException {
        this.req = req;
        this.reqHdrs = req.headers();
        this.rspHdrs = new Headers();
        this.method = m;
        this.uri = u;
        this.connection = connection;
        this.reqContentLen = len;
        /* ros only used for headers, body written directly to stream */
 
View Full Code Here

                }
                String uriStr = requestLine.substring (start, space);
                URI uri = new URI (uriStr);
                start = space+1;
                String version = requestLine.substring (start);
                Headers headers = req.headers();
                String s = headers.getFirst ("Transfer-encoding");
                long clen = 0L;
                if (s !=null && s.equalsIgnoreCase ("chunked")) {
                    clen = -1L;
                } else {
                    s = headers.getFirst ("Content-Length");
                    if (s != null) {
                        clen = Long.parseLong(s);
                    }
                }
                ctx = contexts.findContext (protocol, uri.getPath());
                if (ctx == null) {
                    reject (Code.HTTP_NOT_FOUND,
                            requestLine, "No context found for request");
                    return;
                }
                connection.setContext (ctx);
                if (ctx.getHandler() == null) {
                    reject (Code.HTTP_INTERNAL_ERROR,
                            requestLine, "No handler for context");
                    return;
                }
                tx = new ExchangeImpl (
                    method, uri, req, clen, connection
                );
                String chdr = headers.getFirst("Connection");
                Headers rheaders = tx.getResponseHeaders();

                if (chdr != null && chdr.equalsIgnoreCase ("close")) {
                    tx.close = true;
                }
                if (version.equalsIgnoreCase ("http/1.0")) {
                    tx.http10 = true;
                    if (chdr == null) {
                        tx.close = true;
                        rheaders.set ("Connection", "close");
                    } else if (chdr.equalsIgnoreCase ("keep-alive")) {
                        rheaders.set ("Connection", "keep-alive");
                        int idle=(int)ServerConfig.getIdleInterval()/1000;
                        int max=(int)ServerConfig.getMaxIdleConnections();
                        String val = "timeout="+idle+", max="+max;
                        rheaders.set ("Keep-Alive", val);
                    }
                }

                if (newconnection) {
                    connection.setParameters (
View Full Code Here

    Headers headers () throws IOException {
        if (hdrs != null) {
            return hdrs;
        }
        hdrs = new Headers();

        char s[] = new char[10];
        int firstc = is.read();
        while (firstc != LF && firstc != CR && firstc >= 0) {
            int len = 0;
View Full Code Here

    {
        public void handle(HttpExchange exchange) throws IOException
        {
            assertEquals("HTTP/1.1", exchange.getProtocol());
            assertEquals("POST", exchange.getRequestMethod());
            Headers headers = exchange.getRequestHeaders();
            assertTrue (headers.containsKey("foo"));
            String val = headers.getFirst("foo");
         
            assertEquals ("fooValue", val);
            assertNotNull (exchange.getHttpContext());
            assertEquals ("/foo", exchange.getHttpContext().getPath());
            assertTrue (this == exchange.getHttpContext().getHandler());
            assertTrue (exchange.getHttpContext().getAttributes().containsKey("fooAttribute"));
            assertEquals("fooValue", (String)exchange.getHttpContext().getAttributes().get("fooAttribute"));
          
            assertEquals ("Was Here", (String)exchange.getAttribute("fooFilter"));
            assertEquals ("Was Also Here", (String)exchange.getAttribute("barFilter"));
           
            assertNotNull(exchange.getPrincipal());
            assertEquals("humpty", exchange.getPrincipal().getName());
           
            String response = "Hello World!";
            InputStream is = exchange.getRequestBody();
            String body = IO.toString(is);
            assertEquals(0, body.length());
           
            Headers responseHeaders = exchange.getResponseHeaders();
            responseHeaders.add("bar", "barValue");
            exchange.sendResponseHeaders(200, response.length());
            OutputStream os = exchange.getResponseBody();
            os.write(response.getBytes());
            os.close();
        }
View Full Code Here

    }

    @Override
    public Headers getRequestHeaders()
    {
        Headers headers = new Headers();
        Enumeration en = _req.getHeaderNames();
        while (en.hasMoreElements())
        {
            String name = (String) en.nextElement();
            Enumeration en2 = _req.getHeaders(name);
            while (en2.hasMoreElements())
            {
                String value = (String) en2.nextElement();
                headers.add(name, value);
            }
        }
        return headers;
    }
View Full Code Here

    @Override
    public void handle(HttpExchange exchange) throws IOException {
        String requestMethod = exchange.getRequestMethod();
        if (requestMethod.equalsIgnoreCase("GET")) {
            String fileName = exchange.getRequestURI().getPath().substring("/s4/".length());
            Headers responseHeaders = exchange.getResponseHeaders();
            responseHeaders.set(HttpHeaders.Names.CONTENT_TYPE, HttpHeaders.Values.BYTES);
            exchange.sendResponseHeaders(200, Files.toByteArray(new File(tmpDir, fileName)).length);

            OutputStream responseBody = exchange.getResponseBody();

            ByteStreams.copy(new FileInputStream(new File(tmpDir, fileName)), responseBody);
View Full Code Here

    @Override
    public void handle(HttpExchange httpExchange) throws IOException {
        try {
            if (HttpTransportConstants.METHOD_GET.equals(httpExchange.getRequestMethod())) {
                Headers headers = httpExchange.getResponseHeaders();
                headers.set(HttpTransportConstants.HEADER_CONTENT_TYPE, CONTENT_TYPE);
                ByteArrayOutputStream os = new ByteArrayOutputStream();
                transform(definition.getSource(), new StreamResult(os));
                byte[] buf = os.toByteArray();
                httpExchange.sendResponseHeaders(HttpTransportConstants.STATUS_OK, buf.length);
                FileCopyUtils.copy(buf, httpExchange.getResponseBody());
View Full Code Here

            Graphics2D bufImageGraphics = bufferedImage.createGraphics();
            bufImageGraphics.drawImage(scaledImage, 0, 0, null);
            ByteArrayOutputStream bos = new ByteArrayOutputStream(8196);
            javax.imageio.ImageIO.write(bufferedImage, "jpg", bos);
            byte[] bs = bos.toByteArray();
            Headers hds = t.getResponseHeaders();
            hds.set("Content-Type", "image/jpeg");
            hds.set("Cache-Control", "no-cache");
            hds.set("Cache-Control", "no-store");
            t.sendResponseHeaders(200, bs.length);
            OutputStream os = t.getResponseBody();
            os.write(bs);
            os.close();
        } else {
            AjaxFIFOImageCache imageCache = viewer.getAjaxImageCache();
                    byte[] img = imageCache.getImage(key);
   
            if(img != null) {
                Headers hds = t.getResponseHeaders();
                hds.set("Content-Type", "image/jpeg");
                t.sendResponseHeaders(200, img.length);
               
                OutputStream os = t.getResponseBody();
                try {
                    os.write(img, 0, img.length);
View Full Code Here

        String cmd = path.substring(i + 1);
        s_logger.info("Get CMD request for " + cmd);
        if (cmd.equals("getstatus")) {
            ConsoleProxyClientStatsCollector statsCollector = ConsoleProxy.getStatsCollector();
           
            Headers hds = t.getResponseHeaders();
            hds.set("Content-Type", "text/plain");
            t.sendResponseHeaders(200, 0);
            OutputStreamWriter os = new OutputStreamWriter(t.getResponseBody());
            statsCollector.getStatsReport(os);
            os.close();
        }
View Full Code Here

TOP

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

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.