WebService InvocationTargetException

别来无恙 提交于 2020-03-26 14:00:32

问题


I have 2 SOAP web service applications - Consumer and Producer Both running in separate Wildfly instances on my Mac.

  • The Wildfly with the Producer is running up in a docker container.
  • The Wildfly with the Consumer is running up in a wildfly instance
    running on my Mac.

Now when the Consumer makes a web service call I am encountering the following exception

java.lang.reflect.InvocationTargetException: null
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_181]
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_181]
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_181]
        at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_181]
        at com.sample.consumers.RequestMessageConsumer.getResponse(RequestMessageConsumer.java:885) [classes:?]
        at com.sample.services.jms.MessageListener.onMessage(MessageListener.java:106) [classes:?]
        at org.springframework.jms.listener.AbstractMessageListenerContainer.doInvokeListener(AbstractMessageListenerContainer.java:761) [spring-jms-5.1.9.RELEASE.jar:5.1.9.RELEASE]
        at org.springframework.jms.listener.AbstractMessageListenerContainer.invokeListener(AbstractMessageListenerContainer.java:699) [spring-jms-5.1.9.RELEASE.jar:5.1.9.RELEASE]
        at org.springframework.jms.listener.AbstractMessageListenerContainer.doExecuteListener(AbstractMessageListenerContainer.java:674) [spring-jms-5.1.9.RELEASE.jar:5.1.9.RELEASE]
        at org.springframework.jms.listener.AbstractPollingMessageListenerContainer.doReceiveAndExecute(AbstractPollingMessageListenerContainer.java:318) [spring-jms-5.1.9.RELEASE.jar:5.1.9.RELEASE]
        at org.springframework.jms.listener.AbstractPollingMessageListenerContainer.receiveAndExecute(AbstractPollingMessageListenerContainer.java:245) [spring-jms-5.1.9.RELEASE.jar:5.1.9.RELEASE]
        at org.springframework.jms.listener.DefaultMessageListenerContainer$AsyncMessageListenerInvoker.invokeListener(DefaultMessageListenerContainer.java:1189) [spring-jms-5.1.9.RELEASE.jar:5.1.9.RELEASE]
        at org.springframework.jms.listener.DefaultMessageListenerContainer$AsyncMessageListenerInvoker.executeOngoingLoop(DefaultMessageListenerContainer.java:1179) [spring-jms-5.1.9.RELEASE.jar:5.1.9.RELEASE]
        at org.springframework.jms.listener.DefaultMessageListenerContainer$AsyncMessageListenerInvoker.run(DefaultMessageListenerContainer.java:1076) [spring-jms-5.1.9.RELEASE.jar:5.1.9.RELEASE]
        at java.lang.Thread.run(Thread.java:748) [?:1.8.0_181]
Caused by: javax.xml.ws.soap.SOAPFaultException: Fault occurred while processing.
        at org.apache.cxf.jaxws.JaxWsClientProxy.invoke(JaxWsClientProxy.java:161) ~[cxf-rt-frontend-jaxws-3.1.6.jar:3.1.6]
        at com.sun.proxy.$Proxy806.externalDocument(Unknown Source) ~[?:?]
        ... 18 more
