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