325N/A/*
325N/A * Copyright (c) 2005, 2011, Oracle and/or its affiliates. All rights reserved.
325N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
325N/A *
325N/A * This code is free software; you can redistribute it and/or modify it
325N/A * under the terms of the GNU General Public License version 2 only, as
325N/A * published by the Free Software Foundation. Oracle designates this
325N/A * particular file as subject to the "Classpath" exception as provided
325N/A * by Oracle in the LICENSE file that accompanied this code.
325N/A *
325N/A * This code is distributed in the hope that it will be useful, but WITHOUT
325N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
325N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
325N/A * version 2 for more details (a copy is included in the LICENSE file that
325N/A * accompanied this code).
325N/A *
325N/A * You should have received a copy of the GNU General Public License version
325N/A * 2 along with this work; if not, write to the Free Software Foundation,
325N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
325N/A *
325N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
325N/A * or visit www.oracle.com if you need additional information or have any
325N/A * questions.
325N/A */
325N/A
325N/Apackage javax.xml.ws.spi;
325N/A
325N/Aimport java.net.URL;
325N/Aimport java.util.List;
325N/Aimport java.util.Iterator;
325N/Aimport java.util.Map;
325N/Aimport java.lang.reflect.Method;
325N/Aimport javax.xml.namespace.QName;
325N/Aimport javax.xml.ws.*;
325N/Aimport javax.xml.ws.wsaddressing.W3CEndpointReference;
325N/A
325N/Aimport org.w3c.dom.Element;
325N/A
325N/A/**
325N/A * Service provider for <code>ServiceDelegate</code> and
325N/A * <code>Endpoint</code> objects.
325N/A * <p>
325N/A *
325N/A * @since JAX-WS 2.0
325N/A */
325N/Apublic abstract class Provider {
325N/A
325N/A /**
325N/A * A constant representing the property used to lookup the
325N/A * name of a <code>Provider</code> implementation
325N/A * class.
325N/A */
325N/A static public final String JAXWSPROVIDER_PROPERTY
325N/A = "javax.xml.ws.spi.Provider";
325N/A
325N/A /**
325N/A * A constant representing the name of the default
325N/A * <code>Provider</code> implementation class.
325N/A **/
325N/A // Using two strings so that package renaming doesn't change it
325N/A static final String DEFAULT_JAXWSPROVIDER
325N/A = "com.sun"+".xml.internal.ws.spi.ProviderImpl";
325N/A
325N/A /**
325N/A * Take advantage of Java SE 6's java.util.ServiceLoader API.
325N/A * Using reflection so that there is no compile-time dependency on SE 6.
325N/A */
325N/A static private final Method loadMethod;
325N/A static private final Method iteratorMethod;
325N/A static {
325N/A Method tLoadMethod = null;
325N/A Method tIteratorMethod = null;
325N/A try {
325N/A Class<?> clazz = Class.forName("java.util.ServiceLoader");
325N/A tLoadMethod = clazz.getMethod("load", Class.class);
325N/A tIteratorMethod = clazz.getMethod("iterator");
325N/A } catch(ClassNotFoundException ce) {
325N/A // Running on Java SE 5
325N/A } catch(NoSuchMethodException ne) {
325N/A // Shouldn't happen
325N/A }
325N/A loadMethod = tLoadMethod;
325N/A iteratorMethod = tIteratorMethod;
325N/A }
325N/A
325N/A
325N/A /**
325N/A * Creates a new instance of Provider
325N/A */
325N/A protected Provider() {
325N/A }
325N/A
325N/A /**
325N/A *
325N/A * Creates a new provider object.
325N/A * <p>
325N/A * The algorithm used to locate the provider subclass to use consists
325N/A * of the following steps:
325N/A * <p>
325N/A * <ul>
325N/A * <li>
325N/A * If a resource with the name of
325N/A * <code>META-INF/services/javax.xml.ws.spi.Provider</code>
325N/A * exists, then its first line, if present, is used as the UTF-8 encoded
325N/A * name of the implementation class.
325N/A * </li>
325N/A * <li>
325N/A * If the $java.home/lib/jaxws.properties file exists and it is readable by
325N/A * the <code>java.util.Properties.load(InputStream)</code> method and it contains
325N/A * an entry whose key is <code>javax.xml.ws.spi.Provider</code>, then the value of
325N/A * that entry is used as the name of the implementation class.
325N/A * </li>
325N/A * <li>
325N/A * If a system property with the name <code>javax.xml.ws.spi.Provider</code>
325N/A * is defined, then its value is used as the name of the implementation class.
325N/A * </li>
325N/A * <li>
325N/A * Finally, a default implementation class name is used.
325N/A * </li>
325N/A * </ul>
325N/A *
325N/A */
325N/A public static Provider provider() {
325N/A try {
325N/A Object provider = getProviderUsingServiceLoader();
325N/A if (provider == null) {
325N/A provider = FactoryFinder.find(JAXWSPROVIDER_PROPERTY, DEFAULT_JAXWSPROVIDER);
325N/A }
325N/A if (!(provider instanceof Provider)) {
325N/A Class pClass = Provider.class;
325N/A String classnameAsResource = pClass.getName().replace('.', '/') + ".class";
325N/A ClassLoader loader = pClass.getClassLoader();
325N/A if(loader == null) {
325N/A loader = ClassLoader.getSystemClassLoader();
325N/A }
325N/A URL targetTypeURL = loader.getResource(classnameAsResource);
325N/A throw new LinkageError("ClassCastException: attempting to cast" +
325N/A provider.getClass().getClassLoader().getResource(classnameAsResource) +
325N/A "to" + targetTypeURL.toString() );
325N/A }
325N/A return (Provider) provider;
325N/A } catch (WebServiceException ex) {
325N/A throw ex;
325N/A } catch (Exception ex) {
325N/A throw new WebServiceException("Unable to createEndpointReference Provider", ex);
325N/A }
325N/A }
325N/A
325N/A
325N/A private static Provider getProviderUsingServiceLoader() {
325N/A if (loadMethod != null) {
325N/A Object loader;
325N/A try {
325N/A loader = loadMethod.invoke(null, Provider.class);
325N/A } catch (Exception e) {
325N/A throw new WebServiceException("Cannot invoke java.util.ServiceLoader#load()", e);
325N/A }
325N/A
325N/A Iterator<Provider> it;
325N/A try {
325N/A it = (Iterator<Provider>)iteratorMethod.invoke(loader);
325N/A } catch(Exception e) {
325N/A throw new WebServiceException("Cannot invoke java.util.ServiceLoader#iterator()", e);
325N/A }
325N/A return it.hasNext() ? it.next() : null;
325N/A }
325N/A return null;
325N/A }
325N/A
325N/A /**
325N/A * Creates a service delegate object.
325N/A * <p>
325N/A * @param wsdlDocumentLocation A URL pointing to the WSDL document
325N/A * for the service, or <code>null</code> if there isn't one.
325N/A * @param serviceName The qualified name of the service.
325N/A * @param serviceClass The service class, which MUST be either
325N/A * <code>javax.xml.ws.Service</code> or a subclass thereof.
325N/A * @return The newly created service delegate.
325N/A */
325N/A public abstract ServiceDelegate createServiceDelegate(
325N/A java.net.URL wsdlDocumentLocation,
325N/A QName serviceName, Class<? extends Service> serviceClass);
325N/A
325N/A /**
325N/A * Creates a service delegate object.
325N/A * <p>
325N/A * @param wsdlDocumentLocation A URL pointing to the WSDL document
325N/A * for the service, or <code>null</code> if there isn't one.
325N/A * @param serviceName The qualified name of the service.
325N/A * @param serviceClass The service class, which MUST be either
325N/A * <code>javax.xml.ws.Service</code> or a subclass thereof.
325N/A * @param features Web Service features that must be configured on
325N/A * the service. If the provider doesn't understand a feature,
325N/A * it must throw a WebServiceException.
325N/A * @return The newly created service delegate.
325N/A *
325N/A * @since JAX-WS 2.2
325N/A */
325N/A public ServiceDelegate createServiceDelegate(
325N/A java.net.URL wsdlDocumentLocation,
325N/A QName serviceName, Class<? extends Service> serviceClass, WebServiceFeature ... features) {
325N/A throw new UnsupportedOperationException("JAX-WS 2.2 implementation must override this default behaviour.");
325N/A }
325N/A
325N/A
325N/A /**
325N/A *
325N/A * Creates an endpoint object with the provided binding and implementation
325N/A * object.
325N/A *
325N/A * @param bindingId A URI specifying the desired binding (e.g. SOAP/HTTP)
325N/A * @param implementor A service implementation object to which
325N/A * incoming requests will be dispatched. The corresponding
325N/A * class MUST be annotated with all the necessary Web service
325N/A * annotations.
325N/A * @return The newly created endpoint.
325N/A */
325N/A public abstract Endpoint createEndpoint(String bindingId,
325N/A Object implementor);
325N/A
325N/A
325N/A /**
325N/A * Creates and publishes an endpoint object with the specified
325N/A * address and implementation object.
325N/A *
325N/A * @param address A URI specifying the address and transport/protocol
325N/A * to use. A http: URI MUST result in the SOAP 1.1/HTTP
325N/A * binding being used. Implementations may support other
325N/A * URI schemes.
325N/A * @param implementor A service implementation object to which
325N/A * incoming requests will be dispatched. The corresponding
325N/A * class MUST be annotated with all the necessary Web service
325N/A * annotations.
325N/A * @return The newly created endpoint.
325N/A */
325N/A public abstract Endpoint createAndPublishEndpoint(String address,
325N/A Object implementor);
325N/A
325N/A /**
325N/A * read an EndpointReference from the infoset contained in
325N/A * <code>eprInfoset</code>.
325N/A *
325N/A * @param eprInfoset infoset for EndpointReference
325N/A *
325N/A * @return the <code>EndpointReference</code> unmarshalled from
325N/A * <code>eprInfoset</code>. This method never returns <code>null</code>.
325N/A *
325N/A * @throws WebServiceException If there is an error creating the
325N/A * <code>EndpointReference</code> from the specified <code>eprInfoset</code>.
325N/A *
325N/A * @throws NullPointerException If the <code>null</code>
325N/A * <code>eprInfoset</code> value is given.
325N/A *
325N/A * @since JAX-WS 2.1
325N/A **/
325N/A public abstract EndpointReference readEndpointReference(javax.xml.transform.Source eprInfoset);
325N/A
325N/A
325N/A /**
325N/A * The getPort method returns a proxy. If there
325N/A * are any reference parameters in the
325N/A * <code>endpointReference</code>, then those reference
325N/A * parameters MUST appear as SOAP headers, indicating them to be
325N/A * reference parameters, on all messages sent to the endpoint.
325N/A * The parameter <code>serviceEndpointInterface</code> specifies
325N/A * the service endpoint interface that is supported by the
325N/A * returned proxy.
325N/A * The parameter <code>endpointReference</code> specifies the
325N/A * endpoint that will be invoked by the returned proxy.
325N/A * In the implementation of this method, the JAX-WS
325N/A * runtime system takes the responsibility of selecting a protocol
325N/A * binding (and a port) and configuring the proxy accordingly from
325N/A * the WSDL metadata of the
325N/A * <code>serviceEndpointInterface</code> and the <code>EndpointReference</code>.
325N/A * For this method
325N/A * to successfully return a proxy, WSDL metadata MUST be available and the
325N/A * <code>endpointReference</code> MUST contain an implementation understood
325N/A * <code>serviceName</code> metadata.
325N/A *
325N/A *
325N/A * @param endpointReference the EndpointReference that will
325N/A * be invoked by the returned proxy.
325N/A * @param serviceEndpointInterface Service endpoint interface
325N/A * @param features A list of WebServiceFeatures to configure on the
325N/A * proxy. Supported features not in the <code>features
325N/A * </code> parameter will have their default values.
325N/A * @return Object Proxy instance that supports the
325N/A * specified service endpoint interface
325N/A * @throws WebServiceException
325N/A * <UL>
325N/A * <LI>If there is an error during creation
325N/A * of the proxy
325N/A * <LI>If there is any missing WSDL metadata
325N/A * as required by this method}
325N/A * <LI>If this
325N/A * <code>endpointReference</code>
325N/A * is illegal
325N/A * <LI>If an illegal
325N/A * <code>serviceEndpointInterface</code>
325N/A * is specified
325N/A * <LI>If a feature is enabled that is not compatible with
325N/A * this port or is unsupported.
325N/A * </UL>
325N/A *
325N/A * @see WebServiceFeature
325N/A *
325N/A * @since JAX-WS 2.1
325N/A **/
325N/A public abstract <T> T getPort(EndpointReference endpointReference,
325N/A Class<T> serviceEndpointInterface,
325N/A WebServiceFeature... features);
325N/A
325N/A /**
325N/A * Factory method to create a <code>W3CEndpointReference</code>.
325N/A *
325N/A * <p>
325N/A * This method can be used to create a <code>W3CEndpointReference</code>
325N/A * for any endpoint by specifying the <code>address</code> property along
325N/A * with any other desired properties. This method
325N/A * can also be used to create a <code>W3CEndpointReference</code> for
325N/A * an endpoint that is published by the same Java EE application.
325N/A * To do so the <code>address</code> property can be provided or this
325N/A * method can automatically determine the <code>address</code> of
325N/A * an endpoint that is published by the same Java EE application and is
325N/A * identified by the <code>serviceName</code> and
325N/A * <code>portName</code> propeties. If the <code>address</code> is
325N/A * <code>null</code> and the <code>serviceName</code> and
325N/A * <code>portName</code> do not identify an endpoint published by the
325N/A * same Java EE application, a
325N/A * <code>javax.lang.IllegalStateException</code> MUST be thrown.
325N/A *
325N/A * @param address Specifies the address of the target endpoint
325N/A * @param serviceName Qualified name of the service in the WSDL.
325N/A * @param portName Qualified name of the endpoint in the WSDL.
325N/A * @param metadata A list of elements that should be added to the
325N/A * <code>W3CEndpointReference</code> instances <code>wsa:metadata</code>
325N/A * element.
325N/A * @param wsdlDocumentLocation URL for the WSDL document location for
325N/A * the service.
325N/A * @param referenceParameters Reference parameters to be associated
325N/A * with the returned <code>EndpointReference</code> instance.
325N/A *
325N/A * @return the <code>W3CEndpointReference</code> created from
325N/A * <code>serviceName</code>, <code>portName</code>,
325N/A * <code>metadata</code>, <code>wsdlDocumentLocation</code>
325N/A * and <code>referenceParameters</code>. This method
325N/A * never returns <code>null</code>.
325N/A *
325N/A * @throws java.lang.IllegalStateException
325N/A * <ul>
325N/A * <li>If the <code>address</code>, <code>serviceName</code> and
325N/A * <code>portName</code> are all <code>null</code>.
325N/A * <li>If the <code>serviceName</code> service is <code>null</code> and the
325N/A * <code>portName</code> is NOT <code>null</code>.
325N/A * <li>If the <code>address</code> property is <code>null</code> and
325N/A * the <code>serviceName</code> and <code>portName</code> do not
325N/A * specify a valid endpoint published by the same Java EE
325N/A * application.
325N/A * <li>If the <code>serviceName</code>is NOT <code>null</code>
325N/A * and is not present in the specified WSDL.
325N/A * <li>If the <code>portName</code> port is not <code>null</code> and it
325N/A * is not present in <code>serviceName</code> service in the WSDL.
325N/A * <li>If the <code>wsdlDocumentLocation</code> is NOT <code>null</code>
325N/A * and does not represent a valid WSDL.
325N/A * </ul>
325N/A * @throws WebServiceException If an error occurs while creating the
325N/A * <code>W3CEndpointReference</code>.
325N/A *
325N/A * @since JAX-WS 2.1
325N/A */
325N/A public abstract W3CEndpointReference createW3CEndpointReference(String address, QName serviceName, QName portName,
325N/A List<Element> metadata, String wsdlDocumentLocation, List<Element> referenceParameters);
325N/A
325N/A
325N/A /**
325N/A * Factory method to create a <code>W3CEndpointReference</code>.
325N/A * Using this method, a <code>W3CEndpointReference</code> instance
325N/A * can be created with extension elements, and attributes.
325N/A * <code>Provider</code> implementations must override the default
325N/A * implementation.
325N/A *
325N/A * <p>
325N/A * This method can be used to create a <code>W3CEndpointReference</code>
325N/A * for any endpoint by specifying the <code>address</code> property along
325N/A * with any other desired properties. This method
325N/A * can also be used to create a <code>W3CEndpointReference</code> for
325N/A * an endpoint that is published by the same Java EE application.
325N/A * To do so the <code>address</code> property can be provided or this
325N/A * method can automatically determine the <code>address</code> of
325N/A * an endpoint that is published by the same Java EE application and is
325N/A * identified by the <code>serviceName</code> and
325N/A * <code>portName</code> propeties. If the <code>address</code> is
325N/A * <code>null</code> and the <code>serviceName</code> and
325N/A * <code>portName</code> do not identify an endpoint published by the
325N/A * same Java EE application, a
325N/A * <code>javax.lang.IllegalStateException</code> MUST be thrown.
325N/A *
325N/A * @param address Specifies the address of the target endpoint
325N/A * @param interfaceName the <code>wsam:InterfaceName</code> element in the
325N/A * <code>wsa:Metadata</code> element.
325N/A * @param serviceName Qualified name of the service in the WSDL.
325N/A * @param portName Qualified name of the endpoint in the WSDL.
325N/A * @param metadata A list of elements that should be added to the
325N/A * <code>W3CEndpointReference</code> instances <code>wsa:metadata</code>
325N/A * element.
325N/A * @param wsdlDocumentLocation URL for the WSDL document location for
325N/A * the service.
325N/A * @param referenceParameters Reference parameters to be associated
325N/A * with the returned <code>EndpointReference</code> instance.
325N/A * @param elements extension elements to be associated
325N/A * with the returned <code>EndpointReference</code> instance.
325N/A * @param attributes extension attributes to be associated
325N/A * with the returned <code>EndpointReference</code> instance.
325N/A *
325N/A * @return the <code>W3CEndpointReference</code> created from
325N/A * <code>serviceName</code>, <code>portName</code>,
325N/A * <code>metadata</code>, <code>wsdlDocumentLocation</code>
325N/A * and <code>referenceParameters</code>. This method
325N/A * never returns <code>null</code>.
325N/A *
325N/A * @throws java.lang.IllegalStateException
325N/A * <ul>
325N/A * <li>If the <code>address</code>, <code>serviceName</code> and
325N/A * <code>portName</code> are all <code>null</code>.
325N/A * <li>If the <code>serviceName</code> service is <code>null</code> and the
325N/A * <code>portName</code> is NOT <code>null</code>.
325N/A * <li>If the <code>address</code> property is <code>null</code> and
325N/A * the <code>serviceName</code> and <code>portName</code> do not
325N/A * specify a valid endpoint published by the same Java EE
325N/A * application.
325N/A * <li>If the <code>serviceName</code>is NOT <code>null</code>
325N/A * and is not present in the specified WSDL.
325N/A * <li>If the <code>portName</code> port is not <code>null</code> and it
325N/A * is not present in <code>serviceName</code> service in the WSDL.
325N/A * <li>If the <code>wsdlDocumentLocation</code> is NOT <code>null</code>
325N/A * and does not represent a valid WSDL.
325N/A * <li>If the <code>wsdlDocumentLocation</code> is NOT <code>null</code> but
325N/A * wsdli:wsdlLocation's namespace name cannot be got from the available
325N/A * metadata.
325N/A * </ul>
325N/A * @throws WebServiceException If an error occurs while creating the
325N/A * <code>W3CEndpointReference</code>.
325N/A * @since JAX-WS 2.2
325N/A */
325N/A public W3CEndpointReference createW3CEndpointReference(String address,
325N/A QName interfaceName, QName serviceName, QName portName,
325N/A List<Element> metadata, String wsdlDocumentLocation, List<Element> referenceParameters,
325N/A List<Element> elements, Map<QName, String> attributes) {
325N/A throw new UnsupportedOperationException("JAX-WS 2.2 implementation must override this default behaviour.");
325N/A }
325N/A
325N/A /**
325N/A * Creates and publishes an endpoint object with the specified
325N/A * address, implementation object and web service features.
325N/A * <code>Provider</code> implementations must override the
325N/A * default implementation.
325N/A *
325N/A * @param address A URI specifying the address and transport/protocol
325N/A * to use. A http: URI MUST result in the SOAP 1.1/HTTP
325N/A * binding being used. Implementations may support other
325N/A * URI schemes.
325N/A * @param implementor A service implementation object to which
325N/A * incoming requests will be dispatched. The corresponding
325N/A * class MUST be annotated with all the necessary Web service
325N/A * annotations.
325N/A * @param features A list of WebServiceFeatures to configure on the
325N/A * endpoint. Supported features not in the <code>features
325N/A * </code> parameter will have their default values.
325N/A * @return The newly created endpoint.
325N/A * @since JAX-WS 2.2
325N/A */
325N/A public Endpoint createAndPublishEndpoint(String address,
325N/A Object implementor, WebServiceFeature ... features) {
325N/A throw new UnsupportedOperationException("JAX-WS 2.2 implementation must override this default behaviour.");
325N/A }
325N/A
325N/A /**
325N/A * Creates an endpoint object with the provided binding, implementation
325N/A * object and web service features. <code>Provider</code> implementations
325N/A * must override the default implementation.
325N/A *
325N/A * @param bindingId A URI specifying the desired binding (e.g. SOAP/HTTP)
325N/A * @param implementor A service implementation object to which
325N/A * incoming requests will be dispatched. The corresponding
325N/A * class MUST be annotated with all the necessary Web service
325N/A * annotations.
325N/A * @param features A list of WebServiceFeatures to configure on the
325N/A * endpoint. Supported features not in the <code>features
325N/A * </code> parameter will have their default values.
325N/A * @return The newly created endpoint.
325N/A * @since JAX-WS 2.2
325N/A */
325N/A public Endpoint createEndpoint(String bindingId, Object implementor,
325N/A WebServiceFeature ... features) {
325N/A throw new UnsupportedOperationException("JAX-WS 2.2 implementation must override this default behaviour.");
325N/A }
325N/A
325N/A /**
325N/A * Creates an endpoint object with the provided binding, implementation
325N/A * class, invoker and web service features. Containers typically use
325N/A * this to create Endpoint objects. <code>Provider</code>
325N/A * implementations must override the default implementation.
325N/A *
325N/A * @param bindingId A URI specifying the desired binding (e.g. SOAP/HTTP).
325N/A * Can be null.
325N/A * @param implementorClass A service implementation class that
325N/A * MUST be annotated with all the necessary Web service
325N/A * annotations.
325N/A * @param invoker that does the actual invocation on the service instance.
325N/A * @param features A list of WebServiceFeatures to configure on the
325N/A * endpoint. Supported features not in the <code>features
325N/A * </code> parameter will have their default values.
325N/A * @return The newly created endpoint.
325N/A * @since JAX-WS 2.2
325N/A */
325N/A public Endpoint createEndpoint(String bindingId, Class<?> implementorClass,
325N/A Invoker invoker, WebServiceFeature ... features) {
325N/A throw new UnsupportedOperationException("JAX-WS 2.2 implementation must override this default behaviour.");
325N/A }
325N/A
325N/A}