Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Forwarding route produces error at the first request. #3474

Closed
onacit opened this issue Jul 28, 2024 · 1 comment
Closed

Forwarding route produces error at the first request. #3474

onacit opened this issue Jul 28, 2024 · 1 comment

Comments

@onacit
Copy link

onacit commented Jul 28, 2024

Describe the bug

First request of a forwarding route fails.

I have a cached-enabled route and a forwarding route.

        - id: some
          uri: http://...
          predicates:
            - Method=GET
            - Path=/some
          filters:
            - AddResponseHeader=Vary, Accept
            - LocalResponseCache=..., ...
        - id: other
          uri: forward:/some
          predicates:
            - Method=GET
            - Header=Accept, application/hal\+json
          filters:
            - SetRequestHeader=Accept, application/xml

The other route fails at first time after the application launched. Subsequent requests work.

Seems like some class tries to clear a read-only thing.

12:22:34.080 [http-nio-8080-exec-3] ERROR o.a.c.c.C.[.[.[.[httpHandlerServlet] -- Servlet.service() for servlet [httpHandlerServlet] threw exception
java.lang.UnsupportedOperationException: null
	at org.springframework.http.ReadOnlyHttpHeaders.clear(ReadOnlyHttpHeaders.java:145)
	Suppressed: reactor.core.publisher.FluxOnAssembly$OnAssemblyException: 
Assembly trace from producer [reactor.core.publisher.MonoDefer] :
	reactor.core.publisher.Mono.defer(Mono.java:219)
	org.springframework.cloud.gateway.filter.NettyWriteResponseFilter.filter(NettyWriteResponseFilter.java:69)
Error has been observed at the following site(s):
	*__________Mono.defer ⇢ at org.springframework.cloud.gateway.filter.NettyWriteResponseFilter.filter(NettyWriteResponseFilter.java:69)
	*___________Mono.then ⇢ at org.springframework.cloud.gateway.filter.NettyWriteResponseFilter.filter(NettyWriteResponseFilter.java:69)
	|_    Mono.doOnCancel ⇢ at org.springframework.cloud.gateway.filter.NettyWriteResponseFilter.filter(NettyWriteResponseFilter.java:101)
	|_     Mono.doOnError ⇢ at org.springframework.cloud.gateway.filter.NettyWriteResponseFilter.filter(NettyWriteResponseFilter.java:102)
	*__________Mono.defer ⇢ at org.springframework.cloud.gateway.handler.FilteringWebHandler$DefaultGatewayFilterChain.filter(FilteringWebHandler.java:123)
	*__________Mono.defer ⇢ at org.springframework.cloud.gateway.handler.FilteringWebHandler$DefaultGatewayFilterChain.filter(FilteringWebHandler.java:123)
	*__________Mono.defer ⇢ at org.springframework.cloud.gateway.handler.FilteringWebHandler$DefaultGatewayFilterChain.filter(FilteringWebHandler.java:123)
	|_     Mono.doFinally ⇢ at org.springframework.cloud.gateway.filter.RemoveCachedBodyFilter.filter(RemoveCachedBodyFilter.java:35)

Sample

You can run my Application and invoke the following command.

curl --location 'http://localhost:8080/api/retrieveEngAddressService/states' \
--header 'Accept: application/hal+json'
@onacit
Copy link
Author

onacit commented Aug 11, 2024

public class SetResponseHeadersAfterCacheExchangeMutator implements AfterCacheExchangeMutator {

	@Override
	public void accept(ServerWebExchange exchange, CachedResponse cachedResponse) {
		ServerHttpResponse response = exchange.getResponse();
		response.getHeaders().clear(); // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
		response.getHeaders().addAll(cachedResponse.headers());
	}

}

@onacit onacit closed this as completed Aug 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant