Package org.w3c.jigsaw.http

Examples of org.w3c.jigsaw.http.Request


  JigsawHttpServletResponse jres = (JigsawHttpServletResponse) response;
  JigsawHttpServletRequest  jreq = (JigsawHttpServletRequest) request;
  if (jres.isStreamObtained())
      throw new IllegalStateException("Can't Forward! OutputStream or "+
           "Writer has allready been obtained.");
  Request req  = (Request)jreq.getRequest().getClone();
  String  host = req.getHost();
  try {
      //update URL...
      if (host == null) {
    req.setURL(new URL(server.getURL(), urlpath));
      } else {
    req.setURL(new URL(server.getURL().getProtocol(), host,
           urlpath));
      }
  } catch (MalformedURLException ex) {
      //should not occurs
  }
 
  //do nothing more with this reply
  jres.getReply().setStatus(HTTP.DONE);

  Reply reply = null;
  try {
      reply = (Reply) server.perform(req);
  } catch (ResourceException ex) {
      reply = req.makeReply(HTTP.INTERNAL_SERVER_ERROR);
      reply.setContent(ex.getMessage());
  } catch (ProtocolException pex) {
      if (pex.hasReply())
    reply = (Reply) pex.getReply();
      else {
    reply = req.makeReply(HTTP.INTERNAL_SERVER_ERROR);
    reply.setContent(pex.getMessage());
      }
  }
  //copy reply into response...
  if (reply.hasStream()) {
View Full Code Here


  throws ServletException, IOException
    {
  JigsawHttpServletResponse jres = (JigsawHttpServletResponse) response;
  JigsawHttpServletRequest  jreq = (JigsawHttpServletRequest) request;

  Request req  = (Request)jreq.getRequest().getClone();
   String  host = req.getHost();

  try {
      //update URL...
      if (host == null)
    req.setURL(new URL(server.getURL(), urlpath));
      else
    req.setURL(new URL(server.getURL().getProtocol(), host,
           urlpath));
  } catch (MalformedURLException ex) {
      //should not occurs
  }

  jres.flushStream(false);

  Reply reply = null;
  try {
      //req.setState(CONTEXT_PATH_P, jreq.getContextPath());
      req.setState(REQUEST_URI_P, jreq.getRequestURI());
      req.setState(SERVLET_PATH_P, jreq.getServletPath());
      req.setState(PATH_INFO_P, jreq.getPathInfo());
      req.setState(QUERY_STRING_P, jreq.getQueryString());
      req.setState(JigsawHttpServletResponse.INCLUDED, Boolean.TRUE);
      reply = (Reply) server.perform(req);
  } catch (ResourceException ex) {
      reply = req.makeReply(HTTP.INTERNAL_SERVER_ERROR);
      reply.setContent(ex.getMessage());
  } catch (ProtocolException pex) {
      if (pex.hasReply())
    reply = (Reply) pex.getReply();
      else {
    reply = req.makeReply(HTTP.INTERNAL_SERVER_ERROR);
    reply.setContent(pex.getMessage());
      }
  }

  if (reply.hasStream()) {
View Full Code Here

     */
    public boolean lookup(LookupState ls, LookupResult lr)
  throws ProtocolException
    {
  if ( ls.isDirectory() ) { // we are not a directory, bail out
      Request req = (Request)ls.getRequest();
      String locstate = (String)req.getState(STATE_CONTENT_LOCATION);
      if (locstate == null) {
    lr.setTarget(null);
    return true;
      }
  }
  ResourceFrame frames[] = getFrames();
  if (frames != null) {
      for (int i = 0 ; i < frames.length ; i++) {
    if (frames[i] == null) {
        continue;
    }
    if (frames[i].lookup(ls,lr)) {
        return true;
    }
      }
  }
  if ( ls.hasMoreComponents() ) {
      // We are not a container resource, and we don't have children:
      lr.setTarget(null);
      return false;
  } else {
      //we are done! try to find the negotiated one...
      RequestInterface reqi = ls.getRequest();
      ResourceReference selected;
      Request request = (Request) reqi;
      // Run content negotiation now:
      // The PUT is special, we negotiate with ETag (if present) or
      // using the metainformation about the PUT entity.
      String method = request.getMethod ();
      try {
    if (method.equals("PUT")) {
        selected = negotiatePut(request);
    } else {
        selected = negotiate(request);
    }
      } catch (ResourceException ex) {
    // the failure will be processed in perform
    return false;
      }
      if (selected != null) {
    try {
        FramedResource resource =
      (FramedResource) selected.unsafeLock();
        resource.lookup(ls, lr);
    } catch (InvalidResourceException ex) {
        // the failure will be processed in perform
    } finally {
        selected.unlock();
    }
      }
      request.setState(STATE_NEG, selected);
      // fake now, we handle the process to have a two-level processing
      // just to add the Vary: header
      lr.setTarget(getResourceReference());
      return true;
  }
View Full Code Here

      return repi;

  if (! checkRequest(req))
      return null;

  Request request = (Request) req;
  ResourceReference selected;
  // get the right resources
  if (request.hasState(STATE_NEG)) {
      selected = (ResourceReference) request.getState(STATE_NEG);
  } else {
      String method = request.getMethod ();
      if (method.equals("PUT")) {
    selected = negotiatePut(request);
      } else {
    selected = negotiate(request);
      }
  }

  // This should never happen: either the negotiation succeed, or the
  // negotiate method should return an error.
  if ( selected == null ) {
      Reply error = request.makeReply(HTTP.INTERNAL_SERVER_ERROR) ;
      error.setContent("Error negotiating among resource's variants.");
      throw new HTTPException(error) ;
  }

  try {
      FramedResource resource = (FramedResource) selected.unsafeLock();
      Reply reply = (Reply)resource.perform(request) ;
      reply.setHeaderValue(reply.H_VARY, getVary());
      HTTPFrame itsframe =
    (HTTPFrame) resource.unsafeGetFrame(httpFrameClass);
      if (itsframe != null) {
    reply.setContentLocation(
          itsframe.getURL(request).toExternalForm()) ;
    return reply;
      }
      Reply error = request.makeReply(HTTP.INTERNAL_SERVER_ERROR) ;
      error.setContent("Error negotiating : "+
           "selected resource has no HTTPFrame");
      throw new HTTPException(error) ;
  } catch (InvalidResourceException ex) {
      Reply error = request.makeReply(HTTP.INTERNAL_SERVER_ERROR) ;
      error.setContent("Error negotiating : Invalid selected resource");
      throw new HTTPException(error) ;
  } finally {
      selected.unlock();
  }
View Full Code Here

    lr.setTarget(null);
    return true;
      } else if ( status == CVS.DIR_NCO ) {
    // Checkout directory, and relocate:
    getCvsManager().updateDirectory(name);
    Request request = (Request)ls.getRequest();
    if ( request != null ) {
        Reply relocate = request.makeReply(HTTP.FOUND);
        try {
      URL myloc    = getURL(request);
      URL location = new URL(myloc, name+"/CVS");
      relocate.setLocation(location);
      lr.setReply(relocate);
View Full Code Here

          getInt(ATTR_PUTSIZE, -1) + " bytes long</P>");
  return er;
    }

    public ReplyInterface ingoingFilter(RequestInterface req) {
  Request request = (Request) req;
  if(request.getMethod().equals("PUT")) {
      if(getBoolean(ATTR_STRICT, true) && !request.hasContentLength())
    return notifyFailure(request, true);
      if(request.getContentLength() > getInt(ATTR_PUTSIZE, -1))
    return notifyFailure(request, false);
  }
  return null;
    }
View Full Code Here

     */

    public boolean lookup(LookupState ls, LookupResult lr)
        throws ProtocolException
    {
  Request request  =
    (Request) (ls.hasRequest() ? ls.getRequest() : null);
  if ((request == null) || ls.isInternal())
      // Internal lookups always allowed
      return false;
  // Check the request, and authenticate if needed:
  String method    = request.getMethod() ;
  String methods[] = getMethods() ;
  if ( methods == null ) {
      authenticate(request) ;
      return false;
  } else {
View Full Code Here

      }
        } else {
      new_c = challenge;
        }
        new_c.setAuthParameter("realm", name);
        Request req = dap.getRequest();
        String opaque = null;
        try {
      MessageDigest md =
          MessageDigest.getInstance(filter.getAlgorithm());
      md.update(req.getMethod().getBytes());
      md.update(nonce.getBytes());
      byte b[] = md.digest();
      opaque = StringUtils.toHexString(b);
        } catch (NoSuchAlgorithmException algex) {
      opaque="op"+nonce;
View Full Code Here

  ResourceReference rr = null;
  FramedResource template = null;
 
  //try with content type in request.
  if (req instanceof Request) {
      Request request = (Request) req;
      MimeType type = request.getContentType();
      if (type != null)
    rr = loadContentType(type.toString());
      if (rr != null) {
    String s_dir = "directory".intern();
    String s_ide = "identifier".intern();
    String s_fil = "filename".intern();
    String s_con = "context".intern();
    if ( defs == null )
        defs = new Hashtable(5) ;
    if ( defs.get(s_dir) == null )
        defs.put(s_dir, directory) ;
    if ( defs.get(s_ide) == null )
        defs.put(s_ide, name) ;
    if ( defs.get(s_con) == null )
        defs.put(s_con, getContext());
    //read attribute from request
    try {
        template = (FramedResource) rr.lock();
        // Create, initialize and return the new resouce
        try {
      FramedResource resource = null;
      resource = (FramedResource) template.getClone(defs);
      // Now update HTTPFrame from request
      String contentLanguage[] =
          request.getContentLanguage();
      String contentEncoding[] =
          request.getContentEncoding();
      //get the HTTPFrame.
      Class httpFrameClass =
          Class.forName("org.w3c.jigsaw.frames.HTTPFrame");
      HTTPFrame hframe = (HTTPFrame)
          resource.getFrame(httpFrameClass);
View Full Code Here

    // should never happen
  }
    }

    public ReplyInterface ingoingFilter(RequestInterface request) {
  Request req = (Request) request;
  String  requrl = req.getURL().toExternalForm();
  PatternMatcher matcher = new Perl5Matcher();
  Pattern pat[] = getPatterns();
  if (pat == null || pat.length == 0)
      return null;
  String sub[] = getSubstitutions();
  String result = null;
  for (int i=0; i< pat.length; i++) {
      if (matcher.matches(requrl, pat[i])) {
    Substitution s = new Perl5Substitution(sub[i]);
    result = Util.substitute(matcher, pat[i], s, requrl,
           Util.SUBSTITUTE_ALL);
    break;
      }
  }
  if (result != null) {
      URL loc = null;
      try {
    loc = new URL(req.getURL(), result);
      } catch (MalformedURLException ex) {
    return null;
      }
      Reply reply = req.makeReply(HTTP.FOUND);
      reply.setLocation(loc);
      HtmlGenerator g = new HtmlGenerator("Moved");
      g.append("<P>This resource has moved, click  if your browser"
         + " doesn't support automatic redirection<BR>"+
         "<A HREF=\""+loc.toExternalForm()+"\">"+
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.