spring-cloud-gateway icon indicating copy to clipboard operation
spring-cloud-gateway copied to clipboard

java.lang.UnsupportedOperationException: null

Open blameAndEva opened this issue 3 years ago • 2 comments

  private Mono<Void> writeBodyLog(ServerWebExchange exchange, GatewayFilterChain chain, GatewayLog gatewayLog) {

        ServerRequest serverRequest = ServerRequest.create(exchange, messageReaders);


        Mono<String> modifiedBody = serverRequest.bodyToMono(String.class)
                .flatMap(body ->{
                    gatewayLog.setRequestBody(body);
                    return Mono.just(body);
                });

      
        BodyInserter bodyInserter = BodyInserters.fromPublisher(modifiedBody, String.class);

        HttpHeaders headers = new HttpHeaders();
        headers.putAll(exchange.getRequest().getHeaders());

        // the new content type will be computed by bodyInserter
        // and then set in the request decorator
        headers.remove(HttpHeaders.CONTENT_LENGTH);

        CachedBodyOutputMessage outputMessage = new CachedBodyOutputMessage(exchange, headers);


        return bodyInserter.insert(outputMessage, new BodyInserterContext())
                // .log("modify_request", Level.INFO)
                .then(Mono.defer(() -> {
                    ServerHttpRequest decorator = decorate(exchange, headers, outputMessage);
                    return chain.filter(exchange.mutate().request(decorator).build());
                }));


    }

blameAndEva avatar May 28 '22 21:05 blameAndEva

try to log the body of request in a gateWay filter and found the same probleam java.lang.UnsupportedOperationException: null #861 i try to add the request body is just does not work

blameAndEva avatar May 28 '22 21:05 blameAndEva

more detail about error : java.lang.UnsupportedOperationException: null at java.util.AbstractList.add(AbstractList.java:148) ~[na:1.8.0_251] Suppressed: reactor.core.publisher.FluxOnAssembly$OnAssemblyException: Error has been observed at the following site(s):

blameAndEva avatar May 28 '22 22:05 blameAndEva

If you'd like us to spend some time investigating, please take the time to provide a complete, minimal, verifiable sample (something that we can unzip attached to this issue or git clone, build, and deploy) that reproduces the problem.

spencergibb avatar Mar 13 '24 20:03 spencergibb

If you would like us to look at this issue, please provide the requested information. If the information is not provided within the next 7 days this issue will be closed.

spring-cloud-issues avatar Mar 20 '24 20:03 spring-cloud-issues

Closing due to lack of requested feedback. If you would like us to look at this issue, please provide the requested information and we will re-open the issue.

spring-cloud-issues avatar Mar 27 '24 20:03 spring-cloud-issues