Getting Error message as NULL while invoking a service in one spring boot application from another spring boot application using RestTemplate - spring

AM trying to invoke a spring boot microservice from another application.
Here is my Server code, if any exception occurs
return ResponseEntity.status(HttpStatus.FORBIDDEN)
.body(new com.test.models.ResponseEntity("Tenant details
not found"));
Here is my client code,
ResponseEntity<Object> uploadResponse =
restTemplate.exchange("http://TESTAPPLICATION/v1/object",
HttpMethod.POST, requestEntity, Object.class);
Am getting a response as
Caused by: org.springframework.web.client.HttpClientErrorException: 403 null
If I hit my endpoint from PostMan, am getting proper response message.
But from my client-side application am getting response message as null. Please let me know what is going wrong.
UPDATE:
Screenshot.
Client Responds with INTERNAL_SERVER_ERROR. But from my server iam responding 403.

Related

Error handling with feign client - resilence4j

My spring boot app has a feign client that POST a payload to external endpoint.
There is requirement to audit all the calls, especially when any errors occurs in calling the endpoint (connection, unauthorized etc), after retry are exhausted. To audit,
need some information from original payload
http status
underlying exception message,
backup original payload for reference
endpoint
I tried below approaches (for error handling), but still unable to find a solution that covers all above
feign Fallbackfactory - it has handle to exception, but unable to effectively capture feign response/original payload
fallbackMethod with resilence4j - here i get access to original payload and exception, but again unable to capture actual response status (401, 503 etc)
CustomErrorDecoder - Here able to get access to feign Response, but then have to map response body (any request body/payload). Also have to map exception
Appreciate any suggestion/ advise?

Feign is giving Exception code 0 instead of 503 when calling service unavailable

I am using feign client to call other microservice but when the calling service is down feign should give the exception of "503 service unavailable" but it giving exceptionCode = 0 with the message "Loadbalance does not have an available server to the client".
If the service is down, I want to hit the ErrorDecoder and retry the call, but Feign is giving 0 exception codes, so it cannot reach the error decoder.
What I am missing?
Check your service is registered with the discovery server.
Check your spring properties 'spring-application-name' is equal to feignClient annotation's value properties

RuntimeException is not displaying the error message in postman

I am using spring boot restful API every time I try
if(userRepository.findByEmail != null) Throw new RuntimeException("This email already exists");
I don't get the message back I only get the error with an empty message in postman instead I get only inside spring boot command the message I passed in RuntimeException.
They've changed this in Spring 2.3.0, to see the error message through postman you need to add server.error.include-message=always in your properties file (application.properties)

Consume SOAP Web services from spring with security header

I'm getting deprecated message for the bean Wss4jSecurityInterceptor. I'm using >spring-boot-starter-ws(1.4.7-RELEASE). spring-ws-security(2.4.4-RELEASE), org.apache.ws.security wss4j (1.6.9).
How to add the username token to consume SOAP services using Spring WebService Template ?
Sorry..Silly error..Need to upgrade to "org.springframework.ws.soap.security.wss4j2.Wss4jSecurityInterceptor;"...wss4j2 instead of wss4j.
However still Null pointer exception " Received Fault message for request Exception=null.
Settled. The application message exception object isn't extracted properly from the SoapFaultClientException.. e.getSoapFault().getFaultDetail()

Spring integration http outbound gateway logging errors

I have an integration flow where I'm reading messages from a jms channel and sending them through a REST api call using http-outbound-gateway.
Now when I get a 5xx Http server error I'd like to log the the URL of the service along with the response message.
I see that the RestTemplate instance already logs the URL and calls a ResponseErrorHandler which can be a custom implementation.
My problem is: the ResponseErrorHandler only receives a ClientHttpResponse as a parameter and I can't know the URL from that instance. What I need is to log the server error like: 'Error URL - Response ...'
How can I do that? I can't override RestTemplate's error handling and the ResponseErrorHandler doesn't have enough info.
Thank you very much.
Well, what I see there.
The HttpRequestExecutingMessageHandler (<int-http:outbound-gateway>) catches all underlying exceptions:
catch (Exception e) {
throw new MessageHandlingException(requestMessage, "HTTP request execution failed for URI ["
+ (realUri == null ? uri : realUri.toString())
+ "]", e);
}
Including the result of that DefaultResponseErrorHandler from the RestTemplate.
And as you see we use here for the MessageHandlingException uri as well as the requestMessage.
Further this exception will be delegated to that jms channel.
Why isn't that enough for you?
From other side you can add <request-handler-advice-chain> to the <int-http:outbound-gateway> with ExpressionEvaluatingRequestHandlerAdvice to get deal with that MessageHandlingException just in place: http://docs.spring.io/spring-integration/docs/latest-ga/reference/html/messaging-endpoints-chapter.html#expression-advice

Resources