I have the following REST endpoint:
private static final String TOKEN_HEADER = "Authorization";
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "OK"),
@ApiResponse(responseCode = "404", description = "NOT_FOUND")
})
@GetMapping(value = "/book/{ISBN}",
produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<EntityModel<Book>> getBook(
@PathVariable(name = "ISBN") String isbn,
@RequestParam(defaultValue = "true") Boolean verbose) {
createLoggerMessage(Thread.currentThread().getStackTrace()[1].getMethodName());
final String token = httpServletRequest.getHeader(TOKEN_HEADER).substring(7);
// call validateToken
Book books = bookService.getBook(isbn, verbose);
return ResponseEntity.status(HttpStatus.OK)
.body(bookAssembler.toModel(books));
}
And a SOAP endpoint:
private static final String NAMESPACE_URI = "http://com.pos.JWT/Token";
private final TokenService validateTokenService;
@PayloadRoot(namespace = NAMESPACE_URI, localPart = "Request-ValidateToken")
@ResponsePayload
public ResponseValidateToken validateToken(@RequestPayload RequestValidateToken input) {
return validateTokenService.validateToken(input.getToken());
}
public ResponseValidateToken validateToken(String token) {
if (blackList.contains(token)) {
throw new RuntimeException("Token invalid");
}
if (!jwtTokenUtil.isValidToken(token)) {
blackList.add(token);
throw new RuntimeException("Token invalid");
}
final String username = jwtTokenUtil.getUsernameFromToken(token);
final String role = jwtTokenUtil.getRoleFromToken(token);
checkIfUserFromTokenExists(username);
return setResponse(username, role);
}
I get the token through header and I want to call from REST the SOAP endpoint for validating the token, how I could do that?
I tried to set HttpHeader with content-type MediaType.TEXT_XML and BearerAuth with the token from header, but I dont know how I could send the request to server
P.S: I forgot to mention, they are in separate modules