001    /*
002    // $Id: //open/mondrian/src/main/mondrian/xmla/XmlaRequestCallback.java#10 $
003    // This software is subject to the terms of the Common Public License
004    // Agreement, available at the following URL:
005    // http://www.opensource.org/licenses/cpl.html.
006    // Copyright (C) 2005-2007 Julian Hyde
007    // All Rights Reserved.
008    // You must accept the terms of that agreement to use this software.
009    */
010    package mondrian.xmla;
011    
012    import java.util.Map;
013    
014    import javax.servlet.ServletConfig;
015    import javax.servlet.ServletException;
016    import javax.servlet.http.HttpServletRequest;
017    import javax.servlet.http.HttpServletResponse;
018    
019    import org.w3c.dom.Element;
020    
021    
022    /**
023     * Extract data from HTTP request, SOAP header for following XML/A request.<p/>
024     *
025     * Fill context binding with whatever data you want, then use them in
026     * {@link XmlaServlet#handleSoapHeader} and {@link XmlaServlet#handleSoapBody}.
027     *
028     * @author Gang Chen
029     * @version $Id: //open/mondrian/src/main/mondrian/xmla/XmlaRequestCallback.java#10 $
030     */
031    public interface XmlaRequestCallback {
032        String AUTHORIZATION = "Authorization";
033        String EXPECT = "Expect";
034        String EXPECT_100_CONTINUE = "100-continue";
035    
036        public class Helper {
037            public static XmlaException authorizationException(Exception ex) {
038                return new XmlaException(
039                    XmlaConstants.CLIENT_FAULT_FC,
040                    XmlaConstants.CHH_AUTHORIZATION_CODE,
041                    XmlaConstants.CHH_AUTHORIZATION_FAULT_FS,
042                    ex);
043            }
044    
045            /*
046        HTTP/1.1 100 Continue
047        Server: Microsoft-IIS/5.0
048        Date: Tue, 21 Feb 2006 21:07:57 GMT
049        X-Powered-By: ASP.NET
050            */
051            public static void generatedExpectResponse(
052                HttpServletRequest request,
053                HttpServletResponse response,
054                Map<String, Object> context) throws Exception
055            {
056                response.reset();
057                response.setStatus(HttpServletResponse.SC_CONTINUE);
058            }
059        }
060    
061        void init(ServletConfig servletConfig) throws ServletException;
062    
063        /**
064         * Process the request header items. Specifically if present the
065         * Authorization and Expect headers. If the Authorization header is
066         * present, then the callback can validate the user/password. If
067         * authentication fails, the callback should throw an XmlaException
068         * with the correct XmlaConstants values. The XmlaRequestCallback.Helper
069         * class contains the authorizationException method that can be used
070         * by a callback to generate the XmlaException with the correct values.
071         * If the Expect header is set with "100-continue", then it is
072         * upto the callback to create the appropriate response and return false.
073         * In this case, the XmlaServlet stops processing and returns the
074         * response to the client application. To facilitate the generation of
075         * the response, the XmlaRequestCallback.Helper has the method
076         * generatedExpectResponse that can be called by the callback.
077         * <p>
078         * Note that it is upto the XMLA client to determine whether or not
079         * there is an Expect header entry (ADOMD.NET seems to like to do this).
080         *
081         * @return true if XmlaServlet handling is to continue and false if
082         *         there was an Expect header "100-continue".
083         */
084        boolean processHttpHeader(
085            HttpServletRequest request,
086            HttpServletResponse response,
087            Map<String, Object> context) throws Exception;
088    
089        /**
090         * This is called after the headers have been process but before the
091         * body (DISCOVER/EXECUTE) has been processed.
092         *
093         */
094        void preAction(
095            HttpServletRequest request,
096            Element[] requestSoapParts,
097            Map<String, Object> context) throws Exception;
098    
099        /**
100         * The Callback is requested to generate a sequence id string. This
101         * sequence id was requested by the XMLA client and will be used
102         * for all subsequent communications in the Soap Header block.
103         *
104         */
105        String generateSessionId(Map<String, Object> context);
106    
107        /**
108         * This is called after all Mondrian processing (DISCOVER/EXECUTE) has
109         * occurred.
110         *
111         */
112        void postAction(HttpServletRequest request,
113                    HttpServletResponse response,
114                    byte[][] responseSoapParts,
115                    Map<String, Object> context) throws Exception;
116    }
117    
118    // End XmlaRequestCallback.java