Annotation of java/classes/org/w3c/jigsaw/servlet/ServletWrapperFrame.java, revision 1.5
1.1 bmahe 1: // ServletWrapperFrame.java
1.5 ! ylafon 2: // $Id: ServletWrapperFrame.java,v 1.4 1998/02/17 13:43:52 bmahe Exp $
1.1 bmahe 3: // (c) COPYRIGHT MIT and INRIA, 1996.
4: // Please first read the full copyright statement in file COPYRIGHT.html
5:
6: package org.w3c.jigsaw.servlet;
7:
8: import java.io.* ;
9: import java.util.*;
10:
11: import javax.servlet.*;
12:
13: import org.w3c.tools.resources.store.*;
14: import org.w3c.util.*;
15: import org.w3c.www.mime.*;
16: import org.w3c.www.http.*;
17: import org.w3c.jigsaw.http.*;
18: import org.w3c.jigsaw.frames.*;
19: import org.w3c.tools.resources.*;
20:
1.2 bmahe 21: import org.w3c.tools.resources.ProtocolException;
22: import org.w3c.tools.resources.NotAProtocolException;
23:
1.1 bmahe 24: /**
25: * @author Alexandre Rafalovitch <alex@access.com.au>
26: * @author Anselm Baird-Smith <abaird@w3.org>
27: * @author Benoit Mahe <bmahe@w3.org>
28: */
29:
30: public class ServletWrapperFrame extends HTTPFrame {
31:
1.5 ! ylafon 32: public static final
! 33: String STATE_EXTRA_PATH = "org.w3c.jigsaw.servlet.extraPath";
1.1 bmahe 34:
1.5 ! ylafon 35: protected ServletWrapper wrapper = null;
1.1 bmahe 36:
1.5 ! ylafon 37: public void registerResource(FramedResource resource) {
! 38: super.registerOtherResource(resource);
! 39: if (resource instanceof ServletWrapper)
! 40: wrapper = (ServletWrapper) resource;
1.1 bmahe 41: }
42:
1.5 ! ylafon 43: /**
! 44: * Create a reply to answer to request on this file.
! 45: * This method will create a suitable reply (matching the given request)
! 46: * and will set all its default header values to the appropriate
! 47: * values. The reply will not have LastModified field setted.
! 48: * @param request The request to make a reply for.
! 49: * @return An instance of Reply, suited to answer this request.
! 50: */
! 51:
! 52: public Reply createDefaultReply(Request request, int status) {
! 53: Reply reply = super.createDefaultReply(request, status);
! 54: reply.setLastModified( -1 );
! 55: return reply;
! 56: }
1.1 bmahe 57:
1.5 ! ylafon 58: /**
! 59: * Dispatch the give request to our servlet.
! 60: * <p>If the servlet cannot be inititalized, we just throw an error message
! 61: * otherwise, we just delegate that request processing to the underlying
! 62: * servlet instance.
! 63: * @param request The request to be processed.
! 64: * @exception ProtocolException If the wrapped servlet is not initialized.
! 65: */
! 66:
! 67: public ReplyInterface perform(RequestInterface req)
! 68: throws ProtocolException, NotAProtocolException
! 69: {
! 70: ReplyInterface repi = performFrames(req);
! 71: if (repi != null)
! 72: return repi;
! 73:
! 74: if (! checkRequest(req))
! 75: return null;
! 76:
! 77: Request request = (Request) req;
! 78:
! 79: if (wrapper == null) {
! 80: Reply reply = request.makeReply(HTTP.INTERNAL_SERVER_ERROR);
! 81: reply.setContent("Servlet Wrapper Frame not configured properly: "+
! 82: "must be attached to a ServletWrapper.");
! 83: throw new HTTPException(reply);
! 84: }
! 85:
! 86: wrapper.checkServletClass();
! 87:
! 88: // Check that the servlet has been initialized properly:
! 89: if ( ! wrapper.isInited() ) {
! 90: Reply reply = request.makeReply(HTTP.INTERNAL_SERVER_ERROR);
! 91: reply.setContent("Servlet not configured properly");
! 92: throw new HTTPException(reply);
! 93: }
! 94: // Dispatch the request:
! 95: Reply reply = createDefaultReply(request, HTTP.OK);
! 96: reply.setContentType(MimeType.TEXT_HTML);
! 97: try {
! 98: wrapper.service(request, reply);
! 99: } catch (Exception ex) {
! 100: if ( wrapper.debug )
! 101: ex.printStackTrace();
! 102: reply = request.makeReply(HTTP.INTERNAL_SERVER_ERROR);
! 103: reply.setContent("Servlet has thrown exception:" + ex.toString());
! 104: }
! 105: return reply;
1.1 bmahe 106: }
107:
1.5 ! ylafon 108: /**
! 109: * Jigsaw's lookup on servlets.
! 110: * Once here, we have reached a leaf servlet (or at least the remaining
! 111: * lookup is to be done at the servlet itself). We keep track of the
! 112: * <em>path info</em> and mark that servlet as the target of request.
! 113: * @param ls The lookup state.
! 114: * @param lr The lookup result.
! 115: * @exception ProtocolException If some error occurs.
! 116: */
! 117:
! 118: protected boolean lookupOther(LookupState ls, LookupResult lr)
! 119: throws ProtocolException
! 120: {
! 121: // Get the extra path information:
! 122: String extraPath = ls.getRemainingPath(true);
! 123: if ((extraPath == null) || extraPath.equals(""))
! 124: extraPath = "/";
! 125: // Keep this path info into the request, if possible:
! 126: Request request = (Request) ls.getRequest();
! 127: if ( request != null )
! 128: request.setState(STATE_EXTRA_PATH, extraPath);
! 129: lr.setTarget(resource.getResourceReference());
! 130: return super.lookupOther(ls, lr);
! 131: }
1.1 bmahe 132:
133: }
134:
135:
136:
137:
138:
139:
140:
141:
Webmaster