【问题标题】:Getting java.lang.reflect.InvocationTargetException in webservice在 web 服务中获取 java.lang.reflect.InvocationTargetException
【发布时间】:2013-09-19 05:31:33
【问题描述】:

我正在使用 Webservice 进行货币转换。我使用了已经可用的 WSDL“http://www.webservicex.net/CurrencyConvertor.asmx?WSDL”。使用上面的 WSDL 我已经生成了 Web 服务客户端。使用那个 web 服务客户端我正在做货币转换。但是当我运行我的 web 服务时,它给了我 InvocationTargetException。下面是我得到的异常堆栈跟踪。

Exception in thread "main" java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader.main(JarRsrcLoader.java:56)
Caused by: (404)Not Found
at org.apache.axis.transport.http.HTTPSender.readFromSocket(HTTPSender.java:744)
at org.apache.axis.transport.http.HTTPSender.invoke(HTTPSender.java:144)
at org.apache.axis.strategies.InvocationStrategy.visit(InvocationStrategy.java:32)
at org.apache.axis.SimpleChain.doVisiting(SimpleChain.java:118)
at org.apache.axis.SimpleChain.invoke(SimpleChain.java:83)
at org.apache.axis.client.AxisClient.invoke(AxisClient.java:165)
at org.apache.axis.client.Call.invokeEngine(Call.java:2784)
at org.apache.axis.client.Call.invoke(Call.java:2767)
at org.apache.axis.client.Call.invoke(Call.java:2443)
at org.apache.axis.client.Call.invoke(Call.java:2366)
at org.apache.axis.client.Call.invoke(Call.java:1812)
at NET.webserviceX.www.CurrencyConvertorSoapStub.conversionRate(CurrencyConvertorSoapStub.java:13)
at CurrenyConversionRateValue.main(CurrenyConversionRateValue.java:19)
... 5 more 

Can anyone please help me to resolve this issue.

Below is the code snippet of CurrencyConvertorSoapStub where i am getting exception.

    public double conversionRate(NET.webserviceX.www.Currency fromCurrency, NET.webserviceX.www.Currency toCurrency) throws java.rmi.RemoteException
     {
            if (super.cachedEndpoint == null)
            {
                throw new org.apache.axis.NoEndPointException();
            }
            org.apache.axis.client.Call _call = createCall();
            _call.setOperation(_operations[0]);
            _call.setUseSOAPAction(true);
            _call.setSOAPActionURI("http://www.webserviceX.NET/ConversionRate");
            _call.setEncodingStyle(null);
            _call.setProperty(org.apache.axis.client.Call.SEND_TYPE_ATTR, Boolean.FALSE);
            _call.setProperty(org.apache.axis.AxisEngine.PROP_DOMULTIREFS, Boolean.FALSE);
            _call.setSOAPVersion(org.apache.axis.soap.SOAPConstants.SOAP11_CONSTANTS);
            _call.setOperationName(new javax.xml.namespace.QName("http://www.webserviceX.NET/", "ConversionRate"));

            setRequestHeaders(_call);
            setAttachments(_call);
     try {       
     java.lang.Object _resp = _call.invoke(new java.lang.Object[] {fromCurrency, toCurrency});

            if (_resp instanceof java.rmi.RemoteException) {
                throw (java.rmi.RemoteException)_resp;
            }
            else {
                extractAttachments(_call);
                try {
                    return ((java.lang.Double) _resp).doubleValue();
                } catch (java.lang.Exception _exception) {
                    return ((java.lang.Double) org.apache.axis.utils.JavaUtils.convert(_resp, double.class)).doubleValue();
                }
            }
      } catch (org.apache.axis.AxisFault axisFaultException) {
      throw axisFaultException;
    }
        }

    }

Can anyone please help me to resolve this exception and to get my webservice work.

【问题讨论】:

  • InvocationTargetException 通常在客户端无法访问服务器时出现。网络相关问题。

标签: java web-services wsdl


【解决方案1】:

上述异常已解决。它是由于 CurrencyConversion Web 服务客户端的防火墙配置阻止而发生的。删除防火墙配置后它工作正常。感谢您的回答。

【讨论】:

    【解决方案2】:

    我是 webservice 的新手,但是当您配置客户端时,您指定的服务名称与您的 wsdl 名称不同

    _call.setOperationName(new javax.xml.namespace.QName("http://www.webserviceX.NET/","ConversionRate")); 
    

    我认为我应该像你在 wsdl 文件中映射的那样

    【讨论】:

    • 感谢user2269148的回复。我也是webservice的新手。我没有手动指定服务名称。我只是从上面提到的 WSDL 生成了 java webservice 客户端,并将它用于货币转换。它在我当地工作得很好。但是,当我在另一个具有 tomcat 服务器的系统中点击相同的 web 服务时,它给了我上述错误。我需要让它工作。谁能帮我解决这个问题。我是否需要进行任何配置更改,例如任何端口被阻止才能访问我的网络服务?请帮助我。
    • 谁能帮帮我。这很重要。
    【解决方案3】:

    我也遇到了同样的异常,即调用目标异常,当您的应用程序中有更多时间占用进程时,此异常会出现,为什么因为 web 服务是由线程实现的,要在启动时解决这个问题,您只需加载所有文件,意味着在启动tomcat时我们可以加载所有文件。

    【讨论】:

      【解决方案4】:

      当您无法访问 WebServices 即 URL 不可用(阻塞 FW、错误配置等)时会发生此异常。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-07-27
        相关资源
        最近更新 更多