Example usage for java.lang Exception getCause

List of usage examples for java.lang Exception getCause

Introduction

In this page you can find the example usage for java.lang Exception getCause.

Prototype

public synchronized Throwable getCause() 

Source Link

Document

Returns the cause of this throwable or null if the cause is nonexistent or unknown.

Usage

From source file:com.wineaccess.wine.WineAdapterHelper.java

/**
 * This method is used to update the wine in the database.
 * /*www.java  2 s. c  o m*/
 * @param wineUpdatePO is used to take the input in this PO.
 * @return output map containing response
 */
public static Map<String, Object> updateWine(final WineUpdatePO wineUpdatePO) {

    logger.info("start updateWine method");

    String errorMsg = StringUtils.EMPTY;

    final Map<String, Object> output = new ConcurrentHashMap<String, Object>();

    Response response = null;
    // TODO add check if any order is pending for wine then wine can not be edited
    try {

        MasterData vintage = null;
        MasterData bottleInMl = null;
        MasterData wineStyle = null;

        vintage = MasterDataRepository.getMasterDataById(Long.parseLong(wineUpdatePO.getVintageId()));
        if (vintage == null) {
            // vintage not exist
            response = ApplicationUtils.errorMessageGenerate(

                    SystemErrorCode.UPDATE_WINE_INVALID_VINTAGE,
                    SystemErrorCode.UPDATE_WINE_INVALID_VINTAGE_TEXT, SUCCESS_CODE);

            logger.error("vintage not exist");
        }

        if (response == null) {
            bottleInMl = MasterDataRepository.getMasterDataById(Long.parseLong(wineUpdatePO.getBottleInMlId()));
            if (bottleInMl == null) {
                // bottleInMlId not exist
                response = ApplicationUtils.errorMessageGenerate(

                        SystemErrorCode.UPDATE_WINE_INVALID_BOTTLE_IN_ML,
                        SystemErrorCode.UPDATE_WINE_INVALID_BOTTLE_IN_ML_TEXT, SUCCESS_CODE);

                logger.error("bottleInMlId not exist");
            }

        }

        ProductItemModel productItemModel = ProductItemRepository
                .getProductItemById(Long.parseLong(wineUpdatePO.getId()));
        if (productItemModel == null) {
            response = ApplicationUtils.errorMessageGenerate(

                    SystemErrorCode.UPDATE_WINE_INVALID_WINE_ID,
                    SystemErrorCode.UPDATE_WINE_INVALID_WINE_ID_TEXT, SUCCESS_CODE);

            logger.error("Product Id not exist");
        }

        WineModel wineModel = null;
        if (response == null) {
            wineModel = WineRepository.getWineById(productItemModel.getItemId());
            if (wineModel == null) {
                // Wine not exist
                response = ApplicationUtils.errorMessageGenerate(

                        SystemErrorCode.UPDATE_WINE_INVALID_WINE_ID,
                        SystemErrorCode.UPDATE_WINE_INVALID_WINE_ID_TEXT, SUCCESS_CODE);

                logger.error("Wine Id not exist");
            }
        }

        if (response == null) {

            String wineFullName = PropertyholderUtils.getStringProperty("wine.full.name");

            wineFullName = wineFullName.replace("<vintage>", vintage.getName() + " ");

            wineFullName = wineFullName.replace("<winery>", wineModel.getWineryId().getWineryName() + " ");

            wineFullName = wineFullName.replace("<winename>", wineUpdatePO.getWineName());

            wineModel.setWineFullName(wineFullName);
            wineModel.setWineName(wineUpdatePO.getWineName());
            wineModel.setVintage(vintage);
            wineModel.setBottleInMl(bottleInMl);
            wineModel.setVerietal(
                    MasterDataRepository.getMasterDataById(Long.parseLong(wineUpdatePO.getVarietalId())));

            if (wineUpdatePO.getAlcoholPercentage() != null) {

                wineModel.setAlcoholPercentage(Double.parseDouble(wineUpdatePO.getAlcoholPercentage()));

            }

            if (wineUpdatePO.getWineStyleId() != null) {

                wineStyle = MasterDataRepository
                        .getMasterDataById(Long.parseLong(wineUpdatePO.getWineStyleId()));
                wineModel.setWineType(wineStyle);
            }
            if (wineUpdatePO.getStatus() != null) {
                wineModel.setIsEnabled(Boolean.parseBoolean(wineUpdatePO.getStatus()));
            }

            WineRepository.update(wineModel);

            WineVO wineVO = new WineVO(SystemErrorCode.WINE_UPDATE_SUCCESS_TEXT);

            BeanUtils.copyProperties(wineVO, wineModel);

            wineVO.setId(productItemModel.getId());
            wineVO.setWineId(wineModel.getId());
            wineVO.setWineryId(wineModel.getWineryId().getId());

            if (wineModel.getWarehouseId() != null) {
                wineVO.setWarehouseId(wineModel.getWarehouseId().getId());
            }

            response = new com.wineaccess.response.SuccessResponse(wineVO, SUCCESS_CODE);
        }
    } catch (Exception e) {

        errorMsg = e.getCause().getMessage();

        logger.error("Exception occured during processing of update wine " + e);
    }

    if (response == null) {
        if (errorMsg.contains("uk_wine")) {

            response = ApplicationUtils.errorMessageGenerate(SystemErrorCode.WINE_UPDATE_WINE_DUPLICATE,
                    SystemErrorCode.WINE_UPDATE_WINE_DUPLICATE_TEXT, SUCCESS_CODE);

            logger.error("Duplicate entry for wine name ");

        } else {

            response = ApplicationUtils.errorMessageGenerate(SystemErrorCode.WINE_UPDATE_UNKNOWN_ERROR,
                    SystemErrorCode.WINE_UPDATE_UNKNOWN_ERROR_TEXT, SUCCESS_CODE);

            logger.error("Unkonwn error ");
        }
    }

    output.put(OUPUT_PARAM_KEY, response);

    logger.info("exit updateWine method");

    return output;
}

