servicedelegate.java
来自「开源的axis2框架的源码。用于开发WEBSERVER」· Java 代码 · 共 493 行 · 第 1/2 页
JAVA
493 行
// First, let's try loading the interfaces with the SEI classLoader
ClassLoader classLoader = getClassLoader(sei);
try {
interfaces = loadClasses(classLoader, interfacesNames);
} catch (ClassNotFoundException e1) {
// Let's try with context classLoader now
classLoader = getContextClassLoader();
try {
interfaces = loadClasses(classLoader, interfacesNames);
} catch (ClassNotFoundException e2) {
// TODO: NLS
throw ExceptionFactory.makeWebServiceException("Unable to load proxy classes", e2);
}
}
JAXWSProxyHandler proxyHandler = new JAXWSProxyHandler(this, interfaces[0], endpointDesc);
Object proxyClass = Proxy.newProxyInstance(classLoader, interfaces, proxyHandler);
return sei.cast(proxyClass);
}
/*
* (non-Javadoc)
* @see javax.xml.ws.spi.ServiceDelegate#getExecutor()
*/
public Executor getExecutor() {
//FIXME: Use client provider executor too.
if (executor == null) {
executor = getDefaultExecutor();
}
return executor;
}
/*
* (non-Javadoc)
* @see javax.xml.ws.spi.ServiceDelegate#getHandlerResolver()
*/
public HandlerResolver getHandlerResolver() {
if (handlerResolver == null) {
handlerResolver = new HandlerResolverImpl(serviceDescription);
}
return handlerResolver;
}
/*
* (non-Javadoc)
* @see javax.xml.ws.spi.ServiceDelegate#getPorts()
*/
public Iterator<QName> getPorts() {
return getServiceDescription().getPorts().iterator();
}
/*
* (non-Javadoc)
* @see javax.xml.ws.spi.ServiceDelegate#getServiceName()
*/
public QName getServiceName() {
return serviceQname;
}
/*
* (non-Javadoc)
* @see javax.xml.ws.spi.ServiceDelegate#getWSDLDocumentLocation()
*/
public URL getWSDLDocumentLocation() {
return ((ServiceDescriptionWSDL)serviceDescription).getWSDLLocation();
}
/*
* (non-Javadoc)
* @see javax.xml.ws.spi.ServiceDelegate#setExecutor(java.util.concurrent.Executor)
*/
public void setExecutor(Executor e) {
if (e == null) {
throw ExceptionFactory
.makeWebServiceException(Messages.getMessage("cannotSetExcutorToNull"));
}
executor = e;
}
/*
* (non-Javadoc)
* @see javax.xml.ws.spi.ServiceDelegate#setHandlerResolver(javax.xml.ws.handler.HandlerResolver)
*/
public void setHandlerResolver(HandlerResolver handlerresolver) {
this.handlerResolver = handlerresolver;
}
//================================================
// Internal public APIs
//================================================
/** Get the ServiceDescription tree that this ServiceDelegate */
public ServiceDescription getServiceDescription() {
return serviceDescription;
}
//TODO Change when ServiceDescription has to return ServiceClient or OperationClient
/**
*
*/
public ServiceClient getServiceClient(QName portQName) throws WebServiceException {
return serviceDescription.getServiceClient(portQName);
}
//================================================
// Impl methods
//================================================
//TODO: Need to make the default number of threads configurable
private Executor getDefaultExecutor() {
ExecutorFactory executorFactory = (ExecutorFactory) FactoryRegistry.getFactory(
ExecutorFactory.class);
return executorFactory.getExecutorInstance();
}
private boolean isValidServiceName() {
return serviceQname != null && !"".equals(serviceQname.toString().trim());
}
private boolean isValidWSDLLocation() {
URL wsdlLocation = getWSDLDocumentLocation();
return wsdlLocation != null && !"".equals(wsdlLocation.toString().trim());
}
// TODO: Remove this method and put the WSDLWrapper methods on the ServiceDescriptor directly
private WSDLWrapper getWSDLWrapper() {
return ((ServiceDescriptionWSDL)serviceDescription).getWSDLWrapper();
}
private boolean isServiceDefined(QName serviceName) {
return getWSDLWrapper().getService(serviceName) != null;
}
private BindingImpl addBinding(EndpointDescription endpointDesc, String bindingId) {
// TODO: before creating binding do I have to do something with Handlers ... how is Binding related to Handler, this mistry sucks!!!
if (bindingId != null) {
//TODO: create all the bindings here
if (bindingId.equals(SOAPBinding.SOAP11HTTP_BINDING)) {
//instantiate soap11 binding implementation here and call setBinding in BindingProvider
return new org.apache.axis2.jaxws.binding.SOAPBinding(endpointDesc);
}
if (bindingId.equals(SOAPBinding.SOAP12HTTP_BINDING)) {
//instantiate soap11 binding implementation here and call setBinding in BindingProvider
return new org.apache.axis2.jaxws.binding.SOAPBinding(endpointDesc);
}
if (bindingId.equals(HTTPBinding.HTTP_BINDING)) {
//instantiate http binding implementation here and call setBinding in BindingProvider
return new org.apache.axis2.jaxws.binding.HTTPBinding(endpointDesc);
}
}
return new org.apache.axis2.jaxws.binding.SOAPBinding(endpointDesc);
}
private boolean isValidDispatchType(Class clazz) {
return clazz != null && (clazz == String.class ||
clazz == Source.class ||
clazz == DataSource.class ||
clazz == SOAPMessage.class);
}
/** @return ClassLoader */
private static ClassLoader getClassLoader(final Class cls) {
// NOTE: This method must remain private because it uses AccessController
ClassLoader cl = null;
try {
cl = (ClassLoader)AccessController.doPrivileged(
new PrivilegedExceptionAction() {
public Object run() throws ClassNotFoundException {
return cls.getClassLoader();
}
}
);
} catch (PrivilegedActionException e) {
if (log.isDebugEnabled()) {
log.debug("Exception thrown from AccessController: " + e);
}
throw ExceptionFactory.makeWebServiceException(e.getException());
}
return cl;
}
/** @return ClassLoader */
private static ClassLoader getContextClassLoader() {
// NOTE: This method must remain private because it uses AccessController
ClassLoader cl = null;
try {
cl = (ClassLoader)AccessController.doPrivileged(
new PrivilegedExceptionAction() {
public Object run() throws ClassNotFoundException {
return Thread.currentThread().getContextClassLoader();
}
}
);
} catch (PrivilegedActionException e) {
if (log.isDebugEnabled()) {
log.debug("Exception thrown from AccessController: " + e);
}
throw ExceptionFactory.makeWebServiceException(e.getException());
}
return cl;
}
/**
* Return the class for this name
*
* @return Class
*/
private static Class forName(final String className, final boolean initialize,
final ClassLoader classLoader) throws ClassNotFoundException {
// NOTE: This method must remain protected because it uses AccessController
Class cl = null;
try {
cl = (Class)AccessController.doPrivileged(
new PrivilegedExceptionAction() {
public Object run() throws ClassNotFoundException {
return Class.forName(className, initialize, classLoader);
}
}
);
} catch (PrivilegedActionException e) {
if (log.isDebugEnabled()) {
log.debug("Exception thrown from AccessController: " + e);
}
throw (ClassNotFoundException)e.getException();
}
return cl;
}
private static Class[] loadClasses(ClassLoader classLoader, String[] classNames)
throws ClassNotFoundException {
Class[] classes = new Class[classNames.length];
for (int i = 0; i < classNames.length; i++) {
classes[i] = forName(classNames[i], true, classLoader);
}
return classes;
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?