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

When using SimpleClientHttpRequestFactory, non-GET requests sent with RestTemplate have the wrong HttpMethod when SSLBundles are used #36007

Closed
TheReaLedu opened this issue Jun 21, 2023 · 0 comments
Assignees
Labels
type: bug A general bug
Milestone

Comments

@TheReaLedu
Copy link

TheReaLedu commented Jun 21, 2023

Spring Boot Version: 3.1.0
Java version: 17

When using newly (in 3.1.0) added support for SSLBundles, all HTTP requests made via RestTemplate (org.springframework.web.client.RestTemplate) are sent as GET requests, even if the request was made as other Http method.

For example, RestTemplate call like this (POST)

restTemplate.postForEntity(httpRequest.getUrl(), httpPayload, httpRequest.getReturnClass());

is logged as GET request on remote NGINX web server.

RestTemplate is registered as Bean with following:

     @Bean
    public RestTemplate configureRestTemplate(RestTemplateBuilder restTemplateBuilder, SslBundles sslBundles)
    {
        return restTemplateBuilder
                .setSslBundle(sslBundles.getBundle("server"))
                .build();
    }

From what i could see from debugging, this method call checks for ssl bundle, but does not call setRequestMethod() on the connection object:
ClientHttpRequestFactories.prepareConnection()

@Override
protected void prepareConnection(HttpURLConnection connection, String httpMethod) throws IOException {
  if (this.sslBundle != null && connection instanceof HttpsURLConnection secureConnection) {
	  SSLSocketFactory socketFactory = this.sslBundle.createSslContext().getSocketFactory();
	  secureConnection.setSSLSocketFactory(socketFactory);
  }
}

For reference, default prepareConnection() implementation that is invoked when SslBundles are not used (different RequestFactory implementation):

SimpleClientHttpRequestFactory.prepareConnection()

protected void prepareConnection(HttpURLConnection connection, String httpMethod) throws IOException {
  if (this.connectTimeout >= 0) {
	  connection.setConnectTimeout(this.connectTimeout);
  }
  if (this.readTimeout >= 0) {
	  connection.setReadTimeout(this.readTimeout);
  }
  connection.setDoInput(true);
  if ("GET".equals(httpMethod)) {
	  connection.setInstanceFollowRedirects(true);
  }
  else {
	  connection.setInstanceFollowRedirects(false);
  }
  if ("PUT".equals(httpMethod) || "POST".equals(httpMethod)) {
	  connection.setDoOutput(true);
  }
  else {
	  connection.setDoOutput(false);
  }
  connection.setRequestMethod(httpMethod);   // <- set request method
}
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Jun 21, 2023
@wilkinsona wilkinsona self-assigned this Jun 21, 2023
@wilkinsona wilkinsona added the type: bug A general bug label Jun 21, 2023
@wilkinsona wilkinsona added this to the 3.1.x milestone Jun 21, 2023
@wilkinsona wilkinsona removed the status: waiting-for-triage An issue we've not yet triaged label Jun 21, 2023
@wilkinsona wilkinsona changed the title REST requests are sent with wrong HttpMethod when SSLBundles are used When using SimpleClientHttpRequestFactory, non-GET requests sent with RestTemplate have the wrong HttpMethod when SSLBundles are used Jun 21, 2023
@wilkinsona wilkinsona modified the milestones: 3.1.x, 3.1.1 Jun 21, 2023
ndwlocatieservices added a commit to ndwnu/nls-accessibility-map that referenced this issue Oct 31, 2024
This PR contains the following updates:

| Package | Type | Update | Change |
|---|---|---|---|
| [nu.ndw.nls.geometry:nls-geometry](https://spring.io/projects/spring-boot) ([source](https://github.com/spring-projects/spring-boot)) | compile | patch | `3.1.0` -> `3.1.1` |
| [nu.ndw.nls:routing-map-matcher-library](https://spring.io/projects/spring-boot) ([source](https://github.com/spring-projects/spring-boot)) | compile | patch | `13.0.3` -> `13.0.4` |
| [nu.ndw.nls.springboot:openapi](https://spring.io/projects/spring-boot) ([source](https://github.com/spring-projects/spring-boot)) | build | patch | `5.0.7` -> `5.0.8` |
| [nu.ndw.nls.springboot:oauth2-client-credentials](https://spring.io/projects/spring-boot) ([source](https://github.com/spring-projects/spring-boot)) | compile | patch | `5.0.7` -> `5.0.8` |
| [nu.ndw.nls.springboot:test](https://spring.io/projects/spring-boot) ([source](https://github.com/spring-projects/spring-boot)) | test | patch | `5.0.7` -> `5.0.8` |
| [nu.ndw.nls.springboot:security](https://spring.io/projects/spring-boot) ([source](https://github.com/spring-projects/spring-boot)) | compile | patch | `5.0.7` -> `5.0.8` |
| [nu.ndw.nls.springboot:messaging](https://spring.io/projects/spring-boot) ([source](https://github.com/spring-projects/spring-boot)) | compile | patch | `5.0.7` -> `5.0.8` |
| [nu.ndw.nls.springboot:monitoring](https://spring.io/projects/spring-boot) ([source](https://github.com/spring-projects/spring-boot)) | compile | patch | `5.0.7` -> `5.0.8` |
| [nu.ndw.nls.springboot:client-feign](https://spring.io/projects/spring-boot) ([source](https://github.com/spring-projects/spring-boot)) | compile | patch | `5.0.7` -> `5.0.8` |
| [nu.ndw:nls-nwb-data-access-jooq](https://spring.io/projects/spring-boot) ([source](https://github.com/spring-projects/spring-boot)) | compile | patch | `7.1.4` -> `7.1.5` |
| [org.codehaus.mojo:exec-maven-plugin](https://www.mojohaus.org/exec-maven-plugin) ([source](https://github.com/mojohaus/exec-maven-plugin)) | build | minor | `3.4.1` -> `3.5.0` |
| [org.springframework.boot:spring-boot-starter-parent](https://spring.io/projects/spring-boot) ([source](https://github.com/spring-projects/spring-boot)) | parent | patch | `3.3.4` -> `3.3.5` |

---

### Release Notes

<details>
<summary>spring-projects/spring-boot (nu.ndw.nls.geometry:nls-geometry)</summary>

### [`v3.1.1`](https://github.com/spring-projects/spring-boot/releases/tag/v3.1.1)

[Compare Source](spring-projects/spring-boot@v3.1.0...v3.1.1)

#### 🐞 Bug Fixes

-   Websockets don't work when using WebFlux with Jetty [#&#8203;36009](spring-projects/spring-boot#36009)
-   When using SimpleClientHttpRequestFactory, non-GET requests sent with RestTemplate have the wrong HttpMethod when SSLBundles are used [#&#8203;36007](spring-projects/spring-boot#36007)
-   Spring Boot properties migrator can create circular references [#&#8203;35934...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug A general bug
Projects
None yet
Development

No branches or pull requests

3 participants