From source file:co.turnus.trace.io.XmlTraceReader.java

public XmlTraceReader(File file, TraceFactory factory) {
    try {/*from  w w w.ja v a2 s.c  o m*/
        XMLInputFactory inputFactory = XMLInputFactory.newInstance();
        String extension = TurnusUtils.getExtension(file);
        if (!extension.equals(TurnusExtension.TRACE) && !extension.equals(TurnusExtension.TRACE_COMPRESSED)) {
            throw new TurnusRuntimeException("Trace file reader: unsupported extension");
        }

        InputStream stream = new BufferedInputStream(new FileInputStream(file));
        if (extension.equals(TurnusExtension.TRACE_COMPRESSED)) {
            stream = new CompressorStreamFactory().createCompressorInputStream(CompressorStreamFactory.GZIP,
                    stream);
        }
        reader = inputFactory.createXMLStreamReader(stream);

    } catch (Exception e) {
        throw new TurnusRuntimeException("Error initializing the trace reader", e.getCause());
    }

    this.factory = factory;
    tempDep = new TempDependency();
    tempStep = new TempStep();
}

From source file:co.turnus.trace.io.XmlTraceStreamWriter.java

public XmlTraceStreamWriter(File file) {
    switch (TurnusUtils.getExtension(file)) {
    case TurnusExtension.TRACE_COMPRESSED:
        compressedXml = true;/*from w ww  .  ja va  2s .c  om*/
        break;
    case TurnusExtension.TRACE:
        compressedXml = false;
        break;
    default:
        throw new TurnusRuntimeException("Trace file writer: unsupported file extension");
    }

    try {
        stream = new FileOutputStream(file);
        if (compressedXml) {
            stream = new CompressorStreamFactory().createCompressorOutputStream(CompressorStreamFactory.GZIP,
                    stream);
        }
        stream = new BufferedOutputStream(stream);
    } catch (Exception e) {
        throw new TurnusRuntimeException("Error opening the trace file output stream", e.getCause());
    }
}

