Question

Here is my controller

@RequestMapping(value = "/ping", method = RequestMethod.POST)
public @ResponseBody PingResponse ping(@RequestBody PingRequest request){
    try {
        Thread.sleep(request.delay);
    } catch (NumberFormatException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (InterruptedException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    PingResponse res = new PingResponse();
    res.setTimeStamp(request.getTimeStamp());

    return res;
}

Here are pojos

class PingRequest {
    private long delay;
    private long timeStamp;
    public long getDelay() {
        return delay;
    }
    public void setDelay(long delay) {
        this.delay = delay;
    }
    public long getTimeStamp() {
        return timeStamp;
    }
    public void setTimeStamp(long timeStamp) {
        this.timeStamp = timeStamp;
    }

}

class PingResponse {
    private long timeStamp;

    public long getTimeStamp() {
        return timeStamp;
    }

    public void setTimeStamp(long timeStamp) {
        this.timeStamp = timeStamp;
    }

}

Http Request

POST http://localhost:9000/myapp/ping HTTP/1.1
Host: localhost:9000
Content-Length: 41
Content-Type: application/json

{"timeStamp":1393860018158,"delay":1000 }

Http Response

HTTP/1.1 400 Bad Request

Why am I getting Http 400?

No correct solution

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top