-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
203 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
...ient-reactive/src/main/java/io/quarkus/ts/http/restclient/reactive/proxy/ProxyClient.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package io.quarkus.ts.http.restclient.reactive.proxy; | ||
|
||
import javax.ws.rs.GET; | ||
import javax.ws.rs.Path; | ||
import javax.ws.rs.Produces; | ||
import javax.ws.rs.core.MediaType; | ||
|
||
import org.eclipse.microprofile.rest.client.annotation.RegisterClientHeaders; | ||
import org.eclipse.microprofile.rest.client.inject.RegisterRestClient; | ||
|
||
import io.smallrye.mutiny.Uni; | ||
|
||
@RegisterRestClient | ||
@RegisterClientHeaders | ||
public interface ProxyClient { | ||
|
||
@GET | ||
@Path("/") | ||
@Produces(MediaType.TEXT_HTML) | ||
Uni<String> getSite(); | ||
|
||
@GET | ||
@Path("/example.txt") | ||
@Produces(MediaType.TEXT_PLAIN) | ||
Uni<String> getText(); | ||
|
||
@GET | ||
@Path("/auth") | ||
@Produces(MediaType.TEXT_PLAIN) | ||
Uni<String> getAuthorized(); | ||
} |
41 changes: 41 additions & 0 deletions
41
...nt-reactive/src/main/java/io/quarkus/ts/http/restclient/reactive/proxy/ProxyResource.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package io.quarkus.ts.http.restclient.reactive.proxy; | ||
|
||
import javax.inject.Inject; | ||
import javax.ws.rs.GET; | ||
import javax.ws.rs.Path; | ||
import javax.ws.rs.Produces; | ||
import javax.ws.rs.core.MediaType; | ||
|
||
import org.eclipse.microprofile.rest.client.inject.RestClient; | ||
|
||
import io.smallrye.mutiny.Uni; | ||
|
||
@Path("/proxied") | ||
public class ProxyResource { | ||
|
||
@Inject | ||
@RestClient | ||
ProxyClient client; | ||
|
||
@GET | ||
@Path("/") | ||
@Produces(MediaType.TEXT_HTML) | ||
public Uni<String> getRoot() { | ||
return client.getSite(); | ||
} | ||
|
||
@GET | ||
@Path("/banned") | ||
@Produces(MediaType.TEXT_PLAIN) | ||
public Uni<String> getBanned() { | ||
return client.getText(); | ||
} | ||
|
||
@GET | ||
@Path("/authorization") | ||
@Produces(MediaType.TEXT_PLAIN) | ||
public Uni<String> getAuthorized() { | ||
return client.getAuthorized(); | ||
} | ||
|
||
} |
6 changes: 6 additions & 0 deletions
6
http/rest-client-reactive/src/main/resources/proxy.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
quarkus.rest-client."io.quarkus.ts.http.restclient.reactive.proxy.ProxyClient".url=http://example.com | ||
quarkus.rest-client."io.quarkus.ts.http.restclient.reactive.proxy.ProxyClient".proxy-address=localhost:8090 | ||
quarkus.rest-client."io.quarkus.ts.http.restclient.reactive.proxy.ProxyClient".proxy-user=proxyuser | ||
quarkus.rest-client."io.quarkus.ts.http.restclient.reactive.proxy.ProxyClient".proxy-password=proxypassword | ||
quarkus.rest-client.logging.scope=request-response | ||
quarkus.log.category."org.jboss.resteasy.reactive.client.logging".level=DEBUG |
65 changes: 65 additions & 0 deletions
65
http/rest-client-reactive/src/test/java/io/quarkus/ts/http/restclient/reactive/ProxyIT.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package io.quarkus.ts.http.restclient.reactive; | ||
|
||
import java.util.Base64; | ||
|
||
import org.apache.http.HttpStatus; | ||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import io.quarkus.test.bootstrap.RestService; | ||
import io.quarkus.test.scenarios.QuarkusScenario; | ||
import io.quarkus.test.services.Container; | ||
import io.quarkus.test.services.QuarkusApplication; | ||
import io.restassured.response.Response; | ||
|
||
@QuarkusScenario | ||
public class ProxyIT { | ||
private static final String USER = "proxyuser"; | ||
private static final String PASSWORD = "proxypassword"; | ||
|
||
@Container(image = "quay.io/quarkusqeteam/proxy", port = 8090, expectedLog = "Configuration complete; ready for start up") | ||
static RestService proxy = new RestService(); | ||
|
||
@QuarkusApplication | ||
static RestService proxyApp = new RestService() | ||
.withProperties("proxy.properties") | ||
.withProperty("quarkus.rest-client.\"io.quarkus.ts.http.restclient.reactive.proxy.ProxyClient\".proxy-user", USER) | ||
.withProperty("quarkus.rest-client.\"io.quarkus.ts.http.restclient.reactive.proxy.ProxyClient\".proxy-password", | ||
PASSWORD) | ||
.withProperty("quarkus.rest-client.\"io.quarkus.ts.http.restclient.reactive.proxy.ProxyClient\".proxy-address", | ||
() -> proxy.getHost().replace("http://", "") + ":" + proxy.getPort()); | ||
|
||
@Test | ||
void getThrough() { | ||
Response proxied = proxyApp.given().with().get("/proxied/"); | ||
Assertions.assertEquals(HttpStatus.SC_OK, proxied.statusCode()); | ||
Assertions.assertTrue(proxied.body().asString().contains("Example Domain")); | ||
} | ||
|
||
@Test | ||
void banned() { | ||
Response banned = proxyApp.given().with().get("/proxied/banned"); | ||
Assertions.assertEquals(HttpStatus.SC_OK, banned.statusCode()); | ||
Assertions.assertEquals("Reading is prohibited by corporate policy!", | ||
banned.body().asString()); | ||
} | ||
|
||
@Test | ||
/* | ||
* Nginx returns content of Proxy-Auth Header. | ||
* We check, that this content is made according to the specification. | ||
* https://developer.mozilla.org/en-US/docs/Web/HTTP/Authentication#proxy_authentication | ||
*/ | ||
void authorization() { | ||
Response response = proxyApp.given().with().get("/proxied/authorization"); | ||
Assertions.assertEquals(HttpStatus.SC_OK, response.statusCode()); | ||
String authorizationType = "Basic"; | ||
String credentials = encode(USER + ":" + PASSWORD); | ||
String header = response.body().asString(); | ||
Assertions.assertEquals(authorizationType + " " + credentials, header); | ||
} | ||
|
||
private static String encode(String source) { | ||
return Base64.getEncoder().encodeToString(source.getBytes()); | ||
} | ||
} |
2 changes: 2 additions & 0 deletions
2
http/rest-client-reactive/src/test/resources/proxy/Dockerfile
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
FROM nginx:1.21 | ||
COPY nginx.conf /etc/nginx/nginx.conf |
11 changes: 11 additions & 0 deletions
11
http/rest-client-reactive/src/test/resources/proxy/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
This folder contains everything for building and deploying proxy container, based on nginx | ||
It is based on these resources: | ||
* http://nginx.org/en/docs/beginners_guide.html#proxy | ||
* http://nginx.org/en/docs/http/ngx_http_proxy_module.html | ||
* https://www.baeldung.com/nginx-forward-proxy | ||
|
||
By default, the container listens on port 8090. | ||
|
||
Script run.sh is mainly for debugging | ||
|
||
Script deploy.sh is for building and deploying to quay.io |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
docker build -t nginx-proxy . | ||
docker tag nginx-proxy quay.io/quarkusqeteam/proxy:latest | ||
docker push quay.io/quarkusqeteam/proxy:latest |
16 changes: 16 additions & 0 deletions
16
http/rest-client-reactive/src/test/resources/proxy/nginx.conf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
events {} | ||
http { | ||
server { | ||
listen 8090; | ||
resolver 8.8.8.8; | ||
location / { | ||
proxy_pass http://$host; | ||
} | ||
location ~ \.(txt)$ { | ||
return 203 "Reading is prohibited by corporate policy!"; | ||
} | ||
location /auth { | ||
return 200 $http_proxy_authorization; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
docker build -t nginx-proxy . && docker run -p 8090:8090 nginx-proxy |