public class MockServerExample {
public static void main(String[] args) {
MockServerClient client = new MockServerClient("localhost", 8080);
client.when(
request()
.withMethod("GET")
.withPath("/api/user"))
.respond(
response()
.withStatusCode(200)
.withBody("{\"name\": \"MockUser\", \"age\": 25}")
);
HttpClient httpClient = HttpClient.newHttpClient();
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create("http://localhost:8080/api/user"))
.build();
CompletableFuture<HttpResponse<String>> response = httpClient.sendAsync(request, BodyHandlers.ofString());
response.thenAccept(res -> {
System.out.println("Response Code: " + res.statusCode());
System.out.println("Response Body: " + res.body());
});
}
}
public class ProxyNettyExample {
public static void main(String[] args) {
ProxyServerBootstrap bootstrap = ProxyServerBootstrap.bootstrap()
.withName("MyProxyServer")
.withAddress("localhost", 8888)
.withProxyHandlerFactory(new HttpProxyHandlerFactory());
bootstrap.start();
}
}