Example usage for java.lang Throwable getLocalizedMessage

List of usage examples for java.lang Throwable getLocalizedMessage

Introduction

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

Prototype

public String getLocalizedMessage() 

Source Link

Document

Creates a localized description of this throwable.

Usage

From source file:com.buddycloud.mediaserver.web.ChannelResource.java

@Post("application/x-www-form-urlencoded|multipart/form-data")
public Representation postWebFormMedia(Representation entity) {
    setServerHeader();/*from ww w .j  ava 2 s . co  m*/

    Request request = getRequest();
    //      The HTTP API sets the headers 
    //      addCORSHeaders(request);

    String auth = getQueryValue(Constants.AUTH_QUERY);

    String userId = null;
    String token = null;

    try {
        userId = getUserId(request, auth);
        token = getTransactionId(request, auth);
    } catch (Throwable t) {
        setStatus(Status.CLIENT_ERROR_BAD_REQUEST);
        return new StringRepresentation(t.getLocalizedMessage(), MediaType.APPLICATION_JSON);
    }

    Representation checkRequest = checkRequest(userId, token, request.getResourceRef().getIdentifier());
    if (checkRequest != null) {
        return checkRequest;
    }

    MediaDAO mediaDAO = DAOFactory.getInstance().getDAO();

    String entityId = (String) request.getAttributes().get(Constants.ENTITY_ARG);

    String result = "";
    try {
        if (MediaType.MULTIPART_FORM_DATA.equals(entity.getMediaType(), true)) {
            result = mediaDAO.insertFormDataMedia(userId, entityId, getRequest(), false);
        } else {
            result = mediaDAO.insertWebFormMedia(userId, entityId, new Form(entity), false);
        }

        setStatus(Status.SUCCESS_CREATED);
    } catch (FileUploadException e) {
        setStatus(Status.CLIENT_ERROR_BAD_REQUEST);
    } catch (UserNotAllowedException e) {
        setStatus(Status.CLIENT_ERROR_FORBIDDEN);
    } catch (Throwable t) {
        return unexpectedError(t);
    }

    return new StringRepresentation(result, MediaType.APPLICATION_JSON);
}

From source file:org.opennms.netmgt.provision.DnsProvisioningAdapter.java

private void sendAndThrow(int nodeId, Throwable e) {
    String message = e.getLocalizedMessage() == null ? "" : ": " + e.getLocalizedMessage();
    Event event = buildEvent(EventConstants.PROVISIONING_ADAPTER_FAILED, nodeId)
            .addParam("reason", MESSAGE_PREFIX + e.getClass().getName() + message).getEvent();
    m_eventForwarder.sendNow(event);//from   ww w  .  j a v  a 2s  . c  o  m
    throw new ProvisioningAdapterException(MESSAGE_PREFIX, e);
}

From source file:com.codesourcery.installer.Installer.java

/**
 * Logs an exception./*  w  w w.  j  av a2s.c  o  m*/
 * 
 * @param e Exception
 */
public static void log(Throwable failure) {
    IStatus status;
    Throwable cause = failure;
    //unwrap target exception if applicable
    if (failure instanceof InvocationTargetException) {
        cause = ((InvocationTargetException) failure).getTargetException();
        if (cause == null)
            cause = failure;
    }
    if (cause instanceof CoreException) {
        status = ((CoreException) cause).getStatus();
    } else {
        status = new Status(IStatus.ERROR, ID, failure.getLocalizedMessage(), cause);
    }

    LogHelper.log(status);
    Log.getDefault().log(status);
}

From source file:org.apache.cayenne.tools.DbGeneratorTask.java

@Override
public void execute() {

    Log logger = new AntLogger(this);

    log(String.format("connection settings - [driver: %s, url: %s, username: %s]", driver, url, userName),
            Project.MSG_VERBOSE);/*from  w  ww .  ja v a  2s . c o  m*/

    log(String.format(
            "generator options - [dropTables: %s, dropPK: %s, createTables: %s, createPK: %s, createFK: %s]",
            dropTables, dropPK, createTables, createPK, createFK), Project.MSG_VERBOSE);

    validateAttributes();

    ClassLoader loader = null;
    Injector injector = DIBootstrap.createInjector(new DbSyncModule(), new ToolsModule(logger));
    try {
        loader = Thread.currentThread().getContextClassLoader();
        Thread.currentThread().setContextClassLoader(DbGeneratorTask.class.getClassLoader());

        // Load the data map and run the db generator.
        DataMap dataMap = loadDataMap();

        // load driver taking custom CLASSPATH into account...
        DriverDataSource dataSource = new DriverDataSource((Driver) Class.forName(driver).newInstance(), url,
                userName, password);

        DbAdapter adapter = getAdapter(injector, dataSource);

        DbGenerator generator = new DbGenerator(adapter, dataMap, Collections.<DbEntity>emptyList(), null,
                NoopJdbcEventLogger.getInstance());
        generator.setShouldCreateFKConstraints(createFK);
        generator.setShouldCreatePKSupport(createPK);
        generator.setShouldCreateTables(createTables);
        generator.setShouldDropPKSupport(dropPK);
        generator.setShouldDropTables(dropTables);

        generator.runGenerator(dataSource);
    } catch (Exception ex) {
        Throwable th = Util.unwindException(ex);

        String message = "Error generating database";

        if (th.getLocalizedMessage() != null) {
            message += ": " + th.getLocalizedMessage();
        }

        log(message, Project.MSG_ERR);
        throw new BuildException(message, th);
    } finally {
        Thread.currentThread().setContextClassLoader(loader);
        injector.shutdown();
    }
}

