Package com.sun.net.httpserver

Examples of com.sun.net.httpserver.Headers


  public  void send(HtmlPage page) throws java.io.IOException {
    send(page, HttpURLConnection.HTTP_OK);
  }
 
  public void send(HtmlPage page, int responseCode) throws java.io.IOException {
      Headers responseHeaders = _exchange.getResponseHeaders();
      responseHeaders.set("Content-Type", "text/html");
      _exchange.sendResponseHeaders(responseCode, 0);
      BufferedWriter out = new BufferedWriter(new OutputStreamWriter(_exchange.getResponseBody()));
      for (int iLine = 0; iLine < page.size(); iLine++) {
        out.write(page.get(iLine));
        out.newLine();
View Full Code Here


  }



  public void sendData(String contentType, InputStream is) throws java.io.IOException {
    Headers responseHeaders = _exchange.getResponseHeaders();
    responseHeaders.set("Content-Type", contentType);
    _exchange.sendResponseHeaders(HttpURLConnection.HTTP_OK, 0);
    OutputStream os = _exchange.getResponseBody();
    int n;
    byte[] buf = new byte[2048];
    while ((n = is.read(buf)) > 0) {
View Full Code Here

  public HttpExchange get() {
    return _exchange;
  }

  public void setResponseHeader(String header, String value) {
    Headers responseHeaders = _exchange.getResponseHeaders();
    responseHeaders.set(header, value);
  }
View Full Code Here

   
    if (allowedFileRequest(exchange.getRequestURI().getPath())) {
      return new Authenticator.Success(new HttpPrincipal("", _realm));
    }
   
    Headers rmap = exchange.getRequestHeaders();
   
    boolean isProtectedRequest = this.isProtectedRequest(exchange);
   
    String auth = rmap.getFirst("Authorization");
    if (auth == null) {
      if ((_mode == DatabaseWikiProperties.AuthenticateAlways)
          || ((_mode == DatabaseWikiProperties.AuthenticateWriteOnly) && (isProtectedRequest))
          || (exchange.getRequestURI().getPath().equals(WikiServer.SpecialFolderLogin))) {
        Headers map = exchange.getResponseHeaders();
        map.set("WWW-Authenticate", "Basic realm=" + "\"" + _realm + "\"");
        return new Authenticator.Retry(401);
      } else {
        return new Authenticator.Success(new HttpPrincipal(User.UnknownUserName, _realm));
      }
    } else {
      int sp = auth.indexOf(' ');
      if (sp == -1 || !auth.substring(0, sp).equals("Basic")) {
        return new Authenticator.Failure(401);
      }
      byte[] b = new Base64().base64ToByteArray(auth.substring(sp + 1));
      String userpass = new String(b);
      int colon = userpass.indexOf(':');
      String uname = userpass.substring(0, colon);
      String pass = userpass.substring(colon + 1);
      if ((_mode == DatabaseWikiProperties.AuthenticateAlways)
          || ((_mode == DatabaseWikiProperties.AuthenticateWriteOnly) && (isProtectedRequest))
          || (exchange.getRequestURI().getPath().equals(WikiServer.SpecialFolderLogin))) {
        if (checkCredentials(uname, pass)) {
          return new Authenticator.Success(new HttpPrincipal(uname, _realm));
        } else {
          Headers map = exchange.getResponseHeaders();
          map.set("WWW-Authenticate", "Basic realm=" + "\"" + _realm  + "\"");
          return new Authenticator.Failure(401);
        }
      } else {
        return new Authenticator.Success(new HttpPrincipal(uname, _realm));
      }
View Full Code Here

  public static void send(HtmlPage page, HttpExchange exchange) throws java.io.IOException {
    send(page, exchange, HttpURLConnection.HTTP_OK);
  }
 
  public static void send(HtmlPage page, HttpExchange exchange, int responseCode) throws java.io.IOException {
      Headers responseHeaders = exchange.getResponseHeaders();
      responseHeaders.set("Content-Type", "text/html");
      exchange.sendResponseHeaders(responseCode, 0);
      BufferedWriter out = new BufferedWriter(new OutputStreamWriter(exchange.getResponseBody()));
      for (int iLine = 0; iLine < page.size(); iLine++) {
        out.write(page.get(iLine));
        out.newLine();
View Full Code Here

    }

    private InBoundHeaders getHeaders(HttpExchange exchange) {
        InBoundHeaders rh = new InBoundHeaders();
       
        Headers eh = exchange.getRequestHeaders();
        for (Entry<String, List<String>> e : eh.entrySet()) {
            rh.put(e.getKey(), e.getValue());
        }
       
        return rh;
    }
View Full Code Here

            this.exchange = exchange;
        }
       
        public OutputStream writeStatusAndHeaders(long contentLength,
                ContainerResponse cResponse) throws IOException {
            Headers eh = exchange.getResponseHeaders();
            for (Map.Entry<String, List<Object>> e : cResponse.getHttpHeaders().entrySet()) {
                List<String> values = new ArrayList<String>();
                for (Object v : e.getValue())
                    values.add(ContainerResponse.getHeaderValue(v));
                eh.put(e.getKey(), values);
            }

            if (cResponse.getStatus() == 204) {
                // Work around bug in LW HTTP server
                // http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6886436
View Full Code Here

            byte[] data = new byte[(int) fileRequest.length()];
            FileInputStream fr = new FileInputStream(fileRequest);
            int count = fr.read(data);

            //set the Content-type header
            Headers h = xchange.getResponseHeaders();
            String canonicalPath = fileRequest.getCanonicalPath();
            int lastIndex = canonicalPath.lastIndexOf(".");
            String fileExtension = canonicalPath.substring(lastIndex + 1);

            if (fileExtension.equalsIgnoreCase("crl"))
            {
                //h.set("Content-Type","application/x-pkcs7-crl");
                h.set("Content-Type","application/pkix-crl");
            }
            else if (fileExtension.equalsIgnoreCase("crt")
                    || fileExtension.equalsIgnoreCase("cer")
                    || fileExtension.equalsIgnoreCase("der"))
            {
                h.set("Content-Type", "application/x-x509-ca-cert");
            }

            //write out the requested file
            xchange.sendResponseHeaders(200, data.length);
            OutputStream os = xchange.getResponseBody();
View Full Code Here

            System.out.printf("Protocol: %s\n", he.getProtocol());
            System.out.printf("RemoteAddress: %s\n", he.getRemoteAddress());
            System.out.printf("LocalAddress: %s\n", he.getLocalAddress());
            System.out.printf("ContextPath: %s\n", he.getHttpContext().getPath());
            System.out.printf("ContextAttributes: %s\n", he.getHttpContext().getAttributes());
            Headers headers = he.getRequestHeaders();
            for(String key : headers.keySet()) {
                System.out.printf("Header(%s): %s\n", key, headers.getFirst(key));
            }
            return queryParams;
         }
View Full Code Here

        ModelNode dmr = null;
        ModelNode response;
        int status = 200;

        Headers requestHeaders = http.getRequestHeaders();
        boolean encode = "application/dmr-encoded".equals(requestHeaders.getFirst("Accept"))
                || "application/dmr-encoded".equals(requestHeaders.getFirst("Content-Type"));

        try {
            dmr = isGet ? convertGetRequest(request) : convertPostRequest(http.getRequestBody(), encode);
            response = modelController.execute(OperationBuilder.Factory.create(dmr).build());
        } catch (Throwable t) {
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.