简体   繁体   English

为HTTP POST请求javax.ws创建POJO

[英]Create POJO for HTTP POST Request javax.ws

Using javax.ws I need to create a POJO object for POST to a service. 使用javax.ws,我需要创建一个POJO对象以将POST到服务。 The input that I must POST: 我必须发布的输入:

{
  "attributes": {
    "firstname": "John",
    "surname": "Doe",
    "birthyear": 1965
  }
}

I set this up in a class below and then try to call it with: 我在下面的类中进行了设置,然后尝试使用以下方法进行调用:

AuditTrail auditTrail = new AuditTrail(...);

 final Response response = app.target(MY_END_POINT)
.path(auditTrailPath.toString())
.request()
.post(Entity.json(auditTrail));

But i get a HTTP error 204, No Content. 但我收到HTTP错误204,无内容。

Am I doing this right ? 我这样做对吗?

    public class AuditTrail implements Serializable {

        @JsonProperty("attributes")
        public HashMap<String, String> attributes;

        public AuditTrail() {
            attributes = new HashMap<String, String>();
        }

        public AuditTrail(...) {

            attributes = new HashMap<String, String>();
// Set values here...
        }

        public HashMap<String, String> getAttributes() {
            return attributes;
        }

        public void setAttributes(HashMap<String, String> attributes) {
            this.attributes = attributes;
        }
    }

Have you checked your server side? 您检查过服务器端了吗? HTTP Status 204 is NOT an error response. HTTP Status 204 不是错误响应。 It just say "I have received your request and processed it successfully, but there is nothing I need to send back to you in the payload of the response" 它只是说:“我已收到您的请求并已成功处理,但在响应的有效内容中我不需要发回给您”

Refer to https://httpstatuses.com/204 请参阅https://httpstatuses.com/204

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

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