Search in sources :

Example 1 with IndyResponseErrorDetails

use of org.commonjava.indy.client.core.IndyResponseErrorDetails in project indy by Commonjava.

the class IndyFoloAdminClientModule method sealTrackingRecord.

public boolean sealTrackingRecord(String trackingId) throws IndyClientException {
    http.connect();
    HttpPost request = http.newRawPost(UrlUtils.buildUrl(http.getBaseUrl(), "/folo/admin", trackingId, "record"));
    HttpResources resources = null;
    try {
        resources = http.execute(request);
        HttpResponse response = resources.getResponse();
        StatusLine sl = response.getStatusLine();
        if (sl.getStatusCode() != 200) {
            if (sl.getStatusCode() == 404) {
                return false;
            }
            throw new IndyClientException(sl.getStatusCode(), "Error sealing tracking record %s.\n%s", trackingId, new IndyResponseErrorDetails(response));
        }
        return true;
    } finally {
        IOUtils.closeQuietly(resources);
    }
}
Also used : StatusLine(org.apache.http.StatusLine) HttpPost(org.apache.http.client.methods.HttpPost) HttpResources(org.commonjava.indy.client.core.helper.HttpResources) HttpResponse(org.apache.http.HttpResponse) IndyClientException(org.commonjava.indy.client.core.IndyClientException) IndyResponseErrorDetails(org.commonjava.indy.client.core.IndyResponseErrorDetails)

Example 2 with IndyResponseErrorDetails

use of org.commonjava.indy.client.core.IndyResponseErrorDetails in project indy by Commonjava.

the class IndyDiagnosticsClientModule method getDiagnosticBundle.

public ZipInputStream getDiagnosticBundle() throws IndyClientException {
    HttpGet get = new HttpGet(buildUrl(getHttp().getBaseUrl(), "/diag/bundle"));
    HttpResources resources = getHttp().getRaw(get);
    HttpResponse response = resources.getResponse();
    StatusLine sl = response.getStatusLine();
    if (sl.getStatusCode() != 200) {
        throw new IndyClientException(sl.getStatusCode(), "Error retrieving diagnostic bundle: %s", new IndyResponseErrorDetails(response));
    }
    try {
        return new ZipInputStream(resources.getResponseStream());
    } catch (IOException e) {
        throw new IndyClientException("Failed to read bundle stream from response: %s", e, new IndyResponseErrorDetails(response));
    }
}
Also used : StatusLine(org.apache.http.StatusLine) ZipInputStream(java.util.zip.ZipInputStream) HttpGet(org.apache.http.client.methods.HttpGet) HttpResources(org.commonjava.indy.client.core.helper.HttpResources) HttpResponse(org.apache.http.HttpResponse) IndyClientException(org.commonjava.indy.client.core.IndyClientException) IndyResponseErrorDetails(org.commonjava.indy.client.core.IndyResponseErrorDetails) IOException(java.io.IOException)

Aggregations

HttpResponse (org.apache.http.HttpResponse)2 StatusLine (org.apache.http.StatusLine)2 IndyClientException (org.commonjava.indy.client.core.IndyClientException)2 IndyResponseErrorDetails (org.commonjava.indy.client.core.IndyResponseErrorDetails)2 HttpResources (org.commonjava.indy.client.core.helper.HttpResources)2 IOException (java.io.IOException)1 ZipInputStream (java.util.zip.ZipInputStream)1 HttpGet (org.apache.http.client.methods.HttpGet)1 HttpPost (org.apache.http.client.methods.HttpPost)1