Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.LinkedHashSet;
- import java.util.Map;
- import java.util.Set;
- import javax.servlet.ServletConfig;
- import javax.servlet.ServletException;
- import javax.servlet.http.HttpServlet;
- import javax.servlet.http.HttpServletRequest;
- import javax.servlet.http.HttpServletResponse;
- import org.springframework.beans.BeanUtils;
- import org.springframework.context.ConfigurableApplicationContext;
- import org.springframework.core.env.ConfigurableEnvironment;
- import org.springframework.web.context.ConfigurableWebApplicationContext;
- import org.springframework.web.context.ConfigurableWebEnvironment;
- import org.springframework.web.context.WebApplicationContext;
- import org.springframework.web.context.support.WebApplicationContextUtils;
- import org.springframework.web.context.support.XmlWebApplicationContext;
- import com.sun.xml.ws.transport.http.servlet.ServletAdapterList;
- import com.sun.xml.ws.transport.http.servlet.SpringBinding;
- import com.sun.xml.ws.transport.http.servlet.SpringBindingList;
- import com.sun.xml.ws.transport.http.servlet.WSServletDelegate;
- public class HierarchicalWSSpringServlet extends HttpServlet {
- private static final long serialVersionUID = 8701641714441040772L;
- private WebApplicationContext webApplicationContext;
- private WSServletDelegate delegate;
- @Override
- public void init(ServletConfig config) throws ServletException {
- super.init(config);
- // get the configured adapters from Spring
- WebApplicationContext rootContext = WebApplicationContextUtils
- .getRequiredWebApplicationContext(getServletContext());
- WebApplicationContext wac = null;
- ConfigurableWebApplicationContext cwac = (ConfigurableWebApplicationContext) BeanUtils
- .instantiateClass(XmlWebApplicationContext.class);
- cwac.setParent(rootContext);
- cwac.setConfigLocation("/WEB-INF/spring/jaxws/*.xml");
- cwac.setId("jaxws-context");
- cwac.setServletContext(getServletContext());
- cwac.setServletConfig(config);
- cwac.setNamespace(config.getServletName());
- ConfigurableEnvironment env = cwac.getEnvironment();
- if (env instanceof ConfigurableWebEnvironment) {
- ((ConfigurableWebEnvironment) env).initPropertySources(
- getServletContext(), config);
- }
- cwac.refresh();
- wac = cwac;
- this.webApplicationContext = wac;
- Set<SpringBinding> bindings = new LinkedHashSet<SpringBinding>();
- // backward compatibility. recognize all bindings
- Map<String, SpringBindingList> m = wac.getBeansOfType(SpringBindingList.class);
- for (SpringBindingList sbl : m.values())
- bindings.addAll(sbl.getBindings());
- bindings.addAll(wac.getBeansOfType(SpringBinding.class).values());
- // create adapters
- ServletAdapterList l = new ServletAdapterList(getServletContext());
- for (SpringBinding binding : bindings)
- binding.create(l);
- delegate = new WSServletDelegate(l, getServletContext());
- }
- @Override
- public void destroy() {
- if (this.webApplicationContext instanceof ConfigurableApplicationContext) {
- ((ConfigurableApplicationContext) this.webApplicationContext).close();
- }
- delegate.destroy();
- delegate = null;
- }
- @Override
- protected void doPost(HttpServletRequest request, HttpServletResponse response)
- throws ServletException {
- delegate.doPost(request, response, getServletContext());
- }
- @Override
- protected void doGet(HttpServletRequest request, HttpServletResponse response)
- throws ServletException {
- delegate.doGet(request, response, getServletContext());
- }
- @Override
- protected void doPut(HttpServletRequest request, HttpServletResponse response)
- throws ServletException {
- delegate.doPut(request, response, getServletContext());
- }
- @Override
- protected void doDelete(HttpServletRequest request, HttpServletResponse response)
- throws ServletException {
- delegate.doDelete(request, response, getServletContext());
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement