2013-07-08 90 views
2

我試圖調用一個簡單的公共Web服務在Groovy腳本WSClient,但在初始化時它爆炸......Groovy:在WSClient拋出JAXBException

TestService.groovy:

@Grab(group='org.codehaus.groovy.modules', module='groovyws', version='0.5.2') 
import groovyx.net.ws.WSClient 

def proxy = new WSClient("http://www.w3schools.com/webservices/tempconvert.asmx?WSDL", this.class.classLoader) 
proxy.initialize(); 

def result = proxy.CelsiusToFahrenheit(0) 
println "You are probably freezing at ${result} degrees Farhenheit" 

錯誤消息:

SEVERE: Could not compile java files for http://www.w3schools.com/webservices/tempconvert.asmx?WSDL. 
Caught: java.lang.IllegalStateException: Unable to create JAXBContext for generated packages: Provider com.sun.xml.bind.v2.ContextFactory could not be instantiated: javax.xml.bind.JAXBException: "org.tempuri" doesnt contain ObjectFactory.class or jaxb.index 
java.lang.IllegalStateException: Unable to create JAXBContext for generated pack 
ages: Provider com.sun.xml.bind.v2.ContextFactory could not be instantiated: jav 
ax.xml.bind.JAXBException: "org.tempuri" doesnt contain ObjectFactory.class or j 
axb.index 
     at org.apache.cxf.endpoint.dynamic.DynamicClientFactory.createClient(DynamicClientFactory.java:343) 
     at org.apache.cxf.endpoint.dynamic.DynamicClientFactory.createClient(DynamicClientFactory.java:196) 
     at org.apache.cxf.endpoint.dynamic.DynamicClientFactory.createClient(DynamicClientFactory.java:175) 
     at groovyx.net.ws.AbstractCXFWSClient.createClient(AbstractCXFWSClient.java:229) 
     at groovyx.net.ws.WSClient.initialize(WSClient.java:108) 
     at groovyx.net.ws.IWSClient$initialize.call(Unknown Source) 
     at TestService.run(TestService.groovy:5) 
Caused by: javax.xml.bind.JAXBException: Provider com.sun.xml.bind.v2.ContextFactory could not be instantiated: javax.xml.bind.JAXBException: "org.tempuri" doesnt contain ObjectFactory.class or jaxb.index - with linked exception: 
[javax.xml.bind.JAXBException: "org.tempuri" doesnt contain ObjectFactory.classor jaxb.index] 
     at org.apache.cxf.endpoint.dynamic.DynamicClientFactory.createClient(DynamicClientFactory.java:340) 
     ... 6 more 
Caused by: javax.xml.bind.JAXBException: "org.tempuri" doesnt contain ObjectFactory.class or jaxb.index 
     at com.sun.xml.bind.v2.ContextFactory.createContext(ContextFactory.java:197) 
     ... 7 more 

任何提示?爲什麼我應該有一個jaxb.in​​dex?

剛剛發現,與Java 1.7(jdk1.7.0_21)出現問題......它與Java 6(jdk1.6.0_31)

任何暗示運行的Java 7工作的時候是OK?

+0

我的回答有幫助嗎? – jesseplymale

回答

2

the GroovyWS page所述,GroovyWS目前處於休眠狀態。

@Grab(group='com.github.groovy-wslite', module='groovy-wslite', version='0.8.0') 
import wslite.soap.* 

def client = new SOAPClient('http://www.w3schools.com/webservices/tempconvert.asmx') 
def response = client.send(SOAPAction:'http://tempuri.org/CelsiusToFahrenheit') { 
    body { 
     CelsiusToFahrenheit('xmlns':'http://tempuri.org/') { 
      Celsius('0') 
     } 
    } 
} 

def result = response.CelsiusToFahrenheitResponse.CelsiusToFahrenheitResult.text() 
println "You are probably freezing at ${result} degrees Farhenheit" 

請注意,這需要你來看看WSDL得到SOAP消息的命名空間,不同的代碼GroovyWS版本:你可以使用groovy-wslite library做同樣的事情(儘管有wordier語法)。但它的作品!

+0

出現以下錯誤:org.codehaus.groovy.control.MultipleCompilationErrorsException:啓動失敗: 轉換過程中的一般錯誤:錯誤抓取Grapes - [未解析的依賴關係 :com.github.groovy-wslite#groovy-wslite; 0.8.0 :未找到] – pinei

+0

剛配置的代理屬性和相關性已解決。該腳本運作良好。謝謝。 – pinei

相關問題