Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
263 views
in Technique[技术] by (71.8m points)

java - Returning different statuscode in cXML must I also send HTTP Statuscode back?

In CXML if the Sender credentials was not correct then in my cxml I send this as a response back to the sender of the cXML post:

<Status code="401" text="Unauthorized ">Credentials provided in the Request (the Sender element) were not recognized by the server.</Status>

According to cXML this is correct. But do I also need to change my HTTP statuscode to 401 or will 200 OK suffice?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

As It is mentioned in the cxml User Guide cxml error handling is on top of http (transport layer) error message, you can see them as functional errors so you still reply with an HTTP 200

3.1.9.1 Status

Because cXML is layered above HTTP in most cases, many errors (such as HTTP 404/Not Found) are handled by the transport. All transport errors should be treated as transient and the client should retry, as if a cXML 500 range status code had been received. All HTTP replies that don’t include valid cXML content, including HTTP 404/Not found and HTTP 500/Internal Server Error status codes, are considered transport errors. Other common transport problems include timeouts, TCP errors (such as “connection refused”), and DNS errors (such as “host unknown”). Validation errors in parsing a Request document would normally result in a cXML permanent error in the 400 range, preferably 406/Not Acceptable.

In your case, you want to reply with

  • HTTP 200 / OK answer
  • cXML 401 / Unauthorized

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...