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 */ 022package org.granite.messaging.webapp; 023 024import java.io.IOException; 025 026import javax.servlet.ServletException; 027import javax.servlet.http.HttpServlet; 028import javax.servlet.http.HttpServletRequest; 029import javax.servlet.http.HttpServletResponse; 030 031import org.granite.logging.Logger; 032import org.granite.context.AMFContextImpl; 033import org.granite.context.GraniteContext; 034import org.granite.messaging.amf.AMF0Message; 035import org.granite.messaging.amf.process.AMF0MessageProcessor; 036 037/** 038 * @author Franck WOLFF 039 */ 040public class AMFMessageServlet extends HttpServlet { 041 042 private static final long serialVersionUID = 1L; 043 044 private static final Logger log = Logger.getLogger(AMFMessageServlet.class); 045 046 @Override 047 protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { 048 try { 049 GraniteContext context = GraniteContext.getCurrentInstance(); 050 if (context == null) 051 throw new ServletException( 052 "No GraniteContext (" + AMFMessageFilter.class.getName() + " not configured in web.xml ?)"); 053 054 AMFContextImpl amf = (AMFContextImpl)context.getAMFContext(); 055 056 AMF0Message amf0Request = amf.getAMF0Request(); 057 058 log.debug(">> Processing AMF0 request: %s", amf0Request); 059 060 AMF0Message amf0Response = AMF0MessageProcessor.process(amf0Request); 061 062 log.debug("<< Returning AMF0 response: %s", amf0Response); 063 064 amf.setAmf0Response(amf0Response); 065 } catch (Exception e) { 066 log.error(e, "AMF message error"); 067 throw new ServletException(e); 068 } 069 } 070}