Package org.w3c.jigsaw.http

Examples of org.w3c.jigsaw.http.Reply


    {
  // check if it is the right resource below!
  if (!(fresource instanceof ImageFileResource)) {
      return super.putFileResource(request);
  }
  Reply reply = null;
  int status = HTTP.OK;
  fresource.checkContent();
  updateCachedHeaders();
  // Is this resource writable ?
  if ( ! getPutableFlag() ) {
      Reply error = request.makeReply(HTTP.NOT_ALLOWED) ;
      error.setContent("Method PUT not allowed.") ;
      throw new HTTPException (error) ;
  }
  HttpEntityTag etag = getComETag();
  // no IfMatch, or no matching ETag, maybe a PUT on the image
  int cim = checkIfMatch(request, etag);
  if ((request.getIfMatch() == null) ||
      (cim == COND_FAILED) || (cim == COND_WEAK)) {
      return super.putFileResource(request);
  }
  // check all the others validator

  // Check remaining validators (checking if-none-match is lame
  // as we already require the If-Match
  if ((checkIfNoneMatch(request, etag) == COND_FAILED)
      || (checkIfModifiedSince(request) == COND_FAILED)
      || (checkIfUnmodifiedSince(request) == COND_FAILED)) {
      Reply r = request.makeReply(HTTP.PRECONDITION_FAILED);
      r.setContent("Pre-condition failed.");
      return r;
  }
  // Check the request:
  InputStream in = null;
  try {
      in = request.getInputStream();
      if ( in == null ) {
    Reply error = request.makeReply(HTTP.BAD_REQUEST) ;
    error.setContent ("<p>Request doesn't have a valid content.");
    throw new HTTPException (error) ;
      }
  } catch (IOException ex) {
      throw new ClientException(request.getClient(), ex);
  }
  // We do not support (for the time being) put with ranges:
  if ( request.hasContentRange() ) {
      Reply error = request.makeReply(HTTP.BAD_REQUEST);
      error.setContent("partial PUT not supported.");
      throw new HTTPException(error);
  }
  // Check that if some type is provided it doesn't conflict:
  if ( request.hasContentType() ) {
      MimeType rtype = request.getContentType() ;
      MimeType type  = getCommentType() ;
      if ( type == null ) {
    setValue (ATTR_CONTENT_TYPE, rtype) ;
      } else if ( rtype.match (type) < 0 ) {
    if (debug) {
        System.out.println("No match between: ["+
               rtype.toString()+"] and ["+
               type.toString()+"]");
    }
    Reply error = request.makeReply(HTTP.UNSUPPORTED_MEDIA_TYPE) ;
    error.setContent ("<p>Invalid content type: "+type.toString());
    throw new HTTPException (error) ;
      }
  }
  ImageFileResource ifresource = (ImageFileResource) fresource;
  // Write the body back to the file:
View Full Code Here


  {
      String diff = null ;
      try {
    diff = getCvsManager().diff(name);
      } catch (CvsException cvs_ex) {
    Reply error = request.makeReply(HTTP.INTERNAL_SERVER_ERROR) ;
    HtmlGenerator g = getHtmlGenerator("CVS diff command failed") ;
    g.append ("<p>The CVS <strong>diff</strong> command failed "
        + " on " + name
        + " with the following error message: "
        + "<em>" + cvs_ex.getMessage() + "</em>"
        + "<hr> from class: " + this.getClass().getName()) ;
    error.setStream (g) ;
    throw new HTTPException (error) ;
      } catch (InvalidResourceException ex) {
    Reply error = request.makeReply(HTTP.INTERNAL_SERVER_ERROR) ;
    HtmlGenerator g = getHtmlGenerator("CVS diff command failed") ;
    g.append ("<p>The CVS <strong>diff</strong> command failed "
        + " on " + name
        + " with the following error message: "
        + "<em>" + ex.getMessage() + "</em>"
        + "<hr> from class: " + this.getClass().getName()) ;
    error.setStream (g) ;
    throw new HTTPException (error) ;
      } finally {
    rr_cvsframe.unlock();
      }
      // if there are no differences, generate a dummy report
      Reply         reply = request.makeReply(HTTP.OK) ;
      if((diff == null) || (diff.length() == 0)) {
    HtmlGenerator g = getHtmlGenerator("CVS diff command results");
    g.append("<P>No differences between " + name
       + " and the repository</P>");
    reply.setStream(g);
      } else {
    HtmlGenerator g = getHtmlGenerator("Diff result");
    g.append ("<center>");
    g.append (" [ <a href=\"../\">Up to directory</A> ] &middot;");
    g.append (" [ <a href=\""+getCvsURL(),
        "\">Back to CVS</A> ] \n");
    g.append ("</center>");
    g.append ("<hr noshade width=\"80%\"><p>");
    g.append ("<span class=\"title\"> CVS diff of ",
        name,"</span>\n");
    g.append ("<pre>",parseDiff(diff),"</pre>\n");
    g.append ("<p><hr noshade width=\"80%\">");
    g.append ("<center>");
    g.append (" [ <a href=\"../\">Up to directory</A> ] &middot;");
    g.append (" [ <a href=\""+getCvsURL(),
        "\">Back to CVS</A> ] \n");
    g.append ("</center>");
    reply.setStream(g);
      }
      return reply ;
  }
View Full Code Here

      g.append ("<input type=\"submit\" name=\"submit\" " +
          "value=\" Save Comment \">" );
      g.append ("</td></tr>");
      g.append ("</table></center></form>\n");
      g.append ("<hr noshade width=\"80%\">");
      Reply reply = request.makeReply(HTTP.OK) ;
      reply.setStream(g);
      return reply;
  }
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 d.getValue("editlog") ;
  }
