Package org.w3c.jigsaw.http

Examples of org.w3c.jigsaw.http.Request


  throws ProtocolException, ResourceException
    {
  Reply        reply  = (Reply) performFrames(req);
  if (reply != null)
      return reply;
  Request request = (Request) req;
  httpd    server = (httpd) getServer();
  String     host = request.getHost();
  request.setState(Request.ORIG_URL_STATE, request.getURL());
  request.setState(JigsawRequestDispatcher.REQUEST_URI_P,
       getRequestURI(request));
  request.setState(JigsawRequestDispatcher.QUERY_STRING_P,
       request.getQueryString());
  request.setState(JigsawRequestDispatcher.SERVLET_PATH_P, getURLPath());
  try {
      String target = null;
      if (request.hasQueryString())
    target = getTarget()+"?"+request.getQueryString();
      else
    target = getTarget();

      if (host == null) {
    request.setURL(new URL(server.getURL(), target));
      } else {
    int ic = host.indexOf(':');
    // we will take care of '[' later (ipv6 address)
    if ( ic < 0 ) {
        request.setURL(new URL(server.getURL().getProtocol(),
             host, target));
    } else {
        request.setURL(new URL(server.getURL().getProtocol(),
             host.substring(0, ic),
             Integer.parseInt(
                 host.substring(ic+1)),
             target));
    }
      }
      request.setInternal(true);
  } catch (MalformedURLException ex) {
      Reply error = request.makeReply(HTTP.INTERNAL_SERVER_ERROR);
      error.setContent("<html><head><title>Server Error</title>"+
           "</head><body><h1>Server misconfigured</h1>"+
           "<p>The resource <b>"+getIdentifier()+"</b>"+
           "has an invalid target attribute : <p><b>"+
           getTarget()+"</b></body></html>");     
View Full Code Here


  // Get the extra path information:
  String extraPath = ls.getRemainingPath(true);
  if ((extraPath == null) || extraPath.equals(""))
      extraPath = "/";
  // Keep this path info into the request, if possible:
  Request request = (Request) ls.getRequest();
  if ( request != null ) {
      if (request.getState(JigsawRequestDispatcher.PATH_INFO_P) == null)
    request.setState(JigsawRequestDispatcher.PATH_INFO_P,
         extraPath);
  }
  lr.setTarget(resource.getResourceReference());
  return super.lookupResource(ls, lr);
    }
View Full Code Here

    public synchronized
  ReplyInterface ingoingFilter (RequestInterface req)
  throws HTTPException
    {
  Request request = (Request) req;
  int limit   = getLimit() ;
  int timeout = getTimeout() ;

  if ( limit < 0 )
      return null;
  while ( count >= limit ) {
      if ( timeout > 0 ) {
    try {
        wait((long) timeout, 0) ;
    } catch (InterruptedException ex) {
    }
    if ( count >= limit ) {
        String msg = "Simultaneous number of access to this page "
      + "is limited to " + limit + " you was not able to "
      + "get in." ;
        Reply error = request.makeReply(HTTP.SERVICE_UNAVAILABLE);
        error.setContent (msg) ;
        throw new HTTPException (error) ;
    }
      } else {
    try {
View Full Code Here

             params);
        //perform the request
        try {
      FramedResource wrapper =
          (FramedResource)r_wrapper.lock();
      Request req = (Request)request.getClone();
      req.setState(JigsawHttpServletResponse.INCLUDED,
             Boolean.TRUE);
      return (Reply) wrapper.perform(req);
        } catch (ProtocolException ex) {
      ex.printStackTrace();
      // return default reply
View Full Code Here

     */
    public ReplyInterface outgoingFilter(RequestInterface req,
           ReplyInterface rep)
  throws ProtocolException
    {
  Request request = (Request) req;
  Reply   reply   = (Reply) rep;
  int count = 1;
  HttpCookieList cookies = request.getCookie();
  // Display and get available count:
  if ( cookies != null ) {
      HttpCookie c = cookies.getCookie(NAME);
      if ( c != null ) {
    System.out.println("cookie-count="+c.getValue());
View Full Code Here

     */

    public synchronized
  ReplyInterface ingoingFilter (RequestInterface req)
    {
  Request request = (Request) req;
  int limit = getLimit();

  if (request.getURL().toExternalForm().length() > limit) {
      Reply error = request.makeReply(HTTP.REQUEST_URI_TOO_LONG);
      HtmlGenerator g = new HtmlGenerator("Request URI Too Long");
      g.append ("Your request should have an URI of less than " +
          limit + " bytes");
      error.setStream(g);
      return error;
View Full Code Here

  // Get the extra path information:
  String extraPath = ls.getRemainingPath(true);
  if ((extraPath == null) || extraPath.equals(""))
      extraPath = "/";
  // Keep this path info into the request, if possible:
  Request request = (Request) ls.getRequest();
  if ( request != null )
      request.setState(STATE_EXTRA_PATH, extraPath);
  lr.setTarget(getResource().getResourceReference());
  return super.lookup(ls, lr);
    }
View Full Code Here

  // Try to lookup on the host header:
  ResourceReference vrroot = null;
  ContainerResource root = null;
 
  root = (ContainerResource)getResource();
  Request r = (Request)ls.getRequest();
  if ( r != null ) {
      String host = r.getURL().getHost();
      String protocol = r.getURL().getProtocol();
      if (host == null) {
    host = r.getHost();
    if ( host != null ) {
        // must strip the port if different from 80!
        if (host.endsWith(":80") && protocol.equals("http")) {
      host = host.substring(0, host.lastIndexOf(":80"));
        }
        // and the same for https (443)
        if (host.endsWith(":443") && protocol.equals("https")) {
      host = host.substring(0, host.lastIndexOf(":443"));
        }
    }
      } else {
    int port = r.getURL().getPort();
    if (port != -1) {
        if ( (protocol.equals("http") && (port != 80)) ||
       (protocol.equals("https") && (port != 443)) ) {
      host = host + ":" + port;
        }
View Full Code Here

      return repi;

  if (! checkRequest(req))
      return null;

  Request request = (Request) req;
  PipedInputStream pis = null;

  if (wrapper == null) {
      Reply reply = request.makeReply(HTTP.INTERNAL_SERVER_ERROR);
      reply.setContent("Servlet Wrapper Frame not configured properly: "+
           "must be attached to a ServletWrapper.");
      throw new HTTPException(reply);
  }

  try {
      wrapper.checkServlet();
  } catch (ClassNotFoundException ex) {
      Reply reply = request.makeReply(HTTP.INTERNAL_SERVER_ERROR);
      reply.setContent("The server was unable to find the "+
           "servlet class : "+ex.getMessage());
      if ( wrapper.debug )
    ex.printStackTrace();
      throw new HTTPException(reply);
  } catch (ServletException ex) {
      Reply reply = request.makeReply(HTTP.INTERNAL_SERVER_ERROR);
      reply.setContent("The server was unable to initialize the "+
           "servlet : "+ex.getMessage());
      if ( wrapper.debug )
    ex.printStackTrace();
      throw new HTTPException(reply);
  }

  // Check that the servlet has been initialized properly:
  if ( ! wrapper.isInited() ) {
      Reply reply = request.makeReply(HTTP.INTERNAL_SERVER_ERROR);
      reply.setContent("Servlet not configured properly");
      throw new HTTPException(reply);
  }
  // Dispatch the request:
  Reply reply = createDefaultReply(request, HTTP.OK);
  reply.setContentType(MimeType.TEXT_HTML);
  try {
      if (request.hasState(JigsawHttpServletResponse.INCLUDED)) {
    wrapper.service(request, reply);
      } else {
    pis = new PipedInputStream();
    request.setState(JigsawHttpServletResponse.STREAM, pis);
    PipedOutputStream pos = new PipedOutputStream(pis);
    reply.setState(JigsawHttpServletResponse.STREAM, pos);
    reply.setStream(pis);
    Object o = new Object();
    reply.setState(JigsawHttpServletResponse.MONITOR, o);
    // wait until the reply is constructed by the processing thread
    ServerInterface server = getServer();
    if (server instanceof httpd) {
        synchronized (o) {
      wrapper.service(request, reply);
      o.wait((long)((httpd)server).getRequestTimeOut());
        }
        Object strm;
        strm = reply.getState(JigsawHttpServletResponse.STREAM);
        if (strm != null) {
      // it is a timeout
      try {
          pis.close();
          pos.close();
      } catch (IOException ex) {};
      if (strm instanceof PipedOutputStream) {
          ServletWrapper.ServletRunner r;
          r = (ServletWrapper.ServletRunner)
                 reply.getState(ServletWrapper.RUNNER);
          if (r != null) {
        r.signalTimeout();
          }
          throw new ServletException("Timed out");
      }
        }
    } else {
        synchronized (o) {
      wrapper.service(request, reply);
      o.wait();
        }
    }
      }
  } catch (UnavailableException uex) {
       reply = request.makeReply(HTTP.SERVICE_UNAVAILABLE);
       if (uex.isPermanent()) {
     reply.setContent("<h2>The servlet is permanently "+
          "unavailable :</h2>"+
          "Details: <b>"+uex.getMessage()+"</b>");
       } else {
     int delay = uex.getUnavailableSeconds();
     if (delay > 0) {
         reply.setRetryAfter(delay);
         reply.setContent("<h2>The servlet is temporarily "+
              "unavailable :</h2>"+
              "Delay : "+delay+
              " seconds<br><br>Details: <b>"+
              uex.getMessage()+"</b>");
     } else {
         reply.setContent("<h2>The servlet is temporarily "+
              "unavailable :</h2>"+
              "Details: <b>"+uex.getMessage()+"</b>");
     }
       }
       if (pis != null) {
     try {
         pis.close();
     } catch (IOException ioex) {}
       }
  } catch (Exception ex) {
      if ( wrapper.debug )
    ex.printStackTrace();
      reply = request.makeReply(HTTP.INTERNAL_SERVER_ERROR);
      reply.setContent("Servlet has thrown exception:" + ex.toString());
      if (pis != null) {
    try {
        pis.close();
    } catch (IOException ioex) {}
View Full Code Here

  // Get the extra path information:
  String extraPath = ls.getRemainingPath(true);
  if ((extraPath == null) || extraPath.equals(""))
      extraPath = "/";
  // Keep this path info into the request, if possible:
  Request request = (Request) ls.getRequest();
  if ( request != null ) {
      if (request.getState(JigsawRequestDispatcher.PATH_INFO_P) == null)
    request.setState(JigsawRequestDispatcher.PATH_INFO_P,
         extraPath);
  }
  lr.setTarget(resource.getResourceReference());
  return super.lookupOther(ls, lr);
    }
View Full Code Here

TOP

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

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.