Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.axis2.jaxws.spi;
import java.lang.reflect.Field;
import java.lang.reflect.Proxy;
import java.net.MalformedURLException;
import java.net.URL;
import java.security.PrivilegedActionException;
import java.security.PrivilegedExceptionAction;
import java.util.Iterator;
import java.util.concurrent.Executor;
import javax.activation.DataSource;
import javax.xml.bind.JAXBContext;
import javax.xml.namespace.QName;
import javax.xml.soap.SOAPMessage;
import javax.xml.transform.Source;
import javax.xml.ws.Dispatch;
import javax.xml.ws.EndpointReference;
import javax.xml.ws.Service;
import javax.xml.ws.WebServiceException;
import javax.xml.ws.WebServiceFeature;
import javax.xml.ws.Service.Mode;
import javax.xml.ws.handler.HandlerResolver;
import org.apache.axiom.om.OMElement;
import org.apache.axis2.client.ServiceClient;
import org.apache.axis2.context.ConfigurationContext;
import org.apache.axis2.java.security.AccessController;
import org.apache.axis2.jaxws.ExceptionFactory;
import org.apache.axis2.jaxws.addressing.util.EndpointReferenceUtils;
import org.apache.axis2.jaxws.client.PropertyMigrator;
import org.apache.axis2.jaxws.client.dispatch.JAXBDispatch;
import org.apache.axis2.jaxws.client.dispatch.XMLDispatch;
import org.apache.axis2.jaxws.client.proxy.JAXWSProxyHandler;
import org.apache.axis2.jaxws.context.listener.ProviderOMContextListener;
import org.apache.axis2.jaxws.description.DescriptionFactory;
import org.apache.axis2.jaxws.description.EndpointDescription;
import org.apache.axis2.jaxws.description.ServiceDescription;
import org.apache.axis2.jaxws.description.ServiceDescriptionWSDL;
import org.apache.axis2.jaxws.description.builder.DescriptionBuilderComposite;
import org.apache.axis2.jaxws.handler.HandlerResolverImpl;
import org.apache.axis2.jaxws.i18n.Messages;
import org.apache.axis2.jaxws.registry.FactoryRegistry;
import org.apache.axis2.jaxws.spi.migrator.ApplicationContextMigratorUtil;
import org.apache.axis2.jaxws.util.WSDLWrapper;
import org.apache.axis2.jaxws.utility.ExecutorFactory;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
/**
* The ServiceDelegate serves as the backing implementation for all of the methods in the {@link
* javax.xml.ws.Service} API. This is the plug point for the client implementation.
*/
public class ServiceDelegate extends javax.xml.ws.spi.ServiceDelegate {
private static final Log log = LogFactory.getLog(ServiceDelegate.class);
private static ThreadLocal sparseServiceCompositeThreadLocal = new ThreadLocal();
private static ThreadLocal sparsePortCompositeThreadLocal = new ThreadLocal();
private Executor executor;
private ServiceDescription serviceDescription;
private QName serviceQname;
private ServiceClient serviceClient = null;
private HandlerResolver handlerResolver = null;
/**
* NON-STANDARD SPI! Set any metadata to be used on the creation of the NEXT Service by this thread.
* NOTE that this uses ThreadLocal to store the metadata, and that ThreadLocal is cleared after it is
* used to create a Service. That means:
* 1) The thread that sets the metadata to use MUST be the thread that creates the Service
* 2) Creation of the Service should be the very next thing the thread does
* 3) The metadata will be set to null when the Service is created, so to create another
* service with the same metadata, it will need to be set again prior to creating the
* service
* 4) The metadata can be set prior to creating both generic Service and generated Service
* instances.
*
* This allows creating a generic Service (javax.xml.ws.Service) or a generated Service
* (subclass of javax.xml.ws.Service) specifying additional metadata via a
* sparse composite. This can be used by a runtime to create a Service for a requester using
* additional metadata such as might come from a deployment descriptor or from resource
* injection processing of @Resource or @WebServiceRef(s) annotations. Additional metadata
* may include things like @WebServiceClient.wsdlLocation or a @HandlerChain specification.
*
* @see javax.xml.ws.Service#create(QName)
* @see javax.xml.ws.Service#create(URL, QName)
*
* @param composite Additional metadata (if any) to be used in creation of the service
*/
static public void setServiceMetadata(DescriptionBuilderComposite composite) {
sparseServiceCompositeThreadLocal.set(composite);
}
/**
* NON-STANDARD SPI! Returns the composite that will be used on the creation of the next
* Service by this thread.
*
* @see #setServiceMetadata(DescriptionBuilderComposite)
*
* @return composite that will be used on the creation of the next Service by this thread, or null
* if no composite is to be used.
*/
static DescriptionBuilderComposite getServiceMetadata() {
return sparseServiceCompositeThreadLocal.get();
}
/**
* Remove any composite so that creation of the next Service by this thread will NOT be
* affected by any additional metadata.
*
* @see #setServiceMetadata(DescriptionBuilderComposite)
*
*/
static void resetServiceMetadata() {
sparseServiceCompositeThreadLocal.set(null);
}
/**
* NON-STANDARD SPI! Set any metadata to be used on the creation of the NEXT Port by this thread.
* NOTE that this uses ThreadLocal to store the metadata, and that ThreadLocal is cleared after it is
* used to create a Port. That means:
* 1) The thread that sets the metadata to use MUST be the thread that creates the Port
* 2) Creation of the Port should be the very next thing the thread does
* 3) The metadata will be set to null when the Port is created, so to create another
* Port with the same metadata, it will need to be set again prior to creating the
* Port
* 4) The metadata can be set prior to creating Port which specifies a QName via
* Service.getPort(QName, Class) or one that only specifies the SEI class via
* Service.getPort(Class)
* 5) Metadata can not be specified for dynamic ports, i.e. those added via
* Service.addPort(...).
* 6) Metadata can not be specfied when creating a dispatch client, i.e. via
* Service.createDispatch(...)
* 7) The Service used to create the port can be the generic service or a generated
* service.
*
* This allows creating Port specifying additional metadata via a sparse composite.
* This can be used by a runtime to create a Port for a requester using
* additional metadata such as might come from a deployment descriptor or from resource
* injection processing. Additional metadata might include things like
* a @HandlerChain specification.
*
* @see javax.xml.ws.Service#getPort(Class)
* @see javax.xml.ws.Service#getPort(QName, Class)
*
* @param composite Additional metadata (if any) to be used in creation of the port
*/
static public void setPortMetadata(DescriptionBuilderComposite composite) {
sparsePortCompositeThreadLocal.set(composite);
}
/**
* NON-STANDARD SPI! Returns the composite that will be used on the creation of the next
* Port by this thread.
*
* @see #setPortMetadata(DescriptionBuilderComposite)
*
* @return composite that will be used on the creation of the next Port by this thread, or null
* if no composite is to be used.
*/
static DescriptionBuilderComposite getPortMetadata() {
return sparsePortCompositeThreadLocal.get();
}
/**
* Remove any composite so that creation of the next Port by this thread will NOT be
* affected by any additional metadata.
*
* @see #setPortMetadata(DescriptionBuilderComposite)
*
*/
static void resetPortMetadata() {
sparsePortCompositeThreadLocal.set(null);
}
public ServiceDelegate(URL url, QName qname, Class clazz, WebServiceFeature... features) throws WebServiceException {
super();
this.serviceQname = qname;
if (!isValidServiceName()) {
throw ExceptionFactory
.makeWebServiceException(Messages.getMessage("serviceDelegateConstruct0", ""));
}
if ((features != null) && (features.length != 0)) {
throw ExceptionFactory
.makeWebServiceException(Messages.getMessage("serviceDelegateConstruct2", serviceQname.toString()));
}
// Get any metadata that is to be used to build up this service, then reset it so it isn't used
// to create any other services.
DescriptionBuilderComposite sparseComposite = getServiceMetadata();
resetServiceMetadata();
if (sparseComposite != null) {
serviceDescription = DescriptionFactory.createServiceDescription(url, serviceQname, clazz, sparseComposite, this);
} else {
serviceDescription = DescriptionFactory.createServiceDescription(url, serviceQname, clazz);
}
// TODO: This check should be done when the Service Description is created above; that should throw this exception.
// That is because we (following the behavior of the RI) require the WSDL be fully specified (not partial) on the client
if (isValidWSDLLocation()) {
if (!isServiceDefined(serviceQname)) {
throw ExceptionFactory.makeWebServiceException(Messages.getMessage(
"serviceDelegateConstruct0", serviceQname.toString(), url.toString()));
}
}
//TODO: Is this the best place for this code?
ConfigurationContext context = serviceDescription.getAxisConfigContext();
// Register the necessary ApplicationContextMigrators
ApplicationContextMigratorUtil.addApplicationContextMigrator(context,
Constants.APPLICATION_CONTEXT_MIGRATOR_LIST_ID, new PropertyMigrator());
}
//================================================
// JAX-WS API methods
//================================================
/*
* (non-Javadoc)
* @see javax.xml.ws.spi.ServiceDelegate#addPort(javax.xml.namespace.QName, java.lang.String, java.lang.String)
*/
// Creates a DISPATCH ONLY port. Per JAXWS Sec 4.1 javax.xm..ws.Service, p. 49, ports added via addPort method
// are only suitibale for creating Distpach instances.
public void addPort(QName portName, String bindingId, String endpointAddress)
throws WebServiceException {
verifyServiceDescriptionActive();
if (log.isDebugEnabled()) {
log.debug("Calling addPort : ("
+ portName + "," + bindingId + "," + endpointAddress + ")");
}
if(endpointAddress!=null && endpointAddress.trim().length()==0){
ExceptionFactory.makeWebServiceException(Messages.getMessage("addPortErr1", (portName!=null)?portName.getLocalPart():"", endpointAddress));
}
EndpointDescription endpointDesc =
DescriptionFactory.updateEndpoint(serviceDescription, null, portName,
DescriptionFactory.UpdateType.ADD_PORT, this, bindingId, endpointAddress);
// TODO: Need to set endpointAddress and set or check bindingId on the EndpointDesc
endpointDesc.setEndpointAddress(endpointAddress);
endpointDesc.setClientBindingID(bindingId);
}
/*
* (non-Javadoc)
* @see javax.xml.ws.spi.ServiceDelegate#createDispatch(javax.xml.namespace.QName, java.lang.Class, javax.xml.ws.Service.Mode)
*/
public Dispatch createDispatch(QName portName, Class type, Mode mode)
throws WebServiceException {
return createDispatch(portName, type, mode, (WebServiceFeature[]) null);
}
/*
* (non-Javadoc)
* @see javax.xml.ws.spi.ServiceDelegate#createDispatch(javax.xml.namespace.QName, javax.xml.bind.JAXBContext, javax.xml.ws.Service.Mode)
*/
public Dispatch createDispatch(QName portName, JAXBContext context, Mode mode) {
return createDispatch(portName, context, mode, (WebServiceFeature[]) null);
}
@Override
public Dispatch createDispatch(EndpointReference jaxwsEPR, Class type, Mode mode, WebServiceFeature... features) {
if (log.isDebugEnabled()) {
log.debug("Create Dispatch with epr: " + jaxwsEPR);
}
verifyServiceDescriptionActive();
if (jaxwsEPR == null) {
throw ExceptionFactory
.makeWebServiceException(Messages.getMessage("dispatchNoEndpointReference"));
}
if (!isValidDispatchType(type)) {
throw ExceptionFactory
.makeWebServiceException(Messages.getMessage("dispatchInvalidType"));
}
if (!isValidDispatchTypeWithMode(type, mode)) {
throw ExceptionFactory
.makeWebServiceException(Messages.getMessage("dispatchInvalidTypeWithMode"));
}
org.apache.axis2.addressing.EndpointReference axis2EPR =
EndpointReferenceUtils.createAxis2EndpointReference("");
String addressingNamespace = null;
try {
addressingNamespace = EndpointReferenceUtils.convertToAxis2(axis2EPR, jaxwsEPR);
}
catch (Exception e) {
throw ExceptionFactory.
makeWebServiceException(Messages.getMessage("invalidEndpointReference",
e.toString()));
}
EndpointDescription endpointDesc =
DescriptionFactory.updateEndpoint(serviceDescription, null, axis2EPR,
addressingNamespace,
DescriptionFactory.UpdateType.CREATE_DISPATCH,
this);
if (endpointDesc == null) {
throw ExceptionFactory.makeWebServiceException(
Messages.getMessage("endpointDescriptionConstructionFailure",
jaxwsEPR.toString()));
}
XMLDispatch dispatch = new XMLDispatch(this, endpointDesc, axis2EPR, addressingNamespace, features);
if (mode != null) {
dispatch.setMode(mode);
} else {
dispatch.setMode(Service.Mode.PAYLOAD);
}
if (serviceClient == null)
serviceClient = getServiceClient(endpointDesc.getPortQName());
if(type == OMElement.class) {
if (log.isDebugEnabled()) {
log.debug("This a Dispatch. The custom builder is installed.");
}
ProviderOMContextListener.create(serviceClient.getServiceContext());
}
dispatch.setServiceClient(serviceClient);
dispatch.setType(type);
return dispatch;
}
@Override
public Dispatch