|
Glassfish example source code file (WSServletContextListener.java)
The Glassfish WSServletContextListener.java source code
/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright (c) 1997-2010 Oracle and/or its affiliates. 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_1_1.html
* or packager/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 packager/legal/LICENSE.txt.
*
* GPL Classpath Exception:
* Oracle designates this particular file as subject to the "Classpath"
* exception as provided by Oracle in the GPL Version 2 section of the License
* file that accompanied this code.
*
* Modifications:
* If applicable, add the following below the License Header, with the fields
* enclosed by brackets [] replaced by your own identifying information:
* "Portions Copyright [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
* Version 2] license." If you don't indicate a single choice of license, a
* recipient has the option to distribute your version of this file under
* either the CDDL, the GPL Version 2 or to extend the choice of license to
* its licensees as provided above. However, if you add GPL Version 2 code
* and therefore, elected the GPL Version 2 license, then the option applies
* only if the new code is made subject to such option by the copyright
* holder.
*/
package org.glassfish.webservices;
import com.sun.enterprise.container.common.spi.util.ComponentEnvManager;
import com.sun.enterprise.deployment.*;
import com.sun.enterprise.deployment.runtime.ws.ReliabilityConfig;
import com.sun.logging.LogDomains;
import com.sun.xml.ws.api.BindingID;
import com.sun.xml.ws.api.WSBinding;
import com.sun.xml.ws.api.server.*;
import com.sun.xml.ws.developer.SchemaValidationFeature;
import com.sun.xml.ws.developer.StreamingAttachmentFeature;
import com.sun.xml.ws.rx.rm.api.ReliableMessagingFeature;
import com.sun.xml.ws.rx.rm.api.ReliableMessagingFeatureBuilder;
import com.sun.xml.ws.rx.rm.api.RmProtocolVersion;
import com.sun.xml.ws.transport.http.servlet.ServletAdapter;
import com.sun.xml.ws.transport.http.servlet.ServletAdapterList;
import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.xml.ws.RespectBindingFeature;
import javax.xml.ws.WebServiceException;
import javax.xml.ws.WebServiceFeature;
import javax.xml.ws.soap.AddressingFeature;
import javax.xml.ws.soap.MTOMFeature;
import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.Collection;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
* This class serves for initialization of JAX-WS WSEndpoints when the context is initialized on deployment.
*
* @author Rama Pulavarthi
*/
public class WSServletContextListener implements ServletContextListener {
private static Logger logger = LogDomains.getLogger(JAXWSServlet.class, LogDomains.WEBSERVICES_LOGGER);
private String contextRoot;
@Override
public void contextInitialized(ServletContextEvent sce) {
WebServiceContractImpl wscImpl = WebServiceContractImpl.getInstance();
ComponentEnvManager compEnvManager = wscImpl.getComponentEnvManager();
JndiNameEnvironment jndiNameEnv = compEnvManager.getCurrentJndiNameEnvironment();
WebBundleDescriptor webBundle = null;
if (jndiNameEnv != null && jndiNameEnv instanceof WebBundleDescriptor) {
webBundle = ((WebBundleDescriptor) jndiNameEnv);
} else {
throw new WebServiceException("Cannot intialize the JAXWSServlet for " + jndiNameEnv);
}
contextRoot = webBundle.getContextRoot();
WebServicesDescriptor webServices = webBundle.getWebServices();
try {
for (WebServiceEndpoint endpoint : webServices.getEndpoints()) {
registerEndpoint(endpoint, sce.getServletContext());
}
} catch (Throwable t) {
logger.log(Level.WARNING, "Deployment failed", t);//TODO Fix Rama
sce.getServletContext().removeAttribute("ADAPTER_LIST");
throw new RuntimeException("Servlet web service endpoint '" +
"' failure", t);
}
}
private void registerEndpoint(WebServiceEndpoint endpoint, ServletContext servletContext) throws Exception {
ClassLoader classLoader = servletContext.getClassLoader();
WsUtil wsu = new WsUtil();
// Complete all the injections that are required
Class serviceEndpointClass =
Class.forName(endpoint.getServletImplClass(), true, classLoader);
// Get the proper binding using BindingID
String givenBinding = endpoint.getProtocolBinding();
//TODO Rama
// if(endpoint.getWsdlExposed() != null) {
// wsdlExposed = Boolean.parseBoolean(endpoint.getWsdlExposed());
// }
// Get list of all wsdls and schema
SDDocumentSource primaryWsdl = null;
Collection docs = null;
if (endpoint.getWebService().hasWsdlFile()) {
URL pkgedWsdl = null;
try {
pkgedWsdl = servletContext.getResource('/' + endpoint.getWebService().getWsdlFileUri());
} catch (MalformedURLException e) {
logger.severe("Cannot load the wsdl from the aplication : " + e.getMessage());
}
if (pkgedWsdl == null) {
pkgedWsdl = endpoint.getWebService().getWsdlFileUrl();
}
if (pkgedWsdl != null) {
primaryWsdl = SDDocumentSource.create(pkgedWsdl);
docs = wsu.getWsdlsAndSchemas(pkgedWsdl);
if (logger.isLoggable(Level.FINE)) {
logger.log(Level.INFO, "Creating endpoint with packaged WSDL " +
primaryWsdl.getSystemId().toString());
logger.log(Level.FINE, "Metadata documents:");
for (Object source : docs) {
logger.log(Level.FINE, ((SDDocumentSource) source).getSystemId().toString());
}
}
}
}
// Create a Container to pass ServletContext and also inserting the pipe
JAXWSContainer container = new JAXWSContainer(servletContext,
endpoint);
// Get catalog info
java.net.URL catalogURL = servletContext.getResource('/' + endpoint.getBundleDescriptor().getDeploymentDescriptorDir() + File.separator + "jax-ws-catalog.xml");
// Create Binding and set service side handlers on this binding
boolean mtomEnabled = wsu.getMtom(endpoint);
WSBinding binding = null;
// Only if MTOm is enabled create the Binding with the MTOMFeature
ArrayList<WebServiceFeature> wsFeatures = new ArrayList
Other Glassfish examples (source code examples)Here is a short list of links related to this Glassfish WSServletContextListener.java source code file: |
| ... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2024 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.