Package org.w3c.jigsaw.http

Examples of org.w3c.jigsaw.http.Reply


                       
      // synchronization object
      Object o = null;
      try {
               
                Reply reply = srResp.getReply();
                if (reply != null) {
                        o = reply.getState(JigsawHttpServletResponse.MONITOR);
                }
               
                ClassLoader loader = switchContext(srServlet);
                try {
            srServlet.service(srReq , srResp);
                }
                finally {
                            resetContext(loader);
                }
               
    // processing done, release the servlet
                try {
                    int duration = (int)Math.min(System.currentTimeMillis() - start, Integer.MAX_VALUE);
        servletPool.releaseServlet(srServlet, duration);
    } finally {
        srServlet = null;
                }
    // and remove the timer
    if ( stimer != null ) {
        server.timer.recallTimer(stimer);
        stimer = null;
    }
    srResp.flushStream(true);
      } catch (UnavailableException uex) {
    String message = null;
    srResp.setStatus(HTTP.SERVICE_UNAVAILABLE);
    if (uex.isPermanent()) {
        message = "<h2>The servlet is permanently "+
      "unavailable :</h2>"+
      "Details: <b>"+uex.getMessage()+"</b>";
        try {
      srResp.sendError(HTTP.SERVICE_UNAVAILABLE, message);
        } catch (IOException ioex) {
      // not much to do now...
        }
    } else {
        int delay = uex.getUnavailableSeconds();
        if (delay > 0) {
      message = "<h2>The servlet is temporarily "+
          "unavailable :</h2>"+
          "Delay : "+delay+
          " seconds<br><br>Details: <b>"+
          uex.getMessage()+"</b>";
      srResp.getReply().setRetryAfter(delay);
      try {
          srResp.sendError(HTTP.SERVICE_UNAVAILABLE,message);
      } catch (IOException ioex) {
          // not much to do now...
      }
        } else {
      message = "<h2>The servlet is temporarily "+
          "unavailable :</h2>"+
          "Details: <b>"+uex.getMessage()+
          "</b>";
      try {   
          srResp.sendError(HTTP.SERVICE_UNAVAILABLE,message);
      } catch (IOException ioex) {
          // not much to do now...
      }
        }
    }
      } catch (Exception ex) {
    if (debug) {
        ex.printStackTrace();
    }
    if (srResp.isStreamObtained()) {
        try {
      srResp.flushStream(false);
      OutputStream os = srResp.getRawOutputStream();
      if (os != null) {
          synchronized (os) {
        PrintWriter pw = new PrintWriter(os);
        ex.printStackTrace(pw);
        pw.flush();
          }
      }
      srResp.flushStream(true);
        } catch (IOException ioex) {}
    } else {
        try {
      srResp.sendError(HTTP.INTERNAL_SERVER_ERROR,
           "Servlet has thrown exception:" +
           ex.toString());
        } catch (IOException ioex) {
      // no stream to write on, fail silently
        }
    }
      } finally {
    if ( stimer != null ) {
        server.timer.recallTimer(stimer);
        stimer = null;
    }
                if (srServlet != null) {
        try {
                        int duration = (int)Math.min(System.currentTimeMillis() - start, Integer.MAX_VALUE);
      servletPool.releaseServlet(srServlet, duration);
        }
        catch (ServletException ex) {
      // ignore
        }
                }
    // release the monitor waiting for the end of the reply setup
    if (o != null) {
        synchronized (o) {
      o.notifyAll();
        }
    }
    srServlet = null;
    srReq = null;
    // adds the END state
    Reply r = srResp.getReply();
    if (r != null) {
        r.setState(ENDED, new Object());
    }
    srResp = null;
      }
  }
View Full Code Here


      InetAddress ia = sc.getInetAddress();
      if (ia.equals(proxy_ia)) // same, it is ok :)
    return null;
  }
  // failed, restrict access
  Reply r = request.makeReply(HTTP.USE_PROXY);
  if (r != null) {
      HtmlGenerator g = new HtmlGenerator("Use Proxy");
      g.append("You should use the following proxy to access" +
         " this resource: " + getString(ATTR_PROXY, "localhost"));
      r.setStream(g);
  }
  r.setLocation(proxy_url);
  return r;
    }
View Full Code Here

     * @exception ResourceException If this resource got a fatal error.
     */
    protected Reply getFileResource(Request request)
  throws ProtocolException, ResourceException
    {
  Reply reply = handle(request) ;
  return reply != null
      ? reply
      : super.getFileResource(request) ;
    }
View Full Code Here

     * @exception ResourceException If this resource got a fatal error.
     */
    public Reply post(Request request)
  throws ProtocolException, ResourceException
    {
  Reply reply = handle(request) ;
  return reply != null
      ? reply
      : super.post(request) ;
    }
View Full Code Here

  if(segments == null) {
      parseFirstTime() ;
      if( (segments = getSegments()) == null )
    return null ; // Last resort: fall back to superclass
  }
  Reply reply = null ;
  try {
      // Obtain a command registry
      updateRegistry() ;

      vars = (Dictionary)
    request.getState(STATE_VARIABLES) ;

      // Initialize the registry-dependent variables:
      vars = commReg.initVariables(this,request,vars) ;

      // Add our "very global" variables
      vars.put("secure",getValue(ATTR_SECURE,Boolean.TRUE)) ;
      vars.put("maxDepth",getValue(ATTR_MAX_DEPTH,new Integer(10))) ;
      vars.put("depth",depth) ;
      vars.put("registry",commReg) ;

      // Prepare the initial reply
      // (which represents the unparsed parts of the document)
      // and a prototype reply for segments that return null.
      reply = createDefaultReply(request,HTTP.OK) ;
      Reply defSegReply = createDefaultReply(request,HTTP.OK) ;

      int unpSize = getUnparsedSize() ;
      if(unpSize == -1)
    reply.setHeaderValue(Reply.H_CONTENT_LENGTH,null) ;
      else
    reply.setContentLength(unpSize) ;
      defSegReply.setHeaderValue(Reply.H_CONTENT_LENGTH,null) ;

      long ims = request.getIfModifiedSince() ;
      long cmt = fresource.getFileStamp()
      // used to be getLastModified()
      // should be something better
      // than either
      if(SSIFrame.debug)
    System.out.println("@@@@ IMS: "+cmt+" vs "+ims) ;
      if(ims != -1 && cmt != -1 && cmt <= ims) {
    reply.setStatus(HTTP.NOT_MODIFIED) ;
    defSegReply.setStatus(HTTP.NOT_MODIFIED) ;
      } else if(ims != -1) {
    if(SSIFrame.debug)
        System.out.println("@@@@ Removed NOT MODIFIED") ;
      }

     
      if(cmt != -1)
    defSegReply.setLastModified(cmt) ;
     
      // For each segment:
      //   . obtain a reply,
      //   . merge its headers with the global reply's headers,
      Reply[] partReps = new Reply[segments.length] ;
View Full Code Here

  long a = super.getLastModified() ;
  return a - a % 1000 ;
    }
    public final Reply createDefaultReply(Request request, int status)
    {
  Reply reply = super.createDefaultReply(request,status) ;
  reply.setHeaderValue(Reply.H_LAST_MODIFIED,null) ;
  reply.setKeepConnection(false);
  return reply ;
    }
View Full Code Here

    }
      }
  }
     
  // Every possible scheme has failed for this request, emit an error
  Reply e = null;
  if ( request.isProxy() ) {
      e = request.makeReply(HTTP.PROXY_AUTH_REQUIRED);
      e.setProxyAuthenticate(challenge);
  } else {
      e = request.makeReply(HTTP.UNAUTHORIZED);
      e.setWWWAuthenticate (challenge);
  }
  HtmlGenerator g = new HtmlGenerator("Unauthorized");
  g.append ("<h1>Unauthorized access</h1>"
      + "<p>You are denied access to this resource.");
  e.setStream(g);
  throw new HTTPException (e);
    }