From source file:com.kii.sample.hellothingif.LoginFragment.java

@OnClick(R.id.buttonAddUser)
void onAddUserClicked() {
    String username = mUsername.getText().toString();
    String userPassword = mUserPassword.getText().toString();

    ProgressDialogFragment.show(getActivity(), getFragmentManager(), R.string.progress_add_user);

    PromiseAPIWrapper api = new PromiseAPIWrapper(mAdm, null);
    mAdm.when(api.addUser(username, userPassword)).then(new DoneCallback<KiiUser>() {
        @Override/*from   w  ww . j ava2 s.  c o m*/
        public void onDone(KiiUser user) {
            ProgressDialogFragment.close(getFragmentManager());
            showToast("The user has been added.");
        }
    }).fail(new FailCallback<Throwable>() {
        @Override
        public void onFail(final Throwable tr) {
            ProgressDialogFragment.close(getFragmentManager());
            showToast("Failed to add the user: " + tr.getLocalizedMessage());
        }
    });
}

From source file:com.netthreads.traffic.view.TrafficDataMapFragment.java

/**
 * Process data using defined visitor.//from   ww  w  .  jav a 2 s. c o m
 *
 * @param region
 * @param visitor
 */
private void visitData(String region, CursorVisitor visitor) {
    Cursor cursor = null;
    int itemCount = 0;

    Context context = getActivity();

    try {
        SELECT_REGIONS[0] = region;
        cursor = getActivity().getContentResolver().query(TrafficDataRecordProvider.CONTENT_URI,
                TrafficDataListFragment.PROJECTION, WHERE_REGION, SELECT_REGIONS, null);

        itemCount = cursor.getCount();

        if (itemCount > 0) {
            cursor.moveToFirst();

            while (!cursor.isAfterLast()) {
                visitor.visit(context, cursor);

                cursor.moveToNext();
            }
        }

    } catch (Throwable t) {
        Log.e("visitData", t.getLocalizedMessage());
    } finally {
        if (cursor != null && (itemCount > 0)) {
            cursor.close();
        }
    }
}

From source file:org.gitools.ui.platform.dialog.ExceptionGlassPane.java

private String getFriendlyMessage(Throwable cause) {
    String message = cause.getLocalizedMessage() == null ? "<empty error message>"
            : cause.getLocalizedMessage();
    if (message.contains("heap space")) {
        message = message + ": Not enough memory for this operation.";
    }/*from  w  ww.  j  a  v a2  s. co  m*/
    return message;
}

From source file:org.rhq.enterprise.gui.common.error.GenericErrorUIBean.java

public GenericErrorUIBean() {
    FacesContext facesContext = FacesContext.getCurrentInstance();
    ExternalContext externalContext = facesContext.getExternalContext();
    Map<String, Object> sessionMap = externalContext.getSessionMap();

    trace = new ArrayList<Tuple<String, String>>();
    Throwable ex = (Exception) sessionMap.remove("GLOBAL_RENDER_ERROR");

    // let's put this in the server log along with showing the user
    log.error("Error processing user request", ex);

    String message = ex.getLocalizedMessage();
    String stack = StringUtil.getFirstStackTrace(ex);
    trace.add(new Tuple<String, String>(message, stack));

    while (ex.getCause() != null) {
        ex = ex.getCause();//  w  w  w .  ja  va  2s  .  com

        message = ex.getLocalizedMessage();
        stack = StringUtil.getFirstStackTrace(ex);
        trace.add(new Tuple<String, String>(message, stack));
    }

    summary = ex.getClass().getSimpleName();
    details = ex.getMessage();
}

From source file:com.anrisoftware.mongoose.environment.EnvironmentImplLogger.java

CommandException commandError(Throwable e, Command command) {
    return logException(new CommandException(COMMAND_ERROR, e).add(COMMAND, command), COMMAND_ERROR_MESSAGE,
            command.getTheName(), e.getLocalizedMessage());
}

From source file:com.rapidminer.cryptography.hashing.DigesterProvider.java

/**
 * Converts an {@link Object} to a byte[]. The value has to be an instance
 * of String, Integer, Long, Float, Date or Double.
 * /* w w w. ja  va2  s.  c  o m*/
 * @throws JEPFunctionException
 *             in case the object class is unknown.
 */
private byte[] getBytes(Object value) throws JEPFunctionException {
    try (ByteArrayOutputStream baos = new ByteArrayOutputStream();
            DataOutputStream dos = new DataOutputStream(baos);) {
        writeBytes(value, dos);
        return baos.toByteArray();
    } catch (Throwable t) {
        throw new JEPFunctionException("Error calculating hash value: " + t.getLocalizedMessage());
    }
}