Skip to content

Commit

Permalink
4.x: Helidon Webclient (4.0.10) is not routing the requests through p…
Browse files Browse the repository at this point in the history
…roxy configured using Proxy Builder. helidon-io#9022

Signed-off-by: Jorge Bescos Gascon <[email protected]>
  • Loading branch information
jbescos committed Jul 23, 2024
1 parent 1908a2f commit eb4b381
Show file tree
Hide file tree
Showing 4 changed files with 107 additions and 4 deletions.
6 changes: 6 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
<version.lib.junit-platform>1.9.3</version.lib.junit-platform>
<version.lib.kafka-junit5>3.2.3</version.lib.kafka-junit5>
<version.lib.mockito>2.23.4</version.lib.mockito>
<version.lib.mockserver>5.15.0</version.lib.mockserver>
<version.lib.restito>0.9.1</version.lib.restito>
<version.lib.rxjava2-jdk9-interop>0.1.0</version.lib.rxjava2-jdk9-interop>
<version.lib.rxjava>2.2.10</version.lib.rxjava>
Expand Down Expand Up @@ -1034,6 +1035,11 @@
<artifactId>mockito-core</artifactId>
<version>${version.lib.mockito}</version>
</dependency>
<dependency>
<groupId>org.mock-server</groupId>
<artifactId>mockserver-netty-no-dependencies</artifactId>
<version>${version.lib.mockserver}</version>
</dependency>
<dependency>
<groupId>org.eclipse.jgit</groupId>
<artifactId>org.eclipse.jgit.junit</artifactId>
Expand Down
10 changes: 10 additions & 0 deletions webclient/tests/http1/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -67,5 +67,15 @@
<artifactId>vertx-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mock-server</groupId>
<artifactId>mockserver-netty-no-dependencies</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.helidon.logging</groupId>
<artifactId>helidon-logging-jul</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
/*
* Copyright (c) 2024 Oracle and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package io.helidon.webclient.tests;

import static io.helidon.http.Method.GET;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.mockserver.integration.ClientAndServer.startClientAndServer;
import static org.mockserver.model.HttpForward.forward;
import static org.mockserver.model.HttpRequest.request;

import io.helidon.http.Status;
import io.helidon.webclient.api.HttpClientResponse;
import io.helidon.webclient.api.Proxy;
import io.helidon.webclient.api.WebClient;
import io.helidon.webserver.WebServer;
import io.helidon.webserver.http.HttpRouting;
import io.helidon.webserver.testing.junit5.ServerTest;
import io.helidon.webserver.testing.junit5.SetUpRoute;

import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockserver.integration.ClientAndServer;
import org.mockserver.model.HttpForward.Scheme;

@ServerTest
class HttpMockProxyTest {

private static final int PROXY_PORT = 1080;
private final WebClient webClient;
private final int serverPort;
private ClientAndServer mockServer;

HttpMockProxyTest(WebServer server) {
this.serverPort = server.port();
this.webClient = WebClient.builder()
.baseUri("http://localhost:" + serverPort)
.proxy(Proxy.builder().host("localhost").port(PROXY_PORT).build())
.build();
}

@SetUpRoute
static void routing(HttpRouting.Builder router) {
router.route(GET, "/get", Routes::get);
}

@BeforeEach
public void before() {
mockServer = startClientAndServer(PROXY_PORT);
mockServer.when(request()).forward(forward().withScheme(Scheme.HTTP).withHost("localhost").withPort(serverPort));
}

@AfterEach
public void after() {
mockServer.stop();
}

@Test
public void issue9022() {
try (HttpClientResponse response = webClient.get("/get").request()) {
assertThat(response.status(), is(Status.OK_200));
String entity = response.entity().as(String.class);
assertThat(entity, is("Hello"));
}
}

private static class Routes {
private static String get() {
return "Hello";
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
handlers=java.util.logging.ConsoleHandler
java.util.logging.ConsoleHandler.level=INFO
java.util.logging.ConsoleHandler.formatter=java.util.logging.SimpleFormatter
#All attributes details
handlers=io.helidon.logging.jul.HelidonConsoleHandler
java.util.logging.SimpleFormatter.format=%1$tH:%1$tM:%1$tS %4$s %3$s %5$s%6$s%n
# Global logging level. Can be overridden by specific loggers

#All log level details
.level=INFO
io.helidon.webclient.level=INFO
io.helidon.webclient.http1.ClientRequestImpl.level=INFO
Expand Down

0 comments on commit eb4b381

Please sign in to comment.