Example usage for java.net HttpRetryException getMessage

List of usage examples for java.net HttpRetryException getMessage

Introduction

In this page you can find the example usage for java.net HttpRetryException getMessage.

Prototype

public String getMessage() 

Source Link

Document

Returns the detail message string of this throwable.

Usage

From source file:com.checkmarx.jenkins.CxWebService.java

private CxWSResponseRunID sendScanRequest(final FilePath base64ZipFile, String soapActionName,
        Pair<byte[], byte[]> soapMessage, XmlResponseParser xmlResponseParser) throws AbortException {
    try {/* ww w . j a va2  s.  c om*/

        // Create HTTP connection

        final HttpURLConnection streamingUrlConnection = (HttpURLConnection) webServiceUrl.openConnection();
        streamingUrlConnection.addRequestProperty("Content-Type", "text/xml; charset=utf-8");
        streamingUrlConnection.addRequestProperty("SOAPAction",
                String.format("\"http://Checkmarx.com/v7/%s\"", soapActionName));
        streamingUrlConnection.setDoOutput(true);
        // Calculate the length of the soap message
        final long length = soapMessage.getLeft().length + soapMessage.getRight().length
                + base64ZipFile.length();
        streamingUrlConnection.setFixedLengthStreamingMode((int) length);
        streamingUrlConnection.connect();
        final OutputStream os = streamingUrlConnection.getOutputStream();

        logger.info("Uploading sources to Checkmarx server");
        os.write(soapMessage.getLeft());
        final InputStream fis = base64ZipFile.read();
        org.apache.commons.io.IOUtils.copyLarge(fis, os);

        os.write(soapMessage.getRight());
        os.close();
        fis.close();
        logger.info("Finished uploading sources to Checkmarx server");

        CxWSResponseRunID cxWSResponseRunID = xmlResponseParser.parse(streamingUrlConnection.getInputStream());

        if (!cxWSResponseRunID.isIsSuccesfull()) {
            String message = "Submission of sources for scan failed: \n" + cxWSResponseRunID.getErrorMessage();
            throw new AbortException(message);
        }

        return cxWSResponseRunID;

    } catch (HttpRetryException e) {
        String consoleMessage = "\nCheckmarx plugin for Jenkins does not support Single sign-on authentication."
                + "\nPlease, configure Checkmarx server to work in Anonymous authentication mode.\n";
        logger.error(consoleMessage);
        throw new AbortException(e.getMessage());
    } catch (IOException | JAXBException | XMLStreamException | InterruptedException e) {
        logger.error(e.getMessage(), e);
        throw new AbortException(e.getMessage());
    }
}