在“验证”中正确使用HTTP状态代码。服务器 [英] Proper use of HTTP status codes in a "validation" server

查看:98
本文介绍了在“验证”中正确使用HTTP状态代码。服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序发送给第三方SOA服务器的数据中包含复杂的XML。服务器所有者确实提供了XML模式( .xsd ),并且由于服务器拒绝无效的XML消息,我需要在发送之前在本地验证它们。

Among the data my application sends to a third-party SOA server are complex XMLs. The server owner does provide the XML schemas (.xsd) and, since the server rejects invalid XMLs with a meaningless message, I need to validate them locally before sending.

我可以使用独立的XML模式验证器,但它们很慢,主要是因为解析模式文件所需的时间。所以我以 HTTP Server 的形式编写了自己的模式验证器(在Java中,如果这很重要),它缓存已经解析过的模式。

I could use a stand-alone XML schema validator but they are slow, mainly because of the time required to parse the schema files. So I wrote my own schema validator (in Java, if that matters) in the form of an HTTP Server which caches the already parsed schemas.

问题是:在验证过程中很多事情都可能出错。除意外异常和成功验证外:

The problem is: many things can go wrong in the course of the validation process. Other than unexpected exceptions and successful validation:


  • 服务器可能找不到指定的模式文件

  • 指定的文件可能不是有效的模式文件

  • XML对模式文件无效

因为它是HTTP服务器,所以我想为客户端提供有意义的状态代码。对于上述所有情况,服务器是否应回答 400 错误(错误请求)?或者它们与HTTP无关,它应该在正文中回复 200 ?还有其他任何建议吗?

Since it's an HTTP Server I'd like to provide the client with meaningful status codes. Should the server answer with a 400 error (Bad request) for all the above cases? Or they have nothing to do with HTTP and it should answer 200 with a message in the body? Any other suggestion?

更新:主应用程序是用 Ruby 编写的,没有什么好处xml架构验证库,因此单独的验证服务器不会过度工程化。

Update: the main application is written in Ruby, which doesn't have a good xml schema validation library, so a separate validation server is not over-engineering.

推荐答案

映射错误情况是完全有效的思考在验证过程中有意义的HTTP状态代码。

It's a perfectly valid thinking to map error situations in the validation process to meaningful HTTP status codes.

我想您使用URI将XML文件作为POST内容发送到验证服务器,以确定用于验证的特定模式。

I suppose you send the XML file to your validation server as a POST content using the URI to determine a specific schema for validation.

以下是错误映射的一些建议:

So here are some suggestions for error mappings:


  • 200:XML内容有效

  • 400:XML内容格式不正确,标头不一致,请求与RFC 2616语法不匹配

  • 401:在缓存中找不到架构,服务器需要使用凭据用于对第三方SOA后端进行身份验证以获取模式文件

  • 404:未找到模式文件

  • 409:XML内容无效针对指定的模式

  • 412:指定的文件不是有效的XMl模式

  • 500:验证服务器中的任何意外异常(NullPointerExceptions等。 )

  • 502:在缓存中找不到架构,尝试从第三方SOA服务器请求它失败。

  • 503:验证服务器ver正在重新启动

  • 504:请参见502 with reason = timeout

  • 200: XML content is valid
  • 400: XML content was not well-formed, header were inconsistent, request did not match RFC 2616 syntax
  • 401: schema was not found in cache and server needs credentials to use for authentication against the 3rd party SOA backend in order to obtain the schema file
  • 404: Schema file not found
  • 409: the XML content was invalid against the specified schema
  • 412: Specified file was not a valid XMl schema
  • 500: any unexpected exception in your validation server (NullPointerExceptions et al.)
  • 502: the schema was not found in cache and the attempt to request it from the 3rd party SOA server failed.
  • 503: validation server is restarting
  • 504: see 502 with reason=timeout

这篇关于在“验证”中正确使用HTTP状态代码。服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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