Package org.w3c.jigsaw.http

Examples of org.w3c.jigsaw.http.Reply


        //not exactly what we want but, it ~works
        backup.delete();
        resfile.renameTo(backup);
          }
          //perform the put
          Reply r = super.putFileResource(request);
          int rstatus = r.getStatus();
          // if OK
          if ((rstatus / 100 ) == 2 ) {
        // Do a CVS commit with user name
        commit(request);
          }
          //well done, remove the backup file now
          backup.delete();
          // update the file attrs
          getFileResource().checkContent();
          //return the reply.
          if ((rstatus / 100 ) == 2 ) {
        return createDefaultReply(request,
                r.getStatus());
          } else {
        return r;
          }
      } else {
          // fail
          String msg =
        "File is not up to date, "+
        "please update the file manually "+
        "or use the CVS form.";
          return error( request,
            HTTP.CONFLICT,
            "Error",
            msg );
      }
        } catch (UpToDateCheckFailedException utd_ex) {
      resfile.delete();
      //restore the backup file
      backup.renameTo(resfile);
      //send error
      String msg =  utd_ex.getFilename()+
          " is not up to date, "+
          "please update the file manually "+
          "or use the CVS form.";
      return error( request,
              HTTP.CONFLICT,
              "Error",
              msg );
        } catch (CvsException ex) {
      backup.delete();
      // fail too
      String msg = "CvsException : "+ex.getMessage();
      getServer().errlog(getIdentifier()+" : "
             +ex.getMessage());
      return error( request,
              HTTP.SERVICE_UNAVAILABLE,
              "Error",
              msg );
        }
    } else {
        // Write the file to web space
        Reply r = super.putFileResource(request);
        try {
      //  Do a CVS add with user name
      add(request);
      //  Do a CVS commit with user name
      commit(request);
      getFileResource().checkContent();
        } catch (CvsAddException ex) {
      String msg = "Cvs add failed : <br>'"+
          ex.getMessage()+
          "'<br>please update the file manually "+
          "or use the CVS form";
      return error( request,
              HTTP.SERVICE_UNAVAILABLE,
              "Error",
              msg );
        } catch (CvsException ex) {
      ex.printStackTrace();
      String msg = "Problem during cvs process : "+
          ex.getMessage();
      getServer().errlog(getIdentifier()+" : "+msg);
      return error( request,
              HTTP.INTERNAL_SERVER_ERROR,
              "Internal Server Error",
              msg );
        }
        if (r.getStatus() == HTTP.CREATED) {
      Reply reply = request.makeReply(r.getStatus());
      reply.setContent("<P>Resource succesfully created");
      if (request.hasState(STATE_CONTENT_LOCATION))
          reply.setContentLocation(
        getURL(request).toExternalForm());
      r = createDefaultReply(request, HTTP.CREATED);
      reply.setETag(r.getETag());
      return reply;
        }
        return createDefaultReply(request, r.getStatus());
    }
      } else {
View Full Code Here


      //delete the FileResource
      fresource.delete();
  } catch (MultipleLockException ex) {
      String msg = "Can't delete resource: "+resource.getIdentifier()+
    " is locked. Try again later.";
      Reply error = error( request,
         HTTP.FORBIDDEN,
         "Error",
         msg );
      throw new HTTPException(error);
  }
View Full Code Here

    private static final boolean debug = false;

    CvsDirectory cvs = null ;

    protected Reply badAction(Request request, String action) {
  Reply error = request.makeReply(HTTP.BAD_REQUEST) ;
  HtmlGenerator g = CvsFrame.getHtmlGenerator ("Bad CVS command") ;
  g.append ("<center>");
  g.append ("[ <A HREF=\"./CVS\">Back</A> ]<hr noshade width=\"80%\">");
  g.append ("<p>Your command "
      + "<strong>"+ action + "</strong>"
      + " wasn't undesrtood.<p>");
  g.append ("<hr noshade width=\"80%\"></center>");
  error.setStream (g) ;
  return error;
    }
