Example usage for java.lang Exception getLocalizedMessage

List of usage examples for java.lang Exception getLocalizedMessage

Introduction

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

Prototype

public String getLocalizedMessage() 

Source Link

Document

Creates a localized description of this throwable.

Usage

From source file:com.amazonaws.mturk.cmd.MakeTemplate.java

protected void runCommand(CommandLine cmdLine) throws Exception {

    if (!cmdLine.hasOption(ARG_TEMPLATE)) {
        log.error("Missing: -" + ARG_TEMPLATE);
        printHelp();/*from  w  ww. ja v  a 2 s. c  om*/
        System.exit(-1);
    } else if (!cmdLine.hasOption(ARG_TARGET)) {
        log.error("Missing: -" + ARG_TARGET);
        printHelp();
        System.exit(-1);
    } else if (!cmdLine.hasOption(ARG_TYPE)) {
        log.error("Missing: -" + ARG_TYPE);
        printHelp();
        System.exit(-1);
    } else if (!cmdLine.hasOption(ARG_OS)) {
        log.error("Missing: -" + ARG_OS);
        printHelp();
        System.exit(-1);
    } else if (!cmdLine.hasOption(ARG_TEMPLATE_ROOT_DIR)) {
        log.error("Missing: -" + ARG_TEMPLATE_ROOT_DIR);
        printHelp();
        System.exit(-1);
    } else if (!cmdLine.hasOption(ARG_TARGET_ROOT_DIR)) {
        log.error("Missing: -" + ARG_TARGET_ROOT_DIR);
        printHelp();
        System.exit(-1);
    } else if (!cmdLine.hasOption(ARG_SCRIPT_TEMPLATE_DIR)) {
        log.error("Missing: -" + ARG_SCRIPT_TEMPLATE_DIR);
        printHelp();
        System.exit(-1);
    }

    try {
        makeTemplate(cmdLine.getOptionValue(ARG_TEMPLATE), cmdLine.getOptionValue(ARG_TARGET),
                cmdLine.getOptionValue(ARG_TYPE), cmdLine.getOptionValue(ARG_OS),
                cmdLine.getOptionValue(ARG_TEMPLATE_ROOT_DIR), cmdLine.getOptionValue(ARG_TARGET_ROOT_DIR),
                cmdLine.getOptionValue(ARG_SCRIPT_TEMPLATE_DIR));
    } catch (Exception e) {
        log.error("Error making a template: " + e.getLocalizedMessage(), e);
        e.printStackTrace();
        System.exit(-1);
    }
}

From source file:com.epam.dlab.core.parser.ConditionEvaluate.java

/** Evaluate condition for given row.
 * @param row the row to evaluate.//from  w  ww .  j av a 2s  .c o  m
 * @return <true> if condition is true.
 * @throws ParseException if condition is not return boolean type.
 */
public boolean evaluate(List<String> row) throws ParseException {
    for (int i = 0; i < columnNames.length; i++) {
        jexlContext.set(columnNames[i], row.get(columnIndexes[i]));
    }
    Object value;
    try {
        value = expression.evaluate(jexlContext);
    } catch (Exception e) {
        throw new ParseException(
                "Cannot evaluate condition: " + expression.getSourceText() + ". " + e.getLocalizedMessage(), e);
    }
    if (value instanceof Boolean) {
        return (Boolean) value;
    }
    throw new ParseException("Invalid condition: " + expression.getSourceText());
}

From source file:com.cloud.storage.template.VhdProcessor.java

@Override
public long getVirtualSize(File file) throws IOException {
    try {/*w  w w  . j a va 2 s . co m*/
        long size = getTemplateVirtualSize(file);
        return size;
    } catch (Exception e) {
        s_logger.info("[ignored]" + "failed to get template virtual size for VHD: " + e.getLocalizedMessage());
    }
    return file.length();
}

From source file:com.wonders.bud.freshmommy.web.user.controller.BabyController.java

@RequestMapping(value = "/page", method = RequestMethod.GET)
@ResponseBody//ww w .  j  a v  a 2s.  c o  m
public RestMsg<PageVO<BabyVO>> findBabiesByPage(HttpServletRequest request) {

    RestMsg<PageVO<BabyVO>> rm = new RestMsg<PageVO<BabyVO>>();

    String bName = request.getParameter("bName");
    String bSex = request.getParameter("bSex");
    String starttime = request.getParameter("starttime");//
    String endtime = request.getParameter("endtime");//?
    String row = request.getParameter("row");
    String start = request.getParameter("start");
    String sortorder = request.getParameter("sord"); //?ASC or DESC?DESC
    String sortfield = request.getParameter("sidx");

    try {
        QueryParam param = new QueryParam();
        Map<String, Object> eq = new HashMap<String, Object>();
        if (StringUtils.isNotEmpty(starttime) && StringUtils.isNotEmpty(endtime)) {
            Map<String, Object[]> between = new HashMap<String, Object[]>();
            Object obj[] = new Object[2];
            obj[0] = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss").parse(starttime.trim() + " 00:00:00");
            obj[1] = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss").parse(endtime.trim() + " 23:59:59");
            between.put("bBirthday", obj);
            param.setBetween(between);
        }
        if (StringUtils.isNotBlank(bSex)) {
            eq.put("bSex", Integer.valueOf(bSex));
            param.setEq(eq);
        }
        Map<String, Object> like = new HashMap<String, Object>();
        if (StringUtils.isNotBlank(bName)) {
            like.put("bName", bName);
            param.setLike(like);
        }
        Page<BabyPO> page = new Page<BabyPO>();
        page.setParam(param);
        PageUtil.pageSplit(page, start, row, sortorder, sortfield, null);
        page = babyService.findBabiesByPage(page);
        PageVO<BabyVO> pageVO = new PageVO<BabyVO>();
        List<BabyVO> data = new ArrayList<BabyVO>();
        List<BabyPO> babyList = page.getResult();
        if (null != babyList && babyList.size() > 0) {
            for (BabyPO po : babyList) {
                BabyVO vo = new BabyVO();
                BeanUtils.copyProperties(vo, po);
                vo.setbBirthday(sdf.format(po.getbBirthday()));
                data.add(vo);
            }
        }
        pageVO.setData(data);
        PageUtil.pageVOSplit(page, pageVO);
        rm.setResult(pageVO);
        rm = rm.successMsg();
    } catch (Exception e) {
        rm.errorMsg("?");
        log.error(e.getLocalizedMessage());
    }
    return rm;
}

From source file:com.haulmont.cuba.gui.backgroundwork.LocalizedTaskWrapper.java

protected void showExecutionError(Exception ex) {
    final Frame ownerFrame = wrappedTask.getOwnerFrame();
    if (ownerFrame != null) {
        String localizedMessage = ex.getLocalizedMessage();
        if (StringUtils.isNotBlank(localizedMessage)) {
            ownerFrame.showNotification(
                    messages.getMessage(getClass(), "backgroundWorkProgress.executionError"), localizedMessage,
                    Frame.NotificationType.WARNING);
        } else {/*w  w  w.  j a  va  2 s  . c o m*/
            ownerFrame.showNotification(
                    messages.getMessage(getClass(), "backgroundWorkProgress.executionError"),
                    Frame.NotificationType.WARNING);
        }
    }
}

From source file:com.kylinolap.job.hadoop.hbase.CreateHTableJob.java

