use of com.hp.octane.integrations.dto.connectivity.OctaneResponse in project octane-ci-java-sdk by MicroFocus.
the class VulnerabilitiesServiceImpl method vulnerabilitiesPreflightRequest.
private Date vulnerabilitiesPreflightRequest(String jobId, String buildId) throws IOException {
OctaneResponse response = getBaselineDateFromOctane(jobId, buildId);
if (response.getStatus() == HttpStatus.SC_OK) {
if (response.getBody() == null || "".equals(response.getBody())) {
logger.info(configurer.octaneConfiguration.getLocationForLog() + "vulnerabilities data of " + jobId + " #" + buildId + " is not relevant to Octane");
return null;
} else {
logger.info(configurer.octaneConfiguration.getLocationForLog() + "vulnerabilities data of " + jobId + " #" + buildId + " found to be relevant to Octane");
boolean forTest = false;
// backward compatibility with Octane
if ("true".equals(response.getBody()) || forTest) {
return DateUtils.getDateFromUTCString("2000-01-01", "yyyy-MM-dd");
}
return DateUtils.getDateFromUTCString(response.getBody(), DateUtils.octaneFormat);
}
}
if (response.getStatus() == HttpStatus.SC_SERVICE_UNAVAILABLE || response.getStatus() == HttpStatus.SC_BAD_GATEWAY) {
throw new TemporaryException("vulnerabilities preflight request FAILED, service unavailable");
} else {
throw new PermanentException("vulnerabilities preflight request FAILED with " + response.getStatus() + "");
}
}
use of com.hp.octane.integrations.dto.connectivity.OctaneResponse in project octane-ci-java-sdk by MicroFocus.
the class GeneralRestClient method createResponse.
private OctaneResponse createResponse(HttpResponse response) throws IOException {
OctaneResponse octaneResponse = DTOFactory.getInstance().newDTO(OctaneResponse.class).setStatus(response.getStatusLine().getStatusCode());
// set body
if (response.getEntity() != null) {
octaneResponse.setBody(CIPluginSDKUtils.inputStreamToUTF8String(response.getEntity().getContent()));
}
// set headers
if (response.getAllHeaders() != null && response.getAllHeaders().length > 0) {
Map<String, String> mapHeaders = new HashMap<>();
for (Header header : response.getAllHeaders()) {
mapHeaders.put(header.getName(), header.getValue());
}
octaneResponse.setHeaders(mapHeaders);
}
return octaneResponse;
}
use of com.hp.octane.integrations.dto.connectivity.OctaneResponse in project octane-ci-java-sdk by MicroFocus.
the class GeneralRestClient method executeRequest.
public OctaneResponse executeRequest(OctaneRequest request) throws IOException {
if (authentication.isAuthenticationNeeded()) {
authentication.authenticate(httpClient, false);
}
OctaneResponse result;
HttpClientContext context;
HttpResponse httpResponse = null;
try {
// we are running this loop either once or twice: once - regular flow, twice - when retrying after re-login attempt
for (int i = 0; i < 2; i++) {
HttpUriRequest uriRequest = createHttpRequest(request);
context = createHttpContext(request.getUrl(), request.getTimeoutSec());
httpResponse = httpClient.execute(uriRequest, context);
int statusCode = httpResponse.getStatusLine().getStatusCode();
if (i == 0 && HttpStatus.SC_UNAUTHORIZED == statusCode && authentication.supportAuthenticationOnUnauthorizedException()) {
EntityUtils.consumeQuietly(httpResponse.getEntity());
HttpClientUtils.closeQuietly(httpResponse);
if (!authentication.authenticate(httpClient, true)) {
break;
}
} else {
authentication.onResponse(httpResponse, context);
break;
}
}
result = createResponse(httpResponse);
} finally {
if (httpResponse != null) {
EntityUtils.consumeQuietly(httpResponse.getEntity());
HttpClientUtils.closeQuietly(httpResponse);
}
}
return result;
}
use of com.hp.octane.integrations.dto.connectivity.OctaneResponse in project octane-ci-java-sdk by MicroFocus.
the class OctaneRestClientImpl method login.
private OctaneResponse login(OctaneConfiguration config) throws IOException {
OctaneResponse result;
HttpResponse response = null;
try {
HttpUriRequest loginRequest = buildLoginRequest(config);
HttpClientContext context = createHttpContext(loginRequest.getURI().toString(), 0, true);
response = httpClient.execute(loginRequest, context);
if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
refreshSecurityToken(context, true);
} else {
logger.warn(configurer.octaneConfiguration.getLocationForLog() + "failed to login; response status: " + response.getStatusLine().getStatusCode());
}
result = createNGAResponse(null, response);
} catch (IOException ioe) {
logger.debug(configurer.octaneConfiguration.getLocationForLog() + "failed to login", ioe);
throw ioe;
} finally {
if (response != null) {
EntityUtils.consumeQuietly(response.getEntity());
HttpClientUtils.closeQuietly(response);
}
}
return result;
}
use of com.hp.octane.integrations.dto.connectivity.OctaneResponse in project octane-ci-java-sdk by MicroFocus.
the class PipelineContextServiceImpl method updatePipeline.
@Override
public PipelineContext updatePipeline(String serverIdentity, String jobName, PipelineContext pipelineContext) throws IOException {
String url = getConfigurationUrl(serverIdentity, jobName);
validateReleaseAndMilestone(pipelineContext);
OctaneRestClient octaneRestClient = restService.obtainOctaneRestClient();
Map<String, String> headers = new HashMap<>();
headers.put(ACCEPT_HEADER, ContentType.APPLICATION_JSON.getMimeType());
headers.put(CONTENT_TYPE_HEADER, ContentType.APPLICATION_JSON.getMimeType());
PipelineContextList list = dtoFactory.newDTO(PipelineContextList.class).setData(Arrays.asList(pipelineContext));
String jsonData = dtoFactory.dtoToJson(list);
OctaneRequest request = dtoFactory.newDTO(OctaneRequest.class).setMethod(HttpMethod.PUT).setUrl(url).setBody(jsonData).setHeaders(headers);
OctaneResponse response = octaneRestClient.execute(request);
validateResponse(HttpStatus.SC_OK, response);
PipelineContextList resultList = dtoFactory.dtoFromJson(response.getBody(), PipelineContextList.class);
// we might receive several pipeline context from other workspaces.
// find updated context by id
PipelineContext result = resultList.getData().stream().filter(p -> p.getContextEntityId() == pipelineContext.getContextEntityId()).findFirst().get();
return result;
}
Aggregations