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;
  // check if we must use our parent perform call
  String methods[] = getMethods();
 
  if (methods != null) {
      String reqmeth = request.getMethod();
      boolean affected = false;
      for (int i=0; i< methods.length; i++) {
    if (reqmeth.equals(methods[i])) {
        affected = true;
        break;
    }
      }
      if (!affected) {
    return super.perform(request);
      }
  }
  httpd    server = (httpd) getServer();
  String     host = request.getHost();
  // why this??? commenting while investigating
        //request.setReferer(getURLPath());
  try {
      String target = null;
      String pathinfo = (String) request.getState(PATH_INFO);
      if (pathinfo != null)
    target = getTarget()+pathinfo;
      else
    target = getTarget();

      if (request.hasQueryString())
    target += "?"+request.getQueryString();

      // save the original URL
      request.setState(Request.ORIG_URL_STATE, request.getURL());
      // and mark content location
      request.setState(STATE_CONTENT_LOCATION, "true");
      if (host == null) {
    request.setURL(new URL(server.getURL(), target));
      } else {
//    URL newurl = new URL (new URL(server.getURL().getProtocol(),
//                host,
//                server.getURL().getFile()),
//              target);
    URL newurl = new URL(request.getURL(), target);
    String newhost = null;
    if (newurl.getPort() != -1 &&
        (newurl.getProtocol().equalsIgnoreCase("http") &&
      (newurl.getPort() != 80))) {
        newhost = newurl.getHost() + ":" + newurl.getPort();
    } else {
        newhost = newurl.getHost();
    }
    request.setURL(newurl);
    request.setHost(newhost);
      }
  } 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


     * <strong>false</strong> if it should be continued by the caller.
     */
    public boolean lookup(LookupState ls, LookupResult lr)
  throws ProtocolException
    {
  Request request = (Request) ls.getRequest();
  if ((request != null) && (request.getMethod().equals("PUT"))) {
      if ( ls.hasMoreComponents() ) {
    String name = null;
    try {
        name = ls.peekNextComponent();
        File dir = new File(getDirectory(), name);
View Full Code Here

     */
    public boolean lookupOther(LookupState ls, LookupResult lr)
  throws org.w3c.tools.resources.ProtocolException
    {
  // Get the full URL from the request:
  Request request = (Request) ls.getRequest();
  URL     url     = request.getURL();

  if ( ls.isInternal() )
      return super.lookupOther(ls, lr);
  if ( mirrors != null ) {
      request.setProxy(true);
      lr.setTarget(this.getResource().getResourceReference());
      return true;
  }
  // Emit a not found:
  Reply error = request.makeReply(HTTP.NOT_FOUND);
  if (request.getMethod().equals("GET"))
      error.setContent("Target resource not found.");
  lr.setTarget(null);
  lr.setReply(error);
  return true;
    }
View Full Code Here

     * We wait until the outgoigFilter.
     * @param request The request that is about to be processsed.
     */

    public ReplyInterface ingoingFilter(RequestInterface req) {
  Request request = (Request) req;
  String expect = request.getExpect();
  if (expect != null) {
      if (expect.startsWith("100")) { // expect 100?
    Client client = request.getClient();
    if (client != null) {
        try {
      client.sendContinue();
        } catch (java.io.IOException ex) {
        }
    }
      }
  }
  //register request, but this must be confirmed.
  if ( request.getMethod().equals("DELETE") &&
       (request.getTargetResource() != null) ) {
      boolean done = false;
      synchronized (this) {
    ResourceReference rr = resolvePutListResource();
    PutListResource   l  = null;
    if (rr != null) {
View Full Code Here

     */

    public ReplyInterface outgoingFilter(RequestInterface req,
           ReplyInterface rep)
    {
        Request request = (Request) req;
  Reply   reply   = (Reply) rep;
  int     status  = PutListResource.FILE_UC;
  boolean put     = false;
  // Is this a successfull PUT request ?
  if (((put = request.getMethod().equals("PUT")) ||
       request.getMethod().equals("DELETE"))
      && ((reply.getStatus()/100) == 2)) {
      // Cool, keep track of the modified file:
      ResourceReference rr   = null;
      PutListResource   l    = null;
      boolean           done = false;
      synchronized (this) {
    rr = resolvePutListResource();
    if (rr != null) {
        try {
      l = (PutListResource) rr.lock();
      if ( l != null ) {
          if (put)
        status = l.registerRequest(request);
          else
        status = l.confirmDelete(request);
          done = true;
      }
        } catch (InvalidResourceException ex) {
      done = false;
        } finally {
      rr.unlock();
        }
    }
      }
      // Make sure we did something:
      if ( !done ) {
    httpd s = (httpd) getServer();
    s.errlog(getClass().getName()+
       ": unable to resolve companion PutListResource at "+
       getPutListURL());
      }
     
      switch (status) {
      case PutListResource.FILE_UC:
      case PutListResource.FILE_PB:
      case PutListResource.FILE_DEL:
    return null;
      case PutListResource.FILE_MG:
    Reply   msg = request.makeReply(HTTP.CONFLICT);
    HtmlGenerator g = getHtmlGenerator("Warning");
    g.append ("<H1>Warning</H1> The file on publish space has "+
        "been modified directly but attempting to merge "+
        "has succeed.<p>"+
        "You should update the file before editing "+
        "it again.");
    msg.setStream(g);
    return msg;
      case PutListResource.FILE_CF:
    Reply error = request.makeReply(HTTP.CONFLICT);
    HtmlGenerator gerr = getHtmlGenerator("Warning");
    gerr.append ("<H1>Warning</H1> The file on publish space has "+
           "been modified directly and attempting to merge"+
           " has failed.<p>"+
           "Ask your system administrator.");
View Full Code Here

     * an ACCES FORBIDDEN Reply.
     * @param request The request that is about to be processsed.
     */

    public ReplyInterface ingoingFilter(RequestInterface req) {
  Request request = (Request) req;
  if(request.getMethod().equals("PUT")) {
      try {
    MimeType req_mt = request.getContentType();
    if (req_mt.match(MimeType.TEXT) == MimeType.NO_MATCH)
        return null;
      } catch (NullPointerException ex) {
    // no Content-Type sent! check anyway
      }

      InputStream in = null;
      try {
    in = request.getInputStream();
    if ( in == null ) {
        return null;
    }
      } catch (IOException ex) {
    return null;
      }
      // verify that the target resource is putable
      ResourceReference rr = request.getTargetResource();
      if (rr != null) {
    try {
        FramedResource target = (FramedResource) rr.lock();
        HTTPFrame frame = null;
        try {
      frame = (HTTPFrame) target.getFrame(
         Class.forName("org.w3c.jigsaw.frames.HTTPFrame"));
        } catch (ClassNotFoundException cex) {
      cex.printStackTrace();
      //big big problem ...
        }
        if (frame == null) // can't be putable
      return null;
        // now we can verify if the target resource is putable
        if (! frame.getPutableFlag()) {
      return null;
        }
        // and that the PUT can happen (taken from putFileResource
        int cim = frame.checkIfMatch(request);
        if ((cim == HTTPFrame.COND_FAILED)
      || (cim == HTTPFrame.COND_WEAK)
      || (frame.checkIfNoneMatch(request) ==
          HTTPFrame.COND_FAILED)
      || (frame.checkIfModifiedSince(request) ==
          HTTPFrame.COND_FAILED)
      || (frame.checkIfUnmodifiedSince(request) ==
          HTTPFrame.COND_FAILED)) {
      Reply r = request.makeReply(HTTP.PRECONDITION_FAILED);
      r.setContent("Pre-condition failed.");
      return r;
        }
    } catch (InvalidResourceException ex) {
        ex.printStackTrace();
        // problem ...
    } finally {
        rr.unlock();
    }
      }
      String expect = request.getExpect();
      if (expect != null) {
    if (expect.startsWith("100")) { // expect 100?
        Client client = request.getClient();
        if (client != null) {
      try {
          client.sendContinue();
      } catch (java.io.IOException ex) {
          return null;
      }
        }
    }
      }
      String found = searchForbiddenStrings(in);
      if (found != null) {
    Reply error = request.makeReply(HTTP.FORBIDDEN);
    error.setReason("the string \""+found+"\" is forbidden.");
    error.setContent ("<p>the string \""+found+
          "\" is forbidden.</p><br> click "+
          "<A HREF=\""+getRedirectURL()+"\">here</A>"+
          " for explaination.");
View Full Code Here

     */
    public ReplyInterface perform(RequestInterface req)
  throws ProtocolException, ResourceException
    {
  if (putlist == null) {
      Request request = (Request) req;
      Reply error = request.makeReply(HTTP.INTERNAL_SERVER_ERROR) ;
      error.setContent("The PutListFrame must be associated "+
           "with a PutListResource only!!");
      throw new HTTPException(error);
  }
  return super.perform(req);
View Full Code Here

    public ReplyInterface ingoingFilter(RequestInterface req) {
  ReplyInterface rep = super.ingoingFilter(req);
  if (rep != null)
      return rep;

  Request request = (Request) req;
  if(request.getMethod().equals("PUT")) {
      try {
    MimeType req_mt = request.getContentType();
    if (req_mt.match(MimeType.TEXT) == MimeType.NO_MATCH)
        return null;
      } catch (NullPointerException ex) {
    // no Content-Type sent! check anyway
      }
      InputStream in = null;
      try {
    in = request.getInputStream();
    if ( in == null ) {
        return null;
    }
      } catch (IOException ex) {
    return null;
      }
      // verify that the target resource is putable
      ResourceReference rr = request.getTargetResource();
      if (rr != null) {
    try {
        FramedResource target = (FramedResource) rr.lock();
        HTTPFrame frame = null;
        try {
      frame = (HTTPFrame) target.getFrame(
         Class.forName("org.w3c.jigsaw.frames.HTTPFrame"));
        } catch (ClassNotFoundException cex) {
      cex.printStackTrace();
      //big big problem ...
        }
        if (frame == null) // can't be putable
      return null;
        // now we can verify if the target resource is putable
        if (! frame.getPutableFlag()) {
      return null;
        }
        // and that the PUT can happen (taken from putFileResource
        int cim = frame.checkIfMatch(request);
        if ((cim == HTTPFrame.COND_FAILED)
      || (cim == HTTPFrame.COND_WEAK)
      || (frame.checkIfNoneMatch(request) ==
          HTTPFrame.COND_FAILED)
      || (frame.checkIfModifiedSince(request) ==
          HTTPFrame.COND_FAILED)
      || (frame.checkIfUnmodifiedSince(request) ==
          HTTPFrame.COND_FAILED)) {
      Reply r = request.makeReply(HTTP.PRECONDITION_FAILED);
      r.setContent("Pre-condition failed.");
      return r;
        }
    } catch (InvalidResourceException ex) {
        ex.printStackTrace();
        // problem ...
    } finally {
        rr.unlock();
    }
      }
      String expect = request.getExpect();
      if (expect != null) {
    if (expect.equalsIgnoreCase(HTTP.HTTP_100_CONTINUE)) {
        Client client = request.getClient();
        if (client != null) {
      try {
          client.sendContinue();
      } catch (java.io.IOException ex) {
          return null;
      }
        }
    }
      }
      String found = searchForbiddenStrings(in);
      if (found != null) {
    Reply error = request.makeReply(HTTP.FORBIDDEN);
    error.setReason("the string \""+found+"\" is forbidden.");
    error.setContent ("<p>the string \""+found+
          "\" is forbidden.</p><br> click "+
          "<A HREF=\""+getRedirectURL()+"\">here</A>"+
          " for explaination.");
View Full Code Here

  return getBoolean(ATTR_VALID_STRICT, false);
    }
 

    public ReplyInterface ingoingFilter(RequestInterface req) {
  Request request = (Request) req;

  if(request.getMethod().equals("PUT")) {
      try {
    MimeType req_mt = request.getContentType();
    if (xhtml_mt == null){
        xhtml_mt = new MimeType("application","xhtml+xml");
    }
    if (req_mt.match(xhtml_mt) != MimeType.NO_MATCH) {
        isXhtml = true ;
    } else {
        isXhtml = false ;
    }
    if (req_mt.match(MimeType.TEXT_HTML) == MimeType.NO_MATCH
        && isXhtml == false){
        return null;
    }
    if (req_mt.hasParameter("charset")){
        String charset = req_mt.getParameterValue("charset");
        if (charset.equalsIgnoreCase("iso-2022-jp")){
      tidyCharEncoding = Configuration.ISO2022 ;
        }
        if (charset.equalsIgnoreCase("us-ascii")){
      tidyCharEncoding = Configuration.ASCII ;
        }
        if (charset.equalsIgnoreCase("iso-8859-1")){
      tidyCharEncoding = Configuration.LATIN1 ;
        }
        if (charset.equalsIgnoreCase("utf8")){
      tidyCharEncoding = Configuration.UTF8 ;
        }
        if (charset.equalsIgnoreCase("macroman")){
      tidyCharEncoding = Configuration.MACROMAN ;
        }
    }
      } catch (NullPointerException ex) {
    // no Content-Type sent! check anyway
      }
      InputStream in = null;
      try {
    in = request.getInputStream();
    if ( in == null ) {
        return null;
    }
      } catch (IOException ex) {
    return null;
      }

      // verify that the target resource is putable
      ResourceReference rr = request.getTargetResource();
      if (rr != null) {
    try {
        FramedResource target = (FramedResource) rr.lock();
        HTTPFrame frame = null;
        try {
      frame = (HTTPFrame) target.getFrame(
          Class.forName("org.w3c.jigsaw.frames.HTTPFrame"));
        } catch (ClassNotFoundException cex) {
      cex.printStackTrace();
        //big big problem ...
        }
        if (frame == null) // can't be putable
      return null;
        // now we can verify if the target resource is putable
        if (! frame.getPutableFlag()) {
      return null;
        }
        // and that the PUT can happen (taken from putFileResource
        int cim = frame.checkIfMatch(request);
        if ((cim == HTTPFrame.COND_FAILED)
      || (cim == HTTPFrame.COND_WEAK)
      || (frame.checkIfNoneMatch(request) ==
          HTTPFrame.COND_FAILED)
      || (frame.checkIfModifiedSince(request) ==
          HTTPFrame.COND_FAILED)
      || (frame.checkIfUnmodifiedSince(request) ==
          HTTPFrame.COND_FAILED)) {
     
      Reply r = request.makeReply(HTTP.PRECONDITION_FAILED);
      r.setContent("Pre-condition failed.");
      return r;
        }
    } catch (InvalidResourceException ex) {
        ex.printStackTrace();
        // problem ...
    } finally {
        rr.unlock();
    }
      }

      String expect = request.getExpect();
      if (expect != null) {
    if (expect.startsWith("100")) { // expect 100?
        Client client = request.getClient();
        if (client != null) {
      try {
          client.sendContinue();
      } catch (java.io.IOException ex) {
          return null;
      }
        }
    }
      }

      try {
    ByteArrayOutputStream bout = new ByteArrayOutputStream();
    Tidy tidy = new Tidy();
    if (isXhtml) {
        tidy.setXHTML(true);
    } else {
        tidy.setXHTML(false);
    }
    tidy.setErrout(new PrintWriter(System.err));
    in.mark(65536000);


//    System.out.println(tidyCharEncoding);
    tidy.setCharEncoding(tidyCharEncoding);
/*    tidy.setIndentContent(false);
    tidy.setIndentAttributes(false);
    tidy.setSmartIndent(false);
*/
    tidy.parse(in,bout);

    if (tidy.getParseErrors() != 0){
        //System.out.println("too many errors, bailing out") ;
        in.reset();
    }

    // Need to call tidy in other thread, because of Piped streams.
   
    byte[] bufout = bout.toByteArray();
 
    ByteArrayInputStream tmpbin = new ByteArrayInputStream(bufout);

    request.setContentLength(bufout.length);
    if (bufout.length != 0 ) {
        // tidy is happy let's apply transformation
        request.setStream(tmpbin);
        // add state to set warnings on the way back
        request.setState("tidy", "ok");
    } else {
        if (getValidStrict() == true ){
      // tidy failed and a file MUST validate -> refuse put
      Reply reply = request.makeReply(HTTP.FORBIDDEN) ;
      HtmlGenerator g = new HtmlGenerator("Not Acceptable");
      g.append("<p>This HTML code does not validate. Valid"
         + "code is required here</p>"
         + "<p>Warnings: " + tidy.getParseWarnings()
           + " Errors: "+tidy.getParseErrors()+"</p>");
View Full Code Here

     */
    public ReplyInterface outgoingFilter(RequestInterface req,
           ReplyInterface rep)
  throws ProtocolException
    {
  Request request = (Request) req;
  Reply   reply   = (Reply) rep;
 
  if (request.hasState("tidy")) {
      if (hw == null) {
    hw =
      HttpFactory.makeWarning(HttpWarning.TRANSFORMATION_APPLIED);
    hw.setAgent("Jigsaw");
    hw.setText("Body modified for HTML conformance using JTidy");
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.