Web サービスクライアントのテストプログラムを Maven から TestNG で実行すると、下記のスタックトレースが出力される。

javax.xml.ws.WebServiceException: Cannot dispatch message
	at org.jboss.ws.core.jaxws.client.DispatchImpl$AsyncRunnable.handleAsynInvokeException(DispatchImpl.java:529)
	at org.jboss.ws.core.jaxws.client.DispatchImpl$AsyncRunnable.run(DispatchImpl.java:503)
	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:441)
	at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
	at java.util.concurrent.FutureTask.run(FutureTask.java:138)
	at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
	at java.lang.Thread.run(Thread.java:619)
Caused by: java.lang.UnsupportedOperationException: setProperty must be overridden by all subclasses of SOAPMessage
	at javax.xml.soap.SOAPMessage.setProperty(SOAPMessage.java:445)
	at org.jboss.ws.core.soap.SOAPMessageImpl.<init>(SOAPMessageImpl.java:87)
	at org.jboss.ws.core.soap.MessageFactoryImpl.createMessage(MessageFactoryImpl.java:169)
	at org.jboss.ws.core.jaxws.client.DispatchSOAPBinding.getRequestMessage(DispatchSOAPBinding.java:121)
	at org.jboss.ws.core.jaxws.client.DispatchImpl.getRequestMessage(DispatchImpl.java:450)
	at org.jboss.ws.core.jaxws.client.DispatchImpl.invokeInternalSOAP(DispatchImpl.java:183)
	at org.jboss.ws.core.jaxws.client.DispatchImpl.invokeInternal(DispatchImpl.java:170)
	at org.jboss.ws.core.jaxws.client.DispatchImpl.access$000(DispatchImpl.java:91)
	at org.jboss.ws.core.jaxws.client.DispatchImpl$AsyncRunnable.run(DispatchImpl.java:498)

rt.jarjavax.xml.soap.SOAPMessage がロードされてしまっているため。
pom.xml に下記を追加する。

      <plugin>
        <groupid>org.apache.maven.plugins</groupid>
        <artifactid>maven-surefire-plugin</artifactid>
        <configuration>
          <suitexmlfiles>
            <suitexmlfile>src/test/resources/testng.xml</suitexmlfile>
          </suitexmlfiles>
          <argline>-Djava.endorsed.dirs=${endorsed.dir}</argline>
        </configuration>
      </plugin>

endorsed.dir」で指定するフォルダには、下記のファイルを入れておく($JBOSS_HOME/lib の中と一緒)

  • jaxb-api.jar
  • jbossws-native-jaxrpc.jar
  • jbossws-native-jaxws-ext.jar
  • jbossws-native-jaxws.jar
  • jbossws-native-saaj.jar
  • serializer.jar
  • xalan.jar
  • xercesImpl.jar

ちなみにバージョンは

  • Maven : 2.2
  • TestNG : 5.9
  • JBossWS : 3.1.1.GA

参考URL