无法在src / groovy中获取org.grails.plugins.wsclient.service.WebService?

时间:2012-02-02 15:58:02

标签: web-services grails groovy

我正在尝试在src / groovy中创建一个webservice类,但它给出了错误并且抱怨没有找到web服务。 请帮助我为什么不进入src / groovy。

import org.apache.cxf.transport.http.HTTPConduit
import org.grails.plugins.wsclient.service.WebService
class ConnectWebservice {
WebService webService   ///it complains that not found.

def static wsHandleMap = [:]
def static handle

 static def getProxy =  {url->
           def wsdlURL = url+"?wsdl"
        def proxy = webService.getClient(wsdlURL)  ////not get webService
        proxy?.initialize()

        proxy.metaClass.getCxfClient = { ->
            delegate.client
        }

        // get client instance
        def cxfClient = proxy.cxfClient
        // create new endpoint url
        URL newUrl = new URL(url)
        // assign new created url to the client
        cxfClient.getConduit().getTarget().getAddress().setValue(newUrl.toExternalForm());
        //Extra: to set timeout, use:
        proxy.client.conduit.clientSidePolicy.setReceiveTimeout(999)
        proxy.client.conduit.clientSidePolicy.setConnectionTimeout(999)

        //println proxy

        return proxy

}

2 个答案:

答案 0 :(得分:1)

所以这是在src/groovy里面?

默认情况下,服务不会被注入src/groovy中的文件中。

为了使这个工作,你应该考虑使这个类成为一个服务(如果可能的话,最简单的路由),否则你将需要register the class作为Spring bean来注入所需的服务和类

PS:你已经安装了WSClient插件吗?

答案 1 :(得分:0)

我得到了它的工作。改变了行 -

def proxy = webService.getClient(wsdlURL) 

TO

def proxy = new WSClient(wsdlURL,this.class.classLoader)