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

📄 xfireclientfactorybean.java

📁 Xfire文件 用于开发web service 的一个开源工具 很好用的
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
        _password = password;    }        /**     * The properties that will be set on the Client.     */    public Map getProperties()    {        return _properties;    }    /**     * Set the properties for the Client.     */    public void setProperties(Map properties)    {        this._properties = properties;    }    public QName getEndpoint()    {        return _endpointName;    }    /**     * Set the name of the Endpoint/Port in the WSDL to use with the Client.     *      * @param name     */    public void setEndpoint(QName name)    {        _endpointName = name;    }    public String getUrl()    {        return _url;    }    /**     * Set the URL the Client is to invoke. If this is not supplied, the one from the     * WSDL will be used instead.     * @return     */    public void setUrl(String _url)    {        this._url = _url;    }    public List getFaultHandlers()    {        return faultHandlers;    }    public void setFaultHandlers(List faultHandlers)    {        this.faultHandlers = faultHandlers;    }    public List getInHandlers()    {        return inHandlers;    }    public void setInHandlers(List inHandlers)    {        this.inHandlers = inHandlers;    }    public List getOutHandlers()    {        return outHandlers;    }    public void setOutHandlers(List outHandlers)    {        this.outHandlers = outHandlers;    }    /**     * Creates actual XFire client proxy that this interceptor will delegate to.     *      * @throws Exception     *             if the client proxy could not be created.     */    private Object createClient()        throws Exception    {        Object serviceClient = makeClient();        Class interf = getServiceInterface();        if (LOG.isDebugEnabled())        {            LOG.debug("Created: " + toString());        }        Client client = Client.getInstance(serviceClient);                String username = getUsername();        if (username != null)        {            client.setProperty(Channel.USERNAME, username);            String password = getPassword();            client.setProperty(Channel.PASSWORD, password);            if (LOG.isDebugEnabled())            {                LOG.debug("Enabled HTTP basic authentication for: " + interf + " with username: "                        + username);            }        }                configureClientHandlers(client);                return serviceClient;    }        /**     * Configures the client with the specified inHandlers, outHandlers and     * faultHandlers.     *      * @param client     */    private void configureClientHandlers(Client client)    {        if (this.inHandlers != null)        {            client.getInHandlers().addAll(inHandlers);        }        if (this.outHandlers != null)        {            client.getOutHandlers().addAll(outHandlers);        }        if (this.faultHandlers != null)        {            client.getFaultHandlers().addAll(faultHandlers);        }    }        /**     * Performs actual creation of XFire client proxy.     *      * @return XFire proxy to the service     * @throws java.net.MalformedURLException     *             if {@link XFireProxyFactory#create} threw one     */    private Object makeClient()        throws Exception    {        String serviceName = getServiceName();        String namespace = getNamespaceUri();        Service serviceModel;        if (_wsdlDocumentUrl == null)        {            serviceModel = getServiceFactory().create(getServiceInterface(),                                                      serviceName,                                                      namespace,                                                      _properties);                    }        else        {            QName name = null;            if (serviceName != null && namespace != null)            {                name = new QName(namespace, serviceName);            }                        Resolver resolver = new Resolver(_wsdlDocumentUrl);            URI uri = resolver.getURI();            if (uri == null)            {                throw new XFireRuntimeException("Could not resolve uri " + uri);            }                        serviceModel = getServiceFactory().create(getServiceInterface(),                                                      name,                                                      uri.toURL(),                                                      _properties);        }        String serviceUrl = getUrl();        if (serviceUrl != null)         {            return new XFireProxyFactory().create(serviceModel, serviceUrl);        }                if (_endpointName == null)        {            _endpointName = findFirstSoapEndpoint(serviceModel.getEndpoints());        }                if (_endpointName != null)        {            Endpoint ep = serviceModel.getEndpoint(_endpointName);            if (ep == null)                throw new IllegalStateException("Could not find endpoint with name " + _endpointName + " on service.");                        return new XFireProxyFactory().create(ep);        }        else            throw new IllegalStateException("A WSDL URL or service URL must be supplied.");    }    private QName findFirstSoapEndpoint(Collection endpoints)    {        for (Iterator itr = endpoints.iterator(); itr.hasNext();)        {            Endpoint ep = (Endpoint) itr.next();                        if (ep.getBinding() instanceof AbstractSoapBinding)                return ep.getName();        }        return null;    }    /**     * Gets the Definition contained in the WSDL document (does not currently support reading     * WSDL that is protected with authentication).     * @return Definition describing the service(s)     * @throws Exception if the definition could not be read     */    protected Definition getWSDLDefinition()        throws Exception    {        return WSDLFactory.newInstance().newWSDLReader().readWSDL(getWsdlDocumentUrl());    }    public String toString()    {        StringBuffer builder = new StringBuffer();        builder.append("XFire client proxy for: ");        builder.append(getServiceInterface());        if (getUrl() != null)        {            builder.append(" at: ");            builder.append(getUrl());        }                return builder.toString();    }    /**     * Interceptor for (i.e. proxy to) the actual XFire client proxy. This class     * performs lazy initialization of the XFire client proxy, which can come in     * handy if the service is not guaranteed to be available by the time the     * factory bean is used to created an instance, but will be available by the     * time the client is actually called.     * <p>     * This does add some overhead since synchronization is used to ensure only     * one client is ever allocated. Furthermore if there is a problem accessing     * the service it is not detected until the first call.     */    private class ProxyInterceptor        implements MethodInterceptor    {        // actual XFire client proxy        private Object _serviceClient;        public Object invoke(MethodInvocation invocation)            throws Throwable        {            if (_serviceClient == null)            {                if (AopUtils.isToStringMethod(invocation.getMethod()))                {                    // do not lookup service for toString()                    return "Un-initialized " + XFireClientFactoryBean.this.toString();                }            }            Method method = invocation.getMethod();            Object[] args = invocation.getArguments();            Object client = getClient();            try            {                return method.invoke(client, args);            }            catch (InvocationTargetException e)            {                Object target = SpringUtils.getUserTarget(client);                Client c = Client.getInstance(target);                StringBuffer callTarget = new StringBuffer(c.getUrl()).append(" arguments: ");                for(int x = 0 ; x < args.length ; x ++ )                {                    callTarget.append(args[x].getClass().getName()).append(" : ").append(args[x].toString()).append(" |");                }                Throwable targetException = e.getTargetException();                if (targetException instanceof XFireRuntimeException)                {                    // convert XFire runtime exception to one detailing call                    // made                    XFireRuntimeException xfRt = (XFireRuntimeException) targetException;                    Throwable cause = xfRt.getCause();                    throw new XFireRuntimeException("Exception while calling: " + callTarget.toString(), cause);                }                throw targetException;            }        }        /**         * Gets the actual client proxy. This implementation ensures only one         * client proxy is ever created, even in multi-threaded situations         *          * @return service client proxy         * @throws MalformedURLException         */        private synchronized Object getClient()            throws Exception        {            if (_serviceClient == null)            {                _serviceClient = createClient();            }            return _serviceClient;        }    }}

⌨️ 快捷键说明

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