Java Web服务中错误代码的最佳实践
我为一个特定错误配置了一个异常,收到如下消息:Java Web服务中错误代码的最佳实践,java,web-services,error-handling,Java,Web Services,Error Handling,我为一个特定错误配置了一个异常,收到如下消息: <ef_Anula_DocumentoResponse> <error>Null field</error> </ef_Anula_DocumentoResponse> 空字段 现在,我想为每个异常显示一个错误代码。实现这一目标的最佳方式是什么 (这些只是例子) 1,空字段 空字段 1.空字段 对于这种情况有一个特定的惯例吗 我的问题是,当我设置空字段时,将“”替换为并解码这些字段以使其
<ef_Anula_DocumentoResponse>
<error>Null field</error>
</ef_Anula_DocumentoResponse>
空字段
现在,我想为每个异常显示一个错误代码。实现这一目标的最佳方式是什么
(这些只是例子)
1,空字段
空字段
1.空字段
对于这种情况有一个特定的惯例吗
我的问题是,当我设置
空字段时,将“”替换为并解码这些字段以使其在SOAP UI中看起来友好,这被认为是一种不好的做法。如果要返回多个错误,您可以尝试下面的xml输出
<errors>
<error>
<code>1</code>
<desc>Null field</desc>
</error>
<error>
<code>2</code>
<desc>Null field</desc>
</error>
</errors>
我通过一些链接意识到,受关注的行为是:
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<S:Body>
<ns2:ef_Anula_DocumentoResponse xmlns:ns2="http://service.jaxws.sgd.ws.airc/">
<error_code>100</error_code>
<error>Null field</error>
</ns2:ef_Anula_DocumentoResponse>
</S:Body>
</S:Envelope>
100
空字段
希望将来能有所帮助。这不是我想要的,我的3个例子只是一种方法的行为,一个回答的不同答案。但我会保留你的结构。
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<S:Body>
<ns2:ef_Anula_DocumentoResponse xmlns:ns2="http://service.jaxws.sgd.ws.airc/">
<error_code>100</error_code>
<error>Null field</error>
</ns2:ef_Anula_DocumentoResponse>
</S:Body>
</S:Envelope>