Skip to content

Commit

Permalink
Fix #696 Test HTTPS with the HTTP clients
Browse files Browse the repository at this point in the history
  • Loading branch information
ppalaga committed Feb 11, 2020
1 parent e884ccb commit 694983d
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,16 @@ public String get(@QueryParam("test-port") int port) {
.request(String.class);
}

@Path("/ahc/get-https")
@GET
@Produces(MediaType.TEXT_PLAIN)
public String getHttps() {
return producerTemplate
.to("ahc:https://restcountries.eu/rest/v2/alpha/cz?bridgeEndpoint=true")
.withHeader(Exchange.HTTP_METHOD, "GET")
.request(String.class);
}

@Path("/ahc/post")
@POST
@Consumes(MediaType.TEXT_PLAIN)
Expand Down Expand Up @@ -102,6 +112,16 @@ public String httpGet(@QueryParam("test-port") int port) {
.request(String.class);
}

@Path("/http/get-https")
@GET
@Produces(MediaType.TEXT_PLAIN)
public String httpGetHttps() {
return producerTemplate
.to("https://restcountries.eu/rest/v2/alpha/cz?bridgeEndpoint=true")
.withHeader(Exchange.HTTP_METHOD, "GET")
.request(String.class);
}

@Path("/http/post")
@POST
@Consumes(MediaType.TEXT_PLAIN)
Expand Down Expand Up @@ -131,6 +151,16 @@ public String nettyHttpGet(@QueryParam("test-port") int port) {
.request(String.class);
}

@Path("/netty-http/get-https")
@GET
@Produces(MediaType.TEXT_PLAIN)
public String nettyHttpGetHttps() {
return producerTemplate
.to("netty-http:https://restcountries.eu/rest/v2/alpha/cz")
.withHeader(Exchange.HTTP_METHOD, "GET")
.request(String.class);
}

@Path("/netty-http/post")
@POST
@Consumes(MediaType.TEXT_PLAIN)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;

import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.is;

@QuarkusTest
Expand All @@ -49,6 +50,32 @@ public void basicProducer(String component) {
.body(is("MESSAGE"));
}

@ParameterizedTest
@ValueSource(strings = { "ahc",
"http" /*, "netty-http" disabled because of https://github.com/apache/camel-quarkus/issues/695 */ })
public void httpsProducer(String component) {
RestAssured
.given()
.when()
.get("/test/client/{component}/get-https", component)
.then()
.body(containsString("Czech Republic"));
}

@Test
public void restcountries() throws Exception {
RestAssured
.given()
.baseUri("https://restcountries.eu")
.port(443)
.when()
.accept("application/json")
.get("/rest/v2/alpha/cz")
.then()
.statusCode(200)
.body(containsString("Czech Republic"));
}

@Test
public void basicNettyHttpServer() throws Exception {
final int port = Integer.getInteger("camel.netty-http.test-port");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
*/
package org.apache.camel.quarkus.component.http.it;

import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Map;
import java.util.Objects;

Expand All @@ -25,7 +28,30 @@
public class HttpTestResource implements QuarkusTestResourceLifecycleManager {
@Override
public Map<String, String> start() {
return AvailablePortFinder.reserveNetworkPorts(Objects::toString, "camel.netty-http.test-port");
final Map<String, String> props = AvailablePortFinder.reserveNetworkPorts(Objects::toString,
"camel.netty-http.test-port");
/*
* Native images built using a docker container end up with javax.net.ssl.trustStore system property
* pointing to a non-existing file; see https://quarkus.io/guides/native-and-ssl
* For that case, we have to set javax.net.ssl.trustStore to an existing path explicitly.
*/
final String graalVmHome = System.getenv("GRAALVM_HOME");
final String javaHome = System.getenv("JAVA_HOME");
Path trustStorePath = null;
final String CACERTS_REL_PATH = "jre/lib/security/cacerts";
if (graalVmHome != null && !graalVmHome.isEmpty()
&& Files.exists(trustStorePath = Paths.get(graalVmHome).resolve(CACERTS_REL_PATH))) {
} else if (javaHome != null && !javaHome.isEmpty()
&& Files.exists(trustStorePath = Paths.get(javaHome).resolve(CACERTS_REL_PATH))) {
} else {
throw new IllegalStateException(
"Could not find any existing file to set javax.net.ssl.trustStore; tried $GRAALVM_HOME/" + CACERTS_REL_PATH
+ " and $JAVA_HOME/" + CACERTS_REL_PATH
+ ". You may need to set GRAALVM_HOME or JAVA_HOME properly. Found $GRAALVM_HOME = " + graalVmHome
+ " and $JAVA_HOME = " + graalVmHome);
}
props.put("javax.net.ssl.trustStore", trustStorePath.toString());
return props;
}

@Override
Expand Down

0 comments on commit 694983d

Please sign in to comment.