Web服务使用Axis2 Java抛出异常 [英] Web Service throwing exception using Axis2 Java

查看:207
本文介绍了Web服务使用Axis2 Java抛出异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我实际上正在使用Axis 2在Java中开发Web服务。
我将我的服务设计为POJO(普通旧Java对象),公共方法抛出异常:

I'm actually developing a Web Service in Java using Axis 2. I designed my service as a POJO (Plain Old Java Object) with public method throwing exceptions :

public class MyService {
   public Object myMethod() throws MyException {
        [...]
   }
}

然后我使用Axis2 ant任务生成WSDL。使用WSDL,我生成一个客户端存根来测试我的服务。生成的代码包含一个MyExceptionException,并且存根中的myMethod声明抛出这个:

I then generated the WSDL using Axis2 ant task. With the WSDL I generate a client stub to test my service. The generated code contains a "MyExceptionException" and the "myMethod" in the stub declare to throw this :

public class MyServiceStub extends org.apache.axis2.client.Stub {
    [...]
    public MyServiceStub.MyMethodResponse myMethod(MyServiceStub.MyMethod myMethod)
    throws java.rmi.RemoteException, MyExceptionException0 {
        [...]
    }
    [...]
}

但是当调用catch包围的方法时,MyExceptionException永远不会被传输AxisFault的服务器传输(RemoteException的子类)。

But when calling the method surrounded by a catch, the "MyExceptionException" is never transmitted by the server which transmit an AxisFault instead (subclass of RemoteException).

I假设问题是服务器端,但没有找到。该服务在tomcat 5.5服务器上的axis2 webapp中部署为aar文件。 services.xml如下所示:

I assume the problem is server-side but don't find where. The service is deployed as an aar file in the axis2 webapp on a tomcat 5.5 server. The services.xml looks like this :

<?xml version="1.0" encoding="UTF-8"?>
<service name="MyService" scope="application">
    <description></description>
    <messageReceivers>
        <messageReceiver mep="http://www.w3.org/2004/08/wsdl/in-only" 
            class="org.apache.axis2.rpc.receivers.RPCInOnlyMessageReceiver"/>
        <messageReceiver mep="http://www.w3.org/2004/08/wsdl/in-out"
           class="org.apache.axis2.rpc.receivers.RPCMessageReceiver"/>
    </messageReceivers>
    <parameter name="ServiceClass">MyService</parameter>
    <parameter name="ServiceTCCL">composite</parameter>
</service>

如果行为正常,那么我将放弃使用例外(这对我来说并不重要)项目)但我很谨慎为什么Java2WSDL生成自定义< wsdl:fault>在操作输入&输出声明和WSDL2Java生成一个Exception类(如果这不可用,则声明将其抛入stub方法)...

If the behavior is normal then I'll drop the use of Exceptions (which is not vital to my project) but I'm circumspect why Java2WSDL generate custom <wsdl:fault> in operation input & output declaration and WSDL2Java generate an Exception class (and declare to throw it in the stub method) if this is not usable...

推荐答案

<我真的不认为有问题。您的客户端在服务器上调用方法。该方法导致异常。 Axis将此异常转换为可以发送给客户端以指示错误的内容。

I don't really think there is a problem. Your Client calls a method on the server. That method results in an exception. Axis transforms this exception to something which can be send to the client to indicate the error.

据我所知,所有异常都包含在AxisFault中,然后是AxisFault我相信,传输到客户端的是SoapFault消息,其中包含异常消息的描述。

All exceptions, as far as I know, are wrapped into an AxisFault which is then transmitted to the client as, I believe, a SoapFault message with as description the exception message.

换句话说,客户端应该只看到AxisFaults作为异常(异常类) )没有序列化并发送。服务器异常应该成为客户端的AxisFaults。

In other words, the client should only see AxisFaults as the exception (exception class) is not serialized and send. Server exceptions should become AxisFaults at the client side.

这篇关于Web服务使用Axis2 Java抛出异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