Caused by: org.apache.cxf.binding.soap.SoapFault: Fault occurred while processing.
        at org.apache.cxf.binding.soap.interceptor.Soap12FaultInInterceptor.unmarshalFault(Soap12FaultInInterceptor.java:155) ~[cxf-rt-bindings-soap-3.1.6.jar:3.1.6]
        at org.apache.cxf.binding.soap.interceptor.Soap12FaultInInterceptor.handleMessage(Soap12FaultInInterceptor.java:66) ~[cxf-rt-bindings-soap-3.1.6.jar:3.1.6]
        at org.apache.cxf.binding.soap.interceptor.Soap12FaultInInterceptor.handleMessage(Soap12FaultInInterceptor.java:52) ~[cxf-rt-bindings-soap-3.1.6.jar:3.1.6]
        at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:308) ~[cxf-core-3.1.6.jar:3.1.6]
        at org.apache.cxf.interceptor.AbstractFaultChainInitiatorObserver.onMessage(AbstractFaultChainInitiatorObserver.java:112) ~[cxf-core-3.1.6.jar:3.1.6]
        at org.apache.cxf.binding.soap.interceptor.CheckFaultInterceptor.handleMessage(CheckFaultInterceptor.java:69) ~[cxf-rt-bindings-soap-3.1.6.jar:3.1.6]
        at org.apache.cxf.binding.soap.interceptor.CheckFaultInterceptor.handleMessage(CheckFaultInterceptor.java:34) ~[cxf-rt-bindings-soap-3.1.6.jar:3.1.6]
        at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:308) ~[cxf-core-3.1.6.jar:3.1.6]
        at org.apache.cxf.endpoint.ClientImpl.onMessage(ClientImpl.java:798) ~[cxf-core-3.1.6.jar:3.1.6]
        at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.handleResponseInternal(HTTPConduit.java:1670) ~[cxf-rt-transports-http-3.1.6.jar:3.1.6]
        at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.handleResponse(HTTPConduit.java:1551) ~[cxf-rt-transports-http-3.1.6.jar:3.1.6]
        at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.close(HTTPConduit.java:1348) ~[cxf-rt-transports-http-3.1.6.jar:3.1.6]
        at org.apache.cxf.io.CacheAndWriteOutputStream.postClose(CacheAndWriteOutputStream.java:56) ~[cxf-core-3.1.6.jar:3.1.6]
        at org.apache.cxf.io.CachedOutputStream.close(CachedOutputStream.java:216) ~[cxf-core-3.1.6.jar:3.1.6]
        at org.apache.cxf.transport.AbstractConduit.close(AbstractConduit.java:56) ~[cxf-core-3.1.6.jar:3.1.6]
        at org.apache.cxf.transport.http.HTTPConduit.close(HTTPConduit.java:651) ~[cxf-rt-transports-http-3.1.6.jar:3.1.6]
        at org.apache.cxf.interceptor.MessageSenderInterceptor$MessageSenderEndingInterceptor.handleMessage(MessageSenderInterceptor.java:62) ~[cxf-core-3.1.6.jar:3.1.6]
        at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:308) ~[cxf-core-3.1.6.jar:3.1.6]
        at org.apache.cxf.endpoint.ClientImpl.doInvoke(ClientImpl.java:514) ~[cxf-core-3.1.6.jar:3.1.6]
        at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:423) ~[cxf-core-3.1.6.jar:3.1.6]
        at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:324) ~[cxf-core-3.1.6.jar:3.1.6]
        at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:277) ~[cxf-core-3.1.6.jar:3.1.6]
        at org.apache.cxf.frontend.ClientProxy.invokeSync(ClientProxy.java:96) ~[cxf-rt-frontend-simple-3.1.6.jar:3.1.6]
        at org.apache.cxf.jaxws.JaxWsClientProxy.invoke(JaxWsClientProxy.java:139) ~[cxf-rt-frontend-jaxws-3.1.6.jar:3.1.6]
        at com.sun.proxy.$Proxy806.externalDocument(Unknown Source) ~[?:?]
        ... 18 more

The issue is around :-

Caused by: org.apache.cxf.binding.soap.SoapFault: Fault occurred while processing.

The above stacktrace is from logging of the stackTraceAsString variable - code snippet below

However, there is not much to give an idea of the cause of the failure.

I am able to successfully invoke the Producer web service via SoapUI running on my Mac.

I have checked the endpoint url configured for the Consumer. It is the same as what is used by SoapUI.

Any suggestion to understand the cause and solution would be appreciated.

Thank you in advance.

Pete

snippet of the code

// get the web service operation to invoke for this request type.
final String webServiceOperation = getRequestOperation();

final Class<ProducerWebServiceInterface> clientProducerWebServiceInterface = ProducerWebServiceInterface.class;

// get the appropriate web service method to invoke
Method method = null;
WebServiceResponse serviceResponse = null;

try {

    method = clientProducerWebServiceInterface.getMethod(webServiceOperation, type);

    serviceResponse = (WebServiceResponse) method.invoke(client, operation);

}

catch (final SecurityException | NoSuchMethodException | IllegalArgumentException | IllegalAccessException exception) {

        logError ( exception );

}
catch ( final Exception exception ) {

    StringWriter stringWriter = new StringWriter();
    PrintWriter printWriter = new PrintWriter(stringWriter);
    exception.printStackTrace(printWriter);
    String stackTraceAsString = stringWriter.toString();

        logError ( exception );

}

Seems the line of code

return invoke0(method, obj, args);

in the NativeMethodAccessorImpl class is throwing the InvocationTargetException but still no idea what the cause. The params - method, obj, args - all look ok. I identified this by setting a break point in eclipse to break at the InvocationTargetException occurance.

class NativeMethodAccessorImpl extends MethodAccessorImpl {
    private final Method method;
    private DelegatingMethodAccessorImpl parent;
    private int numInvocations;

    NativeMethodAccessorImpl(Method method) {
        this.method = method;
    }

    public Object invoke(Object obj, Object[] args)
        throws IllegalArgumentException, InvocationTargetException
    {
        // We can't inflate methods belonging to vm-anonymous classes because
        // that kind of class can't be referred to by name, hence can't be
        // found from the generated bytecode.
        if (++numInvocations > ReflectionFactory.inflationThreshold()
                && !ReflectUtil.isVMAnonymousClass(method.getDeclaringClass())) {
            MethodAccessorImpl acc = (MethodAccessorImpl)
                new MethodAccessorGenerator().
                    generateMethod(method.getDeclaringClass(),
                                   method.getName(),
                                   method.getParameterTypes(),
                                   method.getReturnType(),
                                   method.getExceptionTypes(),
                                   method.getModifiers());
            parent.setDelegate(acc);
        }

        return invoke0(method, obj, args);

来源:https://stackoverflow.com/questions/60700938/webservice-invocationtargetexception

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!