View Full Code Here

  public Reply get (Request request)
      throws ProtocolException
  {
      if ( ! request.hasState("query") ) {
    Reply error = request.makeReply(HTTP.INTERNAL_SERVER_ERROR);
    error.setContent("Invalid query field.");
    throw new HTTPException (error) ;
      }
      String cmd = request.getQueryString() ;
      if ( cmd.equalsIgnoreCase("log") ) {
    return dolog(request) ;
      } else if ( cmd.equalsIgnoreCase ("diff")) {
    return dodiff(request) ;
      } else {
    String rev = getRevisionToEdit(request);
    if (rev != null)
        return doEditRev(request, rev);
    else {
        Reply error =
      request.makeReply(HTTP.INTERNAL_SERVER_ERROR) ;
        error.setContent ("Unknown command: "+cmd) ;
        throw new HTTPException(error) ;
    }
      }
  }
View Full Code Here

  {
      String revision = data.getValue("revision");
      String comment  = data.getValue("comment");
     
      if (revision == null) {
    Reply error = request.makeReply(HTTP.INTERNAL_SERVER_ERROR) ;
    error.setContent("No revision selected !");
    throw new HTTPException (error) ;
      } else if (comment == null) {
    Reply error = request.makeReply(HTTP.BAD_REQUEST) ;
    error.setContent("Empty comment not allowed.");
    throw new HTTPException (error) ;
      }
      try {
    String command[] = new String[2];
    command[0] = "-m"+revision+":\""+comment+"\"";
    command[1] = name;
    getCvsManager().admin(command);
      } catch (CvsException ex) {
    Reply error = request.makeReply(HTTP.INTERNAL_SERVER_ERROR) ;
    HtmlGenerator g =
        getHtmlGenerator("CVS admin command failed") ;
    g.append ("<p>The CVS <strong>admin</strong> command failed "
        + " on " + name
        + " with the following error message: "
        + "<em>" + ex.getMessage() + "</em>");
    error.setStream (g) ;
    throw new HTTPException (error) ;
      } catch (InvalidResourceException inv_ex) {
    Reply error = request.makeReply(HTTP.INTERNAL_SERVER_ERROR);
    error.setContent("CvsFrame invalid");
    return error;
      }
      //well done
      return dolog(request);
  }
View Full Code Here

  g.append("<li>File : "+fres.getFile());
  g.append("<li>Last Modified Time : ",
     new Date(fres.getLastModified()).toString(),
     "</ul>");
  // now emit the reply
  Reply reply = createDefaultReply(request, HTTP.OK) ;
  reply.setStream(g) ;
  return reply ;
    }
View Full Code Here

  g.append("<li>Directory : "+dres.getDirectory());
  g.append("<li>Last Modified Time : ",
     new Date(dres.getLastModified()).toString(),
     "</ul>");
  // now emit the reply
  Reply reply = createDefaultReply(request, HTTP.OK) ;
  reply.setStream(g) ;
  return reply ;
    }
View Full Code Here

  g.append("<ul><li>Identifier : ",res.getIdentifier());
  g.append("<li>Last Modified Time : ",
     new Date(res.getLastModified()).toString(),
     "</ul>");
  // now emit the reply
  Reply reply = createDefaultReply(request, HTTP.OK) ;
  reply.setStream(g) ;
  return reply ;

    }
View Full Code Here

    protected static Reply error(Request request,
         int status,
         String title,
         String msg)
    {
  Reply error = request.makeReply(status);
  HtmlGenerator g = CvsFrame.getHtmlGenerator(title);
  g.append("<span class=\"title\">",title,"</span>\n");
  g.append("<p>",msg);
  error.setStream(g);
  return error;
    }
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.