Unable to print Response as String without corrupting the response.
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 9.8k
- Forks
- 1.9k
- Avg merge
- 1d 2h
- Merged PRs (30d)
- 41
Description
I am trying to write an aspect for all feign calls that we use in our microservices. we use feign in almost all our microservices. I am trying to log the request and response of all the feign calls. The code is below:
@Slf4j
@Configuration
@Aspect
@Order(0)
public class FeignRequestResponse {
@Pointcut("execution(public * org.springframework.cloud.openfeign.ribbon.LoadBalancerFeignClient.execute(..))")
public void pointCutFeign() {
}
@Around("pointCutFeign()")
public Object myAroundFeign(ProceedingJoinPoint joinPoint) throws Throwable {
int uniqueIdentifier = generateUniqueIdentifier(10000000,0);
if (joinPoint.getArgs().length > 0) {
Request request = (Request) joinPoint.getArgs()[0];
log.info("THE PICKUP SERVICE REQUEST IDENTIFIER IS {} ,THE PICKUP REQUEST URL IS {}, THE PICKUP REQUEST METHOD IS {},THE PICKUP REQUEST BODY IS {}", uniqueIdentifier,request.url(),request.httpMethod().name(),request.requestBody().asString());
}
Response response = (Response) joinPoint.proceed();
log.info("THE PICKUP SERVICE RESPONSE ID = {},PICKUP RESPONSE STATUS = {},PICKUP RESPONSE BODY = {}", uniqueIdentifier,response.status(),IOUtils.toString(response.body.asInputStream());
return response;
}
The problem here is for above codeIOUtils.toString(response.body.asInputStream() is getting response displayed properly as String but then response object is getting mangled so due to that response object is becoming null and hence all the api's output is shown as null.
Is there a way where we can display Response object's body as String and also return Response object without disturbing it.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the FeignRequestResponse aspect shown in the issue, especially joinPoint.proceed() and response.body.asInputStream(). Read the Feign Response body handling to understand why reading the stream affects the returned response. Done means the body can be logged as text while the returned API response remains intact; no repository file or test is named.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100