From source file:com.ecofactor.qa.automation.platform.ops.impl.IOSOperations.java

/**
 * Creates the device driver.//from  w w w .ja  va 2  s  .c om
 * @return the web driver
 * @throws DeviceException the device exception
 * @see com.ecofactor.qa.automation.mobile.ops.impl.AbstractMobileOperations#createDeviceDriver()
 */
@Override
protected WebDriver createDeviceDriver() throws DeviceException {

    WebDriver driver = null;
    if (!hasErrors) {
        try {
            final File classpathRoot = new File(System.getProperty("user.dir"));
            final File app = new File(classpathRoot, "/EcoFactor_iOS/EcoFactorNew.zip");
            setLogString("Application Path: " + app.getPath(), true);
            final DesiredCapabilities capabilities = new DesiredCapabilities();
            capabilities.setCapability("device", "iphone");
            capabilities.setCapability(CapabilityType.BROWSER_NAME, JenkinsParamUtil.getDeviceName());
            capabilities.setCapability(CapabilityType.VERSION, "7.0");
            capabilities.setCapability(CapabilityType.PLATFORM, SystemUtil.getOSType());
            capabilities.setCapability("cleanSession", true);
            capabilities.setCapability("app", app.getAbsolutePath());
            capabilities.setCapability(CapabilityType.TAKES_SCREENSHOT, true);
            driver = new SwipeableWebDriver(new URL(getAppiumHostUrl()), capabilities);
        } catch (Exception ex) {
            if (ex.getCause() instanceof HttpHostConnectException) {
                setErrorMsg("Appium not started");
                setLogString(errorMsg, true);
                hasErrors = true;
                throw new DeviceException("\033[41;1m" + getErrorMsg());
            }
            setLogString("\033[41;1mERROR in initialze (" + ex.getMessage() + ")", true);
            throw new DeviceException("ERROR in initialze (" + ex.getMessage() + ")");
        }
    }
    return driver;
}

From source file:com.ms.commons.summer.web.handler.ComponentMethodHandlerAdapter.java

/**
 * token?// w  w  w .j ava  2s . c o m
 * 
 * @param method
 * @param model
 * @param request
 * @param response
 * @param c
 * @return
 */
private Object checkToken(Object handle, Method method, Map<String, Object> model, HttpServletRequest request,
        HttpServletResponse response) throws Exception {
    ValidationToken validation = method.getAnnotation(ValidationToken.class);
    if (validation == null) {
        return null;
    }
    Method validationMethod = getValidationMethod(validation, handle.getClass());
    if (validationMethod == null) {
        String msg = "??:[" + validation.methodName() + "]!!";
        logger.error(msg);
        throw new ValidationException(msg);
    }
    String content = validation.content();
    // 
    try {
        return validationMethod.invoke(handle, model, content);
    } catch (Exception e) {
        Throwable cause = e.getCause();
        if (cause != null && cause instanceof Exception) {
            throw (Exception) cause;
        }
        throw e;
    }
}

From source file:de.hybris.platform.commerceorgaddon.controllers.pages.PermissionManagementPageController.java

