001    /**
002     * Copyright (c) 2000-2012 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.servlet;
016    
017    import com.liferay.portal.kernel.servlet.PluginContextListener;
018    import com.liferay.portal.security.ac.AccessControlThreadLocal;
019    import com.liferay.portal.security.pacl.PACLClassLoaderUtil;
020    
021    import java.io.IOException;
022    
023    import javax.servlet.ServletConfig;
024    import javax.servlet.ServletContext;
025    import javax.servlet.ServletException;
026    import javax.servlet.http.HttpServletRequest;
027    import javax.servlet.http.HttpServletResponse;
028    
029    /**
030     * @author Brian Wing Shun Chan
031     */
032    public class AxisServlet extends com.liferay.util.axis.AxisServlet {
033    
034            @Override
035            public void init(ServletConfig servletConfig) throws ServletException {
036                    ServletContext servletContext = servletConfig.getServletContext();
037    
038                    _pluginClassLoader = (ClassLoader)servletContext.getAttribute(
039                            PluginContextListener.PLUGIN_CLASS_LOADER);
040    
041                    if (_pluginClassLoader == null) {
042                            super.init(servletConfig);
043                    }
044                    else {
045                            ClassLoader contextClassLoader =
046                                    PACLClassLoaderUtil.getContextClassLoader();
047    
048                            try {
049                                    PACLClassLoaderUtil.setContextClassLoader(_pluginClassLoader);
050    
051                                    super.init(servletConfig);
052                            }
053                            finally {
054                                    PACLClassLoaderUtil.setContextClassLoader(contextClassLoader);
055                            }
056                    }
057            }
058    
059            @Override
060            public void service(
061                            HttpServletRequest request, HttpServletResponse response)
062                    throws IOException, ServletException {
063    
064                    boolean remoteAccess = AccessControlThreadLocal.isRemoteAccess();
065    
066                    try {
067                            AccessControlThreadLocal.setRemoteAccess(true);
068    
069                            if (_pluginClassLoader == null) {
070                                    super.service(request, response);
071                            }
072                            else {
073                                    ClassLoader contextClassLoader =
074                                            PACLClassLoaderUtil.getContextClassLoader();
075    
076                                    try {
077                                            PACLClassLoaderUtil.setContextClassLoader(
078                                                    _pluginClassLoader);
079    
080                                            super.service(request, response);
081                                    }
082                                    finally {
083                                            PACLClassLoaderUtil.setContextClassLoader(
084                                                    contextClassLoader);
085                                    }
086                            }
087                    }
088                    catch (IOException ioe) {
089                            throw ioe;
090                    }
091                    catch (ServletException se) {
092                            throw se;
093                    }
094                    catch (Exception e) {
095                            throw new ServletException(e);
096                    }
097                    finally {
098                            AccessControlThreadLocal.setRemoteAccess(remoteAccess);
099                    }
100            }
101    
102            private ClassLoader _pluginClassLoader;
103    
104    }