Skip to content
This repository has been archived by the owner on Jun 11, 2024. It is now read-only.

Can't start proxy on custom port with Java 10+ #319

Open
fkrivsky opened this issue Nov 25, 2020 · 0 comments
Open

Can't start proxy on custom port with Java 10+ #319

fkrivsky opened this issue Nov 25, 2020 · 0 comments

Comments

@fkrivsky
Copy link

Describe the bug

We are automating multiple proxies initialization on custom ports using REST Assured (or and Java 11 HTTP client).
Attempts to start proxy on custom port with POST calls using the aforementioned tools end up with proxy starting but not on specified port.

Code for REST Assured:

		String body = "{\"port\":\""+ port +"\"}";

		var response = given()
			.accept("application/json")
			.contentType("application/json")
			.body(body)
//				.log().all()
		.when()
			.post(proxyAddress)
		.then()
			.log().ifError();

Code for Java HTTP client:

		String body = "{\"port\":\""+ port +"\"}";
		System.out.println(body);
		HttpClient client = HttpClient.newHttpClient();

		HttpRequest request = HttpRequest.newBuilder()
				.uri(URI.create(proxyAddress))
				.timeout(Duration.ofMinutes(1))
				.header("Content-Type", "application/json")
				.POST(BodyPublishers.ofString(body))
				.build();

		client.sendAsync(request, BodyHandlers.ofString())
				.thenApply(HttpResponse::body)
				.thenAccept(System.out::println).join();

To Reproduce

Steps to reproduce the behavior:

  1. Start BUP instance
    
  2. Send a POST call using the code examples above
    
  3. Proxy is started but on default port, e.g. response reads { "port": 8082 }
    
  4. Same behavior is reproducible with text and JSON-formatted payload.
    

REST Assured logs:

Example of request:

Request method:	POST
Request URI:	http://localhost:8080/proxy/
Proxy:			<none>
Request params:	<none>
Query params:	<none>
Form params:	<none>
Path params:	<none>
Headers:		Accept=application/json
			Content-Type=application/json; charset=UTF-8
Cookies:		<none>
Multiparts:		<none>
Body:
{
    "port": "10001"
}

Respective response:

HTTP/1.1 200 OK
Date: Wed, 25 Nov 2020 17:58:25 GMT
Content-Type: application/json
Content-Length: 13
Server: Jetty(9.4.20.v20190813)

{
    "port": 8088
}

Java client log:

[port:10001
{"port":8088}]

Expected behavior

Proxy should be started on the specified port.

Please complete the following information:

  • OS: Windows 10, Linux
    
  • Java: 11
    
  • Versions: 2.0.1, 2.1.0, 2.1.1
    

Additional context

Using curl for starting the proxy seems to work fine however it does not fit in our workflow.

Other POST call using REST Assured works fine - specifically, we are sending JSON-formatted hosts entries to http://(address}:8080/proxy/{port}/hosts and that is without problem.

#245 seems to provide information about root cause - however it was closed without resolution.

@fkrivsky fkrivsky changed the title Can't start proxy on custom port with java tools like RestAssured and Java 11 HTTP Client Can't start proxy on custom port with Java 10+ Dec 16, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant