Home > Back-end >  Call what is the difference between Gateway and don't call back information? Use the GetRequest
Call what is the difference between Gateway and don't call back information? Use the GetRequest

Time:09-17

Spring cloud project, using the gateway gateway, through a method call forward gateway interface can't receive the information returned, Java is normal background data processing, direct call target interface, can receive return information, what reason is this excuse me? Gateway returns information is how to deal with it?

 
Public Mono The filter (ServerWebExchange exchange, GatewayFilterChain chain) {
ServerHttpResponse originalResponse=exchange. The method getResponse ();
DataBufferFactory bufferFactory=originalResponse. BufferFactory ();
ServerHttpResponseDecorator decoratedResponse=new ServerHttpResponseDecorator (originalResponse) {
@ Override
Public Mono WriteWith (Publisher<? Extends DataBuffer> Body) {
If (body instanceof Flux) {
Flux<? Extends DataBuffer> FluxBody=(Flux<? Extends DataBuffer>) The body;
Return super. WriteWith (fluxBody. The map (dataBuffer - & gt; {
//probably should reuse buffers
Byte [] the content=new byte [dataBuffer readableByteCount ()];
DataBuffer. Read (content);
//release memory
DataBufferUtils. Release (dataBuffer);
String s=new String (the content, the Charset. Class.forname (" utf-8 "));
//TODO, s is the value of the response
Byte [] uppedContent=new String (the content, the Charset. Class.forname (" utf-8 ")). GetBytes ();
Return bufferFactory. Wrap (uppedContent);
}));
}
//if the body is not a flux. Never got there.
Return super. WriteWith (body);
}
};
//replace the response with the decorator
Return chain. The filter (exchange. Mutate (). The response (decoratedResponse). The build ());
}


View the return information, found that the contentType is null?

CodePudding user response:

Calls the method is a c # GetRequestStream () method

CodePudding user response:

There are a great god please help?

CodePudding user response:

Remove the filter you configured to direct, to test, should be the filter you have any question, enhance the log, recording analysis analysis

CodePudding user response:

reference tianfang reply: 3/f
remove your filter configured to direct, to test, should be the filter you have any question, enhance the log, recording analysis analysis

To check the reason, request brought Expect=100 - continue inside, cause the request does not return, after removing it
  • Related