001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common Development
008: * and Distribution License("CDDL") (collectively, the "License"). You
009: * may not use this file except in compliance with the License. You can obtain
010: * a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
011: * or glassfish/bootstrap/legal/LICENSE.txt. See the License for the specific
012: * language governing permissions and limitations under the License.
013: *
014: * When distributing the software, include this License Header Notice in each
015: * file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
016: * Sun designates this particular file as subject to the "Classpath" exception
017: * as provided by Sun in the GPL Version 2 section of the License file that
018: * accompanied this code. If applicable, add the following below the License
019: * Header, with the fields enclosed by brackets [] replaced by your own
020: * identifying information: "Portions Copyrighted [year]
021: * [name of copyright owner]"
022: *
023: * Contributor(s):
024: *
025: * If you wish your version of this file to be governed by only the CDDL or
026: * only the GPL Version 2, indicate your decision by adding "[Contributor]
027: * elects to include this software in this distribution under the [CDDL or GPL
028: * Version 2] license." If you don't indicate a single choice of license, a
029: * recipient has the option to distribute your version of this file under
030: * either the CDDL, the GPL Version 2 or to extend the choice of license to
031: * its licensees as provided above. However, if you add GPL Version 2 code
032: * and therefore, elected the GPL Version 2 license, then the option applies
033: * only if the new code is made subject to such option by the copyright
034: * holder.
035: */
036:
037: package com.sun.xml.ws.transport.http.servlet;
038:
039: import com.sun.istack.NotNull;
040: import com.sun.xml.ws.api.server.Container;
041: import com.sun.xml.ws.resources.WsservletMessages;
042: import com.sun.xml.ws.transport.http.DeploymentDescriptorParser;
043: import com.sun.xml.ws.transport.http.HttpAdapter;
044:
045: import javax.servlet.ServletContext;
046: import javax.servlet.ServletContextAttributeEvent;
047: import javax.servlet.ServletContextAttributeListener;
048: import javax.servlet.ServletContextEvent;
049: import javax.servlet.ServletContextListener;
050: import javax.xml.ws.WebServiceException;
051: import java.net.URL;
052: import java.util.List;
053: import java.util.logging.Level;
054: import java.util.logging.Logger;
055:
056: /**
057: * Parses {@code sun-jaxws.xml} and sets up
058: * {@link HttpAdapter}s for all deployed endpoints.
059: *
060: * <p>
061: * This code is the entry point at the server side in the servlet deployment.
062: * The user application writes this in their <tt>web.xml</tt> so that we can
063: * start when the container starts the webapp.
064: *
065: * @author WS Development Team
066: */
067: public final class WSServletContextListener implements
068: ServletContextAttributeListener, ServletContextListener {
069:
070: private WSServletDelegate delegate;
071:
072: public void attributeAdded(ServletContextAttributeEvent event) {
073: }
074:
075: public void attributeRemoved(ServletContextAttributeEvent event) {
076: }
077:
078: public void attributeReplaced(ServletContextAttributeEvent event) {
079: }
080:
081: public void contextDestroyed(ServletContextEvent event) {
082: if (delegate != null) { // the deployment might have failed.
083: delegate.destroy();
084: }
085:
086: if (logger.isLoggable(Level.INFO)) {
087: logger.info(WsservletMessages.LISTENER_INFO_DESTROY());
088: }
089: }
090:
091: public void contextInitialized(ServletContextEvent event) {
092: if (logger.isLoggable(Level.INFO)) {
093: logger.info(WsservletMessages.LISTENER_INFO_INITIALIZE());
094: }
095: ServletContext context = event.getServletContext();
096: ClassLoader classLoader = Thread.currentThread()
097: .getContextClassLoader();
098: if (classLoader == null) {
099: classLoader = getClass().getClassLoader();
100: }
101: try {
102: // Parse the descriptor file and build endpoint infos
103: DeploymentDescriptorParser<ServletAdapter> parser = new DeploymentDescriptorParser<ServletAdapter>(
104: classLoader, new ServletResourceLoader(context),
105: createContainer(context), new ServletAdapterList());
106: URL sunJaxWsXml = context.getResource(JAXWS_RI_RUNTIME);
107: if (sunJaxWsXml == null)
108: throw new WebServiceException(WsservletMessages
109: .NO_SUNJAXWS_XML(JAXWS_RI_RUNTIME));
110: List<ServletAdapter> adapters = parser.parse(sunJaxWsXml
111: .toExternalForm(), sunJaxWsXml.openStream());
112:
113: delegate = createDelegate(adapters, context);
114:
115: context.setAttribute(WSServlet.JAXWS_RI_RUNTIME_INFO,
116: delegate);
117:
118: } catch (Throwable e) {
119: logger.log(Level.SEVERE, WsservletMessages
120: .LISTENER_PARSING_FAILED(e), e);
121: context.removeAttribute(WSServlet.JAXWS_RI_RUNTIME_INFO);
122: throw new WSServletException("listener.parsingFailed", e);
123: }
124: }
125:
126: /**
127: * Creates {@link Container} implementation that hosts the JAX-WS endpoint.
128: */
129: protected @NotNull
130: Container createContainer(ServletContext context) {
131: return new ServletContainer(context);
132: }
133:
134: /**
135: * Creates {@link WSServletDelegate} that does the real work.
136: */
137: protected @NotNull
138: WSServletDelegate createDelegate(List<ServletAdapter> adapters,
139: ServletContext context) {
140: return new WSServletDelegate(adapters, context);
141: }
142:
143: private static final String JAXWS_RI_RUNTIME = "/WEB-INF/sun-jaxws.xml";
144:
145: private static final Logger logger = Logger
146: .getLogger(com.sun.xml.ws.util.Constants.LoggingDomain
147: + ".server.http");
148: }
|