View Full Code Here

           FilterInterface[] filters,
           int fidx)
  throws ProtocolException
    {
  Request request = (Request) req;
  Reply   reply   = (Reply) rep;
  if(!isTagged(request))
      return null ;
 
  if(isCachable(reply)) {
      switch(reply.getStatus()) {
      case HTTP.OK:
      case HTTP.NO_CONTENT:
      case HTTP.MULTIPLE_CHOICE:
      case HTTP.MOVED_PERMANENTLY:
    try {
        SimpleCacheEntry ce = cache.store(request,reply) ;
        if(ce != null) {
      // storing a reply changes it, so this must be done:
      Reply fRep = applyOut(request,reply,filters,fidx) ;
      if(fRep != null) return fRep ;
      else return reply ;
        }
    } catch(SimpleCacheException ex) {
        cache.remove(request) ;
View Full Code Here

      InputStream in    = new StringBufferInputStream(query) ;
      URLDecoder  d     = new URLDecoder (in, getOverrideFlag()) ;
      try {
    d.parse () ;
      } catch (URLDecoderException e) {
    Reply error = request.makeReply(HTTP.BAD_REQUEST) ;
    error.setContent("Invalid request: "+
         "unable to decode form data.");
    throw new HTTPException (error) ;
      } catch (IOException e) {
    Reply error = request.makeReply(HTTP.BAD_REQUEST) ;
    error.setContent("Invalid request: unable to read form data.");
    throw new HTTPException (error) ;
      }
      return handle (request, d) ;
  }
  Reply reply = createDefaultReply(request, HTTP.OK);
  PageCompileOutputStream out = new PageCompileOutputStream();
  try {
      get(request, reply, out);
  } catch (IOException ex) {
      Reply error = request.makeReply(HTTP.INTERNAL_SERVER_ERROR);
      PageCompileOutputStream err = new PageCompileOutputStream();
      PrintWriter writer = new PrintWriter(err);
      writer.print("The generated frame at\n\n"+
       request.getURL()+"\n\n"+
       "reported this exception : \n\n"+ex.getMessage()+
       "\n\nStack trace : \n\n");
      ex.printStackTrace(writer);
      writer.flush();
      writer.close();
      error.setStream(err.getInputStream());
      error.setContentLength(err.size());
      error.setContentType(MimeType.TEXT_PLAIN);
      return error;
  }
  reply.setStream(out.getInputStream());
  reply.setContentLength(out.size());
  return reply;
View Full Code Here

     */
    public Reply test_get(Request request)
  throws ProtocolException, ResourceException
    {
  CCPPRequest ccpp  = getCCPPRequest(request);
  Reply       reply = super.get(request);

  ProfileRef refs[] = ccpp.getProfileReferences();
  for (int i = 0 ; i < refs.length ; i++) {
      try {
    if (refs[i].isURI()) {
View Full Code Here

     * CCPP HEAD method
     */
    public Reply head(Request request)
  throws ProtocolException, ResourceException
    {
  Reply reply = null;
  reply = get(request) ;
  reply.setStream((InputStream) null);
  return reply;
    }
View Full Code Here

       Reply reply,
       URLDecoder data,
       PageCompileOutputStream out)
  throws ProtocolException, IOException
    {
  Reply error = request.makeReply(HTTP.NOT_ALLOWED) ;
  if ( allowed != null )
      error.setHeaderValue(Reply.H_ALLOW, allowed);
  error.setContent("Method POST not allowed on this resource.") ;
  throw new HTTPException (error) ;
    }
View Full Code Here

    public Reply handle (Request request, URLDecoder data)
  throws ProtocolException
    {
  PageCompileOutputStream out = new PageCompileOutputStream();
  Reply reply = createDefaultReply(request, HTTP.OK);

  try {
      post(request, reply, data, out);
  } catch (IOException ex) {
      Reply error = request.makeReply(HTTP.INTERNAL_SERVER_ERROR);
      PageCompileOutputStream err = new PageCompileOutputStream();
      PrintWriter writer = new PrintWriter(err);
      writer.print("The generated frame at\n\n"+
       request.getURL()+"\n\n"+
       "reported this exception : \n\n"+ex.getMessage()+
       "\n\nStack trace : \n\n");
      ex.printStackTrace(writer);
      writer.flush();
      writer.close();
      error.setStream(err.getInputStream());
      error.setContentLength(err.size());
      error.setContentType(MimeType.TEXT_PLAIN);
      return error;
  }
  reply.setStream(out.getInputStream());
  reply.setContentLength(out.size());
  return reply;
View Full Code Here

  String reqheader = (String) values[2] ;
  boolean here = values[3] != null ;

  boolean notMod = false ;

  Reply reply = ssiframe.createCommandReply(request,HTTP.OK) ;
  String content = null ;
 
  if(var != null) {
      if(var.equals("DOCUMENT_URI")) {
    URL theUrl = here
        ? request.getURL()
        : request.getOriginal().getURL() ;
    if(theUrl != null)
        content = theUrl.toString() ;
      } else {
    Dictionary ssiVars = (Dictionary)
        variables.get(here ? "ssiVars" : "topSsiVars") ;
   
    if(ssiVars == null) return null ;
   
    if(var.equals("DATE_LOCAL")) {
        content =
      TimeFormatter
      .format(new Date(),
        (String) variables.get("datefmt")) ;
    } else if(var.equals("DATE_GMT")) {
       
        // FIXME: won't do formatting
        content = new Date().toGMTString() ;
       
    } else if(var.equals("LAST_MODIFIED")) {
       
        content = TimeFormatter
      .format((Date) ssiVars.get("X_LAST_MODIFIED"),
        (String) variables.get("datefmt")) ;
       
    } else {
       
        content = (String) ssiVars.get(var) ;
        if (content == null)
      content = "";
    }
      }
      long ims = request.getIfModifiedSince() ;
      if(ims != -1) {
    if( var == null ) notMod = true ;
    else {
        Boolean result = (Boolean) modFlags.get(var) ;
        notMod =
      (result == null) ? true : ! result.booleanValue() ;
    }
      }
  } else if(reqstate != null) {
      Object state = here
    ? request.getState(reqstate)
    : request.getOriginal().getState(reqstate) ;
   
      if(state != null)
    content = state.toString() ;
  } else if(reqheader != null) {
      reqheader = reqheader.toLowerCase() ;
      HeaderValue hvalue =  here
    ? request.getHeaderValue(reqheader)
    : request.getOriginal().getHeaderValue(reqheader) ;

      if(hvalue != null)
    content = hvalue.toExternalForm() ;
  } else return null ;
 
  if(content != null) {
      reply.setContent(content) ;
  } else return null ;

  if(notMod) {
      reply.setStatus(HTTP.NOT_MODIFIED) ;
      reply.setLastModified(request.getIfModifiedSince()) ;
  }

  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.