Annotation of java/classes/org/w3c/jigsaw/servlet/ServletMapperFrame.java, revision 1.3

1.1       bmahe       1: // ServletMapperFrame.java
1.3     ! bmahe       2: // $Id: ServletMapperFrame.java,v 1.2 1999/03/30 12:48: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.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:     /**
                     50:      * Perform the request.
                     51:      * @param req The request to handle.
                     52:      * @exception ProtocolException If request couldn't be processed.
                     53:      * @exception ResourceException If the resource got a fatal error.
                     54:      */
                     55:     public ReplyInterface perform(RequestInterface req) 
                     56:        throws ProtocolException, ResourceException
                     57:     {
                     58:        Reply        reply  = (Reply) performFrames(req);
                     59:        if (reply != null) 
                     60:            return reply;
                     61:        Request request = (Request) req;
                     62:        httpd    server = (httpd) getServer();
                     63:        String     host = request.getHost();
                     64:        request.setState(ServletWrapperFrame.STATE_EXTRA_PATH,
                     65:                         getURLPath());
                     66:        try {
                     67:            String target = null;
                     68:            if (request.hasQueryString())
                     69:                target = getTarget()+"?"+request.getQueryString();
                     70:            else
                     71:                target = getTarget();
                     72: 
                     73:            if (host == null)
                     74:                request.setURL(new URL(server.getURL(), target));
                     75:            else 
                     76:                request.setURL(new URL(server.getURL().getProtocol(),
                     77:                                       host, target));
1.3     ! bmahe      78:            request.setInternal(true);
1.1       bmahe      79:        } catch (MalformedURLException ex) {
                     80:            Reply error = request.makeReply(HTTP.INTERNAL_SERVER_ERROR);
                     81:            error.setContent("<html><head><title>Server Error</title>"+
                     82:                             "</head><body><h1>Server misconfigured</h1>"+
                     83:                             "<p>The resource <b>"+getIdentifier()+"</b>"+
                     84:                             "has an invalid target attribute : <p><b>"+
                     85:                             getTarget()+"</b></body></html>");      
                     86:            throw new HTTPException (error);
                     87:        }
                     88:        return server.perform(request);
                     89:     }
                     90: }

Webmaster