java中的SOAP故障处理 [英] SOAP fault handling in java

查看:132
本文介绍了java中的SOAP故障处理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对SOAP很新,我正在努力了解SOAP故障处理(在Java中)。我已经阅读了这个话题,但仍然有一些对我来说不清楚的概念。



更具体地说,如何使用Eclipse WSDL编辑器处理各种响应代码。我已经使用Eclipse WSDL编辑器来创建我的WSDL,但是我可以使用SoapUI等其他工具来完成这个(处理错误)。



我附加了一个图像一个简单的Web服务,应该采取UserID(请求)并返回有关用户的信息,如名称,年龄等(响应)。我想处理响应可能返回的警告和错误代码。例如。重复的UserID找到>代码ABC或没有找到用户ID>代码XYZ。



我真的不明白这些代码返回的位置和哪里他们。答案会将ABC作为字符串返回吗?





以下问题基于附件图像。
我需要将displayUserInfoFault设置为扩展Exception类并将throws displayUserInfoFault添加到displayUserInfo()方法的新类吗?



任何指导都将不胜感激。谢谢!

解决方案

如果要对呼叫者返回正确的响应。那么你需要返回一个对象不仅一个字段。例如,您可以创建新类,您可以将其称为响应,其中包含要向呼叫者显示的字段,如 responCode responseDescription 。使用这两个字段可以覆盖不同的错误情况。当然,您需要将方法 playUserInfo 的返回类型更改为类型 Response


I am pretty new to SOAP and I am trying to understand SOAP fault handling (in Java). I have done reading about this topic but there are still some concepts that remain unclear to me.

More specifically, how to handle various response codes using Eclipse WSDL editor. I have used Eclipse WSDL editor to create my WSDL but I am open to using another tool such as SoapUI to accomplish this (handling faults).

I've attached an image of a simple web service that is supposed to take UserID (request) and return information about the user such as name, age etc (response). I would like to handle warning and error codes that may be returned by the response. E.g. duplicate UserID found > code "ABC" or no UserID found > code "XYZ".

I don't really understand how/where these codes are returned and where to process them. Would the response just return "ABC" as a String?

The following question is based on the attached image. Do I need to setup displayUserInfoFault as a new class that extends the Exception class and add "throws displayUserInfoFault" to the displayUserInfo() method?

Any guidance would be much appreciated. Thanks!

解决方案

If you want to return a proper response to the caller. Then you need to return an object not only one fields. For example you can create new class you can call it Response that contains the fields you want to display it to the caller like responCode and responseDescription. Using these two fields you can cover the different error cases you have. And of course you need to change the return type of the method playUserInfo to be of type Response

这篇关于java中的SOAP故障处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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