Example usage for org.apache.commons.lang3.exception ExceptionUtils getMessage

List of usage examples for org.apache.commons.lang3.exception ExceptionUtils getMessage

Introduction

In this page you can find the example usage for org.apache.commons.lang3.exception ExceptionUtils getMessage.

Prototype

public static String getMessage(final Throwable th) 

Source Link

Document

Gets a short message summarising the exception.

Usage

From source file:com.vip.saturn.job.console.service.impl.RegistryCenterServiceImpl.java

@Override
public RequestResult refreshRegCenter() {
    RequestResult result = new RequestResult();
    if (refreshingRegCenter.compareAndSet(false, true)) {
        try {//from   w w w. ja  v  a 2  s .com
            refreshAll();
            result.setSuccess(true);
        } catch (Throwable t) {
            log.error(t.getMessage(), t);
            result.setSuccess(false);
            result.setMessage(ExceptionUtils.getMessage(t));
        } finally {
            refreshingRegCenter.set(false);
        }
    } else {
        result.setSuccess(false);
        result.setMessage("refreshing, try it later!");
    }
    return result;
}

From source file:com.baasbox.controllers.Asset.java

@With({ UserCredentialWrapFilter.class, ConnectToDBFilter.class, CheckAdminRoleFilter.class })
public static Result post() throws Throwable {
    String ct = request().getHeader(CONTENT_TYPE);
    if (ct.indexOf("multipart/form-data") != -1)
        return postFile();
    Map<String, String[]> body = request().body().asFormUrlEncoded();
    if (body == null)
        return badRequest("missing data: is the body x-www-form-urlencoded?");
    String[] meta = body.get("meta");
    String[] name = body.get("name");
    String ret = "";

    String assetName = (name != null && name.length > 0) ? name[0] : null;

    if (assetName != null && StringUtils.isNotEmpty(assetName.trim())) {
        String metaJson = null;/*  w  w  w  .  java2  s . c  o  m*/
        if (meta != null && meta.length > 0) {
            metaJson = meta[0];
        }
        try {
            ODocument doc = AssetService.create(assetName, metaJson);
            ret = prepareResponseToJson(doc);
        } catch (ORecordDuplicatedException e) {
            return badRequest("An asset with the same name already exists");
        } catch (OIndexException e) {
            return badRequest("An asset with the same name already exists");
        } catch (InvalidJsonException e) {
            return badRequest("the meta field has a problem: " + ExceptionUtils.getMessage(e));
        }
    } else {
        return badRequest("missing name field");
    }
    return created(ret);
}

From source file:com.thruzero.common.core.security.SimpleCipher.java

/**
 * @return the given {@code plaintext} as an encrypted string.
 * @throws SimpleCipherException//from   www. j  a v  a2 s. c o  m
 */
public String encrypt(final String plaintext) throws SimpleCipherException {
    String result = null;

    try {
        byte[] plaintextBytes = plaintext.getBytes();
        byte[] enc = encryptionCipher.doFinal(plaintextBytes); // Encrypt the plaintext

        result = Base64.encodeBase64URLSafeString(enc);
    } catch (Exception e) {
        throw new SimpleCipherException(
                "Couldn't encrypt the given plaintext because of " + ExceptionUtils.getMessage(e), e);
    }

    return result;
}

From source file:com.baasbox.service.scripting.ScriptingService.java

private static JsonNode callJsonSync(String url, String method, Map<String, List<String>> params,
        Map<String, List<String>> headers, JsonNode body, Integer timeout) throws Exception {
    try {/*from www .  j  ava2 s .c om*/
        ObjectNode node = Json.mapper().createObjectNode();
        WS.Response resp = null;

        long startTime = System.nanoTime();
        if (timeout == null) {
            resp = HttpClientService.callSync(url, method, params, headers,
                    body == null ? null : (body.isValueNode() ? body.toString() : body));
        } else {
            resp = HttpClientService.callSync(url, method, params, headers,
                    body == null ? null : (body.isValueNode() ? body.toString() : body), timeout);
        }
        long endTime = System.nanoTime();

        int status = resp.getStatus();
        node.put("status", status);
        node.put("execution_time", (endTime - startTime) / 1000000L);

        String header = resp.getHeader("Content-Type");
        if (header == null || header.startsWith("text")) {
            node.put("body", resp.getBody());
        } else if (header.startsWith("application/json")) {
            node.put("body", resp.asJson());
        } else {
            node.put("body", resp.getBody());
        }

        return node;
    } catch (Exception e) {
        BaasBoxLogger.error("failed to connect: " + ExceptionUtils.getMessage(e));
        throw e;
    }

}

From source file:com.thruzero.common.core.security.SimpleCipher.java

/**
 * @return the given {@code encryptedStr} as a decrypted string.
 * @throws SimpleCipherException/*  ww  w  .j  av a  2 s.com*/
 */
public String decrypt(final String encryptedStr) throws SimpleCipherException {
    byte[] decoded = base64.decode(encryptedStr);
    byte[] decrypted;

    try {
        decrypted = decryptionCipher.doFinal(decoded);
    } catch (IllegalBlockSizeException e) {
        throw new SimpleCipherException(
                "Couldn't decrypt the given ciphertext because of " + ExceptionUtils.getMessage(e), e);
    } catch (BadPaddingException e) {
        throw new SimpleCipherException(
                "Couldn't decrypt the given ciphertext - Ensure you're using the same passphrase to decrypt as was used to encrypt.",
                e);
    }

    return new String(decrypted);
}

From source file:com.baasbox.service.push.providers.APNServer.java

@Override
public void setConfiguration(ImmutableMap<ConfigurationKeys, String> configuration) {
    String json = configuration.get(ConfigurationKeys.IOS_CERTIFICATE);
    String name = null;//  w ww . j av  a 2s .  c om
    ObjectMapper mp = new ObjectMapper();
    try {
        ConfigurationFileContainer cfc = mp.readValue(json, ConfigurationFileContainer.class);
        if (cfc == null) {
            isInit = false;
            return;
        }
        name = cfc.getName();
    } catch (Exception e) {
        BaasBoxLogger.error(ExceptionUtils.getMessage(e));
        throw new RuntimeException(e);
    }
    if (name != null && !name.equals("null")) {
        File f = IosCertificateHandler.getCertificate(name);
        this.certificate = f.getAbsolutePath();
    }
    password = configuration.get(ConfigurationKeys.IOS_CERTIFICATE_PASSWORD);
    sandbox = configuration.get(ConfigurationKeys.IOS_SANDBOX).equalsIgnoreCase("true");
    timeout = Integer.parseInt(configuration.get(ConfigurationKeys.APPLE_TIMEOUT));
    isInit = StringUtils.isNotEmpty(this.certificate) && StringUtils.isNotEmpty(password);
}

From source file:net.xby1993.common.util.ExceptionUtil.java

/**
 *  ??: ?.//  www.  j  av  a2  s.c  om
 * 
 * Throwable.toString()??
 * 
 * @see ExceptionUtils#getMessage(Throwable)
 */
public static String toStringWithShortName(Throwable t) {
    return ExceptionUtils.getMessage(t);
}

From source file:nl.b3p.viewer.admin.stripes.GeoServiceActionBean.java

@DontValidate
public Resolution cqlToFilter() throws JSONException {
    JSONObject json = new JSONObject();
    json.put("success", Boolean.FALSE);

    try {/*from w w w  .  ja v  a2  s  .  c o  m*/
        List<Filter> filters = CQL.toFilterList(cql);

        FilterTransformer filterTransformer = new FilterTransformer();
        filterTransformer.setIndentation(4);
        filterTransformer.setOmitXMLDeclaration(true);
        filterTransformer.setNamespaceDeclarationEnabled(false);
        StringWriter sw = new StringWriter();
        for (Filter filter : filters) {
            sw.append('\n');
            filterTransformer.transform(filter, sw);
        }

        json.put("filter", sw.toString());

        json.put("success", Boolean.TRUE);
    } catch (Exception e) {
        String error = ExceptionUtils.getMessage(e);
        if (e.getCause() != null) {
            error += "; cause: " + ExceptionUtils.getMessage(e.getCause());
        }
        json.put("error", error);
    }
    return new StreamingResolution("application/json", new StringReader(json.toString()));
}

