001    /*
002      GRANITE DATA SERVICES
003      Copyright (C) 2011 GRANITE DATA SERVICES S.A.S.
004    
005      This file is part of Granite Data Services.
006    
007      Granite Data Services is free software; you can redistribute it and/or modify
008      it under the terms of the GNU Library General Public License as published by
009      the Free Software Foundation; either version 2 of the License, or (at your
010      option) any later version.
011    
012      Granite Data Services is distributed in the hope that it will be useful, but
013      WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
014      FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License
015      for more details.
016    
017      You should have received a copy of the GNU Library General Public License
018      along with this library; if not, see <http://www.gnu.org/licenses/>.
019    */
020    
021    package org.granite.gravity;
022    
023    import java.io.IOException;
024    import java.io.InputStream;
025    
026    import javax.servlet.ServletConfig;
027    import javax.servlet.ServletException;
028    import javax.servlet.http.HttpServlet;
029    import javax.servlet.http.HttpServletRequest;
030    import javax.servlet.http.HttpServletResponse;
031    
032    import flex.messaging.messages.CommandMessage;
033    import flex.messaging.messages.Message;
034    
035    /**
036     * @author Franck WOLFF
037     */
038    public class AbstractGravityServlet extends HttpServlet {
039    
040            ///////////////////////////////////////////////////////////////////////////
041            // Fields.
042            
043            private static final long serialVersionUID = 1L;
044    
045            ///////////////////////////////////////////////////////////////////////////
046            // Initialization.
047            
048            @Override
049            public void init(ServletConfig config) throws ServletException {
050                    super.init(config);
051                    
052                    GravityServletUtil.init(config);
053            }
054    
055            ///////////////////////////////////////////////////////////////////////////
056            // Connect messages management (request attribute).
057            
058            public static void setConnectMessage(HttpServletRequest request, Message connect) {
059                    GravityServletUtil.setConnectMessage(request, connect);
060            }
061            
062            public static CommandMessage getConnectMessage(HttpServletRequest request) {
063                    return GravityServletUtil.getConnectMessage(request);
064            }
065            
066            public static void removeConnectMessage(HttpServletRequest request) {
067                    GravityServletUtil.removeConnectMessage(request);
068            }
069    
070            ///////////////////////////////////////////////////////////////////////////
071            // Long polling timeout.
072            
073            protected long getLongPollingTimeout() {
074                    return GravityServletUtil.getLongPollingTimeout(getServletContext());
075            }
076    
077            ///////////////////////////////////////////////////////////////////////////
078            // AMF (de)serialization methods.
079            
080            protected Gravity initializeRequest(Gravity gravity, HttpServletRequest request, HttpServletResponse response) {
081                    return GravityServletUtil.initializeRequest(getServletConfig(), gravity, request, response);
082            }
083    
084            @SuppressWarnings("unused")
085            protected Message[] deserialize(Gravity gravity, HttpServletRequest request) throws ClassNotFoundException, IOException, ServletException {
086                    return GravityServletUtil.deserialize(gravity, request);
087            }
088            
089            @SuppressWarnings("unused")
090            protected Message[] deserialize(Gravity gravity, HttpServletRequest request, InputStream is) throws ClassNotFoundException, IOException, ServletException {
091                    return GravityServletUtil.deserialize(gravity, request, is);
092            }
093            
094            protected void serialize(Gravity gravity, HttpServletResponse response, Message[] messages) throws IOException {
095                    GravityServletUtil.serialize(gravity, response, messages);
096            }
097            
098            protected void cleanupRequest(HttpServletRequest request) {
099                    GravityServletUtil.cleanupRequest(request);
100            }
101            
102            ///////////////////////////////////////////////////////////////////////////
103            // Unsupported HTTP methods.
104    
105            @Override
106            protected void doDelete(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
107                    throw new ServletException("Unsupported operation: " + req.getMethod());
108            }
109    
110            @Override
111            protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
112                    throw new ServletException("Unsupported operation: " + req.getMethod());
113            }
114    
115            @Override
116            protected void doHead(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
117                    throw new ServletException("Unsupported operation: " + req.getMethod());
118            }
119    
120            @Override
121            protected void doOptions(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
122                    throw new ServletException("Unsupported operation: " + req.getMethod());
123            }
124    
125            @Override
126            protected void doPut(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
127                    throw new ServletException("Unsupported operation: " + req.getMethod());
128            }
129    
130            @Override
131            protected void doTrace(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
132                    throw new ServletException("Unsupported operation: " + req.getMethod());
133            }
134    }