Change baseURI and port in a filter

464 views
Skip to first unread message

Andrei Stoica

unread,
Oct 14, 2015, 10:46:58 AM10/14/15
to REST assured
Hello,

I have the following situation:

I construct a request using the following code:

1. the properties are set in rest-assured statically

RestAssured.port = Integer.parseInt(property.getProperty("appPort"));
RestAssured.baseURI = property.getProperty("appBaseURI");
RestAssured.basePath = property.getProperty("appBasePath");



2. the request is made as follows:

given().filter(new CustomRequestFilter())
       
.contentType(ContentType.JSON)
       
.body(json)
       
.post("/groups");



3. The filter is:

public class CustomRequestFilter implements Filter{


public static Map<String, String> loginCookies;


@Override
public Response filter(FilterableRequestSpecification requestSpec, FilterableResponseSpecification responseSpec, FilterContext ctx) {
   
   
if(loginCookies!= null){
        requestSpec
.baseUri(httpsUri)
                   
.port(443)
                   
.cookies(loginCookies)
                   
.redirects().follow(true)
                   
.config(config().sslConfig(new SSLConfig().relaxedHTTPSValidation()));
   
}
   
return ctx.next(requestSpec, responseSpec);
}
}





Running the above scenario doesn't change the URI and port even if the loginCookies are not null. The cookies are put in the request and all the remaining config, like redirect and sslConfig.

What can I do to be able to change the static URI and port in the filter?

Johan Haleby

unread,
Oct 15, 2015, 12:30:09 AM10/15/15
to rest-a...@googlegroups.com
Hi, 

Great question. Unfortunately I don't think you can change the base uri or port from a filter. When I look at the code it seems like the internal "SendRequestFilter" always uses the original settings available in the FilterContext. One solution could be to rebuild FilterContext between each filter invocation (at least if base uri or port has changed). Would you mind adding this as an issue?

Regards,
/Johan

--
You received this message because you are subscribed to the Google Groups "REST assured" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rest-assured...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Andrei Stoica

unread,
Oct 15, 2015, 7:58:54 AM10/15/15
to REST assured
Hello Johan,

I added a issue on git for this: https://github.com/jayway/rest-assured/issues/600.

Can you explain more about rebuilding the FilterContext. I'm not sure how can I achieve that.

I tried it this way:

String path = ctx.getCompleteRequestPath();
String methodPath = path.substring(path.indexOf("/app"));
FilterContext fc = new FilterContextImpl(LoginService.webBaseUri + ":443" + methodPath, "", ctx.getRequestMethod(), null, null);
return fc.next(requestSpec, responseSpec);


but it returns null response.

Regards,
Andrei.

Johan Haleby

unread,
Oct 15, 2015, 8:11:36 AM10/15/15
to rest-a...@googlegroups.com
That was just some thoughts on how it could be solved if the code is changed. Unfortunately I don't think there's a workaround right now :( 
Reply all
Reply to author
Forward
0 new messages