Annotation of java/classes/org/w3c/jigsaw/servlet/ServletMapperFrame.java, revision 1.2.4.5
1.1 bmahe 1: // ServletMapperFrame.java
1.2.4.5 ! bmahe 2: // $Id: ServletMapperFrame.java,v 1.6 2000/03/13 17:28:51 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.util.*;
9: import java.io.* ;
10: import java.net.*;
11:
12: import org.w3c.tools.resources.*;
13: import org.w3c.jigsaw.http.*;
14: import org.w3c.jigsaw.frames.*;
15: import org.w3c.www.http.*;
16:
17: import org.w3c.tools.resources.ProtocolException;
18: import org.w3c.tools.resources.ResourceException;
19:
20: /**
21: * Perform an internal redirect.
22: */
23: public class ServletMapperFrame extends HTTPFrame {
24: /**
25: * Attributes index - The index for the target attribute.
26: */
27: protected static int ATTR_TARGET = -1 ;
28:
29: static {
30: Attribute a = null ;
31: Class cls = null ;
32: // Get a pointer to our class:
33: try {
34: cls = Class.forName("org.w3c.jigsaw.servlet.ServletMapperFrame") ;
35: } catch (Exception ex) {
36: ex.printStackTrace() ;
37: System.exit(1) ;
38: }
39: a = new StringAttribute("servlet-url"
40: , null
41: , Attribute.EDITABLE);
42: ATTR_TARGET = AttributeRegistry.registerAttribute(cls, a) ;
43: }
44:
45: protected String getTarget() {
46: return (String) getValue(ATTR_TARGET, null);
47: }
48:
49: /**
1.2.4.5 ! bmahe 50: * Gets, from the first line of the HTTP request,
! 51: * the part of this request's URI that is to the left of any query string.
! 52: */
! 53: public String getRequestURI(Request request)
! 54: {
! 55: String uri = null;
! 56: //fixme test
! 57: if (request.isProxy()) {
! 58: uri = request.getURL().toExternalForm();
! 59: } else {
! 60: uri = request.getURLPath();
! 61: }
! 62: if (request.hasQueryString()) {
! 63: String query = request.getQueryString();
! 64: int idx = uri.lastIndexOf(query);
! 65: uri = uri.substring(0, idx-1);
! 66: }
! 67: return uri;
! 68: }
! 69:
! 70: /**
1.1 bmahe 71: * Perform the request.
72: * @param req The request to handle.
73: * @exception ProtocolException If request couldn't be processed.
74: * @exception ResourceException If the resource got a fatal error.
75: */
76: public ReplyInterface perform(RequestInterface req)
77: throws ProtocolException, ResourceException
78: {
79: Reply reply = (Reply) performFrames(req);
80: if (reply != null)
81: return reply;
82: Request request = (Request) req;
83: httpd server = (httpd) getServer();
84: String host = request.getHost();
1.2.4.5 ! bmahe 85: request.setState(JigsawRequestDispatcher.REQUEST_URI_P,
! 86: getRequestURI(request));
! 87: request.setState(JigsawRequestDispatcher.QUERY_STRING_P,
! 88: request.getQueryString());
1.2.4.4 bmahe 89: request.setState(JigsawRequestDispatcher.SERVLET_PATH_P, getURLPath());
1.1 bmahe 90: try {
91: String target = null;
92: if (request.hasQueryString())
93: target = getTarget()+"?"+request.getQueryString();
94: else
95: target = getTarget();
96:
97: if (host == null)
98: request.setURL(new URL(server.getURL(), target));
99: else
100: request.setURL(new URL(server.getURL().getProtocol(),
101: host, target));
1.2.4.1 bmahe 102: request.setInternal(true);
1.1 bmahe 103: } catch (MalformedURLException ex) {
104: Reply error = request.makeReply(HTTP.INTERNAL_SERVER_ERROR);
105: error.setContent("<html><head><title>Server Error</title>"+
106: "</head><body><h1>Server misconfigured</h1>"+
107: "<p>The resource <b>"+getIdentifier()+"</b>"+
108: "has an invalid target attribute : <p><b>"+
109: getTarget()+"</b></body></html>");
110: throw new HTTPException (error);
111: }
112: return server.perform(request);
113: }
114: }
Webmaster