@RequestMapping(value = "/add/save", method = RequestMethod.POST)
@RequireHardLogIn/*from  www .j  ava 2s.c  om*/
public String saveNewPermissionDetails(@Valid final B2BPermissionForm b2BPermissionForm,
        final BindingResult bindingResult, final Model model, final RedirectAttributes redirectModel)
        throws CMSItemNotFoundException, ParseException {
    b2BPermissionFormValidator.validate(b2BPermissionForm, bindingResult);
    if (bindingResult.hasErrors()) {
        model.addAttribute(b2BPermissionForm);
        GlobalMessages.addErrorMessage(model, "form.global.error");
        return (ResponsiveUtils.isResponsive()) ? getAddErrorPermissionPage(model)
                : getAddPermissionPage(model);
    }

    final B2BPermissionData b2BPermissionData = populateB2BPermissionDataFromForm(b2BPermissionForm);
    try {
        b2bPermissionFacade.addPermission(b2BPermissionData);
    } catch (final Exception e) {
        LOG.warn("Exception while saving the permission details " + e);
        if (e.getCause() instanceof InterceptorException && ((InterceptorException) e.getCause())
                .getInterceptor().getClass().equals(UniqueAttributesInterceptor.class)) {
            model.addAttribute(b2BPermissionForm);
            bindingResult.rejectValue("code", "text.company.managePermissions.code.exists.error.title");
            GlobalMessages.addErrorMessage(model, "form.global.error");
            return (ResponsiveUtils.isResponsive()) ? getAddErrorPermissionPage(model)
                    : getAddPermissionPage(model);
        }
    }

    storeCmsPageInModel(model, getContentPageForLabelOrId(ORGANIZATION_MANAGEMENT_CMS_PAGE));
    setUpMetaDataForContentPage(model, getContentPageForLabelOrId(ORGANIZATION_MANAGEMENT_CMS_PAGE));
    final List<Breadcrumb> breadcrumbs = myCompanyBreadcrumbBuilder.createManagePermissionsBreadcrumb();
    model.addAttribute("breadcrumbs", breadcrumbs);
    GlobalMessages.addFlashMessage(redirectModel, GlobalMessages.CONF_MESSAGES_HOLDER,
            "text.confirmation.permission.created");
    return String.format(REDIRECT_TO_PERMISSION_DETAILS, urlEncode(b2BPermissionData.getCode()));
}

From source file:com.baidu.qa.service.test.parser.CaseFolderParserImpl.java

/**
 * ?suite// w ww .  j  a v  a2  s  .c o m
 * @param folderpath case
 * @return case?
 * @throws Exception
 */
private List<CaseData> getCasedataFromFolder(String folderpath) throws Exception {

    List<CaseData> cases = new ArrayList<CaseData>();
    List<String> resultpaths = new ArrayList<String>();
    try {
        // ?case
        searchFolders(folderpath, Constant.FILENAME_CASEINFO, resultpaths);

        for (int i = 0; i < resultpaths.size(); i++) {
            CaseData casedata = parsecase(resultpaths.get(i));
            // case?stop
            if (casedata != null && casedata.getStatus() != null
                    && !casedata.getStatus().toUpperCase().equals(Constant.CASE_STATUS_STOP)) {
                cases.add(casedata);
            }
        }

        // debug ?debugcase
        List<CaseData> debuglist = new ArrayList<CaseData>();
        for (CaseData casedata : cases) {
            if (casedata.getStatus().toUpperCase().equals(Constant.CASE_STATUS_DEBUG)) {
                {
                    debuglist.add(casedata);
                }
            }
        }

        if (debuglist.size() > 0) {
            if (hasdebug == false) {
                casesuites = new ArrayList<CaseSuite>();
            }
            hasdebug = true;
            return debuglist;
        }
        if (hasdebug == true) {
            return null;
        }
        return (cases);
    } catch (Exception ex) {
        throw new RuntimeException("parse suite folder error", ex.getCause());
    }
}

From source file:com.scistor.queryrouter.server.impl.JdbcHandlerImpl.java

/**
 * //from   w w w. j a  va2  s. co m
 * initJdbcTemplate
 * 
 * @param dataSource
 *            dataSource
 */
@Override
public synchronized void initJdbcTemplate(DataSource dataSource) {
    long begin = System.currentTimeMillis();
    try {
        if (this.getJdbcTemplate() == null || !this.getJdbcTemplate().getDataSource().equals(dataSource)) {
            this.setJdbcTemplate(new JdbcTemplate(dataSource));
            logger.info("queryId:{} initJdbcTemplate cost:" + (System.currentTimeMillis() - begin) + "ms", 1);
        }
        //            String maxSize = PropertiesFileUtils.getPropertiesKey(PROPERY_SERVER_FILE_NAME,
        //                    PROPERY_MAX_RESULT_SIZE);
        //            if (!StringUtils.isEmpty(maxSize)) {
        //                memoryMaxSize = Integer.valueOf(maxSize).intValue();
        //            }
        this.dataSource = dataSource;
    } catch (Exception e) {
        e.printStackTrace();
        logger.error("getDataSource error:" + e.getCause().getMessage());
    }
}

