Search in sources :

Example 1 with GalleyException

use of org.commonjava.maven.galley.GalleyException in project galley by Commonjava.

the class AbstractHttpJob method executeHttp.

protected boolean executeHttp() throws TransferException {
    try {
        client = http.createClient(location);
        response = client.execute(request, http.createContext(location));
        final StatusLine line = response.getStatusLine();
        final int sc = line.getStatusCode();
        logger.debug("{} {} : {}", request.getMethod(), line, url);
        if (!successStatuses.contains(sc)) {
            logger.debug("Detected failure response: " + sc);
            success = TransferResponseUtils.handleUnsuccessfulResponse(request, response, location, url);
            logger.debug("Returning non-error failure response for code: " + sc);
            return false;
        }
    } catch (final NoHttpResponseException e) {
        throw new TransferTimeoutException(location, url, "Repository remote request failed for: {}. Reason: {}", e, url, e.getMessage());
    } catch (final ConnectTimeoutException e) {
        throw new TransferTimeoutException(location, url, "Repository remote request failed for: {}. Reason: {}", e, url, e.getMessage());
    } catch (final SocketTimeoutException e) {
        throw new TransferTimeoutException(location, url, "Repository remote request failed for: {}. Reason: {}", e, url, e.getMessage());
    } catch (final ClientProtocolException e) {
        throw new TransferLocationException(location, "Repository remote request failed for: {}. Reason: {}", e, url, e.getMessage());
    } catch (BadGatewayException e) {
        throw e;
    } catch (final GalleyException e) {
        throw new TransferException("Repository remote request failed for: {}. Reason: {}", e, url, e.getMessage());
    } catch (final IOException e) {
        throw new TransferLocationException(location, "Repository remote request failed for: {}. Reason: {}", e, url, e.getMessage());
    } finally {
        /*
            * we need to integrate the writeMetadata() method into the executeHttp() call in a finally block,
            * and with a condition that it only runs on HEAD or GET. This would allow us to capture metadata on failed requests too,
            * which is critical for responding consistently to the user after a failed request is cached in the NFC.
            */
        String method = request.getMethod();
        if ("GET".equalsIgnoreCase(method) || "HEAD".equalsIgnoreCase(method)) {
            Transfer target = getTransfer();
            ObjectMapper mapper = getMetadataObjectMapper();
            if (target != null && mapper != null) {
                writeMetadata(target, mapper);
            }
        }
    }
    return true;
}
Also used : NoHttpResponseException(org.apache.http.NoHttpResponseException) TransferTimeoutException(org.commonjava.maven.galley.TransferTimeoutException) IOException(java.io.IOException) GalleyException(org.commonjava.maven.galley.GalleyException) ClientProtocolException(org.apache.http.client.ClientProtocolException) StatusLine(org.apache.http.StatusLine) TransferException(org.commonjava.maven.galley.TransferException) SocketTimeoutException(java.net.SocketTimeoutException) Transfer(org.commonjava.maven.galley.model.Transfer) BadGatewayException(org.commonjava.maven.galley.BadGatewayException) TransferLocationException(org.commonjava.maven.galley.TransferLocationException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) ConnectTimeoutException(org.apache.http.conn.ConnectTimeoutException)

Aggregations

ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 IOException (java.io.IOException)1 SocketTimeoutException (java.net.SocketTimeoutException)1 NoHttpResponseException (org.apache.http.NoHttpResponseException)1 StatusLine (org.apache.http.StatusLine)1 ClientProtocolException (org.apache.http.client.ClientProtocolException)1 ConnectTimeoutException (org.apache.http.conn.ConnectTimeoutException)1 BadGatewayException (org.commonjava.maven.galley.BadGatewayException)1 GalleyException (org.commonjava.maven.galley.GalleyException)1 TransferException (org.commonjava.maven.galley.TransferException)1 TransferLocationException (org.commonjava.maven.galley.TransferLocationException)1 TransferTimeoutException (org.commonjava.maven.galley.TransferTimeoutException)1 Transfer (org.commonjava.maven.galley.model.Transfer)1