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

Add initialization of hints to request/response modification. #299

Closed
wants to merge 8 commits into from
Closed

Conversation

re6exp
Copy link
Contributor

@re6exp re6exp commented Apr 24, 2018

No description provided.

@pivotal-issuemaster
Copy link

@re6exp Please sign the Contributor License Agreement!

Click here to manually synchronize the status of this Pull Request.

See the FAQ for frequently asked questions.

@@ -123,14 +124,14 @@ public GatewayFilterSpec hystrix(Consumer<HystrixGatewayFilterFactory.Config> co
return filter(factory.apply(this.routeBuilder.getId(), configConsumer));
}

public <T, R> GatewayFilterSpec modifyRequestBody(Class<T> inClass, Class<R> outClass, RewriteFunction<T, R> rewriteFunction) {
public <T, R> GatewayFilterSpec modifyRequestBody(Class<T> inClass, Class<R> outClass, RewriteFunction<T, R> rewriteFunction, Map<String, Object> inHints, Map<String, Object> outHints) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since RC1 is already public, let's leave the original methods and either overload, or create a spec.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't worry about RC1, just keep the originals and either overload or create a spec similar to what is in your branch.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, I'll overload methods with specs. Is it OK? If yes, tomorrow I'll send you PR to master branch, keeping existed signatures as they were before.

OK, tomorrow I am going to review what you write here... It's late (Moscow time 10 p.m.), I'm pretty tired and I'm going to go to bed.

@spencergibb
Copy link
Member

Tomorrow is fine

@codecov-io
Copy link

codecov-io commented Apr 25, 2018

Codecov Report

Merging #299 into master will decrease coverage by 9.29%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff            @@
##           master     #299     +/-   ##
=========================================
- Coverage   71.73%   62.43%   -9.3%     
=========================================
  Files         119        8    -111     
  Lines        3216      410   -2806     
  Branches      231       34    -197     
=========================================
- Hits         2307      256   -2051     
+ Misses        783      130    -653     
+ Partials      126       24    -102
Impacted Files Coverage Δ
...framework/cloud/gateway/route/builder/UriSpec.java
...ud/gateway/filter/AdaptCachedBodyGlobalFilter.java
.../gateway/config/GatewayRedisAutoConfiguration.java
...ter/factory/rewrite/HttpMessageWriterResponse.java
...cloud/gateway/filter/NettyWriteResponseFilter.java
...filter/factory/RedirectToGatewayFilterFactory.java
.../gateway/handler/RoutePredicateHandlerMapping.java
...way/filter/ratelimit/PrincipalNameKeyResolver.java
...CloudFoundryRouteServiceRoutePredicateFactory.java
...y/filter/factory/AbstractGatewayFilterFactory.java
... and 97 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 7a1bbf0...98394ab. Read the comment docs.

@pivotal-issuemaster
Copy link

@re6exp Thank you for signing the Contributor License Agreement!

@re6exp
Copy link
Contributor Author

re6exp commented Apr 27, 2018

@spencergibb
Hm... do not merge, I've found some errors while I've been adding tests. Now I'm fixing them.
They are:

  • no MediaType to set to out results both in request/response, they are only being got from headers;
  • request tests do not work completely because of throw new IllegalStateException( "SyncInvocableHandlerMethod should have completed synchronously."); in RewriteUtils#process();
  • see also issue ModifyResponse doesn't modify Content-Length Header #304 ;

@re6exp
Copy link
Contributor Author

re6exp commented Apr 28, 2018

@spencergibb

I've fixed some issues with response body modification. Tests covering response body modification were copied from my old branch with some modification. They work. With Spring Web 5.0.6 BUILD-SNAPSHOT all of them run successfully including SSE.

BUT tests for request body modification can't even run because of IllegalStateException in RewriteUtils. I have no idea how to fix it.

@spencergibb
Copy link
Member

rebuilding

Copy link
Member

@spencergibb spencergibb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I few comments

<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>5.0.6.BUILD-SNAPSHOT</version>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is bad. This should already be a dependency.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prior version doesn't work. I wrote comments here and in old issues.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rebase, and you won't need this anymore.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Glad to hear that!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed (by my side - not committed yet).

*
*/
@Configuration
@EnableWebFlux
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is autoconfigured by boot.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in other words, it shouldn't be needed here, just WebFluxConfigurer

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed.

@@ -37,7 +40,7 @@

import static org.springframework.cloud.gateway.filter.factory.rewrite.RewriteUtils.process;

public class ModifyRequestBodyGatewayFilterFactory
public class ModifyRequestBodyGatewayFilterFactory<T, R>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think these generics make sense here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When user writes code it helps him.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I understand, old code will work too.

@spencergibb
Copy link
Member

Build is timing out

Running org.springframework.cloud.gateway.filter.body.RewriteRequestBodyFilterTest

@re6exp
Copy link
Contributor Author

re6exp commented May 17, 2018

Hm, it worked... 22 days ago.

UPD: code worked - I add local snapshot to my app, it works.

@re6exp
Copy link
Contributor Author

re6exp commented May 17, 2018

The main problem for me was request modification tests. They were being terminated abnormally.
Hints are working in real code of my app.

So, Spencer, should I change smth you wrote about, and commit one more time, or you plan to do by yourself?

@re6exp
Copy link
Contributor Author

re6exp commented May 17, 2018

I can do it tomorrow.

@re6exp
Copy link
Contributor Author

re6exp commented May 18, 2018

Tests for response body modification run perfectly - thx to Rossen, he fixed problem with sse serialization in v. 5.0.6 which has been released some time ago.

But ModifyRequestBodyTest doesn't work - neither before nor now, as I wrote in comments before. Because I don't use request body modification in my app I can't confirm this code does work really. Tests do not. These tests worked on my original branch, with old API - this API was bad I know but it worked, tests were passed. After I change API to the new, I always get an exception throwed in RewriteUtils while testing request body modification. I have no idea how to fix it.

Time out while running ModifyRequestBodyTest, the cause is:

java.lang.IllegalStateException: SyncInvocableHandlerMethod should have completed synchronously.
	at org.springframework.cloud.gateway.filter.factory.rewrite.RewriteUtils.process(RewriteUtils.java:49) ~[classes/:na]
	at org.springframework.cloud.gateway.filter.factory.rewrite.ModifyRequestBodyGatewayFilterFactory.lambda$0(ModifyRequestBodyGatewayFilterFactory.java:66) ~[classes/:na]
	at org.springframework.cloud.gateway.filter.OrderedGatewayFilter.filter(OrderedGatewayFilter.java:44) ~[classes/:na]
	at org.springframework.cloud.gateway.handler.FilteringWebHandler$DefaultGatewayFilterChain.lambda$0(FilteringWebHandler.java:115) ~[classes/:na]
	at reactor.core.publisher.MonoDefer.subscribe(MonoDefer.java:44) ~[reactor-core-3.1.7.RELEASE.jar:3.1.7.RELEASE]
	at reactor.core.publisher.MonoDefer.subscribe(MonoDefer.java:52) ~[reactor-core-3.1.7.RELEASE.jar:3.1.7.RELEASE]
	at reactor.core.publisher.Mono.subscribe(Mono.java:3080) ~[reactor-core-3.1.7.RELEASE.jar:3.1.7.RELEASE]
	at reactor.core.publisher.MonoIgnoreThen$ThenIgnoreMain.drain(MonoIgnoreThen.java:167) ~[reactor-core-3.1.7.RELEASE.jar:3.1.7.RELEASE]

This blocks any changes I made in this PR.

@rstoyanchev
Copy link

I've only had a very brief look, but RewriteUtils#process seems to be written in a way that assumes no blocking can occur. When I look at places where it's used, that's not the case, like here reading from the body.

The error message is referring to a Spring Framework class, the SyncInvocableHandlerMethod, which is not relevant or used here AFAICS, but that class has a similar check and it's guaranteed to not block because it can only be configured with synchronous argument resolvers.

@re6exp
Copy link
Contributor Author

re6exp commented May 19, 2018

So, this leads to when I run tests, they can't be successfully finished, do I understand right?

Reading the body cause to blocking operation, which is disallowed (so isTerminated() check returns false) and leads junit tests to crash... Do I understand your comment correct?

There is an example of a gateway application, which somehow can be executed and uses httpbin.org-like backend. I did not run it. May be it works, OK, but the tests do not. :(

I can assume it my fault, but this code works with another API and should, in principle, working here too.

@rstoyanchev
Copy link

Reading the body cause to blocking operation, which is disallowed (so isTerminated() check returns false) and leads junit tests to crash... Do I understand your comment correct?

The body may not be read immediately, so the isTerminated check makes no sense. It cannot be guaranteed to return true.

@re6exp
Copy link
Contributor Author

re6exp commented May 21, 2018

And in case of using junits it crashs. As I guessed...
Thank you, Rossen!

@re6exp re6exp mentioned this pull request Jun 9, 2018
22 tasks
@re6exp re6exp closed this Jun 21, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants