Package org.w3c.jigsaw.http

Examples of org.w3c.jigsaw.http.Reply


      // should be check100Continue() or something
      ContinueEvent cevent = (ContinueEvent) event;
      if ((req.getMajorVersion() == 1) && (req.getMinorVersion() == 1)) {
    try {
        if ((cevent.packet != null) && (frame != null)) {
      Reply r = null;
      try {
          r = frame.dupReply(request, cevent.packet);
          r.setStream((InputStream)null);
      } catch (Exception ex) {}
      request.getClient().sendContinue(r);
        } else {
            request.getClient().sendContinue();
        }
View Full Code Here


    public ReplyInterface outgoingFilter(RequestInterface req,
           ReplyInterface rep)
  throws ProtocolException
    {
  Request request = (Request) req;
  Reply   reply   = (Reply) rep;
  // Anything to compress ?
  if ( ! reply.hasStream() ) {
      return null;
  }
  // if there is already a Content-Encoding, skip this
  if (reply.getContentEncoding() != null) {
      return null;
  }
  // Match possible mime types:
  MimeType t[]     = getMimeTypes();
  boolean  matched = false;
  if ( t != null ) {
      for (int i = 0 ; i < t.length ; i++) {
    if ( t[i] == null )
        continue;
    if ( t[i].match(reply.getContentType()) > 0 ) {
        matched = true;
        break;
    }
      }
  }
  if ( ! matched )
      return null;
  // Compress:
  try {
      PipedOutputStream pout = new PipedOutputStream();
      PipedInputStream  pin  = new PipedInputStream(pout);
      new GZIPDataMover(reply.openStream()
            , new GZIPOutputStream(pout));
      reply.addContentEncoding("gzip");
      reply.setContentLength(-1);
      reply.setStream(pin);
  } catch (Exception ex) {
      ex.printStackTrace();
  }
  return null;
    }
View Full Code Here

     */

    protected void error(Request request, String msg)
  throws ProtocolException
    {
  Reply reply = request.makeReply(HTTP.INTERNAL_SERVER_ERROR);
  reply.setContent(msg);
  throw new HTTPException(reply);
    }
View Full Code Here

  reply.setContent(msg);
  throw new HTTPException(reply);
    }

    protected Reply okReply(Request request, byte bits[]) {
  Reply reply = request.makeReply(HTTP.OK);
  reply.setContentType(AdminContext.conftype);
  if ( bits != null ) {
      ByteArrayInputStream in = new ByteArrayInputStream(bits);
      reply.setContentLength(bits.length);
      reply.setStream(in);
  }
  return reply;
    }
View Full Code Here

    public ReplyInterface perform(RequestInterface ri)
  throws org.w3c.tools.resources.ProtocolException,
         org.w3c.tools.resources.ResourceException
    {
  Request     request  = (Request) ri;
  Reply       reply    = null;
  Reply       extReply = null;
  HttpExtList cman     = request.getHttpCManExtDecl();
  HttpExtList copt     = request.getHttpCOptExtDecl();
  HttpExtList man      = request.getHttpManExtDecl();

  if ((cman != null) || (copt != null)) {
View Full Code Here

         HttpExtList cman,
         HttpExtList copt)
  throws org.w3c.tools.resources.ProtocolException
    {
  if (cman != null) {
      Reply error = request.makeReply(HTTP.NOT_EXTENDED) ;
      HtmlGenerator content = new HtmlGenerator("Error");
      content.append("<h1>Mandatory extension(s) not supported:",
         "</h1><p>\n");
      content.append("<ul>\n");
      HttpExt exts[] = cman.getHttpExts();
      for (int i=0 ; i < exts.length ; i++)
    content.append("<li> "+exts[i].getName()+"\n");
      content.append("</ul>\n");
      error.setStream(content);
      return error;
  }
  return null;
    }
View Full Code Here

     */
    protected Reply getOtherResource(Request request)
  throws ProtocolException, ResourceException
    {
  // we don't manage this kind of resource
  Reply error = request.makeReply(HTTP.NOT_IMPLEMENTED) ;
  error.setContent("Method GET not implemented.<br><br>"+
       "The administration server does not use plain "+
       "HTTP but a variant of it. The only tool available "+
       "for now is an application called <b>JigAdmin</b>. "+
       "Please read the documentation.");
  throw new HTTPException (error) ;
View Full Code Here

    protected Reply dupReply(Request request
           , org.w3c.www.protocol.http.Reply rep)
  throws HTTPException, IOException
    {
  Reply reply = request.makeReply(rep.getStatus());
  // get rid of "by default" headers wchich SHOULD NOT be modified
  reply.setHeaderValue(Reply.H_SERVER, null);
        // Duplicate reply header values:
  Enumeration e = rep.enumerateHeaderDescriptions();
  while ( e.hasMoreElements() ) {
      HeaderDescription d = (HeaderDescription) e.nextElement();
      HeaderValue       v = rep.getHeaderValue(d);
      if ( v != null )
    reply.setHeaderValue(d, v);
  }
  // Get rid of hop by hop headers:
  reply.setHeaderValue(Reply.H_CONNECTION, null);
  reply.setHeaderValue(Reply.H_PROXY_CONNECTION, null);
  reply.setHeaderValue(Reply.H_PROXY_AUTHENTICATE, null);
  reply.setHeaderValue(Reply.H_PUBLIC, null);
  reply.setHeaderValue(Reply.H_TRANSFER_ENCODING, null);
  reply.setHeaderValue(Reply.H_UPGRADE, null);
  reply.setHeaderValue(Reply.H_TRAILER, null);
  reply.removeHeader("keep-alive");
  // Get rid of the fields enumerated in the connection header:
  String conn[] = rep.getConnection();
  if (conn != null) {
      for (int i = 0 ; i < conn.length ; i++)
    reply.removeHeader(conn[i]);
  }
  // check if nasty people are mixing Content-Length and chunking
  if (reply.getContentLength() >= 0 ) {
      String te[] = rep.getTransferEncoding() ;
      if ( te != null ) {
    for (int i = 0 ; i < te.length ; i++) {
        if (te[i].equals("chunked")) {
      reply.setContentLength(-1);
        }
    }
      }
  }
  // Update the via route:
  reply.addVia(getVia());
  // Update the reply output stream:
  try {
      reply.setStream(rep.getInputStream());
  } catch (Exception ex) {};
  // if reply is using bad HTTP version we should close it
  if (rep.getMajorVersion() == 0) {
      reply.setKeepConnection(false);
  }
  // if HTTP/1.0 and no Content-Length also...
  if ((rep.getMajorVersion() == 1) &&
      (rep.getMajorVersion() == 0) &&
      (reply.getContentLength() == -1)) {
      reply.setKeepConnection(false);
  }
  // check the age
  int age = rep.getAge();
  if (age >= 0 ) {
      // check if it is an heuristic expiration without a warning
      if (age > 86400) {
    if ((rep.getExpires() == -1) && (rep.getMaxAge() == -1) &&
        (rep.getSMaxAge() == -1)) {
        // rfc2616: 13.2.4 on behalf of a bad upstream server
        HttpWarning w[] = rep.getWarning();
        boolean doit = true;
        if (w != null) {
      for (int i=0; doit && (i<w.length); i++) {
          doit = (w[i].getStatus() != 113);
      }
        }
        if (doit) {
      reply.addWarning(WARN_HEURISTIC);
        }
    }
      }
  }
  reply.setProxy(true);
  return reply;
    }
View Full Code Here

  int sz;

  if (fb > cl-1) { // first byte already out of range
      HttpContentRange cr = HttpFactory.makeContentRange("bytes", 0,
                     cl - 1, cl);
      Reply rr;
      rr = createDefaultReply(request,
            HTTP.REQUESTED_RANGE_NOT_SATISFIABLE);
      rr.setContentLength(-1);
      rr.setHeaderValue(rr.H_CONTENT_RANGE, cr);
      if (getMD5Flag())
    rr.setContentMD5(null);
      return rr;
  }

  if ((fb < 0) && (lb >= 0)) { // ex: bytes=-20 final 20 bytes
      if (lb >= cl)   // cut the end
    lb = cl;
      sz = lb;
      fb = cl - lb;
      lb = cl - 1;
  } else if (lb < 0) {  // ex: bytes=10- the last size - 10
      lb = cl-1;
      sz = lb-fb+1;
  } else {              // ex: bytes=10-20
      if (lb >= cl// cut the end
    lb = cl-1;
      sz = lb-fb+1;
  }
  if ((fb < 0) || (lb < 0) || (fb <= lb)) {
      HttpContentRange cr = null;
      fb = (fb < 0) ? 0 : fb;
      lb = ((lb > cl) || (lb < 0)) ? cl : lb;
      cr = HttpFactory.makeContentRange("bytes", fb, lb, cl);
      // Emit reply:
      Reply rr = createDefaultReply(request, HTTP.PARTIAL_CONTENT);
      // FIXME check for MD5 of only the subpart
      try { // create the MD5 for the subpart
    if (getMD5Flag()) {
        String s = null;
        try {
      ByteRangeOutputStream br;
      br = new ByteRangeOutputStream(fresource.getFile(),
                   fb, lb+1);
      Md5 md5 = new Md5 (br);
      byte b[] = md5.getDigest();
      Base64Encoder b64;
      ByteArrayOutputStream bs = new ByteArrayOutputStream();
      b64 = new Base64Encoder(new ByteArrayInputStream(b),
            bs);
      b64.process();
      s = bs.toString();
        } catch (Exception md_ex) {
      // default to null, no action here then
        }
        if (s == null)
      rr.setContentMD5(null);
        else
      rr.setContentMD5(s);
    }
          rr.setContentLength(sz);
    rr.setHeaderValue(rr.H_CONTENT_RANGE, cr);
    rr.setStream(new ByteRangeOutputStream(fresource.getFile(),
                   fb,
                   lb+1));
    return rr;
      } catch (IOException ex) {
      }
View Full Code Here

        try {
            dresource.delete();
        } catch (MultipleLockException ex) {
        }
        // Emit an error back:
        Reply error = request.makeReply(HTTP.NOT_FOUND) ;
        error.setContent ("<h1>Document not found</h1>"+
                 "<p>The document "+
              request.getURL()+
              " is indexed but not available."+
              "<p>The server is misconfigured.") ;
        throw new HTTPException (error) ;
    }
    refresh =
      (dresource.getDirectory().lastModified() >
                                             listing_stamp);
      }
  }
  if ((! computeContainerListing(refresh)) &&
      ( checkIfModifiedSince(request) == COND_FAILED )) {
      // Is it an IMS request ?
      Reply reply = createDefaultReply(request, HTTP.NOT_MODIFIED) ;
      return reply;
  }
  // New content or need update:
  Reply reply = createDefaultReply(request, HTTP.OK) ;
  reply.setLastModified(listing_stamp) ;
  reply.setStream(listing) ;
  // check MD5
  return reply ;
    }
View Full Code Here

TOP

Related Classes of org.w3c.jigsaw.http.Reply

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.