Saturday, October 21, 2017

Weird error when invoking soap - llegalAccessError: tried to access field org.apache.cxf.staxutils.OverlayW3CDOMStreamWriter.isOverlaid

Leave a Comment

Ive been working on a soap client since a time and I still cannot figure it out.

I have this error:

Exception in thread "main" java.lang.IllegalAccessError: tried to access field org.apache.cxf.staxutils.OverlayW3CDOMStreamWriter.isOverlaid from class org.apache.cxf.binding.soap.saaj.SAAJStreamWriter         at org.apache.cxf.binding.soap.saaj.SAAJStreamWriter.getPrefix(SAAJStreamWriter.java:79)         at org.apache.cxf.binding.soap.interceptor.SoapOutInterceptor.writeSoapEnvelopeStart(SoapOutInterceptor.java:109)         at org.apache.cxf.binding.soap.interceptor.SoapOutInterceptor.handleMessage(SoapOutInterceptor.java:87)         at org.apache.cxf.binding.soap.interceptor.SoapOutInterceptor.handleMessage(SoapOutInterceptor.java:67)         at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:308)         at org.apache.cxf.endpoint.ClientImpl.doInvoke(ClientImpl.java:514)         at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:423)         at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:324)         at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:277)         at org.apache.cxf.endpoint.ClientImpl.invokeWrapped(ClientImpl.java:312)         at org.apache.cxf.jaxws.DispatchImpl.invoke(DispatchImpl.java:321)         at org.apache.cxf.jaxws.DispatchImpl.invoke(DispatchImpl.java:240)         at com.sigetel.web.web.rest.consumer.SoapClient.invoke(SoapClient.java:63)         at com.sigetel.web.web.rest.consumer.SoapClient.main(SoapClient.java:37)     Disconnected from the target VM, address: '127.0.0.1:60128', transport: 'socket'  Process finished with exit code 1 

I saw its kinda common but still cannot make it work.

Here is my code:

 Dispatch<SOAPMessage> dispatch = service.createDispatch(portName, SOAPMessage.class, Service.Mode.MESSAGE);         SOAPMessage response;         SOAPBody responseBody;         dispatch.getRequestContext().put(Dispatch.SOAPACTION_USE_PROPERTY, true);         dispatch.getRequestContext().put(Dispatch.SOAPACTION_URI_PROPERTY, soapActionUri);         try {             MessageFactory messageFactory = MessageFactory.newInstance();             SOAPMessage message = messageFactory.createMessage();             SOAPPart soapPart = message.getSOAPPart();             StreamSource msgSrc = new StreamSource(new StringReader(request));             soapPart.setContent(msgSrc);             message.saveChanges();               response = dispatch.invoke(message);             responseBody = response.getSOAPBody(); .... 

Reelevant dependencies that might be related:

<dependency>             <groupId>org.apache.cxf</groupId>             <artifactId>cxf-rt-transports-http-jetty</artifactId>             <version>3.1.6</version>         </dependency>          <dependency>             <groupId>com.sun.jersey</groupId>             <artifactId>jersey-client</artifactId>             <version>1.8</version>         </dependency>          <dependency>             <groupId>com.sun.jersey</groupId>             <artifactId>jersey-core</artifactId>             <version>1.9</version>         </dependency>          <dependency>             <groupId>javax.xml.ws</groupId>             <artifactId>jaxws-api</artifactId>             <version>2.2.11</version>         </dependency>          <dependency>             <groupId>org.apache.ws.security</groupId>             <artifactId>wss4j</artifactId>             <version>1.6.11</version>         </dependency> 

EDITED:

and these ones:

<dependency>     <groupId>org.apache.cxf</groupId>     <artifactId>cxf-spring-boot-starter-jaxws</artifactId>     <version>3.1.11</version> </dependency> 

Any idea about this error?

2 Answers

Answers 1

As you may have already noticed, you have incompatible versions of SAAJStreamWriter and OverlayW3CDOMStreamWriter.

SAAJStreamWriter is located in package cxf-rt-bindings-soap, which is provided by:

<dependency>     <groupId>org.apache.cxf</groupId>     <artifactId>cxf-spring-boot-starter-jaxws</artifactId>     <version>3.1.11</version> </dependency> 

OverlayW3CDOMStreamWriter is located in pachage cxf-core, which is provided by:

<dependency>     <groupId>org.apache.cxf</groupId>     <artifactId>cxf-rt-transports-http-jetty</artifactId>     <version>3.1.6</version> </dependency> 

Try one of the latest versions of org.apache.cxf - 3.1.13 or 3.2.0 - the same version for both dependencies.

Answers 2

You are pulling incorrect version of OverlayW3CDOMStreamWriter.

SAAJStreamWriter extends OverlayW3CDOMStreamWriter which has isOverlaid field.

The isOverlaid was changed from package private to protected in 3.2 version and was backported to 3.1.7 version so it can accessed in sub class SAAJStreamWriter

Both the below dependencies is pulling cxf core which has OverlayW3CDOMStreamWriter

1.

<dependency>     <groupId>org.apache.cxf</groupId>     <artifactId>cxf-spring-boot-starter-jaxws</artifactId>     <version>3.1.11</version> </dependency> 

cxf-rt-frontend-jaxws - cxf-rt-bindings-soap - 3.1.11 for SAAJStreamWriter

cxf-rt-transports-http - cxf-core - 3.1.11 for OverlayW3CDOMStreamWriter

2.

<dependency>     <groupId>org.apache.cxf</groupId>     <artifactId>cxf-rt-transports-http-jetty</artifactId>     <version>3.1.6</version> </dependency> 

cxf-rt-transports-http - cxf-core - 3.1.6 for OverlayW3CDOMStreamWriter

cxf core 3.1.6 was chosen over 3.1.11 since it is nearer as by default maven resolves version conflicts with a nearest-wins strategy.

So in essence 3.1.11 SAAJStreamWriter class was expecting 3.1.11 OverlayW3CDOMStreamWriter but found 3.1.6 OverlayW3CDOMStreamWriter where the isOverlaid was package private and is the reason for your error.

Fix change to use 3.1.11 for jetty dependency or atleast use version 3.1.7 for both above dependencies.

<dependency>     <groupId>org.apache.cxf</groupId>     <artifactId>cxf-rt-transports-http-jetty</artifactId>     <version>3.1.11</version> </dependency> 

This will pull the 3.1.11 for both cxf core and cxf bindings and should resolve the error.

If You Enjoyed This, Take 5 Seconds To Share It

0 comments:

Post a Comment