Package com.sun.net.httpserver

Examples of com.sun.net.httpserver.Headers


  // //////////////////////////////
  @SuppressWarnings("unchecked")
  public void registerClasses(Object[] objs, HttpExchange httpExchange,
      ITaskAPI ta) throws SysException, IOException {
    ta.registerClasses(((Long) (objs[0])).longValue(), (Set<String>) (objs[1]));
    Headers hd = httpExchange.getResponseHeaders();
    hd.put("Content-Type", Arrays.asList("text/plain; charset=utf-8"));
    hd.put("Content-Length", Arrays.asList(Long.toString(2)));
    httpExchange.sendResponseHeaders(200, 2);
    OutputStream w = httpExchange.getResponseBody();
    w.write("\r\n".getBytes());
    w.close();
  }
View Full Code Here


            res = cntx_child
                .getPrmByFullName(((grp_out == null) || (grp_out
                    .length() == 0)) ? "body" : grp_out
                    + "/body");
            if (res == null) {
              Headers hd = httpExchange.getResponseHeaders();
              hd.put("Content-Type",
                  Arrays.asList("text/plain; charset=" + enc));
              httpExchange.sendResponseHeaders(503, 0);
              OutputStream w = httpExchange.getResponseBody();
              w.write("Обработчик не выбран".getBytes(enc));
              w.close();
              return;
            }
          } else {
            Process.currentProcess().regResourceName(
                cntx_child.id_task, "child.id");
            long wait = Strings.parseIntegerNvl(
                cntx.getPrmByFullName("wait"), 30000);// !!!
            cntx.log(false, "Start waiting (", wait, ")");
            cntx_child.ta.waitFinished(cntx_child.id_subject,
                cntx_child.id_task, wait);
            cntx.log(false, "End waiting");
            res = cntx_child
                .getPrmByFullName(((grp_out == null) || (grp_out
                    .length() == 0)) ? "body" : grp_out
                    + "/body");
          }

          if (res != null) {
            Map<String, Object> result = cntx_child
                .getGroupParams(grp_out);
            long l = 0;
            if (res instanceof FileInputStream) {
              is = (FileInputStream) res;
              l = ((FileInputStream) is).getChannel().size();
            } else if (res instanceof Element) {
              Element el = (Element) res;
              obb = new OutputByteBuffer(8000);
              XMLFileWaiter.putStream(el, obb, "utf-8");
              try {
                obb.close();
                l = obb.getLength();
              } catch (IOException e1) {
                e1.printStackTrace();
              }
              is = obb.getIS();
            } else if (res instanceof OutputByteBuffer) {
              is = ((OutputByteBuffer) res).getIS();
              l = ((OutputByteBuffer) res).getLength();
            } else if (res instanceof File) {
              File f = (File) res;
              cntx.log(false, "source file name = ",
                  f.getCanonicalPath());
              is = new FileInputStream(f.getCanonicalPath());
              l = f.length();
            } else if (res instanceof InputStreamReader) {
              InputStreamReader f = (InputStreamReader) res;
              File x = File.createTempFile("dbms", "clob");
              FileWriter w = new FileWriter(x);
              char[] buf = new char[8 * 1024];
              int len;
              while ((len = f.read(buf)) > 0) {
                w.write(buf, 0, len);
              }
              w.flush();
              w.close();
              is = new FileInputStream(x);
              l = ((FileInputStream) is).getChannel().size();
            } else {
              byte[] buf = res.toString().getBytes(enc);
              is = new ByteArrayInputStream(buf);
              l = buf.length;
            }

            Headers hd = httpExchange.getResponseHeaders();
            hd.put("Content-Type",
                Arrays.asList("text/plain; charset=" + enc));
            hd.put("Content-Length",
                Arrays.asList(Long.toString(l)));
            String h = cntx.getFullName(grp_out, "hdrs.");
            for (Map.Entry<String, Object> e : result.entrySet()) {
              String k = e.getKey();
              if (k.indexOf(h) == 0) {
                k = k.substring(h.length());
                Object o = e.getValue();
                String v;
                if (o != null && o instanceof IDependentParam) {
                  IDependentParam idp = (IDependentParam) o;
                  try {
                    o = idp.getValue(cntx_child);
                  } catch (CalculateException e1) {
                    e1.printStackTrace();
                  }
                }
                if (o == null)
                  continue;
                v = Strings.getString(o);
                hd.put(k, Arrays.asList(v));
              }
            }
            httpExchange.sendResponseHeaders(200, l);
            OutputStream w = httpExchange.getResponseBody();
            byte[] buf = new byte[8 * 1024];
 
View Full Code Here

    public void handle(HttpExchange he) throws IOException {
        //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
       
        String requestMethod = he.getRequestMethod();
        if (requestMethod.equalsIgnoreCase("GET")) {
            Headers responseHeaders = he.getResponseHeaders();
            responseHeaders.set("Content-Type", "text/plain");
            he.sendResponseHeaders(200, 0);
           
            OutputStream responseBody = he.getResponseBody();
            Headers requestHeaders = he.getRequestHeaders();
            Set<String> keySet = requestHeaders.keySet();
            Iterator<String> iter = keySet.iterator();
           
            responseBody.write("OK\n".getBytes());
            //while (iter.hasNext()) {
            //    String key = iter.next();
View Full Code Here

    public void handle(HttpExchange he) throws IOException {
        //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
       
        String requestMethod = he.getRequestMethod();
        if (requestMethod.equalsIgnoreCase("GET")) {
            Headers responseHeaders = he.getResponseHeaders();
            responseHeaders.set("Content-Type", "text/plain");
            he.sendResponseHeaders(200, 0);
           
            OutputStream responseBody = he.getResponseBody();
            Headers requestHeaders = he.getRequestHeaders();
            Set<String> keySet = requestHeaders.keySet();
            Iterator<String> iter = keySet.iterator();
           
            responseBody.write("OK\n".getBytes());
            //while (iter.hasNext()) {
            //    String key = iter.next();
View Full Code Here

        @Override
        public OutputStream writeResponseStatusAndHeaders(final long contentLength, final ContainerResponse context)
                throws ContainerException {
            final MultivaluedMap<String, String> responseHeaders = context.getStringHeaders();
            final Headers serverHeaders = exchange.getResponseHeaders();
            for (final Map.Entry<String, List<String>> e : responseHeaders.entrySet()) {
                for (final String value : e.getValue()) {
                    serverHeaders.add(e.getKey(), value);
                }
            }

            try {
                if (context.getStatus() == 204) {
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

    public void handle(final HttpExchange t) throws IOException
    {
      final String date = new Date().toString();
      _sensors.get(_name).incrementAndGet();
      Headers headers = t.getRequestHeaders();
      Long delay = _delay;
      if (headers.containsKey("delay"))
      {
        List<String> headerValues = headers.get("delay");
        delay = Long.parseLong(headerValues.get(0));
      }
      System.out.println( date + ": " + _serverName
                             + " received a request for the context handler = " + _name);
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);
            }
           
            exchange.sendResponseHeaders(cResponse.getStatus(),
                    getResponseLength(contentLength));
            return exchange.getResponseBody();
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.