2

Groovy スクリプトで WSClient を使用して単純なパブリック Web サービスを呼び出そうとしていますが、初期化時に爆発します...

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 を使用するためのヒントはありますか?

4

1 に答える 1

2

GroovyWS ページに記載されているように、GroovyWS は現在休止中です。groovy-wslite ライブラリを使用して、同じことを行うことができます (ただし、より冗長な構文を使用します) 。

@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"

これは、GroovyWS バージョンのコードとは異なり、SOAP メッセージの名前空間を取得するために WSDL を調べる必要があることに注意してください。しかし、それはうまくいきます!

于 2013-07-12T01:47:37.233 に答える