View Full Code Here

    {
  if (fresource == null)
      throw new ResourceException("this frame is not attached to a "+
              "FileResource. ("+
              resource.getIdentifier()+")");
  Reply reply = null;
  fresource.checkContent();
  updateCachedHeaders();
  // hack, if ;text/html is there,
  // it will be added at first place of the accept
  String param = null;
  String sfile = request.getURL().getFile();
  int pos = sfile.indexOf(';');
  if (pos != -1) {
      param = (String) request.getState("type");
  }
  if (param != null) {
      HttpAccept acc[] = request.getAccept();
      HttpAccept newacc[] = null;
      if (acc != null) {
    newacc = new HttpAccept[acc.length+1];
    System.arraycopy(acc, 0, newacc, 1, acc.length);
      } else {
    newacc = new HttpAccept[1];
      }
      try {
    newacc[0] = HttpFactory.makeAccept(new MimeType(param), 1.1);
    request.setAccept(newacc);
      } catch (MimeTypeFormatException ex) {
    // not a valid mime type... maybe something else, do not care
      }
  }
  boolean commentOnly = negotiate(request);
  HttpEntityTag etag = null;
  if (commentOnly)
      etag = getComETag();
  else
      etag = getETag();
  // Check validators:
  int cim = checkIfMatch(request, etag);
  if ((cim == COND_FAILED) || (cim == COND_WEAK)) {
      reply = request.makeReply(HTTP.PRECONDITION_FAILED);
      reply.setContent("Pre-conditions failed.");
      reply.setContentMD5(null);
      return reply;
  }
  if ( checkIfUnmodifiedSince(request) == COND_FAILED ) {
      reply = request.makeReply(HTTP.PRECONDITION_FAILED);
      reply.setContent("Pre-conditions failed.");
      reply.setContentMD5(null);
      return reply;
  }
  if (checkValidators(request, etag) == COND_FAILED) {
      reply = createDefaultReply(request, HTTP.NOT_MODIFIED);
      reply.setETag(etag);
      reply.setContentMD5(null);
      return reply;
 
  if (! fresource.getFile().exists()) {
      return deleteMe(request);
  } else {
      if (commentOnly) {
    reply = createCommentReply(request);
    reply.setStream((InputStream) null);
      } else {
    reply = createDefaultReply(request, HTTP.OK);
    reply.setVary(vary);
      }
      if (request.hasState(STATE_CONTENT_LOCATION))
    reply.setContentLocation(getURL(request).toExternalForm());
      return reply;
  }
    }
View Full Code Here

    {
  if (fresource == null)
      throw new ResourceException("this frame is not attached to a "+
          "FileResource. ("+
          resource.getIdentifier()+")");
  Reply reply = null;
  File file = fresource.getFile() ;
  fresource.checkContent();
  updateCachedHeaders();
  String param = null;
  String sfile = request.getURL().getFile();
  int pos = sfile.indexOf(';');
  if (pos != -1) {
      param = (String) request.getState("type");
  }
  if (param != null) {
      HttpAccept acc[] = request.getAccept();
      HttpAccept newacc[] = null;
      if (acc != null) {
    newacc = new HttpAccept[acc.length+1];
    System.arraycopy(acc, 0, newacc, 1, acc.length);
      } else {
    newacc = new HttpAccept[1];
      }
      try {
    newacc[0] = HttpFactory.makeAccept(new MimeType(param), 1.1);
    request.setAccept(newacc);
      } catch (MimeTypeFormatException ex) {
    // not a valid mime type... maybe something else, do not care
      }
  }
  boolean commentOnly = negotiate(request);
  HttpEntityTag etag = null;
  if (commentOnly)
      etag = getComETag();
  else
      etag = getETag();
  // Check validators:
  int cim = checkIfMatch(request, etag);
  if ((cim == COND_FAILED) || (cim == COND_WEAK)) {
      reply = request.makeReply(HTTP.PRECONDITION_FAILED);
      reply.setContent("Pre-conditions failed.");
      reply.setContentMD5(null);
      return reply;
  }
  if ( checkIfUnmodifiedSince(request) == COND_FAILED ) {
      reply = request.makeReply(HTTP.PRECONDITION_FAILED);
      reply.setContent("Pre-conditions failed.");
      reply.setContentMD5(null);
      return reply;
  }
  if ( checkValidators(request, etag) == COND_FAILED ) {
      reply = createDefaultReply(request, HTTP.NOT_MODIFIED);
      reply.setETag(etag);
      reply.setContentMD5(null);
      return reply;
  }
  // Does this file really exists, if so send it back
  if ( file.exists() ) {
      if (commentOnly) {
    reply = createCommentReply(request);
      } else {
    reply = createFileReply(request);
      }
      if (request.hasState(STATE_CONTENT_LOCATION))
    reply.setContentLocation(getURL(request).toExternalForm());
      return reply;
  } else {
      return deleteMe(request);
  }
    }
View Full Code Here

  {
      String log = null;
      try {
    log = getCvsManager().log(name);
      } catch (CvsException cvs_ex) {
    Reply error = request.makeReply(HTTP.INTERNAL_SERVER_ERROR) ;
    HtmlGenerator g = getHtmlGenerator("CVS log command failed") ;
    g.append ("<p>The CVS <strong>log</strong> command failed "
        + " on " + name
        + " with the following error message: "
        + "<em>" + cvs_ex.getMessage() + "</em>"
        + "<hr> from class: " + this.getClass().getName()) ;
    error.setStream (g) ;
    throw new HTTPException (error) ;
      } catch (InvalidResourceException ex) {
    Reply error = request.makeReply(HTTP.INTERNAL_SERVER_ERROR) ;
    HtmlGenerator g = getHtmlGenerator("CVS log command failed") ;
    g.append ("<p>The CVS <strong>log</strong> command failed "
        + " on " + name
        + " with the following error message: "
        + "<em>" + ex.getMessage() + "</em>"
        + "<hr> from class: " + this.getClass().getName()) ;
    error.setStream (g) ;
    throw new HTTPException (error) ;
      } finally {
    rr_cvsframe.unlock();
      }
      Reply reply = request.makeReply(HTTP.OK) ;
      reply.setContentType (MimeType.TEXT_HTML) ;
      reply.setStream (parseLog(log)) ;
      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.