Skip to content

Commit

Permalink
Make WSSpringServlet hierachical as same as DispatcherServlet (javaee…
Browse files Browse the repository at this point in the history
…#125)

WSSpringServlet queries for a root context, which has to exist and will
create a subcontext built upon that.

This closes javaee#125
  • Loading branch information
michael-o committed Jan 18, 2022
1 parent 9436a0f commit 1108ff3
Showing 1 changed file with 39 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
*
* Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
*
*
* The contents of this file are subject to the terms of either the GNU
* General Public License Version 2 only ("GPL") or the Common Development
* and Distribution License("CDDL") (collectively, the "License"). You
* may not use this file except in compliance with the License. You can obtain
* a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
* or glassfish/bootstrap/legal/LICENSE.txt. See the License for the specific
* language governing permissions and limitations under the License.
*
*
* When distributing the software, include this License Header Notice in each
* file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
* Sun designates this particular file as subject to the "Classpath" exception
Expand All @@ -19,9 +19,9 @@
* Header, with the fields enclosed by brackets [] replaced by your own
* identifying information: "Portions Copyrighted [year]
* [name of copyright owner]"
*
*
* Contributor(s):
*
*
* If you wish your version of this file to be governed by only the CDDL or
* only the GPL Version 2, indicate your decision by adding "[Contributor]
* elects to include this software in this distribution under the [CDDL or GPL
Expand All @@ -35,9 +35,14 @@
*/
package com.sun.xml.ws.transport.http.servlet;

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.beans.BeanUtils;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.web.context.support.XmlWebApplicationContext;

import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
Expand All @@ -59,23 +64,46 @@ public class WSSpringServlet extends HttpServlet {

private static final long serialVersionUID = -2786173009814679147L;

private WebApplicationContext webApplicationContext;
private WSServletDelegate delegate;

public void init(ServletConfig servletConfig) throws ServletException {
super.init(servletConfig);

// get the configured adapters from Spring
WebApplicationContext wac = WebApplicationContextUtils
WebApplicationContext rootContext = WebApplicationContextUtils
.getRequiredWebApplicationContext(getServletContext());

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(servletConfig);
cwac.setNamespace(servletConfig.getServletName());

ConfigurableEnvironment env = cwac.getEnvironment();
if (env instanceof ConfigurableWebEnvironment) {
((ConfigurableWebEnvironment) env).initPropertySources(
getServletContext(), servletConfig);
}

cwac.refresh();

this.webApplicationContext = cwac;

Set<SpringBinding> bindings = new LinkedHashSet<SpringBinding>();

// backward compatibility. recognize all bindings
Map<String, SpringBindingList> m = wac.getBeansOfType(SpringBindingList.class);
Map<String, SpringBindingList> m = cwac.getBeansOfType(SpringBindingList.class);
for (SpringBindingList sbl : m.values())
bindings.addAll(sbl.getBindings());

bindings.addAll( wac.getBeansOfType(SpringBinding.class).values() );
bindings.addAll( cwac.getBeansOfType(SpringBinding.class).values() );

// create adapters
ServletAdapterList l = new ServletAdapterList(getServletContext());
Expand All @@ -91,11 +119,9 @@ public void init(ServletConfig servletConfig) throws ServletException {
*/
@Override
public void destroy() {
WebApplicationContext wac =
WebApplicationContextUtils.getWebApplicationContext(getServletContext());
if (wac instanceof ConfigurableApplicationContext) {
((ConfigurableApplicationContext) wac).close();
}
if (this.webApplicationContext instanceof ConfigurableApplicationContext) {
((ConfigurableApplicationContext) this.webApplicationContext).close();
}
delegate.destroy();
delegate = null;
}
Expand Down

0 comments on commit 1108ff3

Please sign in to comment.