From source file:nl.b3p.viewer.admin.stripes.GeoServiceActionBean.java

public Resolution validateSldXml() {
    Resolution jsp = new ForwardResolution(JSP_EDIT_SLD);
    Document sldXmlDoc = null;/* www . j a v  a2  s. c o  m*/
    String stage = "Fout bij parsen XML document";
    try {
        DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
        dbf.setNamespaceAware(true);
        DocumentBuilder db = dbf.newDocumentBuilder();

        sldXmlDoc = db.parse(new ByteArrayInputStream(sld.getSldBody().getBytes("UTF-8")));

        stage = "Fout bij controleren SLD";

        Element root = sldXmlDoc.getDocumentElement();
        if (!"StyledLayerDescriptor".equals(root.getLocalName())) {
            throw new Exception("Root element moet StyledLayerDescriptor zijn");
        }
        String version = root.getAttribute("version");
        if (version == null || !("1.0.0".equals(version) || "1.1.0".equals(version))) {
            throw new Exception("Geen of ongeldige SLD versie!");
        }

        SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
        Schema s = sf
                .newSchema(new URL("http://schemas.opengis.net/sld/" + version + "/StyledLayerDescriptor.xsd"));
        s.newValidator().validate(new DOMSource(sldXmlDoc));

    } catch (Exception e) {
        String extra = "";
        if (e instanceof SAXParseException) {
            SAXParseException spe = (SAXParseException) e;
            if (spe.getLineNumber() != -1) {
                extra = " (regel " + spe.getLineNumber();
                if (spe.getColumnNumber() != -1) {
                    extra += ", kolom " + spe.getColumnNumber();
                }
                extra += ")";
            }
        }
        getContext().getValidationErrors()
                .addGlobalError(new SimpleError("{2}: {3}{4}", stage, ExceptionUtils.getMessage(e), extra));
        return jsp;
    }

    getContext().getMessages().add(new SimpleMessage("SLD is valide!"));

    return jsp;
}

From source file:nl.opengeogroep.filesetsync.client.FilesetSyncer.java

public void sync() {
    if (localCanonicalPath == null) {
        state.endRun(STATE_ERROR);//from   ww w  .  j  ava 2 s  .c o m
        return;
    }

    log.info(String.format("Starting sync for job \"%s\", last started %s and finished %s", fs.getName(),
            state.getLastRun() == null ? "never" : "at " + dateToString(state.getLastRun()),
            state.getLastFinished() == null ? "never" : "at " + dateToString(state.getLastFinished())));
    log.trace(fs);

    PluginContext.getInstance().beforeStart(fs, state);
    state.startNewRun();

    serverUrl = fs.getServer();
    if (!serverUrl.endsWith("/")) {
        serverUrl += "/";
    }
    serverUrl += "fileset/";

    try {
        retrieveFilesetList();
        if (fs.isDelete()) {
            deleteLocalFiles();
        }
        compareFilesetList();
        transferFiles();
        setDirectoriesLastModified();

        log.info("Sync job complete");
        state.endRun(STATE_COMPLETED);

        String exitCodeAfterUpdate = fs.getProperty("exitCodeAfterUpdate");
        if (exitCodeAfterUpdate != null && filesUpdated) {
            int code = Integer.parseInt(exitCodeAfterUpdate);
            log.info("Files were updated, exiting with exit code " + code);
            SyncJobStatePersistence.persist();
            System.exit(code);
        }
    } catch (IOException e) {
        state.setFailedTries(state.getFailedTries() + 1);

        log.error("Exception during sync job: " + ExceptionUtils.getMessage(e));
        log.trace("Full stack trace", e);
        if (state.getFailedTries() >= fs.getMaxTries()) {
            log.error("Retryable IOException but max tries reached after " + state.getFailedTries()
                    + " times, fatal error");
            state.endRun(STATE_ERROR);
        } else {
            log.error(String.format("IO exception, retrying later after %d seconds (try %d of max %d)",
                    fs.getRetryWaitTime(), state.getFailedTries(), fs.getMaxTries()));
            state.endRun(STATE_RETRY);
        }
    } finally {
        SyncJobStatePersistence.setCurrentFileset(null);
    }
}