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

Gateway MVC: Path seems not passing through the request body #3183

Closed
estigma88 opened this issue Dec 12, 2023 · 13 comments
Closed

Gateway MVC: Path seems not passing through the request body #3183

estigma88 opened this issue Dec 12, 2023 · 13 comments

Comments

@estigma88
Copy link

Describe the bug
Path seems not passing through the request body, for instance:

spring:
  cloud:
    gateway:
      mvc:
        routes:
          - id: transcoder
            uri: http://localhost:8089
            predicates:
              - Path=/transcoder/v1/**

http://localhost:8089 is a Wiremock server. The following is the Wiremock logs:

                                               Request was not matched
                                               =======================

-----------------------------------------------------------------------------------------------------------------------
| Closest stub                                             | Request                                                  |
-----------------------------------------------------------------------------------------------------------------------
                                                           |
POST                                                       | POST
[path] /transcoder/v1/break                                | /transcoder/v1/break
                                                           |
{                                                          |                                                     <<<<< Body is not present
  "active" : true                                          |
}                                                          |
                                                           |
-----------------------------------------------------------------------------------------------------------------------

And there is the following exception:

java.io.EOFException: EOF reached while reading
	at java.net.http/jdk.internal.net.http.Http2Connection$Http2TubeSubscriber.onComplete(Http2Connection.java:1587) ~[java.net.http:na]
	at java.net.http/jdk.internal.net.http.SocketTube$InternalReadPublisher$ReadSubscription.signalCompletion(SocketTube.java:648) ~[java.net.http:na]
	at java.net.http/jdk.internal.net.http.SocketTube$InternalReadPublisher$InternalReadSubscription.read(SocketTube.java:853) ~[java.net.http:na]
	at java.net.http/jdk.internal.net.http.SocketTube$SocketFlowTask.run(SocketTube.java:181) ~[java.net.http:na]
	at java.net.http/jdk.internal.net.http.common.SequentialScheduler$SchedulableTask.run(SequentialScheduler.java:207) ~[java.net.http:na]
	at java.net.http/jdk.internal.net.http.common.SequentialScheduler.runOrSchedule(SequentialScheduler.java:280) ~[java.net.http:na]
	at java.net.http/jdk.internal.net.http.common.SequentialScheduler.runOrSchedule(SequentialScheduler.java:233) ~[java.net.http:na]
	at java.net.http/jdk.internal.net.http.SocketTube$InternalReadPublisher$InternalReadSubscription.signalReadable(SocketTube.java:782) ~[java.net.http:na]
	at java.net.http/jdk.internal.net.http.SocketTube$InternalReadPublisher$ReadEvent.signalEvent(SocketTube.java:965) ~[java.net.http:na]
	at java.net.http/jdk.internal.net.http.SocketTube$SocketFlowEvent.handle(SocketTube.java:253) ~[java.net.http:na]
	at java.net.http/jdk.internal.net.http.HttpClientImpl$SelectorManager.handleEvent(HttpClientImpl.java:1467) ~[java.net.http:na]
	at java.net.http/jdk.internal.net.http.HttpClientImpl$SelectorManager.lambda$run$3(HttpClientImpl.java:1412) ~[java.net.http:na]
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1596) ~[na:na]
	at java.net.http/jdk.internal.net.http.HttpClientImpl$SelectorManager.run(HttpClientImpl.java:1412) ~[java.net.http:na]

Sample
The following is a sample where you can find a test GatewayissueApplicationTests that is failing.

@liangsqrt
Copy link

i alse meet the same problem, my springboot version is 3.2.0 and the gateway version is org.springframework.cloud:spring-cloud-starter-gateway-mvc:4.1.0

@spencergibb spencergibb added this to the 4.1.1 milestone Dec 19, 2023
@spencergibb spencergibb moved this to In Progress in 2023.0.1 Dec 19, 2023
@spencergibb
Copy link
Member

the sample was missing a @RequestBody, though the issue is still valid.

@github-project-automation github-project-automation bot moved this from In Progress to Done in 2023.0.1 Dec 20, 2023
@estigma88
Copy link
Author

I just tested the sample with implementation("org.springframework.cloud:spring-cloud-starter-gateway-mvc:4.1.1") and it is still failing

@spencergibb
Copy link
Member

spencergibb commented Dec 28, 2023

the sample was missing a `@RequestBody on the body parameter

@estigma88
Copy link
Author

I don't follow, where exactly should I put the @RequestBody on the body parameter? The sample code has:

  • GatewayissueApplication main entry point
  • GatewayissueApplicationTests test
  • application.yml gateway config file

There is no @RestController or similar there. Maybe we are confusing this sample with other issues?

@spencergibb
Copy link
Member

I'll look after the holidays

@oleg-sukhov
Copy link

I face similar problem when using ProxyExchange from the spring-cloud-gateway-mvc. The use case is the following - we are just passing the @RequestBody parameter from one service to another via ProxyExchange. But seems the payload is empty.

@estigma88
Copy link
Author

Any updates on this issue?

@spencergibb
Copy link
Member

looking now

@spencergibb
Copy link
Member

If I remove rest-assured and wiremock and send it to httpbin, the body is sent just fine.

@spencergibb
Copy link
Member

If anyone can recreate this without wiremock and rest-assured, 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. No Kotlin please.

@estigma88
Copy link
Author

@spencergibb Thanks for spending time debugging this issue. You are right, Spring Cloud Gateway is working fine, I changed the HTTP client that it uses, from the JDK client to Apache client, and works fine. I just added this property to the application.yml:

spring:
  cloud:
    gateway:
      mvc:
        http-client:
          type: AUTODETECT

Seems like the JDK HTTP client has some problems connecting with Wiremock over HTTP2, as for the stacktrace here #3183 (comment)

@spencergibb
Copy link
Member

Anyone else able to recreate the issue without wiremock?

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

4 participants