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

Spring MVC/Servlet implementation #36

Closed
spencergibb opened this issue Mar 22, 2017 · 28 comments · Fixed by #2949
Closed

Spring MVC/Servlet implementation #36

spencergibb opened this issue Mar 22, 2017 · 28 comments · Fixed by #2949
Milestone

Comments

@spencergibb
Copy link
Member

spencergibb commented Mar 22, 2017

Would probably need a Servlet implementation of ServerWebExchange so that predicates and filters can be reused.

This was a bad idea, though I tried.

@joshiste
Copy link

I'm just curious. Will this issue be targeted for a 2.x release?

@spencergibb
Copy link
Member Author

@joshiste it will not be

@spencergibb
Copy link
Member Author

Useful for those who can't (or won't) use webflux.

@narasimhamurthyk3

This comment has been minimized.

@wzlee
Copy link

wzlee commented May 7, 2020

Is there any progress?

@spencergibb
Copy link
Member Author

No

@pards
Copy link

pards commented Sep 17, 2020

Is there a plan to allow Spring MVC?
This prevents us from using our common libraries such logging filters in our gateway implementation.

@spencergibb
Copy link
Member Author

#36 (comment)

@mohanrao
Copy link

mohanrao commented Nov 9, 2020

@spencergibb we have been using spring cloud zuul with @EnableZuulProxy mode in an spring boot app which has some rest endpoints exposed with restcontoller. What is the suggestion to use spring cloud gateway in this situation

@spencergibb
Copy link
Member Author

@mohanrao only if you migrate to a webflux application. If you aren't doing anything serlvet specific and are using spring annotations, it shouldn't be too difficult.

@mohanrao
Copy link

Thanks @spencergibb . I will try migrating to a web flux . Our application uses oracle so it's not a true migration for some/most of the rest endpoints

Johnny850807 pushed a commit to Johnny850807/spring-cloud-gateway that referenced this issue Dec 14, 2020
* Added classes for async load balancer interceptor

Fixes spring-cloud#36
@Jeffrey-Hassan
Copy link

+1 for this. My use case is actually quite simple -- I work for a large corporation and want to use spring cloud with a gateway service, but the security libraries to interact with corporate SSO are written in such a way that is extremely dependent on the Servlet Context (hard-coded HttpServletRequest objects throughout the entire stack). For better or worse, I'd be surprised if there's ever a reactive implementation of that library, so it simply doesn't work with spring cloud gateway. Assuming as of now, still no progress?

@spencergibb
Copy link
Member Author

Until it gets assigned a project or milestone, you can assume no progress.

@mohanrao
Copy link

@spencergibb is there any mechanism available to vote to get this needs to assigned to a project or milestone

@spencergibb
Copy link
Member Author

spencergibb commented Feb 16, 2021

The reaction in #36 (comment) is the only voting we have. Note, this is a major effort and basically a parallel implementation.

@spencergibb spencergibb added this to the 4.1.0-M1 milestone May 2, 2023
spencergibb added a commit that referenced this issue May 10, 2023
Includes:
- FilterFunctions
- HandlerFunctions
- TestRestClient

Fixes gh-36
@spencergibb spencergibb mentioned this issue May 10, 2023
75 tasks
@spencergibb spencergibb moved this to In Progress in 2023.0.0-M1 May 10, 2023
@anbusampath
Copy link
Contributor

anbusampath commented May 10, 2023

+1 as Project Loom getting finalized. It's good to have Spring MVC based Gateway.

@sandipchitale
Copy link

Will this support equivalent of the /zuul/ prefix support (bypass dispatcher servlet) of NetFlix Zuul for uploading large files . Or does that not apply to the new architecture? If the use case is still valid, what is the equivalent way to handle it in new Spring MVC implementation of SCG.

@spencergibb
Copy link
Member Author

spencergibb commented May 16, 2023

This will not bypass the dispatcher servlet. I do not know if that use case is valid outside of zuul

