Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Connection reset error on configuring baseUri/basePath using RequestSpecification. #871

Open
akshayamaldhure opened this issue Jun 8, 2017 · 2 comments

Comments

@akshayamaldhure
Copy link

akshayamaldhure commented Jun 8, 2017

I've written a few wrapper methods to use multiple RequestSpecifications in a single API call using static imports in below manner, and I'm facing "Connection refused" issue in case of "Non-working code" below:

import static io.restassured.RestAssured.given;
import static package.addHeader;
import static package.setConfig;
import static package.setLogging;

Working code:

 RestAssured.baseURI = "someBaseURI";
 RestAssured.basePath = "someEndPoint";
 response = given().spec(setLogging()).spec(addHeader("key","value")).when().get();
 System.out.println(response.getBody().asString());

Non-working code (Possibly a bug):

 response = given().spec(setLogging()).spec(setConfig("someBaseURI","someEndPoint")).spec(addHeader("key","value")).when().get();
 System.out.println(response.getBody().asString());

Here are the wrapper method definitions:

	//helper method to enable HTTP method logging
	public static RequestSpecification setLogging() {
		return new RequestSpecBuilder().log(LogDetail.METHOD).build();
	}
	
	//helper method to set baseURI/basePath	
	public static RequestSpecification setConfig(String baseUri, String basePath) {
		return new RequestSpecBuilder().setBaseUri(baseUri).setBasePath(basePath).setContentType(ContentType.JSON).build();
	}

	//helper methods to add request headers
	public static RequestSpecification addHeader(String key, String value) {
		Log.info("Header: "+key+" = "+value);
		return new RequestSpecBuilder().addHeader(key, value).build();
	}

Full error log trace at http://textuploader.com/d0992.

Isolation: Using log().all(), I found that the baseUri is getting set incorrectly. I had set it to "someBaseUri", while the baseUri actually set is http://localhost:8080/.

Request method:	GET
Request URI:	http://localhost:8080/
Proxy:			<none>
Request params:	<none>
Query params:	<none>
Form params:	<none>
Path params:	<none>
Headers:		key=value
				Accept=*/*
				Content-Type=application/json; charset=UTF-8
Cookies:		<none>
Multiparts:		<none>
Body:			<none>
@akshayamaldhure
Copy link
Author

@johanhaleby Could you please assign and prioritise this issue?

@pawarvaibhav
Copy link

Additional reason why fixing this issue is important:
I think very few people depend on RequestSpecification for setting baseURIs and that's why this issue is not prioritized. But if more people use this, they can add several optimizations in their frameworks. Like in my test framework, I can potentially run tests for different end points in parallel.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants