use of nl.knaw.huygens.concordion.extensions.HttpRequest in project timbuctoo by HuygensING.
the class AbstractV2_1EndpointFixture method executeRequestUsingJaxRs.
/**
* Implements the actual http call for the concordion HTTPCommand.
*/
protected ActualResult executeRequestUsingJaxRs(HttpRequest httpRequest) {
WebTarget target = returnUrlToMockedOrRealServer(httpRequest.server).path(httpRequest.path);
for (Map.Entry<String, String> queryParameter : httpRequest.queryParameters.entries()) {
target = target.queryParam(queryParameter.getKey(), queryParameter.getValue());
}
Invocation.Builder request = target.request();
for (Map.Entry<String, String> header : httpRequest.headers.entries()) {
request = request.header(header.getKey(), header.getValue());
}
Response jerseyResult;
if (httpRequest.body != null) {
final String contentType = httpRequest.headers.entries().stream().filter(x -> x.getKey().equalsIgnoreCase("content-type")).map(Map.Entry::getValue).findFirst().orElse("application/json");
jerseyResult = request.method(httpRequest.method, Entity.entity(httpRequest.body, contentType));
} else {
jerseyResult = request.method(httpRequest.method);
}
return ActualResult.fromJaxRs(jerseyResult);
}
use of nl.knaw.huygens.concordion.extensions.HttpRequest in project timbuctoo by HuygensING.
the class AuthenticationV2_1EndpointFixture method doLoginWithoutHeader.
public String doLoginWithoutHeader() {
HttpRequest httpRequest = new HttpRequest("POST", "/v2.1/authenticate");
ActualResult response = super.executeRequestUsingJaxRs(httpRequest);
return String.format("%s %s", response.getStatus(), response.getStatusInfo());
}
use of nl.knaw.huygens.concordion.extensions.HttpRequest in project timbuctoo by HuygensING.
the class AuthenticationV2_1EndpointFixture method doLoginWithInvalidUsernameAndPassword.
public String doLoginWithInvalidUsernameAndPassword() {
HttpRequest httpRequest = new HttpRequest("POST", "/v2.1/authenticate").withHeader("Authorization", "Basic dW5rbm93blVzZXI6cGFzc3dvcmQ=");
ActualResult response = super.executeRequestUsingJaxRs(httpRequest);
return String.format("%s %s", response.getStatus(), response.getStatusInfo());
}
use of nl.knaw.huygens.concordion.extensions.HttpRequest in project timbuctoo by HuygensING.
the class BaseDomainV2_1EndpointFixture method getAuthenticationToken.
public String getAuthenticationToken() {
if (authenticationToken != null) {
return authenticationToken;
}
HttpRequest loginRequest = new HttpRequest("POST", "/v2.1/authenticate").withHeader("Authorization", "Basic dXNlcjpwYXNzd29yZA==");
ActualResult response = executeRequestUsingJaxRs(loginRequest);
authenticationToken = response.getFirstHeader("x_auth_token").orElse("X_AUTH_TOKEN_NOT_RETURNED");
return authenticationToken;
}
use of nl.knaw.huygens.concordion.extensions.HttpRequest in project timbuctoo by HuygensING.
the class RelationSearchV2_1EndpointFixture method getPersonSearchId.
public String getPersonSearchId() {
HttpRequest postRequest = new HttpRequest("POST", "/v2.1/search/wwpersons", "{}").withHeader("Content-type", "application/json").withHeader("VRE_ID", "WomenWriters");
ActualResult response = executeRequestUsingJaxRs(postRequest);
return response.getFirstHeader("Location").map(l -> l.replaceAll("http://[^/]+/", "")).map(l -> l.replaceAll(".*\\/", "")).orElse("");
}
Aggregations