001: // ProxyExtFrame.java
002: // $Id: ProxyExtFrame.java,v 1.4 2000/08/16 21:37:43 ylafon Exp $
003: // (c) COPYRIGHT MIT and INRIA, 1998.
004: // Please first read the full copyright statement in file COPYRIGHT.html
005:
006: package org.w3c.jigsaw.proxy;
007:
008: import org.w3c.jigsaw.html.HtmlGenerator;
009: import org.w3c.jigsaw.http.Request;
010: import org.w3c.jigsaw.http.Reply;
011: import org.w3c.tools.resources.ProtocolException;
012: import org.w3c.tools.resources.ReplyInterface;
013: import org.w3c.tools.resources.RequestInterface;
014: import org.w3c.www.http.HTTP;
015: import org.w3c.www.http.HttpExtList;
016: import org.w3c.www.http.HttpExt;
017:
018: /**
019: * @version $Revision: 1.4 $
020: * @author Benoît Mahé (bmahe@w3.org)
021: */
022: public class ProxyExtFrame extends ProxyFrame {
023:
024: /**
025: * Perform the given proxied request.
026: * @param request The request to perform.
027: * @return A Reply instance.
028: * @exception org.w3c.tools.resources.ProtocolException if processing
029: * the request failed.
030: * @exception org.w3c.tools.resources.ResourceException if the resource
031: * got a fatal error.
032: */
033:
034: public ReplyInterface perform(RequestInterface ri)
035: throws org.w3c.tools.resources.ProtocolException,
036: org.w3c.tools.resources.ResourceException {
037: Request request = (Request) ri;
038: Reply reply = null;
039: Reply extReply = null;
040: HttpExtList cman = request.getHttpCManExtDecl();
041: HttpExtList copt = request.getHttpCOptExtDecl();
042: HttpExtList man = request.getHttpManExtDecl();
043:
044: if ((cman != null) || (copt != null)) {
045: extReply = applyExtensions(request, cman, copt);
046: if (extReply != null)
047: return extReply;
048: if ((cman != null) && (man == null)) {
049: //strip the M-
050: String method = request.getMethod();
051: if (method.startsWith("M-"))
052: request.setMethod(method.substring(2));
053: }
054: }
055: //Send the request, and get the reply
056: reply = (Reply) super .perform(ri);
057:
058: if ((cman != null) || (copt != null))
059: return applyExtensions(reply, cman, copt);
060: return reply;
061: }
062:
063: /**
064: * Apply extension to the request.
065: * @param request the incomming request
066: * @param cman The Mandatory hop-by-hop extension declaration list
067: * @param cman The optionnal hop-by-hop extension declaration list
068: * @return a Reply instance or null if processing the request must continue
069: * @exception org.w3c.tools.resources.ProtocolException if processing
070: * the request failed.
071: */
072: public Reply applyExtensions(Request request, HttpExtList cman,
073: HttpExtList copt)
074: throws org.w3c.tools.resources.ProtocolException {
075: if (cman != null) {
076: Reply error = request.makeReply(HTTP.NOT_EXTENDED);
077: HtmlGenerator content = new HtmlGenerator("Error");
078: content.append("<h1>Mandatory extension(s) not supported:",
079: "</h1><p>\n");
080: content.append("<ul>\n");
081: HttpExt exts[] = cman.getHttpExts();
082: for (int i = 0; i < exts.length; i++)
083: content.append("<li> " + exts[i].getName() + "\n");
084: content.append("</ul>\n");
085: error.setStream(content);
086: return error;
087: }
088: return null;
089: }
090:
091: /**
092: * Apply extension to the reply.
093: * @param request the reply
094: * @param cman The Mandatory hop-by-hop extension declaration list
095: * @param cman The optionnal hop-by-hop extension declaration list
096: * @return a Reply instance.
097: * @exception org.w3c.tools.resources.ProtocolException if processing
098: * the request failed.
099: */
100: public Reply applyExtensions(Reply reply, HttpExtList cman,
101: HttpExtList copt)
102: throws org.w3c.tools.resources.ProtocolException {
103: return reply;
104: }
105:
106: }
|