From source file:co.turnus.trace.io.XmlTraceReader.java

public Trace read() {
    if (progressPrinter != null) {
        progressPrinter.start();// w  w w.ja  va  2s. c  o  m
    }
    trace = factory.newTrace();
    try {
        while (reader.hasNext()) {
            reader.next();
            switch (reader.getEventType()) {
            case XMLEvent.START_ELEMENT:
                startElement(reader.getName());
                break;
            case XMLEvent.END_ELEMENT:
                endElement(reader.getName());
                break;
            default:
                break;
            }
        }
    } catch (Exception e) {
        throw new TurnusRuntimeException("Error parsing the trace file", e.getCause());
    }

    if (trace instanceof PersistentTrace) {
        try {
            ((PersistentTrace) trace).commit();
        } catch (TurnusException e) {
            TurnusLogger.warning("Error while finalising the trace writing", e.getCause());
        }
    }

    if (progressPrinter != null) {
        progressPrinter.finish();
        try {
            progressPrinter.join();
        } catch (InterruptedException e) {
        }
    }
    return trace;
}

From source file:docx4j.TextSubstitution.java

private boolean substituteUsingDocx4j(InputStream docxFile, InputStream xmlData) {
    boolean result = false;
    HeaderPart header = null;//from  w w w  .j  a va  2 s  .  c o  m
    FooterPart footer = null;

    try {
        WordprocessingMLPackage wordMLPackage;
        wordMLPackage = WordprocessingMLPackage.load(docxFile);
        if (wordMLPackage.getCustomXmlDataStorageParts().isEmpty()) {
            this.lastError = "No custom XML data storage parts were found";
            return false;
        }
        // grab the first custom XML data storage part
        CustomXmlDataStoragePart customXmlDataStoragePart = (CustomXmlDataStoragePart) wordMLPackage
                .getCustomXmlDataStorageParts().values().toArray()[0];
        // get a reference to the data in it
        CustomXmlDataStorage customXmlDataStorage = customXmlDataStoragePart.getData();
        // replace it's data with the new XML data
        customXmlDataStorage.setDocument(xmlData);
        // get references to the section wrappers to get references to the header and footer
        List<SectionWrapper> sectionWrappers = wordMLPackage.getDocumentModel().getSections();
        // get references to the header and footer
        for (SectionWrapper sw : sectionWrappers) {
            HeaderFooterPolicy hfp = sw.getHeaderFooterPolicy();
            if (hfp.getDefaultHeader() != null) {
                header = hfp.getDefaultHeader();
                footer = hfp.getDefaultFooter();
            }
        }
        // bindings must be applied before the DOCX can be exported to HTML / PDF
        BindingHandler.applyBindings(wordMLPackage.getMainDocumentPart());
        if (header != null) {
            BindingHandler.applyBindings(header);
        }
        if (footer != null) {
            BindingHandler.applyBindings(footer);
        }
        // save as PDF
        wordMLPackage.setFontMapper(new IdentityPlusMapper());
        org.docx4j.convert.out.pdf.PdfConversion conversion = new org.docx4j.convert.out.pdf.viaXSLFO.Conversion(
                wordMLPackage);
        OutputStream stream = new FileOutputStream(this.filePath);
        org.docx4j.convert.out.pdf.viaXSLFO.PdfSettings pdfSettings = new org.docx4j.convert.out.pdf.viaXSLFO.PdfSettings();
        conversion.output(stream, pdfSettings);
        // save as new DOCX
        //wordMLPackage.save(new java.io.File(folderPath + "/document.docx"));

        result = true;
    } catch (Exception exception) {
        this.lastError = exception.getMessage();
        if (exception.getCause() != null) {
            this.lastError += "; " + exception.getCause().getMessage();
        }
    }
    return result;
}