@Override
public int run(String[] args) throws Exception {
    Options options = new Options();

    options.addOption(OPTION_CUBE_NAME);
    options.addOption(OPTION_PARTITION_FILE_PATH);
    options.addOption(OPTION_HTABLE_NAME);
    parseOptions(options, args);//from  w w w .  j  av a2  s .c om

    Path partitionFilePath = new Path(getOptionValue(OPTION_PARTITION_FILE_PATH));

    String cubeName = getOptionValue(OPTION_CUBE_NAME).toUpperCase();
    KylinConfig config = KylinConfig.getInstanceFromEnv();
    CubeManager cubeMgr = CubeManager.getInstance(config);
    CubeInstance cube = cubeMgr.getCube(cubeName);
    CubeDesc cubeDesc = cube.getDescriptor();

    String tableName = getOptionValue(OPTION_HTABLE_NAME).toUpperCase();
    HTableDescriptor tableDesc = new HTableDescriptor(TableName.valueOf(tableName));
    // https://hbase.apache.org/apidocs/org/apache/hadoop/hbase/regionserver/ConstantSizeRegionSplitPolicy.html
    tableDesc.setValue(HTableDescriptor.SPLIT_POLICY, ConstantSizeRegionSplitPolicy.class.getName());

    Configuration conf = HBaseConfiguration.create(getConf());
    HBaseAdmin admin = new HBaseAdmin(conf);

    try {
        if (User.isHBaseSecurityEnabled(conf)) {
            // add coprocessor for bulk load
            tableDesc.addCoprocessor("org.apache.hadoop.hbase.security.access.SecureBulkLoadEndpoint");
        }

        for (HBaseColumnFamilyDesc cfDesc : cubeDesc.getHBaseMapping().getColumnFamily()) {
            HColumnDescriptor cf = new HColumnDescriptor(cfDesc.getName());
            cf.setMaxVersions(1);
            cf.setCompressionType(Algorithm.LZO);
            cf.setDataBlockEncoding(DataBlockEncoding.FAST_DIFF);
            cf.setInMemory(true);
            cf.setBlocksize(4 * 1024 * 1024); // set to 4MB
            tableDesc.addFamily(cf);
        }

        byte[][] splitKeys = getSplits(conf, partitionFilePath);

        if (admin.tableExists(tableName)) {
            // admin.disableTable(tableName);
            // admin.deleteTable(tableName);
            throw new RuntimeException("HBase table " + tableName + " exists!");
        }

        try {
            initHTableCoprocessor(tableDesc);
            log.info("hbase table " + tableName + " deployed with coprocessor.");

        } catch (Exception ex) {
            log.error("Error deploying coprocessor on " + tableName, ex);
            log.error("Will try creating the table without coprocessor.");
        }

        admin.createTable(tableDesc, splitKeys);
        log.info("create hbase table " + tableName + " done.");

        return 0;
    } catch (Exception e) {
        printUsage(options);
        e.printStackTrace(System.err);
        log.error(e.getLocalizedMessage(), e);
        return 2;
    } finally {
        admin.close();
    }
}

From source file:com.wonders.bud.freshmommy.web.user.controller.UserController.java

/**
 * <p>// w w w. ja  v a2s. c o  m
 * Description:[?]
 * </p>
 * 
 * Created by linqin [2014-11-20]
 * Midified by [] []
 * @param request
 * @return
 */
@RequestMapping(value = "/page", method = RequestMethod.GET)
@ResponseBody
public RestMsg<PageVO<UserVO>> findUsersByPage(HttpServletRequest request) {

    RestMsg<PageVO<UserVO>> rm = new RestMsg<PageVO<UserVO>>();

    String uName = request.getParameter("uName");
    String uSex = request.getParameter("uSex");
    String uDistrict = request.getParameter("uDistrict");
    String status = request.getParameter("status");
    String row = request.getParameter("row");
    String start = request.getParameter("start");
    String sortorder = request.getParameter("sord"); //?ASC or DESC?DESC
    String sortfield = request.getParameter("sidx");

    try {
        Page<UserPO> page = new Page<UserPO>();
        QueryParam param = new QueryParam();

        Map<String, Object> eq = new HashMap<String, Object>();
        Map<String, Object> like = new HashMap<String, Object>();
        if (StringUtils.isNotBlank(uSex)) {
            eq.put("uSex", Integer.valueOf(uSex));
            param.setEq(eq);
        }
        if (StringUtils.isNotBlank(uDistrict)) {
            eq.put("uDistrict", Integer.valueOf(uDistrict));
            param.setEq(eq);
        }
        if (StringUtils.isNotBlank(status)) {
            eq.put("status", Integer.valueOf(status));
            param.setEq(eq);
        }
        if (StringUtils.isNotBlank(uName)) {
            like.put("uName", uName);
            param.setLike(like);
        }
        page.setParam(param);
        PageUtil.pageSplit(page, start, row, sortorder, sortfield, null);

        page = userService.findUsersByPage(page);
        PageVO<UserVO> pageVO = new PageVO<UserVO>();
        List<UserVO> data = new ArrayList<UserVO>();
        List<UserPO> list = page.getResult();
        if (null != list && list.size() > 0) {
            for (UserPO po : list) {
                UserVO vo = new UserVO();
                BeanUtils.copyProperties(vo, po);
                data.add(vo);
            }
        }
        pageVO.setData(data);
        PageUtil.pageVOSplit(page, pageVO);
        rm.setResult(pageVO);
        rm = rm.successMsg();
    } catch (Exception e) {
        rm.errorMsg("?");
        log.error(e.getLocalizedMessage());
    }
    return rm;
}

