繁体   English   中英

在resources.groovy中连接wsclient Web服务

[英]Wiring wsclient Webservices in resources.groovy

我遇到的情况是,我需要能够在三个经典环境中将数据挖掘下来:dev,itg和CAT。 我的Web服务控制器中有工作代码,但由于两个原因,现在将该逻辑分解为自己的服务。 首先,要分开关注点,其次是更好的性能。 将Webservice初始化保留在控制器中意味着每次从控制器调用wsdl到groovy对象的转换都会重复一次,这是不理想的。

但是,在尝试将它们连接在一起时,我总是收到初始化错误。

spring.GrailsRuntimeConfigurator [RuntimeConfiguration] Unable to load beans from resources.groovy
org.codehaus.groovy.runtime.InvokerInvocationException: groovy.lang.MissingMethodException: No signature of method: static org.grails.plugins.wsclient.service.WebService.getClient() is applicable for argument types: (java.lang.String) values: [WSDL-LOCATION-HERE]
Possible solutions: getClient(java.lang.String), getClient(java.lang.String, groovyx.net.ws.cxf.SoapVersion), getClass(), getAt(java.lang.String)

令人反感的代码是:

// Place your Spring DSL code here
import org.grails.plugins.wsclient.service.WebService;
beans = {

    itgFilenetService(testbed.webservices.FileNetService) { 
        wsdlLocation = "WSDL-LOCATION-HERE"
        webService = WebService.getClient(wsdlLocation)
    }

//  FileNetController(testbed.webservices){
//      fileNet = itgFilenetService
//  }

}

我知道我在这里做错了什么,因为显然... WebService.getClient(String)过去已经是合法的构造器了……我想念的是什么?

我在这里尝试提出建议:

def ib = [

    afterPropertiesSet:{
        itgWebService = WebService.getClient("WSDL")
        catWebService = WebService.getClient("WSDL")
        }

    ] as InitializingBean

但是此代码从未在运行时被调用。
我意识到(现在),一个大问题是将Webservice.getClient()视为静态调用。 我以前没有做过,但是很好...边做边学...解决了以下问题:

有两种方法可以解决您的问题。

首先,尝试在服务上实现InitializingBean ,然后将代码移入afterPropertiesSet()。 我怀疑这将解决您的问题,并为您提供更清洁的实施方案。

但是,如果由于某种原因无法正常工作(也许某种程度上该插件的资源不可用,尽管那时应该已经全部可用),则可以随时将代码移至Bootstrap.groovy中。

我建议尝试第一种选择。

根据ws-client插件的文档(http://www.grails.org/plugin/ws-client),.getClient(String)不是静态方法,因此您需要在WebService对象上调用它,而不是班级。 那就是MME的来源。

如果要在resources.groovy中执行此操作,请尝试使用Spring的MethodInvokingFactoryBean

webService(org.grails.plugins.wsclient.service.WebService)

parsedWsdlWSClient(org.springframework.beans.factory.config.MethodInvokingFactoryBean) {
    targetObject = ref('webService')
    targetMethod = 'getClient'
    arguments = ["WSDL-LOCATION-HERE"]
}

itgFilenetService(testbed.webservices.FileNetService) { 
    webService = ref('parsedWsdlWSClient')
}

注意,那么, itgFilenetService.webService将是一个实例WSClient ,不WebService

或者,如果您想利用Grails自动装配,可以将def parsedWsdlWSClient添加到需要它的Grails服务中,并跳过resources.groovy中的分配步骤。

解:

根本不是采用“ grails-y”方式,而是因为即使在意识到静态调用的错误之后,我也无法自动装配才能工作,所以我需要做一些事情。

我最终将常规代码拖入Java类,然后在服务中引用了它。

服务代码:

    static class FileNetService {
         FilenetUtils fu = new FilenetUtils();
         // methods
    }

FilenetUtils:

导入groovyx.net.ws.WSClient;

导入org.grails.plugins.wsclient.service.WebService;

public class FilenetUtils {
    WebService webService = new WebService();

    private static groovyx.net.ws.WSClient itgWebService = null; 
    private static groovyx.net.ws.WSClient catWebService = null;

FilenetUtils()  {
        itgWebService = (WSClient) webService.getClient(FILENET_ITG_URL);
        catWebService = (WSClient) webService.getClient(FILENET_CAT_URL);
    }
//More methods, etc.
}

有用。 我想布线,但是我无法及时完成。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM