/*******************************************************************************
* Copyright 2009, 2010 Innovation Gate GmbH. All Rights Reserved.
*
* This file is part of the OpenWGA server platform.
*
* OpenWGA is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* In addition, a special exception is granted by the copyright holders
* of OpenWGA called "OpenWGA plugin exception". You should have received
* a copy of this exception along with OpenWGA in file COPYING.
* If not, see <http://www.openwga.com/gpl-plugin-exception>.
*
* OpenWGA is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with OpenWGA in file COPYING.
* If not, see <http://www.gnu.org/licenses/>.
******************************************************************************/
package de.innovationgate.wgpublisher.services;
import java.io.IOException;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import org.jdom.IllegalDataException;
import de.innovationgate.utils.WGUtils;
import de.innovationgate.wga.modules.ModuleDefinition;
import de.innovationgate.wga.modules.ModuleDependencyException;
import de.innovationgate.wga.modules.types.WGAServicesSoapProtocolModuleType;
import de.innovationgate.wgpublisher.WGACore;
import de.innovationgate.wgpublisher.WGAFilterConfig;
public class WGAServicesSOAPFilter implements Filter {
public static final String PARAM_PROTOCOL_SERVLET = "ProtocolServlet";
private WGACore _core;
private HttpServlet _servlet;
public void destroy() {
_servlet.destroy();
}
public void doFilter(ServletRequest arg0, ServletResponse arg1, FilterChain arg2) throws IOException, ServletException {
WGAServicesSOAPRequestFacade reqFacade = new WGAServicesSOAPRequestFacade((HttpServletRequest) arg0);
_servlet.service(reqFacade, arg1);
}
public void init(FilterConfig fc) throws ServletException {
try {
checkLicense("WGAServices SOAP Request Filter");
}
catch (ModuleDependencyException e) {
throw new ServletException("License check failed" ,e);
}
WGAFilterConfig wgaFc = (WGAFilterConfig) fc;
WGACore core = WGACore.retrieve(wgaFc.getServletContext());
try {
String protocolServlet = fc.getInitParameter(PARAM_PROTOCOL_SERVLET);
if (protocolServlet == null) {
throw new IllegalDataException("Internal error: No protocol servlet passed to SOAP filter");
}
Class servletClass = core.getLibraryLoader().loadClass(protocolServlet);
_servlet = (HttpServlet) servletClass.newInstance();
ServletConfig sc = new WGAServicesSOAPServletConfig(fc.getServletContext());
_servlet.init(sc);
}
catch (Exception e) {
throw new ServletException("Exception creating WGAServices SOAP servlet", e);
}
}
private void checkLicense(String moduleName) throws ModuleDependencyException {
//###LicenseCheckModuleDefinition.java###//
}
}