Skip to content
This repository has been archived by the owner on Nov 14, 2018. It is now read-only.

Commit

Permalink
"using latest"
Browse files Browse the repository at this point in the history
  • Loading branch information
ekerwin committed Sep 11, 2018
1 parent 8f5ed56 commit 9c85281
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 14 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ version = '12.0.4-SNAPSHOT'
apply plugin: 'com.blackducksoftware.integration.library'

dependencies {
compile 'com.blackducksoftware.integration:integration-rest:0.1.3'
compile 'com.blackducksoftware.integration:integration-rest:0.1.4'

testCompile 'org.codehaus.groovy:groovy-all:2.4.12'
testCompile 'com.squareup.okhttp3:mockwebserver:3.9.0'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
import com.synopsys.integration.rest.RestConstants;
import com.synopsys.integration.rest.exception.IntegrationRestException;
import com.synopsys.integration.rest.proxy.ProxyInfo;
import com.synopsys.integration.rest.request.Response;

/**
* Connection to the Hub application which authenticates using the API token feature (added in Hub 4.4.0)
Expand Down Expand Up @@ -91,17 +92,19 @@ public void authenticateWithBlackduck() throws IntegrationException {
requestBuilder.setUri(authenticationUrl.toString());
final HttpUriRequest request = requestBuilder.build();
logRequestHeaders(request);
try (final CloseableHttpResponse response = getClient().execute(request)) {
logResponseHeaders(response);
final int statusCode = response.getStatusLine().getStatusCode();
final String statusMessage = response.getStatusLine().getReasonPhrase();
try (final CloseableHttpResponse closeableHttpResponse = getClient().execute(request)) {
logResponseHeaders(closeableHttpResponse);
final Response response = new Response(closeableHttpResponse);
final int statusCode = closeableHttpResponse.getStatusLine().getStatusCode();
final String statusMessage = closeableHttpResponse.getStatusLine().getReasonPhrase();
if (statusCode < RestConstants.OK_200 || statusCode >= RestConstants.MULT_CHOICE_300) {
throw new IntegrationRestException(statusCode, statusMessage, String.format("Connection Error: %s %s", statusCode, statusMessage));
final String httpResponseContent = response.getContentString();
throw new IntegrationRestException(statusCode, statusMessage, httpResponseContent, String.format("Connection Error: %s %s", statusCode, statusMessage));
} else {
addCommonRequestHeader(AUTHORIZATION_HEADER, "Bearer " + readBearerToken(response));
addCommonRequestHeader(AUTHORIZATION_HEADER, "Bearer " + readBearerToken(closeableHttpResponse));

// get the CSRF token
final Header csrfToken = response.getFirstHeader(RestConstants.X_CSRF_TOKEN);
final Header csrfToken = closeableHttpResponse.getFirstHeader(RestConstants.X_CSRF_TOKEN);
if (csrfToken != null) {
addCommonRequestHeader(RestConstants.X_CSRF_TOKEN, csrfToken.getValue());
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
import com.synopsys.integration.rest.RestConstants;
import com.synopsys.integration.rest.exception.IntegrationRestException;
import com.synopsys.integration.rest.proxy.ProxyInfo;
import com.synopsys.integration.rest.request.Response;

public class CredentialsRestConnection extends BlackduckRestConnection {
private final String hubUsername;
Expand Down Expand Up @@ -92,15 +93,17 @@ public void authenticateWithBlackduck() throws IntegrationException {
requestBuilder.setEntity(entity);
final HttpUriRequest request = requestBuilder.build();
logRequestHeaders(request);
try (final CloseableHttpResponse response = getClient().execute(request)) {
logResponseHeaders(response);
final int statusCode = response.getStatusLine().getStatusCode();
final String statusMessage = response.getStatusLine().getReasonPhrase();
try (final CloseableHttpResponse closeableHttpResponse = getClient().execute(request)) {
logResponseHeaders(closeableHttpResponse);
final Response response = new Response(closeableHttpResponse);
final int statusCode = closeableHttpResponse.getStatusLine().getStatusCode();
final String statusMessage = closeableHttpResponse.getStatusLine().getReasonPhrase();
if (statusCode < RestConstants.OK_200 || statusCode >= RestConstants.MULT_CHOICE_300) {
throw new IntegrationRestException(statusCode, statusMessage, String.format("Connection Error: %s %s", statusCode, statusMessage));
final String httpResponseContent = response.getContentString();
throw new IntegrationRestException(statusCode, statusMessage, httpResponseContent, String.format("Connection Error: %s %s", statusCode, statusMessage));
} else {
// get the CSRF token
final Header csrfToken = response.getFirstHeader(RestConstants.X_CSRF_TOKEN);
final Header csrfToken = closeableHttpResponse.getFirstHeader(RestConstants.X_CSRF_TOKEN);
if (csrfToken != null) {
addCommonRequestHeader(RestConstants.X_CSRF_TOKEN, csrfToken.getValue());
} else {
Expand Down

0 comments on commit 9c85281

Please sign in to comment.