Jack Boch
Jack Boch

Reputation: 127

How to return an HttpServletResponse from another application?

I have an Angular front and a java back, plus APIs to consume.

So the application works well if I call the api directly on the front but for security reasons I have to go through the back java and the problem is that the responses are not exact complete in the event of an error on the front.

Example I receive an error "0 Unknown" while in the network I receive "409..." And in direct call I have "409..." in both cases.

    public ResponseEntity<Void> addForward(String username, String forward) {
        return localApiClient.put()
                .uri(baseUrl + username + "/targets/" + forward)
                .contentType(MediaType.APPLICATION_JSON)
                .exchangeToMono(ClientResponse::toBodilessEntity)
                .block(REQUEST_TIMEOUT);
    }

    @PutMapping("/{username}/targets/{forward}")
    public ResponseEntity<Void> addForward(
            @PathVariable("username") String username, @PathVariable("forward") String forward) {
        return api.addForward(username, forward);
    }

Upvotes: 0

Views: 55

Answers (1)

kiki keke
kiki keke

Reputation: 119

with this spring code must add a head that should match your expectations

@PutMapping("/{username}/targets/{forward}")
    public ResponseEntity<Void> addForward(
            @PathVariable("username") String username, @PathVariable("forward") String forward) {
        return new ResponseEntity<>(api.addForward(username, forward).getStatusCode());
    }

Upvotes: 1

Related Questions