All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.sun.xml.ws.transport.http.servlet.WSServletContextListener Maven / Gradle / Ivy

There is a newer version: 4.0.2
Show newest version
/*
 * The contents of this file are subject to the terms
 * of the Common Development and Distribution License
 * (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/CDDLv1.0.html.
 * See the License for the specific language governing
 * permissions and limitations under the License.
 * 
 * When distributing Covered Code, include this CDDL
 * Header Notice in each file and include the License file
 * at https://glassfish.dev.java.net/public/CDDLv1.0.html.
 * If applicable, add the following below the CDDL Header,
 * with the fields enclosed by brackets [] replaced by
 * you own identifying information:
 * "Portions Copyrighted [year] [name of copyright owner]"
 * 
 * Copyright 2006 Sun Microsystems Inc. All Rights Reserved
 */

package com.sun.xml.ws.transport.http.servlet;

import com.sun.istack.NotNull;
import com.sun.xml.ws.api.server.BoundEndpoint;
import com.sun.xml.ws.api.server.Container;
import com.sun.xml.ws.api.server.Module;
import com.sun.xml.ws.resources.WsservletMessages;
import com.sun.xml.ws.transport.http.DeploymentDescriptorParser;
import com.sun.xml.ws.transport.http.HttpAdapter;

import javax.servlet.ServletContext;
import javax.servlet.ServletContextAttributeEvent;
import javax.servlet.ServletContextAttributeListener;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.xml.ws.WebServiceException;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;


/**
 * Parses {@code sun-jaxws.xml} and sets up
 * {@link HttpAdapter}s for all deployed endpoints.
 *
 * 

* This code is the entry point at the server side. * * @author WS Development Team */ public final class WSServletContextListener implements ServletContextAttributeListener, ServletContextListener { private WSServletDelegate delegate; public void attributeAdded(ServletContextAttributeEvent event) { } public void attributeRemoved(ServletContextAttributeEvent event) { } public void attributeReplaced(ServletContextAttributeEvent event) { } public void contextDestroyed(ServletContextEvent event) { if (delegate != null) { // the deployment might have failed. delegate.destroy(); } if (logger.isLoggable(Level.INFO)) { logger.info(WsservletMessages.LISTENER_INFO_DESTROY()); } } public void contextInitialized(ServletContextEvent event) { if (logger.isLoggable(Level.INFO)) { logger.info(WsservletMessages.LISTENER_INFO_INITIALIZE()); } ServletContext context = event.getServletContext(); ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); if (classLoader == null) { classLoader = getClass().getClassLoader(); } ServletContainer container = new ServletContainer(context); try { // Parse the descriptor file and build endpoint infos DeploymentDescriptorParser parser = new DeploymentDescriptorParser( classLoader,new ServletResourceLoader(context), container, new ServletAdapterList()); URL sunJaxWsXml = context.getResource(JAXWS_RI_RUNTIME); if(sunJaxWsXml==null) throw new WebServiceException(WsservletMessages.NO_SUNJAXWS_XML(JAXWS_RI_RUNTIME)); List adapters = parser.parse(sunJaxWsXml.toExternalForm(), sunJaxWsXml.openStream()); delegate = new WSServletDelegate(adapters,context); context.setAttribute(WSServlet.JAXWS_RI_RUNTIME_INFO,delegate); } catch (Throwable e) { logger.log(Level.SEVERE, WsservletMessages.LISTENER_PARSING_FAILED(e),e); context.removeAttribute(WSServlet.JAXWS_RI_RUNTIME_INFO); throw new WSServletException("listener.parsingFailed", e); } } /** * Provides access to {@link ServletContext} via {@link Container}. Pipes * can get ServletContext from Container and use it to load some resources. */ private static class ServletContainer extends Container { private final ServletContext servletContext; private final Module module = new Module() { private final List endpoints = new ArrayList(); public @NotNull List getBoundEndpoints() { return endpoints; } }; ServletContainer(ServletContext servletContext) { this.servletContext = servletContext; } public T getSPI(Class spiType) { if (spiType == ServletContext.class) { return (T)servletContext; } if (spiType == Module.class) { return spiType.cast(module); } return null; } } private static final String JAXWS_RI_RUNTIME = "/WEB-INF/sun-jaxws.xml"; private static final Logger logger = Logger.getLogger( com.sun.xml.ws.util.Constants.LoggingDomain + ".server.http"); }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy