⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 xfireclientfactorybean.java

📁 Xfire文件 用于开发web service 的一个开源工具 很好用的
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
package org.codehaus.xfire.spring.remoting;import java.lang.reflect.InvocationTargetException;import java.lang.reflect.Method;import java.net.MalformedURLException;import java.net.URI;import java.util.Collection;import java.util.Iterator;import java.util.List;import java.util.Map;import javax.wsdl.Definition;import javax.wsdl.factory.WSDLFactory;import javax.xml.namespace.QName;import org.aopalliance.intercept.MethodInterceptor;import org.aopalliance.intercept.MethodInvocation;import org.apache.commons.logging.Log;import org.apache.commons.logging.LogFactory;import org.codehaus.xfire.XFireRuntimeException;import org.codehaus.xfire.client.Client;import org.codehaus.xfire.client.XFireProxyFactory;import org.codehaus.xfire.service.Endpoint;import org.codehaus.xfire.service.Service;import org.codehaus.xfire.service.ServiceFactory;import org.codehaus.xfire.service.binding.ObjectServiceFactory;import org.codehaus.xfire.soap.AbstractSoapBinding;import org.codehaus.xfire.spring.SpringUtils;import org.codehaus.xfire.transport.Channel;import org.codehaus.xfire.util.Resolver;import org.springframework.aop.framework.ProxyFactory;import org.springframework.aop.support.AopUtils;import org.springframework.beans.factory.FactoryBean;import org.springframework.beans.factory.InitializingBean;/** * Factory bean to easily create XFire clients via Spring, if the service's Java * interface is available. Naming of properties is done to be the same as * {@link org.springframework.remoting.jaxrpc.JaxRpcPortProxyFactoryBean}.  * <br> * The only mandatory properties to set before using this factory are: * {@link #setServiceClass(Class)} and {@link #setWsdlDocumentUrl(String)}. * <br> * By default this factory bean creates a service endpoint using an instance of  * {@link org.codehaus.xfire.service.binding.ObjectServiceFactory}. Another one can * be configured using {@link #setServiceFactory(ServiceFactory)} * <br> * serviceName and namespaceUri can be derived from the content of the WSDL document  * (if the document only contains one service), but unfortunately that does not (yet)  * work if username/password needs to be supplied to get at the WSDL. *  * @author Fried Hoeben */public class XFireClientFactoryBean    implements FactoryBean, InitializingBean{    private static final Log LOG = LogFactory.getLog(XFireClientFactoryBean.class);    // client proxy, in case lookupServiceOnStartup == true    // proxy to the client proxy, otherwise    private Object _serviceProxy;    private Class _serviceClass;    private ServiceFactory _serviceFactory = new ObjectServiceFactory();    private String _wsdlDocumentUrl;    private String _serviceName;    private String _namespaceUri;    private String _username;    private String _password;    private String _url;        private QName _endpointName;        private Map _properties;        private boolean _lookupServiceOnStartup = true;        private List outHandlers = null;    private List inHandlers = null;    private List faultHandlers = null;        public Object getObject()        throws Exception    {        return _serviceProxy;    }    public Class getObjectType()    {        return (_serviceProxy != null) ? _serviceProxy.getClass() : getServiceClass();    }    public boolean isSingleton()    {        return true;    }    public void afterPropertiesSet()        throws Exception    {        if (getServiceClass() == null)        {            throw new IllegalStateException("serviceInterface is required");        }                ProxyInterceptor interceptor;        if (getLookupServiceOnStartup())        {            // create XFire client proxy directly            _serviceProxy = createClient();        }        else        {            // create proxy for XFire client proxy, this will create the XFire            // client proxy            // when it is first called            interceptor = new ProxyInterceptor();            _serviceProxy = ProxyFactory.getProxy(getServiceClass(), interceptor);        }    }    /**     * @return the service factory that this factory will use     */    public ServiceFactory getServiceFactory()    {        return _serviceFactory;    }    /**     * Sets the service factory that will be used to create a client. If this method is never     * called an instance of {@link org.codehaus.xfire.service.binding.ObjectServiceFactory} will     * be used.     *      * @param factory     *            service factory this factory should use to create a client     */    public void setServiceFactory(ServiceFactory factory)    {        if (factory == null)        {            throw new IllegalArgumentException("Can not set the service factory to null");        }        _serviceFactory = factory;    }    /**     * @return Returns the service's interface.     */    public Class getServiceClass()    {        return _serviceClass;    }    /**     * @param serviceClass     *            The interface implemented by the service called via the proxy.     */    public void setServiceInterface(Class serviceClass)    {        _serviceClass = serviceClass;    }    /**     * @return Returns the service's interface.     */    public Class getServiceInterface()    {        return _serviceClass;    }    /**     * @param serviceClass     *            The interface implemented by the service called via the proxy.     */    public void setServiceClass(Class serviceClass)    {        _serviceClass = serviceClass;    }        /**     * @return Returns the URL where the WSDL to this service can be found.     */    public String getWsdlDocumentUrl()    {        return _wsdlDocumentUrl;    }    /**     * @param wsdlUrl     *            The URL where the WSDL to this service can be found.     */    public void setWsdlDocumentUrl(String wsdlUrl)    {        _wsdlDocumentUrl = wsdlUrl.trim();    }    /**     * Gets the name of the service. If <code>null</code> the name will be     * looked up from the WSDL, or generated from the interface name by XFire.     *      * @return Returns the serviceName.     */    public String getServiceName()    {        return _serviceName;    }    /**     * Sets the name of the service to access. If left <code>null</code> the     * name will be looked up from the WSDL, or generated from the interface     * name by XFire.     *      * @param serviceName     *            The service name to set.     */    public void setServiceName(String serviceName)    {        _serviceName = serviceName;    }    /**     * Gets the default namespace for the service. If <code>null</code> the     * namespace will be looked up from the WSDL, or generated from the     * interface package by XFire.     *      * @return Returns the namespace for the service.     */    public String getNamespaceUri()    {        return _namespaceUri;    }    /**     * Sets the default namespace for the service. If left <code>null</code>     * the namespace will be looked up from the WSDL, or generated from the     * interface package by XFire.     *      * @param namespace     *            The namespace to set.     */    public void setNamespaceUri(String namespace)    {        _namespaceUri = namespace;    }    /**     * Gets whether to look up the XFire service on startup.     *      * @return whether to look up the service on startup.     */    public boolean getLookupServiceOnStartup()    {        return _lookupServiceOnStartup;    }    /**     * Sets whether to look up the XFire service on startup. Default is     * <code>true</code>.     * <p>     * Can be set to <code>false</code> to allow for late start of the target     * server. In this case, the XFire service client proxy will be created on     * first access. This does add some overhead (on each call) since     * synchronization is used to ensure only one client proxy is ever created,     * furthermore errors in the WSDL document URL are not detected until the     * first call.     *      * @param lookupServiceOnStartup     *            whether to look up the service on startup.     */    public void setLookupServiceOnStartup(boolean lookupServiceOnStartup)    {        _lookupServiceOnStartup = lookupServiceOnStartup;    }    /**     * Gets the username for HTTP basic authentication.     *      * @return Returns the username to send.     */    public String getUsername()    {        return _username;    }    /**     * Sets the username for HTTP basic authentication.     *      * @param username     *            The username to set.     */    public void setUsername(String username)    {        _username = username;    }    /**     * Gets the password for HTTP basic authentication.     *      * @return Returns the password to send.     */    public String getPassword()    {        return _password;    }    /**     * Sets the password for HTTP basic authentication.     *      * @param password     *            The password to set.     */    public void setPassword(String password)    {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -