001    /**
002     * Copyright (c) 2000-2013 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portal.kernel.resiliency.spi.agent;
016    
017    import com.liferay.portal.kernel.resiliency.spi.SPI;
018    import com.liferay.portal.kernel.resiliency.spi.SPIUtil;
019    import com.liferay.portal.util.PortalUtil;
020    
021    import java.io.IOException;
022    
023    import javax.servlet.RequestDispatcher;
024    import javax.servlet.ServletContext;
025    import javax.servlet.http.HttpServlet;
026    import javax.servlet.http.HttpServletRequest;
027    import javax.servlet.http.HttpServletResponse;
028    import javax.servlet.http.HttpSession;
029    
030    /**
031     * @author Shuyang Zhou
032     */
033    public class AcceptorServlet extends HttpServlet {
034    
035            @Override
036            protected void service(
037                            HttpServletRequest request, HttpServletResponse response)
038                    throws IOException {
039    
040                    PortalUtil.setPortalPort(request);
041    
042                    ServletContext servletContext = getServletContext();
043    
044                    ServletContext portalServletContext = servletContext.getContext("/");
045    
046                    RequestDispatcher requestDispatcher =
047                            portalServletContext.getRequestDispatcher("/c/portal/resiliency");
048    
049                    SPI spi = SPIUtil.getSPI();
050    
051                    SPIAgent spiAgent = spi.getSPIAgent();
052    
053                    HttpServletRequest spiAgentHttpServletRequest = spiAgent.prepareRequest(
054                            request);
055    
056                    HttpServletResponse spiAgentHttpServletResponse =
057                            spiAgent.prepareResponse(request, response);
058    
059                    Exception exception = null;
060    
061                    try {
062                            requestDispatcher.forward(
063                                    spiAgentHttpServletRequest, spiAgentHttpServletResponse);
064                    }
065                    catch (Exception e) {
066                            exception = e;
067                    }
068    
069                    spiAgent.transferResponse(
070                            spiAgentHttpServletRequest, spiAgentHttpServletResponse, exception);
071    
072                    HttpSession session = spiAgentHttpServletRequest.getSession();
073    
074                    session.invalidate();
075            }
076    
077    }