在webservice中获取java.lang.reflect.InvocationTargetException

时间:2013-09-19 05:31:34

标签: java web-services wsdl

我正在使用Webservice进行货币转换。我使用过已经可用的WSDL“http://www.webservicex.net/CurrencyConvertor.asmx?WSDL”。使用上面的WSDL,我已经生成了Web服务客户端。使用该webservice客户端我正在进行货币转换。但是当我运行我的webservice时,它给了我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.

4 个答案:

答案 0 :(得分:1)

上述异常得到了解决。因为有一个防火墙配置阻塞了CurrencyConversion webservice客户端。删除防火墙配置后,它工作正常。谢谢你的回答。

答案 1 :(得分:0)

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

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

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

答案 2 :(得分:0)

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

答案 3 :(得分:0)

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