简体   繁体   English

Java中的SOAP错误处理

[英]SOAP fault handling in java

I am pretty new to SOAP and I am trying to understand SOAP fault handling (in Java). 我对SOAP还是很陌生,并且试图理解SOAP错误处理(在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. 更具体地说,如何使用Eclipse WSDL编辑器处理各种响应代码。 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). 我已经使用Eclipse WSDL编辑器来创建我的WSDL,但是我愿意使用其他工具(例如SoapUI)来完成此操作(处理错误)。

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). 我已经附加了一个简单的Web服务的图像,该图像应该带有UserID(请求)并返回有关用户的信息,例如名称,年龄等(响应)。 I would like to handle warning and error codes that may be returned by the response. 我想处理可能由响应返回的警告和错误代码。 Eg duplicate UserID found > code "ABC" or no UserID found > code "XYZ". 例如,找到重复的UserID>代码“ ABC”,或者未找到UserID>代码“ 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? 响应会以字符串形式返回“ ABC”吗?

在此处输入图片说明

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? 我是否需要将displayUserInfoFault设置为扩展Exception类的新类,并向displayUserInfo()方法添加“ throws displayUserInfoFault”?

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 . 例如,您可以创建新类,将其称为Response ,其中包含要向调用者显示的字段,如responCoderesponseDescription 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 当然,您需要将playUserInfo方法的返回类型更改为Response类型。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM