You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shenyu.apache.org by GitBox <gi...@apache.org> on 2021/06/25 10:32:07 UTC
[GitHub] [incubator-shenyu] yzydhf opened a new issue #1673: Parse the response
yzydhf opened a new issue #1673:
URL: https://github.com/apache/incubator-shenyu/issues/1673
## Question
Currently we have a situation where we need to process the response, so we need to parse the response body to get the specific data, and then do the following. Here is the process (for example internationalization handler):
public static Mono<Void> result(ServerHttpRequest request, ClientResponse clientResponse, ServerHttpResponse response) {
// DataBufferFactory bufferFactory = response.bufferFactory();
// ServerHttpResponseDecorator decoratedResponse = new ServerHttpResponseDecorator(response) {
// @Override
// public Mono<Void> writeWith(Publisher<? extends DataBuffer> body) {
// if (body instanceof Flux) {
// Flux<? extends DataBuffer> fluxBody = (Flux<? extends DataBuffer>) body;
// return super.writeWith(fluxBody.buffer().map(dataBuffers -> {
//
// DataBuffer dataBuffer = new DefaultDataBufferFactory().join(dataBuffers);
// byte[] content = new byte[dataBuffer.readableByteCount()];
//
// dataBuffer.read(content);
// DataBufferUtils.release(dataBuffer);
//
// String responseStr = new String(content, Charsets.UTF_8);//Garbled
//
// String result = "";
// try{
// ObjectMapper om = new ObjectMapper();
// om.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
// JsonNode jsonNode = om.readTree(responseStr).get(Constants.RESPONSE_CODE_KEY);//Parse error
// if(null == jsonNode){
// HttpResult httpResult = JsonUtils.parseObject(responseStr, HttpResult.class);
// if (!httpResult.isSuccess()) {
// // internationalization
// I18nHandle.errorMsgI18n(httpResult, request.getHeaders().getFirst("Accept-Language"));
// }
// result = om.writeValueAsString(httpResult);
// }
// }catch (Exception e){
// e.printStackTrace();
// }
// this.getDelegate().getHeaders().setContentLength(result.getBytes().length);
// return bufferFactory.wrap(result.getBytes());
// }));
// }
// // if body is not a flux. never got there.
// return super.writeWith(body);
// }
// };
BodyExtractor<Flux<DataBuffer>, ReactiveHttpInputMessage> bodyExtractor = BodyExtractors.toDataBuffers();
return response.writeWith(clientResponse.body(bodyExtractor));
}
The above code ‘String responseStr = new String(content, Charsets.UTF_8); ’ appears garbled。
This causes subsequent JSON parsing errors。
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [incubator-shenyu] yu199195 closed issue #1673: Parse the response
Posted by GitBox <gi...@apache.org>.
yu199195 closed issue #1673:
URL: https://github.com/apache/incubator-shenyu/issues/1673
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@shenyu.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [incubator-shenyu] SaberSola commented on issue #1673: Parse the response
Posted by GitBox <gi...@apache.org>.
SaberSola commented on issue #1673:
URL: https://github.com/apache/incubator-shenyu/issues/1673#issuecomment-869747195
Maybe your business is garbled,or you can check the HttpMessageConverter
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@shenyu.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [incubator-shenyu] SaberSola commented on issue #1673: Parse the response
Posted by GitBox <gi...@apache.org>.
SaberSola commented on issue #1673:
URL: https://github.com/apache/incubator-shenyu/issues/1673#issuecomment-869747195
Maybe your business is garbled,or you can check the HttpMessageConverter
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@shenyu.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org