From source file:org.woofenterprise.dogs.web.controllers.DogsController.java

@RequestMapping(value = "/delete/{id}", method = RequestMethod.POST)
@RolesAllowed("ADMIN")
public String deleteDog(@PathVariable("id") long id, UriComponentsBuilder uriBuilder,
        RedirectAttributes redirectAttributes) {
    try {/*from  w w  w .j a  v a2s  .  c  o  m*/
        DogDTO dog = facade.findDogById(id);
        if (dog == null) {
            throw new ResourceNotFoundException();
        }
        facade.deleteDog(dog);
        redirectAttributes.addFlashAttribute("alert_success", "Dog #" + id + " was deleted.");
    } catch (Exception ex) {
        redirectAttributes.addFlashAttribute("alert_danger",
                "Dog #" + id + " was not deleted. " + ex.getLocalizedMessage());
    }

    return "redirect:" + uriBuilder.path("/dogs/").build().encode().toUriString();
}

From source file:edu.pdx.its.portal.routelandia.ApiPoster.java

public JSONObject postJsonObjectToUrl(String url, JSONObject jsonObject, APIResultWrapper retVal) {
    InputStream inputStream = null;
    String result = "";
    try {/* w  w w  . j a  v a2 s .c om*/

        // 1. create HttpClient
        HttpClient httpclient = new DefaultHttpClient();

        // 2. make POST request to the given URL

        //http://capstoneaa.cs.pdx.edu/api/trafficstats
        HttpPost httpPost = new HttpPost(url);

        // 4. convert JSONObject to JSON to String

        String json = jsonObject.toString();

        // 5. set json to StringEntity
        StringEntity se = new StringEntity(json);

        se.setContentType("application/json;charset=UTF-8");
        se.setContentEncoding(new BasicHeader(HTTP.CONTENT_TYPE, "application/json;charset=UTF-8"));

        // 6. set httpPost Entity
        httpPost.setEntity(se);

        // 7. Set some headers to inform server about the type of the content
        //            httpPost.setHeader("Accept", "application/json");
        //            httpPost.setHeader("Content-type", "application/json");

        // 8. Execute POST request to the given URL
        HttpResponse httpResponse = httpclient.execute(httpPost);

        // Make sure we've got a good response from the API.
        int status = httpResponse.getStatusLine().getStatusCode();
        retVal.setHttpStatus(status);

        result = EntityUtils.toString(httpResponse.getEntity());
        //Log.i("RAW HTTP RESULT", result);
        retVal.setRawResponse(result);

    } catch (Exception e) {
        Log.e("InputStream", e.getLocalizedMessage());
    }

    try {
        Object json = new JSONTokener(result).nextValue();
        if (json instanceof JSONObject) {
            retVal.setParsedResponse((JSONObject) json);
            return (JSONObject) json;
        }
    } catch (JSONException e) {
        e.printStackTrace();
    }

    // If we got this far, we got something very wrong...
    Log.e(TAG, "Didn't get a valid JSON response!");
    return null;
}

From source file:com.epam.dlab.module.aws.S3FileList.java

private List<S3ObjectSummary> reportFilesInBillingBucket(AmazonS3 s3Client) throws AdapterException {
    ListObjectsV2Request request = new ListObjectsV2Request().withBucketName(bucket);
    ListObjectsV2Result result;//  ww  w  .  j  av a2s  .c  o  m
    List<S3ObjectSummary> objectSummaries = new ArrayList<>();
    try {
        do {
            result = s3Client.listObjectsV2(request);
            objectSummaries.addAll(notProcessedFiles(result));
        } while (result.isTruncated());
    } catch (Exception e) {
        throw new AdapterException(
                "Cannot get the file listing of bucket \"" + bucket + "*\". " + e.getLocalizedMessage(), e);
    }
    return objectSummaries;
}