@sandipchitale
Copy link

sandipchitale commented May 30, 2023

I meant the original implementation in Netflix Zuul provided the /zuul/ prefix based bypass of DispatcherServlet because of some suckiness (a comment I saw on SO - https://stackoverflow.com/a/32100705 ) in DispatcherServlet, I think related to buffering of request/response or something like that. That will still be the issue in new SCG MVC implementation right? Hence my question. May be I am misunderstanding as to why originally /zuul/ support was added. And I did not mean to ask for exact /zuul/ prefix solution, but equivalent that deals with the original isuue.

spencergibb added a commit that referenced this issue Jun 8, 2023
Includes:
- FilterFunctions
- HandlerFunctions
- TestRestClient

Fixes gh-36
spencergibb added a commit that referenced this issue Jun 14, 2023
Includes:
- FilterFunctions
- HandlerFunctions
- TestRestClient

Fixes gh-36
spencergibb added a commit that referenced this issue Jun 19, 2023
Includes:
- FilterFunctions
- HandlerFunctions
- TestRestClient

Fixes gh-36
spencergibb added a commit that referenced this issue Jun 21, 2023
Includes:
- FilterFunctions
- HandlerFunctions
- TestRestClient

Fixes gh-36
spencergibb added a commit that referenced this issue Jun 24, 2023
Includes:
- FilterFunctions
- HandlerFunctions
- TestRestClient

Fixes gh-36
spencergibb added a commit that referenced this issue Jun 24, 2023
Includes:
- FilterFunctions
- HandlerFunctions
- TestRestClient

Fixes gh-36
spencergibb added a commit that referenced this issue Jul 5, 2023
* Initial support for Gateway Server MVC

Includes:
- FilterFunctions
- HandlerFunctions
- TestRestClient

Fixes gh-36

* Adds ProxyExchange abstraction and RestTemplate impl.

Also formatting and polish

* Migrates from RestTemplateProxyExchange to ClientHttpRequestFactoryProxyExchange

Also implements GatewayServerResponse that is mutable.

* Removes RestTemplateProxyExchange.javaˆ

* Allows resolving uri by request attribute

* formattingˆ

* Moved beans to GatewayServerMvcAutoConfiguration

* Removes unneeded GatewayServerRequestBuilder.javaˆ

* Adds addRequestParameter filter

* Adds FilterFunctions.setPath()

* Moves FilterFunctions.addResponseHeader()

* Adds FilterFunctions.stripPrefix()

* Moves ProxyExchangeHandlerFunction to bean.

This allows easier autoconfiguration.

* Adds HttpHeadersFilter and RemoveHopByHopR*HeadersFilter

* removes unused imports

* Initial local configuration compatibility with webflux server.

Borrows Operation framework from Spring Boot Actuator.

Discoverable predicates and filters are found via spring.factories. Currently only static methods are supported.

Shortcut configuration is not yet supported.

* Organized classes into individual packages

* Copy request body to proxy exchange client request body

* Changes getApplicationContext() to user RequestContextUtils

rather than relying on the DispatcherServlet attribute.

* Moves content to MvcUtils.java

* Allows for multiple predicates and filters with the same name.

* a get only route is to0 broad and causes a request loop

* Save the anded predicate, whoops.

Adds some trace logging as well.

* Adds initial support for load balancing

* Moves TestRestClient to client package

* Moves handler related classes to handler package

* Creates HandlerDiscoverer to dynamically load HandlerFunctions

* polish

* polish

* Extracts findOperation()ˆ

* Extracts invokeOperation()

* Adds support for config uri type lb://serviceId

* Adds uri template variable support.

Adds supporting methods to MvcUtils.java.

Expands uri templates in existing filters.

* Adds support for host predicate

* Adds support for circuit breaker filter

* Adds initial support for retry filter

* Adds initial support for Bucket4j rateLimit filter

* Removes separate *Supplier classes if not needed.

* Adds header request predicate

* Fixes accept() methods to better values.

* Adds support for cookie predicate

* Adds support for after, before and between time predicates

* Adds support for FilterFunctions.rewritePath()

* Adds support for shortcut configuration.

Adds Shortcut annotation to provide hints.

Extracts OperationMethod into an interface with DefaultOperationMethod the impl.

Adds NormalizedOperationMethod which uses the Shortcut annotation to normalize the arguments and give them the right keys. All Shortcut logic is here.

* Format comments

* Adds support for Forwarded and X-Forwarded-* Headers

* Moves TestLoadBalancerConfig to top level to shareˆ

* Uses JdkClientHttpRequestFactory.

* Adds routeId to RouterFunction.withAttribute()

* Adds toString()ˆ

* Shows sample of combining java dsl

* Implements refresh of config based routes.

* Adds support for proxying multipart form data.

* removes unneeded multipart propertyˆ

* Adds support for RestClientProxyExchange

Not yet the default. Waiting for a change that will eliminate reflection in RestClientProxyExchange

Created ProxyExchange.DefaultRequestBuilder as the code was duplicated in the two implementations.

* polishes ProxyExchangeHandlerFunction

* Adds ProxyExchange.ResponseConsumer

Adds ProxyExchange.Response and migrates away from ResponseHeadersFilter on the request to something more generic.

* Closes clientHttpResponse appropriately.

* Closes clientHttpResponse appropriately.

* Updates to use new WriteFunction interface

* Removes unused apache httpclient5 dependency

* Uses new RestClientCustomizer to add ClientHttpRequestFactory.

Changes constructor of RestClientProxyExchange to take a RestClient.
@github-project-automation github-project-automation bot moved this from In Progress to Done in 2023.0.0-M1 Jul 5, 2023
@spencergibb
Copy link
Member Author

The initial implementation is there. Track the TODO list #2949 (comment) for additional things for M1. Remaining TODO's will get added to new issues for upcoming milestones.

@spencergibb
Copy link
Member Author

spencergibb commented Jul 7, 2023

@sandipchitale reading my SO answer and after adding support for multipart formdata (file uploads), I believe (though I haven't verified) that the modifications I made to multipart handling for an MVC gateway will eliminate previous problems with zuul. Basically, I turn off multipart parsing for gateway requests.

863a199#diff-af291548ea3a7b7c047c3de2f9ef6d6ba8402251f8683be19056eb60dddde0eeR62-R75

@giger85
Copy link
Contributor

giger85 commented Aug 10, 2023

@spencergibb
This function is very interesting.
I will try to change my application from webflux to mvc with upcoming spring boot 3.2 and virtual thread.

@patrickli2013
Copy link

@spencergibb thanks for the hard work! May I know when the M2 will be released?

@spencergibb
Copy link
Member Author

Next week, but this was released in M1

@sandipchitale
Copy link

sandipchitale commented Oct 12, 2023

We have an implementation in a SpringMVC (gateway+angular frontend app) with embedded @EnableZuulProxy. Now that NetFlix Zuul is EOLed we tried to implement some of this using ProxyExchange with mixed success.

It will be helpful if there was some guidance provided on how to replace @EnableZuulProxy functionality with Spring Cloud Gateway MVC.fn . Or the provided functionality is already doing what @EnableZuulProxy does?

@spencergibb
Copy link
Member Author

It may be the subject of a blog or something, but zuul hasn't been supported for a number of years. This implementation provides much more functionality than the zuul implementation though there are likely incompatibilities.

@sandipchitale
Copy link

sandipchitale commented Oct 12, 2023

Thanks @spencergibb. I am pretty confident that a lot of people may be looking for replacement of @EnableZuulProxy. So either a blog post or some form of documentation on this will be extremely helpful. May be we can request Josh long to do a Spring tip on this topic.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
No open projects
Status: Done
Development

Successfully merging a pull request may close this issue.