List of usage examples for java.io ByteArrayInputStream close
public void close() throws IOException
From source file:com.hp.application.automation.tools.results.RunResultRecorder.java
/** * copies, archives and creates the Test reports of LR and UFT runs. * * @param build//from w w w . j a v a 2 s.co m * @param listener * @param resultFiles * @param testResult * @param runWorkspace * @throws ParserConfigurationException * @throws SAXException * @throws IOException * @throws InterruptedException */ @SuppressWarnings({ "squid:S134", "squid:S135" }) private void archiveTestsReport(Run<?, ?> build, TaskListener listener, List<String> resultFiles, TestResult testResult, FilePath runWorkspace) throws ParserConfigurationException, SAXException, IOException, InterruptedException { if ((resultFiles == null) || (resultFiles.isEmpty())) { return; } ArrayList<String> zipFileNames = new ArrayList<String>(); ArrayList<FilePath> reportFolders = new ArrayList<FilePath>(); List<String> reportNames = new ArrayList<String>(); listener.getLogger() .println("Report archiving mode is set to: " + _resultsPublisherModel.getArchiveTestResultsMode()); FilePath projectWS = runWorkspace; // get the artifacts directory where we will upload the zipped report // folder File artifactsDir = new File(build.getRootDir(), "archive"); artifactsDir.mkdirs(); // read each result.xml /* * The structure of the result file is: <testsuites> <testsuite> * <testcase.........report="path-to-report"/> * <testcase.........report="path-to-report"/> * <testcase.........report="path-to-report"/> * <testcase.........report="path-to-report"/> </testsuite> * </testsuites> */ // add previous report names for aggregation when using pipelines. for (SuiteResult suiteResult : testResult.getSuites()) { String[] temp = suiteResult.getName().split("_"); reportNames.add(temp[temp.length - 1]); } for (String resultsFilePath : resultFiles) { FilePath resultsFile = projectWS.child(resultsFilePath); List<ReportMetaData> ReportInfoToCollect = new ArrayList<ReportMetaData>(); DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder dBuilder = dbFactory.newDocumentBuilder(); Document doc = dBuilder.parse(resultsFile.read()); doc.getDocumentElement().normalize(); Node testSuiteNode = doc.getElementsByTagName("testsuite").item(0); Element testSuiteElement = (Element) testSuiteNode; if (testSuiteElement.hasAttribute("name") && testSuiteElement.getAttribute("name").endsWith(".lrs")) { // LR test NodeList testSuiteNodes = doc.getElementsByTagName("testsuite"); for (int i = 0; i < testSuiteNodes.getLength(); i++) { testSuiteNode = testSuiteNodes.item(i); testSuiteElement = (Element) testSuiteNode; if (!testSuiteElement.hasAttribute("name")) { continue; } String testFolderPath = testSuiteElement.getAttribute("name"); String testStatus = ("0".equals(testSuiteElement.getAttribute("failures"))) ? "pass" : "fail"; Node testCaseNode = testSuiteElement.getElementsByTagName("testcase").item(0); if (testCaseNode == null) { listener.getLogger().println("No report folder was found in results"); return; } if (testCaseNode.getNodeType() == Node.ELEMENT_NODE) { Element testCaseElement = (Element) testCaseNode; if (!testCaseElement.hasAttribute(REPORT_NAME_FIELD)) { continue; } String reportFolderPath = testCaseElement.getAttribute(REPORT_NAME_FIELD); FilePath reportFolder = new FilePath(projectWS.getChannel(), reportFolderPath); reportFolders.add(reportFolder); FilePath testFolder = new FilePath(projectWS.getChannel(), testFolderPath); String zipFileName = getUniqueZipFileNameInFolder(zipFileNames, testFolder.getName()); FilePath archivedFile = new FilePath(new FilePath(artifactsDir), zipFileName); if (archiveFolder(reportFolder, testStatus, archivedFile, listener)) { zipFileNames.add(zipFileName); } createHtmlReport(reportFolder, testFolderPath, artifactsDir, reportNames, testResult); createTransactionSummary(reportFolder, testFolderPath, artifactsDir, reportNames, testResult); try { FilePath testSla = copyRunReport(reportFolder, build.getRootDir(), testFolder.getName()); runReportList.add(testSla); } catch (IOException | InterruptedException e) { listener.getLogger().println(e.getMessage()); } } } } else { // UFT Test boolean reportIsHtml = false; NodeList testCasesNodes = ((Element) testSuiteNode).getElementsByTagName("testcase"); for (int i = 0; i < testCasesNodes.getLength(); i++) { Node nNode = testCasesNodes.item(i); if (nNode.getNodeType() == Node.ELEMENT_NODE) { Element eElement = (Element) nNode; if (!eElement.hasAttribute(REPORT_NAME_FIELD)) { continue; } String reportFolderPath = eElement.getAttribute(REPORT_NAME_FIELD); // e.g. "C:\UFTTest\GuiTest1\Report" String testFolderPath = eElement.getAttribute("name"); // e.g. "C:\UFTTest\GuiTest1" String testStatus = eElement.getAttribute("status"); // e.g. "pass" Node nodeSystemInfo = eElement.getElementsByTagName("system-out").item(0); String sysinfo = nodeSystemInfo.getFirstChild().getNodeValue(); String testDateTime = sysinfo.substring(0, 19); FilePath reportFolder = new FilePath(projectWS.getChannel(), reportFolderPath); reportFolders.add(reportFolder); String archiveTestResultMode = _resultsPublisherModel.getArchiveTestResultsMode(); boolean archiveTestResult = false; //check for the new html report FilePath htmlReport = new FilePath(reportFolder, "run_results.html"); FilePath rrvReport = new FilePath(reportFolder, "Results.xml"); if (htmlReport.exists()) { reportIsHtml = true; String htmlReportDir = reportFolder.getRemote(); ReportMetaData reportMetaData = new ReportMetaData(); reportMetaData.setFolderPath(htmlReportDir); reportMetaData.setIsHtmlReport(true); reportMetaData.setDateTime(testDateTime); reportMetaData.setStatus(testStatus); File testFileFullName = new File(testFolderPath); String testName = org.apache.commons.io.FilenameUtils .getName(testFileFullName.getPath()); String resourceUrl = "artifact/UFTReport/" + testName; reportMetaData.setResourceURL(resourceUrl); reportMetaData.setDisPlayName(testName); // use the name, not the full path //don't know reportMetaData's URL path yet, we will generate it later. ReportInfoToCollect.add(reportMetaData); listener.getLogger().println( "add html report info to ReportInfoToCollect: " + "[date]" + testDateTime); } archiveTestResult = isArchiveTestResult(testStatus, archiveTestResultMode); if (archiveTestResult && rrvReport.exists()) { if (reportFolder.exists()) { FilePath testFolder = new FilePath(projectWS.getChannel(), testFolderPath); String zipFileName = getUniqueZipFileNameInFolder(zipFileNames, testFolder.getName()); zipFileNames.add(zipFileName); listener.getLogger().println("Zipping report folder: " + reportFolderPath); ByteArrayOutputStream outstr = new ByteArrayOutputStream(); //don't use FileFilter for zip, or it will cause bug when files are on slave reportFolder.zip(outstr); /* * I did't use copyRecursiveTo or copyFrom due to * bug in * jekins:https://issues.jenkins-ci.org/browse * /JENKINS-9189 //(which is cleaimed to have been * fixed, but not. So I zip the folder to stream and * copy it to the master. */ ByteArrayInputStream instr = new ByteArrayInputStream(outstr.toByteArray()); FilePath archivedFile = new FilePath(new FilePath(artifactsDir), zipFileName); archivedFile.copyFrom(instr); listener.getLogger().println("copy from slave to master: " + archivedFile); outstr.close(); instr.close(); // add to Report list ReportMetaData reportMetaData = new ReportMetaData(); reportMetaData.setIsHtmlReport(false); // reportMetaData.setFolderPath(htmlReportDir); //no need for RRV File testFileFullName = new File(testFolderPath); String testName = testFileFullName.getName(); reportMetaData.setDisPlayName(testName); // use the name, not the full path String zipFileUrlName = "artifact/" + zipFileName; reportMetaData.setUrlName(zipFileUrlName); // for RRV, the file url and resource url are the same. reportMetaData.setResourceURL(zipFileUrlName); reportMetaData.setDateTime(testDateTime); reportMetaData.setStatus(testStatus); ReportInfoToCollect.add(reportMetaData); } else { listener.getLogger().println("No report folder was found in: " + reportFolderPath); } } } } if (reportIsHtml && !ReportInfoToCollect.isEmpty()) { listener.getLogger().println("begin to collectAndPrepareHtmlReports"); collectAndPrepareHtmlReports(build, listener, ReportInfoToCollect, runWorkspace); } if (!ReportInfoToCollect.isEmpty()) { // serialize report metadata File reportMetaDataXmlFile = new File(artifactsDir.getParent(), REPORTMETADATE_XML); String reportMetaDataXml = reportMetaDataXmlFile.getAbsolutePath(); writeReportMetaData2XML(ReportInfoToCollect, reportMetaDataXml, listener); // Add UFT report action try { listener.getLogger().println("Adding a report action to the current build."); HtmlBuildReportAction reportAction = new HtmlBuildReportAction(build); build.addAction(reportAction); } catch (IOException | SAXException | ParserConfigurationException ex) { listener.getLogger().println("a problem adding action: " + ex); } } } } }
From source file:com.microfocus.application.automation.tools.results.RunResultRecorder.java
private Boolean collectAndPrepareHtmlReports(Run build, TaskListener listener, List<ReportMetaData> htmlReportsInfo, FilePath runWorkspace) throws IOException, InterruptedException { File reportDir = new File(new File(build.getRootDir(), "archive"), "UFTReport"); FilePath rootTarget = new FilePath(reportDir); try {//from w ww .j a v a 2 s . co m for (ReportMetaData htmlReportInfo : htmlReportsInfo) { // make sure it's a html report if (!htmlReportInfo.getIsHtmlReport()) { continue; } String htmlReportDir = htmlReportInfo.getFolderPath(); // C:\UFTTest\GuiTest1\Report listener.getLogger().println("collectAndPrepareHtmlReports, collecting:" + htmlReportDir); listener.getLogger().println("workspace: " + runWorkspace); // copy to the subdirs of master FilePath source = new FilePath(runWorkspace, htmlReportDir); // if it's a parallel runner report path, we must change the // resFileName boolean isParallelRunner = isParallelRunnerReportPath(source); listener.getLogger().println("source: " + source); String testName = htmlReportInfo.getDisPlayName(); // like "GuiTest1" String dest = testName; FilePath targetPath = new FilePath(rootTarget, dest); // target path is something like "C:\Program Files // (x86)\Jenkins\jobs\testAction\builds\35\archive\UFTReport\GuiTest1" // zip copy and unzip ByteArrayOutputStream outstr = new ByteArrayOutputStream(); // don't use FileFilter for zip, or it will cause bug when files are on slave source.zip(outstr); ByteArrayInputStream instr = new ByteArrayInputStream(outstr.toByteArray()); String zipFileName = "UFT_Report_HTML_tmp.zip"; FilePath archivedFile = new FilePath(rootTarget, zipFileName); archivedFile.copyFrom(instr); listener.getLogger().println("copy from slave to master: " + archivedFile); outstr.close(); instr.close(); // unzip archivedFile.unzip(rootTarget); archivedFile.delete(); // now,all the files are in the C:\Program Files (x86) // \Jenkins\jobs\testAction\builds\35\archive\UFTReport\Report // we need to rename the above path to targetPath. // So at last we got files in C:\Program Files (x86) // \Jenkins\jobs\testAction\builds\35\archive\UFTReport\GuiTest String unzippedFileName = org.apache.commons.io.FilenameUtils.getName(htmlReportDir); FilePath unzippedFolderPath = new FilePath(rootTarget, unzippedFileName); // C:\Program Files // (x86)\Jenkins\jobs\testAction\builds\35\archive\UFTReport\Report // FilePath unzippedFolderPath = new FilePath(rootTarget, source.getName()); //C:\Program Files // (x86)\Jenkins\jobs\testAction\builds\35\archive\UFTReport\Report unzippedFolderPath.renameTo(targetPath); listener.getLogger() .println("UnzippedFolderPath is: " + unzippedFolderPath + " targetPath is: " + targetPath); // end zip copy and unzip // fill in the urlName of this report. we need a network path not a FS path String resourceUrl = htmlReportInfo.getResourceURL(); String resFileName = isParallelRunner ? "/parallelrun_results.html" : "/run_results.html"; String urlName = resourceUrl + resFileName; // like artifact/UFTReport/GuiTest1/run_results.html // or for Parallel runner /GuiTest1[1]/parallelrun_results.html listener.getLogger().println("set the report urlName to " + urlName); htmlReportInfo.setUrlName(urlName); } } catch (Exception ex) { listener.getLogger().println("catch exception in collectAndPrepareHtmlReports: " + ex); } return true; }
From source file:com.savor.ads.core.Session.java
private Object StringToObject(String str) { Object obj = null;/* ww w. jav a2 s . c o m*/ byte[] base64Bytes; ByteArrayInputStream bais = null; try { String productBase64 = str; if (null == productBase64 || TextUtils.isEmpty(productBase64.trim())) { return null; } base64Bytes = Base64.decode(productBase64, Base64.DEFAULT); bais = new ByteArrayInputStream(base64Bytes); ObjectInputStream ois = new ObjectInputStream(bais); obj = ois.readObject(); ois.close(); } catch (Exception e) { } finally { if (bais != null) { try { bais.close(); } catch (IOException e) { e.printStackTrace(); } } } return obj; }
From source file:com.eviware.soapui.impl.wsdl.monitor.TcpMonWsdlMonitorMessageExchange.java
private void parseReponseData(byte[] capturedResponseData, IncomingWss responseWss) { responseContentLength = capturedResponseData.length; ByteArrayInputStream in = new ByteArrayInputStream(capturedResponseData); try {/*w w w . j a v a 2 s . c om*/ String line = null; do { line = HttpParser.readLine(in, HTTP_ELEMENT_CHARSET); } while (line != null && line.length() == 0); if (line == null) { throw new Exception("Missing request status line"); } Header[] headers = HttpParser.parseHeaders(in, HTTP_ELEMENT_CHARSET); if (headers != null) { for (Header header : headers) { responseHeaders.put(header.getName(), header.getValue()); } } responseContentType = responseHeaders.get("Content-Type", ""); if (responseContentType != null && responseContentType.toUpperCase().startsWith("MULTIPART")) { StringToStringMap values = StringToStringMap.fromHttpHeader(responseContentType); responseMmSupport = new MultipartMessageSupport( new MonitorMessageExchangeDataSource("monitor response", in, responseContentType), values.get("start"), null, true, SoapUI.getSettings().getBoolean(WsdlSettings.PRETTY_PRINT_RESPONSE_MESSAGES)); responseContentType = responseMmSupport.getRootPart().getContentType(); } else { this.responseContent = XmlUtils.prettyPrintXml(Tools.readAll(in, 0).toString()); } processResponseWss(responseWss); } catch (Exception e) { try { in.close(); } catch (IOException e1) { e1.printStackTrace(); } } }
From source file:org.apache.hadoop.yarn.server.resourcemanager.recovery.ZKRMStateStore.java
private void loadRMDelegationTokenState(RMState rmState) throws Exception { List<String> childNodes = getChildrenWithRetries(delegationTokensRootPath, false); for (String childNodeName : childNodes) { String childNodePath = getNodePath(delegationTokensRootPath, childNodeName); byte[] childData = getDataWithRetries(childNodePath, false); if (childData == null) { LOG.warn("Content of " + childNodePath + " is broken."); continue; }/* w ww . j a v a 2 s.com*/ ByteArrayInputStream is = new ByteArrayInputStream(childData); DataInputStream fsIn = new DataInputStream(is); try { if (childNodeName.startsWith(DELEGATION_TOKEN_PREFIX)) { RMDelegationTokenIdentifierData identifierData = new RMDelegationTokenIdentifierData(); identifierData.readFields(fsIn); RMDelegationTokenIdentifier identifier = identifierData.getTokenIdentifier(); long renewDate = identifierData.getRenewDate(); rmState.rmSecretManagerState.delegationTokenState.put(identifier, renewDate); if (LOG.isDebugEnabled()) { LOG.debug("Loaded RMDelegationTokenIdentifier: " + identifier + " renewDate=" + renewDate); } } } finally { is.close(); } } }
From source file:com.hpe.application.automation.tools.results.RunResultRecorder.java
/** * copies, archives and creates the Test reports of LR and UFT runs. * * @param build//from w w w.j a v a 2 s . c o m * @param listener * @param resultFiles * @param testResult * @param runWorkspace * @throws ParserConfigurationException * @throws SAXException * @throws IOException * @throws InterruptedException */ @SuppressWarnings({ "squid:S134", "squid:S135" }) private void archiveTestsReport(Run<?, ?> build, TaskListener listener, List<String> resultFiles, TestResult testResult, FilePath runWorkspace) throws ParserConfigurationException, SAXException, IOException, InterruptedException { if ((resultFiles == null) || (resultFiles.isEmpty())) { return; } ArrayList<String> zipFileNames = new ArrayList<String>(); ArrayList<FilePath> reportFolders = new ArrayList<FilePath>(); List<String> reportNames = new ArrayList<String>(); listener.getLogger() .println("Report archiving mode is set to: " + _resultsPublisherModel.getArchiveTestResultsMode()); // if user specified not to archive report if (_resultsPublisherModel.getArchiveTestResultsMode() .equals(ResultsPublisherModel.dontArchiveResults.getValue())) return; FilePath projectWS = runWorkspace; // get the artifacts directory where we will upload the zipped report // folder File artifactsDir = new File(build.getRootDir(), "archive"); artifactsDir.mkdirs(); // read each result.xml /* * The structure of the result file is: <testsuites> <testsuite> * <testcase.........report="path-to-report"/> * <testcase.........report="path-to-report"/> * <testcase.........report="path-to-report"/> * <testcase.........report="path-to-report"/> </testsuite> * </testsuites> */ // add previous report names for aggregation when using pipelines. PerformanceJobReportAction performanceJobReportAction = build.getAction(PerformanceJobReportAction.class); if (performanceJobReportAction != null) { reportNames .addAll(performanceJobReportAction.getLrResultBuildDataset().getLrScenarioResults().keySet()); } for (String resultsFilePath : resultFiles) { FilePath resultsFile = projectWS.child(resultsFilePath); List<ReportMetaData> ReportInfoToCollect = new ArrayList<ReportMetaData>(); DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder dBuilder = dbFactory.newDocumentBuilder(); Document doc = dBuilder.parse(resultsFile.read()); doc.getDocumentElement().normalize(); Node testSuiteNode = doc.getElementsByTagName("testsuite").item(0); Element testSuiteElement = (Element) testSuiteNode; if (testSuiteElement.hasAttribute("name") && testSuiteElement.getAttribute("name").endsWith(".lrs")) { // LR test NodeList testSuiteNodes = doc.getElementsByTagName("testsuite"); for (int i = 0; i < testSuiteNodes.getLength(); i++) { testSuiteNode = testSuiteNodes.item(i); testSuiteElement = (Element) testSuiteNode; if (!testSuiteElement.hasAttribute("name")) { continue; } String testFolderPath = testSuiteElement.getAttribute("name"); int testPathArr = testFolderPath.lastIndexOf('\\'); String testName = testFolderPath.substring(testPathArr + 1); reportNames.add(testName); String testStatus = ("0".equals(testSuiteElement.getAttribute("failures"))) ? "pass" : "fail"; Node testCaseNode = testSuiteElement.getElementsByTagName("testcase").item(0); if (testCaseNode == null) { listener.getLogger().println("No report folder was found in results"); return; } if (testCaseNode.getNodeType() == Node.ELEMENT_NODE) { Element testCaseElement = (Element) testCaseNode; if (!testCaseElement.hasAttribute(REPORT_NAME_FIELD)) { continue; } String reportFolderPath = testCaseElement.getAttribute(REPORT_NAME_FIELD); FilePath reportFolder = new FilePath(projectWS.getChannel(), reportFolderPath); reportFolders.add(reportFolder); FilePath testFolder = new FilePath(projectWS.getChannel(), testFolderPath); String zipFileName = getUniqueZipFileNameInFolder(zipFileNames, testFolder.getName()); FilePath archivedFile = new FilePath(new FilePath(artifactsDir), zipFileName); if (archiveFolder(reportFolder, testStatus, archivedFile, listener)) { zipFileNames.add(zipFileName); } createHtmlReport(reportFolder, testFolderPath, artifactsDir, reportNames, testResult); createTransactionSummary(reportFolder, testFolderPath, artifactsDir, reportNames, testResult); try { FilePath testSla = copyRunReport(reportFolder, build.getRootDir(), testFolder.getName()); if (testSla == null) { listener.getLogger().println("no RunReport.xml file was created"); } else { runReportList.add(testSla); } } catch (IOException | InterruptedException e) { listener.getLogger().println(e); } } } } else { // UFT Test boolean reportIsHtml = false; NodeList testCasesNodes = ((Element) testSuiteNode).getElementsByTagName("testcase"); for (int i = 0; i < testCasesNodes.getLength(); i++) { Node nNode = testCasesNodes.item(i); if (nNode.getNodeType() == Node.ELEMENT_NODE) { Element eElement = (Element) nNode; if (!eElement.hasAttribute(REPORT_NAME_FIELD)) { continue; } String reportFolderPath = eElement.getAttribute(REPORT_NAME_FIELD); // e.g. "C:\UFTTest\GuiTest1\Report" String testFolderPath = eElement.getAttribute("name"); // e.g. "C:\UFTTest\GuiTest1" String testStatus = eElement.getAttribute("status"); // e.g. "pass" Node nodeSystemInfo = eElement.getElementsByTagName("system-out").item(0); String sysinfo = nodeSystemInfo.getFirstChild().getNodeValue(); String testDateTime = sysinfo.substring(0, 19); FilePath reportFolder = new FilePath(projectWS.getChannel(), reportFolderPath); reportFolders.add(reportFolder); String archiveTestResultMode = _resultsPublisherModel.getArchiveTestResultsMode(); boolean archiveTestResult = false; //check for the new html report FilePath htmlReport = new FilePath(reportFolder, "run_results.html"); FilePath rrvReport = new FilePath(reportFolder, "Results.xml"); if (htmlReport.exists()) { reportIsHtml = true; String htmlReportDir = reportFolder.getRemote(); ReportMetaData reportMetaData = new ReportMetaData(); reportMetaData.setFolderPath(htmlReportDir); reportMetaData.setIsHtmlReport(true); reportMetaData.setDateTime(testDateTime); reportMetaData.setStatus(testStatus); File testFileFullName = new File(testFolderPath); String testName = org.apache.commons.io.FilenameUtils .getName(testFileFullName.getPath()); String resourceUrl = "artifact/UFTReport/" + testName; reportMetaData.setResourceURL(resourceUrl); reportMetaData.setDisPlayName(testName); // use the name, not the full path //don't know reportMetaData's URL path yet, we will generate it later. ReportInfoToCollect.add(reportMetaData); listener.getLogger().println( "add html report info to ReportInfoToCollect: " + "[date]" + testDateTime); } archiveTestResult = isArchiveTestResult(testStatus, archiveTestResultMode); if (archiveTestResult && rrvReport.exists()) { if (reportFolder.exists()) { FilePath testFolder = new FilePath(projectWS.getChannel(), testFolderPath); String zipFileName = getUniqueZipFileNameInFolder(zipFileNames, testFolder.getName()); zipFileNames.add(zipFileName); listener.getLogger().println("Zipping report folder: " + reportFolderPath); ByteArrayOutputStream outstr = new ByteArrayOutputStream(); //don't use FileFilter for zip, or it will cause bug when files are on slave reportFolder.zip(outstr); /* * I did't use copyRecursiveTo or copyFrom due to * bug in * jekins:https://issues.jenkins-ci.org/browse * /JENKINS-9189 //(which is cleaimed to have been * fixed, but not. So I zip the folder to stream and * copy it to the master. */ ByteArrayInputStream instr = new ByteArrayInputStream(outstr.toByteArray()); FilePath archivedFile = new FilePath(new FilePath(artifactsDir), zipFileName); archivedFile.copyFrom(instr); listener.getLogger().println("copy from slave to master: " + archivedFile); outstr.close(); instr.close(); // add to Report list ReportMetaData reportMetaData = new ReportMetaData(); reportMetaData.setIsHtmlReport(false); // reportMetaData.setFolderPath(htmlReportDir); //no need for RRV File testFileFullName = new File(testFolderPath); String testName = testFileFullName.getName(); reportMetaData.setDisPlayName(testName); // use the name, not the full path String zipFileUrlName = "artifact/" + zipFileName; reportMetaData.setUrlName(zipFileUrlName); // for RRV, the file url and resource url are the same. reportMetaData.setResourceURL(zipFileUrlName); reportMetaData.setDateTime(testDateTime); reportMetaData.setStatus(testStatus); ReportInfoToCollect.add(reportMetaData); } else { listener.getLogger().println("No report folder was found in: " + reportFolderPath); } } } } if (reportIsHtml && !ReportInfoToCollect.isEmpty()) { listener.getLogger().println("begin to collectAndPrepareHtmlReports"); collectAndPrepareHtmlReports(build, listener, ReportInfoToCollect, runWorkspace); } if (!ReportInfoToCollect.isEmpty()) { // serialize report metadata File reportMetaDataXmlFile = new File(artifactsDir.getParent(), REPORTMETADATE_XML); String reportMetaDataXml = reportMetaDataXmlFile.getAbsolutePath(); writeReportMetaData2XML(ReportInfoToCollect, reportMetaDataXml, listener); // Add UFT report action try { listener.getLogger().println("Adding a report action to the current build."); HtmlBuildReportAction reportAction = new HtmlBuildReportAction(build); build.addAction(reportAction); } catch (IOException | SAXException | ParserConfigurationException ex) { listener.getLogger().println("a problem adding action: " + ex); } } } } }
From source file:com.eviware.soapui.impl.wsdl.monitor.TcpMonWsdlMonitorMessageExchange.java
private void parseRequestData(byte[] capturedRequestData, IncomingWss requestWss) { requestContentLength = capturedRequestData.length; ByteArrayInputStream in = new ByteArrayInputStream(capturedRequestData); try {/*from w w w . j a v a2 s. c om*/ String line = null; do { line = HttpParser.readLine(in, HTTP_ELEMENT_CHARSET); } while (line != null && line.length() == 0); if (line == null) { throw new Exception("Missing request status line"); } Header[] headers = HttpParser.parseHeaders(in, HTTP_ELEMENT_CHARSET); if (headers != null) { for (Header header : headers) { requestHeaders.put(header.getName(), header.getValue()); } } requestContentType = requestHeaders.get("Content-Type", ""); if (requestContentType != null && requestContentType.toUpperCase().startsWith("MULTIPART")) { StringToStringMap values = StringToStringMap.fromHttpHeader(requestContentType); requestMmSupport = new MultipartMessageSupport( new MonitorMessageExchangeDataSource("monitor request", in, requestContentType), values.get("start"), null, true, SoapUI.getSettings().getBoolean(WsdlSettings.PRETTY_PRINT_RESPONSE_MESSAGES)); requestContentType = requestMmSupport.getRootPart().getContentType(); } else { this.requestContent = XmlUtils.prettyPrintXml(Tools.readAll(in, 0).toString()); } processRequestWss(requestWss); operation = findOperation(); } catch (Exception e) { try { in.close(); } catch (IOException e1) { e1.printStackTrace(); } } }
From source file:es.mityc.firmaJava.libreria.utilidades.Base64.java
/** * Decodes data from Base64 notation, automatically * detecting gzip-compressed data and decompressing it. * * @param s the string to decode//from www . j a v a 2s .c om * @param options encode options such as URL_SAFE * @return the decoded data * @since 1.4 */ public static byte[] decode(String s, int options) { byte[] bytes; try { bytes = s.getBytes(PREFERRED_ENCODING); } // end try catch (UnsupportedEncodingException uee) { bytes = s.getBytes(); } // end catch //</change> // Decode bytes = decode(bytes, 0, bytes.length, options); // Check to see if it's gzip-compressed // GZIP Magic Two-Byte Number: 0x8b1f (35615) int l = bytes.length; if (bytes != null && l >= 4) { int head = ((int) bytes[0] & 0xff) | ((bytes[1] << 8) & 0xff00); if (GZIPInputStream.GZIP_MAGIC == head) { ByteArrayInputStream bais = null; GZIPInputStream gzis = null; ByteArrayOutputStream baos = null; byte[] buffer = new byte[2048]; int length = 0; try { baos = new ByteArrayOutputStream(); bais = new ByteArrayInputStream(bytes); gzis = new GZIPInputStream(bais); int longitud = gzis.read(buffer); while ((length = longitud) >= 0) { baos.write(buffer, 0, length); longitud = gzis.read(buffer); } // end while: reading input // No error? Get new bytes. bytes = baos.toByteArray(); } // end try catch (IOException e) { // Just return originally-decoded bytes } // end catch finally { try { baos.close(); } catch (Exception e) { log.error(e); } try { gzis.close(); } catch (Exception e) { log.error(e); } try { bais.close(); } catch (Exception e) { log.error(e); } } // end finally } // end if: gzipped } // end if: bytes.length >= 2 return bytes; }
From source file:bftsmart.tom.core.Synchronizer.java
private TOMMessage[] deserializeTOMMessages(byte[] playload) { ByteArrayInputStream bis; ObjectInputStream ois;// w ww. j a v a 2s .c o m TOMMessage[] requests = null; try { // deserialize the content of the STOP message bis = new ByteArrayInputStream(playload); ois = new ObjectInputStream(bis); boolean hasReqs = ois.readBoolean(); if (hasReqs) { // Store requests that the other replica did not manage to order //TODO: The requests have to be verified! byte[] temp = (byte[]) ois.readObject(); BatchReader batchReader = new BatchReader(temp, controller.getStaticConf().getUseSignatures() == 1); requests = batchReader.deserialiseRequests(controller); } ois.close(); bis.close(); } catch (IOException ex) { ex.printStackTrace(); java.util.logging.Logger.getLogger(TOMLayer.class.getName()).log(Level.SEVERE, null, ex); } catch (ClassNotFoundException ex) { ex.printStackTrace(); java.util.logging.Logger.getLogger(TOMLayer.class.getName()).log(Level.SEVERE, null, ex); } return requests; }
From source file:bftsmart.tom.core.Synchronizer.java
private void processSTOPDATA(LCMessage msg, int regency) { //TODO: It is necessary to verify the proof of the last decided consensus and the signature of the state of the current consensus! CertifiedDecision lastData = null;//from w w w .ja v a2s .c om SignedObject signedCollect = null; int last = -1; byte[] lastValue = null; Set<ConsensusMessage> proof = null; ByteArrayInputStream bis; ObjectInputStream ois; try { // deserialize the content of the message bis = new ByteArrayInputStream(msg.getPayload()); ois = new ObjectInputStream(bis); if (ois.readBoolean()) { // content of the last decided cid last = ois.readInt(); lastValue = (byte[]) ois.readObject(); proof = (Set<ConsensusMessage>) ois.readObject(); //TODO: Proof is missing! } lastData = new CertifiedDecision(msg.getSender(), last, lastValue, proof); lcManager.addLastCID(regency, lastData); signedCollect = (SignedObject) ois.readObject(); ois.close(); bis.close(); lcManager.addCollect(regency, signedCollect); int bizantineQuorum = (controller.getCurrentViewN() + controller.getCurrentViewF()) / 2; int cftQuorum = (controller.getCurrentViewN()) / 2; // Did I already got messages from a Byzantine/Crash quorum, // related to the last cid as well as for the current? boolean conditionBFT = (controller.getStaticConf().isBFT() && lcManager.getLastCIDsSize(regency) > bizantineQuorum && lcManager.getCollectsSize(regency) > bizantineQuorum); boolean conditionCFT = (lcManager.getLastCIDsSize(regency) > cftQuorum && lcManager.getCollectsSize(regency) > cftQuorum); if (conditionBFT || conditionCFT) { catch_up(regency); } } catch (IOException ex) { ex.printStackTrace(System.err); } catch (ClassNotFoundException ex) { ex.printStackTrace(System.err); } }