spring-cloud / spring-cloud-gateway

An API Gateway built on Spring Framework and Spring Boot providing routing and more.
http://cloud.spring.io
Apache License 2.0
4.55k stars 3.33k forks source link

Support running the gateway with other reactive containers besides netty #145

Open muzuro opened 6 years ago

muzuro commented 6 years ago

I am trying to use tomcat instead netty. To achive this i have excluded netty from dependencies and included tomcat, so my build.gradle dependecies:

dependencies {
    compile (group: 'org.springframework.cloud', name: 'spring-cloud-starter-gateway', version: '2.0.0.M4') {
        exclude group: 'org.springframework.boot', module: 'spring-boot-starter-netty'
    }
    compile group: 'org.springframework.boot', name: 'spring-boot-starter-tomcat', version: '2.0.0.M7'
    compile group: 'org.springframework.boot', name: 'spring-boot-starter-webflux'
}

Hower it is not enough, i get ClassCastException:

java.lang.ClassCastException: org.springframework.core.io.buffer.DefaultDataBufferFactory cannot be cast to org.springframework.core.io.buffer.NettyDataBufferFactory
    at org.springframework.cloud.gateway.filter.NettyWriteResponseFilter.lambda$filter$0(NettyWriteResponseFilter.java:61) ~[spring-cloud-gateway-core-2.0.0.M4.jar:2.0.0.M4]
    at reactor.core.publisher.MonoDefer.subscribe(MonoDefer.java:44) ~[reactor-core-3.1.1.RELEASE.jar:3.1.1.RELEASE]
    at reactor.core.publisher.Mono.subscribe(Mono.java:2913) ~[reactor-core-3.1.1.RELEASE.jar:3.1.1.RELEASE]
    at reactor.core.publisher.MonoIgnoreThen$ThenIgnoreMain.drain(MonoIgnoreThen.java:167) ~[reactor-core-3.1.1.RELEASE.jar:3.1.1.RELEASE]

Is it possible to use tomcat with gateway instead netty? Thanks!

andrewe123 commented 5 years ago

I seem to have hit that same issue when trying to test a gateway application, and am trying to understand my options. Specifically I have a gateway application with some routes that I want to stub out for unit testing.

https://github.com/spring-cloud/spring-cloud-gateway/blob/dc4181bbb0ad04383fb1722f589cfa0a199295e8/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/filter/NettyWriteResponseFilter.java#L81

It looks like this makes the gateway incompatible with every mock server I've tried (okhttp mockserver, wiremock, mockserver-netty), as the mock response is not castable to NettyDataBufferFactory.

Does this sound right so far? If so has anyone came up with a workaround for testing? I'm thinking, instead of using a mock server, stubbing WebClient out might be a suitable option also?

gauravhanda02 commented 5 years ago

Is this issue resolved with Greenwich.SR3 release. Is there a sample pom to use Tomcat with spring cloud gateway?

gauravhanda02 commented 5 years ago

@spencergibb : Is this issue resolved with Greenwich.SR3 release. Is there a sample pom to use Tomcat with spring cloud gateway?

spencergibb commented 5 years ago

No. It won't be in Greenwich, it will be in a Hoxton Service Release (SR)

spencergibb commented 4 years ago

85193a0d98fb9f8b1caabc30071a8a9041d69536 may have fixed this functionality. The class cast exceptions mentioned here https://github.com/spring-cloud/spring-cloud-gateway/issues/145#issue-284704955 are now gone.

Remaining items:

marcingrzejszczak commented 4 years ago

Hmm those would be tests inside the gateway or some separate ones? Cause we could even embed running those tests inside the gateway build.

spencergibb commented 4 years ago

Just all the tests already in gateway

spencergibb commented 4 years ago

See #1544 for progress

jingbing commented 4 years ago

@spencergibb Is it possible to use tomcat with gateway now?

dlsrb6342 commented 4 years ago

Hi @spencergibb I wanna use WebClientHttpRoutingFilter and WebClientWriteResponseFilter with Netty. Is there any issue with Netty? And is there any way to disable NettyRoutingFilter?

spencergibb commented 4 years ago

@dlsrb6342 it's unrelated to this issue. There's no way to disable the netty beans at this moment.

gaurav1264 commented 3 years ago

Hi @spencergibb Any update when tomcat support will be added to Spring cloud gateway please?

manisha-shetty commented 2 years ago

Adding this to the webflux security config resolved the issue for me

`@Bean @Primary public RequestUpgradeStrategy requestUpgradeStrategy() { return new TomcatRequestUpgradeStrategy(); }

@Bean @Primary WebSocketClient tomcatWebSocketClient() { return new TomcatWebSocketClient(); }`

klaus-cicd commented 11 months ago

New anomalies appear.

java.lang.ClassCastException: org.springframework.http.server.reactive.TomcatHttpHandlerAdapter$TomcatServerHttpRequest cannot be cast to javax.servlet.http.HttpServletRequest at org.springframework.web.reactive.socket.server.upgrade.TomcatRequestUpgradeStrategy.getNativeRequest(TomcatRequestUpgradeStrategy.java:159)

ShivaniSK commented 6 months ago

Adding this to the webflux security config resolved the issue for me

`@Bean @primary public RequestUpgradeStrategy requestUpgradeStrategy() { return new TomcatRequestUpgradeStrategy(); }

@bean @primary WebSocketClient tomcatWebSocketClient() { return new TomcatWebSocketClient(); }`

Hi @manisha-shetty , i still face same issue even after adding the above Beans

I added the above mentioned Beans in below class

@EnableMethodSecurity
@EnableWebFluxSecurity
@Configuration
public class SecurityConfig extends WebFluxAutoConfiguration {
}

Is this correct?

ShivaniSK commented 6 months ago

New anomalies appear.

java.lang.ClassCastException: org.springframework.http.server.reactive.TomcatHttpHandlerAdapter$TomcatServerHttpRequest cannot be cast to javax.servlet.http.HttpServletRequest at org.springframework.web.reactive.socket.server.upgrade.TomcatRequestUpgradeStrategy.getNativeRequest(TomcatRequestUpgradeStrategy.java:159)

Hi @klaus-cicd , is this resolved?