Package org.w3c.jigsaw.http

Examples of org.w3c.jigsaw.http.Reply


    public Reply execute(SSIFrame ssiframe,
       Request request,
       ArrayDictionary parameters,
       Dictionary variables)
    {
  Reply reply =
      ssiframe.createCommandReply(request,HTTP.OK) ;
 
  Integer count = (Integer)
    request.getState(org.w3c.jigsaw.filters.CounterFilter.STATE_COUNT) ;
  if(count == null)
      reply.setContent("[unknown]") ;
  else reply.setContent(count.toString()) ;

  // FIXME, NOTE:
  // the handling of weak validation should be configurable
  handleSimpleIMS(request,reply) ;
  return reply ;
View Full Code Here


    }
    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 {
        wait() ;
View Full Code Here

    }
      }
  }
  // We are NOT doing notMod hack here (tricky and useless ?)
  //Reply reply = ssiframe.createCommandReply(request, HTTP.OK);
  Reply reply = request.makeReply(HTTP.OK);
  reply.setContent("");
  return 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());
    try {
        count = Integer.parseInt(c.getValue())+1;
    } catch (Exception ex) {
    }
      }
  }
  String strcount = Integer.toString(count);
  // Set cookie with next value:
  FramedResource frame = (FramedResource) getResource();
  if (frame instanceof HTTPFrame) {
      HTTPFrame target = (HTTPFrame) frame;
      HttpSetCookieList setcookies = HttpFactory.makeSetCookieList(null);
      HttpSetCookie     setcookie  = setcookies.addSetCookie(NAME,
                   strcount);
      setcookie.setMaxAge(getCookieMaxAge());
      URL url = target.getURL(request);
      setcookie.setPath(url.getFile());
      setcookie.setDomain(url.getHost());
      reply.setSetCookie(setcookies);
      reply.addNoCache("Set-Cookie");
  }
  return null;
    }
View Full Code Here

    {
  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;
  }
  return null;
    }
View Full Code Here

    {
  // first, take care of error stream
  (new ProcessErrorReader(process)).start();
  // No header script don't deserve attention:
  if ( checkNoheaderFlag() ) {
      Reply reply = request.makeReply(HTTP.NOHEADER) ;
      reply.setStream (process.getInputStream()) ;
      return reply ;
  }
  // Check for debugging mode:
  if ( checkCgiDebug() ) {
      Reply reply = request.makeReply(HTTP.OK);
      reply.setContentType(MimeType.TEXT_PLAIN);
      reply.setStream(process.getInputStream());
      return reply;
  }
  // We MUST parse at least one header:
  MimeParser p = new MimeParser(process.getInputStream(),
              new CGIHeaderHolderFactory());
  Reply           reply  = null ;
  try {
      CGIHeaderHolder h = (CGIHeaderHolder) p.parse();
      // Check for a status code:
      String svalue   = h.getStatus();
      String location = h.getLocation();
      if ( svalue != null ) {
    int status = -1;
    try {
                    String _st = svalue.trim();
        int _space = _st.indexOf(' ');
                    if (_space != -1) {
      _st = _st.substring(0, _space);
        }
        status = Integer.parseInt(_st);
    } catch (Exception ex) {
        // This script has emited an invalid status line:
        String msg = ("Emited an invalid status line ["+
          svalue + "].");
        getServer().errlog(this, msg);
        // Throw an HTTPException:
        reply = request.makeReply(HTTP.INTERNAL_SERVER_ERROR);
        reply.setContent("CGI script emited invalid status.");
        throw new HTTPException(reply);
    }
    // we will use the default for this frame, but remove
    // the length calculated from the script size.
    reply = createDefaultReply(request, status);
    reply.setContentLength(-1);
      } else {
    // No status code available, any location header ?
    if (location != null) {
        reply = request.makeReply(HTTP.FOUND);
    } else {
        reply = createDefaultReply(request, HTTP.OK);
        reply.setContentLength(-1);
    }
      }
      // Set up the location header if needed:
      if ( location != null ) {
    try {
        reply.setLocation(new URL(getURL(request), location));
    } catch (MalformedURLException ex) {
        // This should really not happen:
        getServer().errlog(this, "unable to create location url "+
               location+
               " in base "+getURL(request));
    }
      }
      // And then, the remaining headers:
      Enumeration e = h.enumerateHeaders();
      if ( e != null ) {
    while ( e.hasMoreElements() ) {
        String hname = (String) e.nextElement();
        reply.setValue(hname, (String) h.getValue(hname));
    }
      }
      reply.setStream(p.getInputStream()) ;
  } catch (IOException ex) {
      ex.printStackTrace();
  } catch (MimeParserException ex) {
      // This script has generated invalid output:
      String msg = (getURL(request)
        +": emited invalid output ["+
        ex.getMessage() +"]");
      getServer().errlog(this, msg);
      // Throw an HTTPException:
      Reply error = request.makeReply(HTTP.INTERNAL_SERVER_ERROR) ;
      error.setContent("CGI error: unable to parse script headers.") ;
      throw new HTTPException (error) ;
  }
  if (reply != null) {
      reply.setDynamic(true);
  }
View Full Code Here

    {
  // Check the command attribute first:
  String      query     = null;
  String      command[] = getCommand() ;
  if ( command == null ) {
      Reply error = request.makeReply(HTTP.INTERNAL_SERVER_ERROR) ;
      error.setContent("CgiResource mis-configured: it doesn't have a "
           + " command attribute");
      throw new HTTPException(error);
  }
  // Ok:
  Vector      env       = new Vector(32) ;
View Full Code Here

       Process       process = null ;
       try {
     process = makeCgiCommand (request) ;
       } catch (IOException e) {
     e.printStackTrace();
     Reply error = request.makeReply(HTTP.NOT_FOUND) ;
     error.setContent("The resource's script wasn't found.") ;
     throw new HTTPException (error) ;
       }
       return handleCGIOutput (process, request) ;
   }
View Full Code Here

      String msg = ("The process "+
        getCommand()[0] +" couldn't be executed ["+
        ex.getMessage() + "]");
      getServer().errlog(this, msg);
      // Throw an internal server error:
      Reply error = request.makeReply(HTTP.INTERNAL_SERVER_ERROR) ;
      error.setContent("CGI script is misconfigured.");
      throw new HTTPException (error) ;
  }
  // Now feed the process:
  try {
      // Send the 100 status code:
      Client client = request.getClient();
      if ( client != null )
    client.sendContinue();
      InputStream in = request.getInputStream();
      if ( in == null ) {
    // There was no input to that CCI, close process stream
    process.getOutputStream().close();
      } else {
    // Some input to feed the process with:
    (new ProcessFeeder(process, in)).start();
      }
  } catch (IOException ex) {
      // This is most probably a bad request:
      Reply error = request.makeReply(HTTP.BAD_REQUEST);
      error.setContent("The request didn't have a valid input.");
      throw new HTTPException(error);
  }
  return handleCGIOutput(process, request);
    }
View Full Code Here

     * @param request The request to make a reply for.
     * @return An instance of Reply, suited to answer this request.
     */

    public Reply createDefaultReply(Request request, int status) {
  Reply reply = super.createDefaultReply(request, status);
  reply.setLastModified( -1 );
  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.