Package com.sun.net.httpserver

Examples of com.sun.net.httpserver.Headers


            long lastModified = f.lastModified();
            String ifModifiedSince = t.getRequestHeaders().getFirst("If-Modified-Since");
            if (ifModifiedSince != null) {
                long d = Date.parse(ifModifiedSince);
                if (d + 1000 >= lastModified) {
                    Headers hds = t.getResponseHeaders();
                    hds.set("Content-Type", contentType);
                    t.sendResponseHeaders(304, -1);

                    if (s_logger.isInfoEnabled())
                        s_logger.info("Sent 304 file has not been " + "modified since " + ifModifiedSince);
                    return;
                }
            }

            long length = f.length();
            Headers hds = t.getResponseHeaders();
            hds.set("Content-Type", contentType);
            hds.set("Last-Modified", new Date(lastModified).toGMTString());
            t.sendResponseHeaders(200, length);
            responseFileContent(t, f);

            if (s_logger.isInfoEnabled())
                s_logger.info("Sent file " + path + " with content type " + contentType);
View Full Code Here


        }
        return sb.toString();
    }  
   
    private void sendResponse(HttpExchange t, String contentType, String response) throws IOException {
        Headers hds = t.getResponseHeaders();
        hds.set("Content-Type", contentType);
   
        t.sendResponseHeaders(200, response.length());
        OutputStream os = t.getResponseBody();
        try {
            os.write(response.getBytes());
View Full Code Here

   
    private void handleClientStart(HttpExchange t, ConsoleProxyClient viewer, String title, String guest) throws IOException {
        List<String> languages = t.getRequestHeaders().get("Accept-Language");
        String response = viewer.onAjaxClientStart(title, languages, guest);
       
        Headers hds = t.getResponseHeaders();
        hds.set("Content-Type", "text/html");
        hds.set("Cache-Control", "no-cache");
        hds.set("Cache-Control", "no-store");
        t.sendResponseHeaders(200, response.length());
       
        OutputStream os = t.getResponseBody();
        try {
            os.write(response.getBytes());
View Full Code Here

    }
   
    private void handleClientUpdate(HttpExchange t, ConsoleProxyClient viewer) throws IOException {
        String response = viewer.onAjaxClientUpdate();
       
        Headers hds = t.getResponseHeaders();
        hds.set("Content-Type", "text/javascript");
        t.sendResponseHeaders(200, response.length());
       
        OutputStream os = t.getResponseBody();
        try {
            os.write(response.getBytes());
View Full Code Here

    }
    RootFolder root = parent.getRoot(RemoteUtil.userName(t), t);
    if (root == null) {
      throw new IOException("Unknown root");
    }
    Headers h = t.getRequestHeaders();
    for(String h1: h.keySet())  {
      LOGGER.debug("key "+h1+"="+h.get(h1));
    }
    String id = RemoteUtil.getId(path, t);
    id = RemoteUtil.strip(id);
    RendererConfiguration r = render;
    if (render == null) {
      r = root.getDefaultRenderer();
    }
    List<DLNAResource> res = root.getDLNAResources(id, false, 0, 0, r);
    if (res.size() != 1) {
      // another error
      LOGGER.debug("media unkonwn");
      throw new IOException("Bad id");
    }
    long len = res.get(0).length();
    Range range = RemoteUtil.parseRange(t.getRequestHeaders(), len);
    String mime = root.getDefaultRenderer().getMimeType(res.get(0).mimeType());
    DLNAResource dlna = res.get(0);
    DLNAMediaInfo m = dlna.getMedia();
    if(mime.equals(FormatConfiguration.MIMETYPE_AUTO) && m != null && m.getMimeType() != null) {
      mime = m.getMimeType();
    }
    if (dlna.getFormat().isVideo()) {
      if (flash) {
        mime = "video/flash";
        dlna.setPlayer(new WebPlayer(WebPlayer.FLASH));
      } else if (!RemoteUtil.directmime(mime)) {
        mime = RemoteUtil.MIME_TRANS;
        dlna.setPlayer(new WebPlayer(WebPlayer.TRANS));
      }
      else {
        dlna.setPlayer(null);
      }
    }

    LOGGER.debug("dumping media " + mime + " " + res);
    InputStream in = dlna.getInputStream(range, root.getDefaultRenderer());
    Headers hdr = t.getResponseHeaders();
    hdr.add("Content-Type", mime);
    hdr.add("Accept-Ranges", "bytes");
    hdr.add("Server", PMS.get().getServerName());
    hdr.add("Connection", "keep-alive");
    t.sendResponseHeaders(200, 0);
    OutputStream os = t.getResponseBody();
    StartStopListenerDelegate startStop = new StartStopListenerDelegate(t.getRemoteAddress().getHostString());
    PMS.get().getFrame().setStatusLine("Serving " + dlna.getName());
    startStop.start(dlna);
View Full Code Here

      throw new IOException("Access denied");
    }
    String id;
    id = RemoteUtil.getId("play/", t);
    String response = mkPage(id, t);
    Headers hdr = t.getResponseHeaders();
    hdr.add("Content-Type", "text/html");
    LOGGER.debug("play page " + response);
    t.sendResponseHeaders(200, response.length());
    try (OutputStream os = t.getResponseBody()) {
      os.write(response.getBytes());
    }
View Full Code Here

      throw new IOException("Access denied");
    }
    String id = RemoteUtil.getId("browse/", t);
    LOGGER.debug("Found id " + id);
    String response = mkBrowsePage(id, t);
    Headers hdr = t.getResponseHeaders();
    hdr.add("Content-Type", "text/html");
    writePage(response, t);
  }
View Full Code Here

    dlna.setPlayer(null);
    Range range = RemoteUtil.parseRange(t.getRequestHeaders(), len);
    Range.Byte rb = range.asByteRange();
    InputStream in = dlna.getInputStream(range, root.getDefaultRenderer());
    String mime = root.getDefaultRenderer().getMimeType(dlna.mimeType());
    Headers hdr = t.getResponseHeaders();
    LOGGER.debug("dumping media " + mime + " " + dlna);
    hdr.add("Content-Type", mime);
    hdr.add("Accept-Ranges", "bytes");
    hdr.add("Server", PMS.get().getServerName());
    hdr.add("Connection", "keep-alive");
    hdr.add("Transfer-Encoding", "chunked");
    if (in.available() != len) {
      hdr.add("Content-Range", "bytes " + rb.getStart() + "-" + in.available() + "/" + len);
      t.sendResponseHeaders(206, in.available());
    } else {
      t.sendResponseHeaders(200, 0);
    }
    OutputStream os = new BufferedOutputStream(t.getResponseBody(), 512 * 1024);
 
View Full Code Here

    @Test
    public void testGetHeaders() throws Exception {
        targetServer.createContext("/request", new HttpHandler() {
            @Override
            public void handle(HttpExchange httpExchange) throws IOException {
                final Headers responseHeaders = httpExchange.getResponseHeaders();
                responseHeaders.add("Content-Type", "application/json; charset=utf8");
                httpExchange.sendResponseHeaders(200, 0);
                httpExchange.close();
            }
        });
View Full Code Here

    String r = ta.getAlias();
    StringBuffer sb = new StringBuffer();
    sb = Handler.getElementByObject(sb, r);
    byte[] rb = sb.toString().getBytes("utf-8");

    Headers hd = httpExchange.getResponseHeaders();
    hd.put("Content-Type", Arrays.asList("text/plain; charset=utf-8"));
    hd.put("Content-Length", Arrays.asList(Long.toString(rb.length + 2)));

    httpExchange.sendResponseHeaders(200, rb.length + 2);
    OutputStream w = httpExchange.getResponseBody();
    w.write(rb);
    w.write("\r\n".getBytes());
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.