soap spring ws -如何自定义<faultcode>soapenv:Server</faultcode>到&lt;faultcode&gt;一些错误代码.例如(一个数字)&lt;/faultcode&gt; [英] soap spring ws -how to customise &lt;faultcode&gt;soapenv:Server&lt;/faultcode&gt; to &lt;faultcode&gt;some error code.eg(a number)&lt;/faultcode&gt;

查看:23
本文介绍了soap spring ws -如何自定义<faultcode>soapenv:Server</faultcode>到&lt;faultcode&gt;一些错误代码.例如(一个数字)&lt;/faultcode&gt;的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用soap spring ws来创建一个soap webservice,我已经成功created.Now 我正在做这个肥皂服务中的错误实现,我是能够使用我创建的类来完成,如下所示

I am using soap spring ws to create a soap webservice and i have successfully created.Now i was doing the fault implementation in this soap service and i was able to do it with a class that i created like the following

public class ServiceSoapFaultMappingExceptionResolver extends SoapFaultMappingExceptionResolver

在下面的重写函数中,

@Override
 protected void customizeFault(Object endpoint, Exception ex, SoapFault fault) {
//code for adding fault details

    Result result = fault.addFaultDetail().getResult();

            // marshal
            try {
                 JAXBContext.newInstance(ExceptionListType.class).createMarshaller().marshal(exceptionList, result);

}

我创建了自定义的soap故障对象并返回了它.这个返回的自定义肥皂错误出现在详细信息标签内.所以我的错看起来像这样.

i created the custom soap fault object and returned that. This returned custom soap fault is coming inside the detail tag. so my fault looks like this.

<soapenv:Fault>
         <faultcode>soapenv:Server</faultcode>
         <faultstring>INVALID NUMBER</faultstring>
         <detail>
            <ns5:exceptionListType xmlns:ns5="http://wellpoint.com/esb/header/v2">
               <ns5:errorCount>1</ns5:errorCount>
               <ns5:Exception>
                  <ns5:UUID> 889c-6f73671534af</ns5:UUID>
                  <ns5:timestamp>09/04/2015 05:47:40</ns5:timestamp>
                  <ns5:node>mynode</ns5:node>
                  <ns5:process>JAVA</ns5:process>
                  <ns5:component>Unknown Component</ns5:component>
                  <ns5:code>5009</ns5:code>
                  <ns5:severity>FATAL</ns5:severity>
                  <ns5:message>An unexpected server error occurred: INVALID   NUMBER</ns5:message>
               </ns5:Exception>
            </ns5:exceptionListType>
         </detail>
      </soapenv:Fault>

现在我想要做的是我有一个与上述错误相关的错误代码,它出现在代码标签内.但我需要这个错误代码出现在这个标签内

now what i want to do is i have an error code associated with the above error and it is coming inside the code tag.But i need this error code come inside this tag

<faultcode>soapenv:Server</faultcode>

喜欢

<faultcode>5009</faultcode>

.我有很多谷歌搜索,但没有运气.我知道拥有除可用的预定义值集之外的值不是一个好习惯.但我的客户要求是这样的.如果有人知道答案,请帮助我.非常感谢.

.I have had a lot of googling and no luck.I know it is not a good practice to have a value other than the predefined set of values available for this.But my client requierment is this. Please help me if anyone knows an answer. Thanks a lot in advance.

推荐答案

我终于找到了解决问题的方法.在customizeFault 方法中,我放置了如下代码.

Finally i found a way to solve the issue. inside the customizeFault method, i put code like below.

    SoapFaultDefinition soapFaultDefinition = new SoapFaultDefinition();
    String ENVELOPE_NAMESPACE_URI = "http://schemas.xmlsoap.org/soap/envelope/";
    QName FAULT_NAME = new QName(ENVELOPE_NAMESPACE_URI, "5999, "e");
    //      soapFaultDefinition.setFaultStringOrReason("--" + ex);
    //      soapFaultDefinition.setLocale(Locale.ENGLISH);
    soapFaultDefinition.setFaultCode(FAULT_NAME);
    super.setDefaultFault(soapFaultDefinition);

这篇关于soap spring ws -如何自定义<faultcode>soapenv:Server</faultcode>到&lt;faultcode&gt;一些错误代码.例如(一个数字)&lt;/faultcode&gt;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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