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.ibm.amc.resources.data.ExceptionResponse.java

public ExceptionResponse(final Throwable exception) {
    super();/* w w w .j  a  v a  2  s  .c o m*/
    // TODO the locale should be taken from user preferences
    final Locale locale = Locale.getDefault();
    if (exception instanceof LocalizedException) {
        final LocalizedException localizedException = (LocalizedException) exception;
        code = localizedException.getMessageCode();
        message = localizedException.getMessage(locale);
        userAction = localizedException.getUserAction(locale);
        explanation = localizedException.getExplanation(locale);
        timeStamp = localizedException.getTimeStamp();
    } else if (exception instanceof DMgrException) {
        final DMgrException dmgrException = (DMgrException) exception;
        message = dmgrException.getMessage(locale);
        if (message != null && message.startsWith(Configuration.DEFAULT_MESSAGE_PREFIX)) {
            // Extract message code
            code = message.substring(0, Configuration.DEFAULT_MESSAGE_PREFIX.length() + 5);
            message = message.substring(Configuration.DEFAULT_MESSAGE_PREFIX.length() + 7);
        }
        userAction = dmgrException.getMessageUseraction(locale);
        explanation = dmgrException.getMessageExplanation(locale);
    } else {
        final StringBuffer buffer = new StringBuffer();
        buffer.append(exception.getClass().getCanonicalName());
        if (exception.getLocalizedMessage() != null) {
            buffer.append(": ");
            buffer.append(exception.getLocalizedMessage());
        }
        message = buffer.toString();
    }

    if (exception.getCause() != null) {
        cause = new ExceptionResponse(exception.getCause());
    }
}

From source file:org.eclipse.paho.android.service.MqttConnection.java

/**
 * Connect to the server specified when we were instantiated
 *
 * @param options//from  w w  w .  ja  va2  s.c  o  m
 *            timeout, etc
 * @param invocationContext
 *            arbitrary data to be passed back to the application
 * @param activityToken
 *            arbitrary identifier to be passed back to the Activity
 */
public void connect(MqttConnectOptions options, String invocationContext, String activityToken) {
    Log.v("mqtt", "MqttConnection connect trace 1");
    connectOptions = options;
    reconnectActivityToken = activityToken;

    if (options != null) {
        cleanSession = options.isCleanSession();
        Log.v("mqtt", "MqttConnection connect trace 2");
    }

    if (connectOptions.isCleanSession()) { // if it's a clean session,
        // discard old data
        service.messageStore.clearArrivedMessages(clientHandle);
        Log.v("mqtt", "MqttConnection connect trace 3");
    }
    Log.v("mqtt", "MqttConnection connect trace 4");
    service.traceDebug(TAG, "Connecting {" + serverURI + "} as {" + clientId + "}");
    final Bundle resultBundle = new Bundle();
    resultBundle.putString(MqttServiceConstants.CALLBACK_ACTIVITY_TOKEN, activityToken);
    resultBundle.putString(MqttServiceConstants.CALLBACK_INVOCATION_CONTEXT, invocationContext);
    resultBundle.putString(MqttServiceConstants.CALLBACK_ACTION, MqttServiceConstants.CONNECT_ACTION);

    try {
        if (persistence == null) {
            Log.v("mqtt", "MqttConnection connect trace 5");
            // ask Android where we can put files
            File myDir = service.getExternalFilesDir(TAG);
            // Log.v("mqtt", "MqttConnection connect trace 5a "+myDir.getAbsolutePath());

            /*File myDir = new File(Environment.getExternalStorageDirectory() + "/MqttConnection");
            Log.v("mqtt","MqttConnection myDir.getAbsolutePath(): "+myDir.getAbsolutePath());
            boolean success = true;
            if (!myDir.exists()) {
            success = myDir.mkdir();
            }
            if (success) {
            // Do something on success
            } else {
            // Do something else on failure
            }*/

            if (myDir == null) {
                // No external storage, use internal storage instead.
                myDir = service.getDir(TAG, Context.MODE_PRIVATE);
                Log.v("mqtt", "MqttConnection connect trace 6");
                if (myDir == null) {
                    //Shouldn't happen.
                    Log.v("mqtt", "MqttConnection connect trace 7");
                    resultBundle.putString(MqttServiceConstants.CALLBACK_ERROR_MESSAGE,
                            "Error! No external and internal storage available");
                    resultBundle.putSerializable(MqttServiceConstants.CALLBACK_EXCEPTION,
                            new MqttPersistenceException());
                    service.callbackToActivity(clientHandle, Status.ERROR, resultBundle);
                    return;
                }
            }
            Log.v("mqtt", "MqttConnection connect trace 8");
            // use that to setup MQTT client persistence storage
            persistence = new MqttDefaultFilePersistence(myDir.getAbsolutePath());
        }

        IMqttActionListener listener = new MqttConnectionListener(resultBundle) {

            @Override
            public void onSuccess(IMqttToken asyncActionToken) {
                Log.v("mqtt", "MqttConnection connect trace 9 onSuccess");
                doAfterConnectSuccess(resultBundle);
                service.traceDebug(TAG, "connect success!");
            }

            @Override
            public void onFailure(IMqttToken asyncActionToken, Throwable exception) {
                Log.v("mqtt", "MqttConnection connect trace 9 onFailure");
                resultBundle.putString(MqttServiceConstants.CALLBACK_ERROR_MESSAGE,
                        exception.getLocalizedMessage());
                resultBundle.putSerializable(MqttServiceConstants.CALLBACK_EXCEPTION, exception);
                service.traceError(TAG,
                        "connect fail, call connect to reconnect.reason:" + exception.getMessage());

                doAfterConnectFail(resultBundle);

            }
        };
        Log.v("mqtt", "MqttConnection connect trace 10");
        if (myClient != null) {
            Log.v("mqtt", "MqttConnection connect trace 11");
            if (isConnecting) {
                Log.v("mqtt", "MqttConnection connect trace 12");
                service.traceDebug(TAG,
                        "myClient != null and the client is connecting. Connect return directly.");
                service.traceDebug(TAG,
                        "Connect return:isConnecting:" + isConnecting + ".disconnected:" + disconnected);
                return;
            } else if (!disconnected) {
                Log.v("mqtt", "MqttConnection connect trace 13");
                service.traceDebug(TAG, "myClient != null and the client is connected and notify!");
                doAfterConnectSuccess(resultBundle);
            } else {
                Log.v("mqtt", "MqttConnection connect trace 14");
                service.traceDebug(TAG, "myClient != null and the client is not connected");
                service.traceDebug(TAG, "Do Real connect!");
                setConnectingState(true);
                myClient.connect(connectOptions, invocationContext, listener);
            }
        }

        // if myClient is null, then create a new connection
        else {
            Log.v("mqtt", "MqttConnection connect trace 15");
            myClient = new MqttAsyncClient(serverURI, clientId, persistence, new AlarmPingSender(service));
            myClient.setCallback(this);

            service.traceDebug(TAG, "Do Real connect!");
            setConnectingState(true);
            myClient.connect(connectOptions, invocationContext, listener);
        }
    } catch (Exception e) {
        handleException(resultBundle, e);
    }
}

From source file:com.esri.squadleader.view.SquadLeaderActivity.java

private void actOnPopup(View viewForMessages, PopupAction popupAction) {
    String errorMessage = null;//from w ww .  ja v a2 s.co  m
    Throwable errorThrowable = null;
    if (null != popupContainer) {
        final Popup popup = popupContainer.getCurrentPopup();
        final PopupInfo popupInfo = popup.getPopupInfo();
        if (popupInfo instanceof FeatureTablePopupInfo) {
            FeatureTablePopupInfo ftPopupInfo = (FeatureTablePopupInfo) popupInfo;
            final FeatureTable table = ftPopupInfo.getTable();
            if (null != table) {
                try {
                    popupAction.takeAction(popup, table);
                } catch (Throwable t) {
                    errorMessage = String.format(popupAction.getActionErrorMessageTemplate(),
                            t.getLocalizedMessage());
                    errorThrowable = t;
                }
            } else {
                errorMessage = getString(R.string.popup_feature_table_null);
            }
        } else {
            errorMessage = getString(R.string.popup_without_feature_table, popupInfo.getClass().getSimpleName(),
                    FeatureTablePopupInfo.class.getSimpleName());
        }
        popup.setEditMode(false);
    } else {
        errorMessage = getString(R.string.popup_container_null);
    }
    if (null != errorMessage) {
        Snackbar.make(viewForMessages, errorMessage, Snackbar.LENGTH_LONG).show();
        if (null == errorThrowable) {
            Log.e(TAG, errorMessage);
        } else {
            Log.e(TAG, errorMessage, errorThrowable);
        }
    }
}

From source file:com.seleniumtests.reporter.SeleniumTestsReporter.java

protected void generateTheStackTrace(final Throwable exception, final ITestNGMethod method, final String title,
        final StringBuffer contentBuffer, final String lastline) {
    contentBuffer.append(" <div class='stContainer' >" + exception.getClass() + ":" + escape(title)
            + "(<a  href='javascript:void(0);'  class='exceptionlnk'>stacktrace</a>)");

    contentBuffer.append("<div class='exception' style='display:none'>");

    final StackTraceElement[] s1 = exception.getStackTrace();
    Throwable t2 = exception.getCause();
    if (t2 == exception) {
        t2 = null;//from ww w  .  java 2  s .c om
    }

    for (int x = 0; x < s1.length; x++) {
        contentBuffer.append((x > 0 ? "<br/>at " : "") + escape(s1[x].toString()));
    }

    if (t2 != null) {
        generateExceptionReport(t2, method, "Caused by " + t2.getLocalizedMessage(), contentBuffer, ""); // jerry
    }

    contentBuffer.append("</div></div>");
}

From source file:org.geotools.gce.imagemosaic.catalogbuilder.CatalogBuilder.java

private void closeIndexObjects() {
    try {/*www  . j ava 2 s .c o m*/
        if (catalog != null) {
            catalog.dispose();
        }
    } catch (Throwable e) {
        LOGGER.log(Level.SEVERE, e.getLocalizedMessage(), e);
    }

    catalog = null;
}

From source file:com.nextgis.ngm_clink_monitoring.fragments.CreateObjectFragment.java

protected void createObject() {
    String fieldName = null;/*  w  w w.  j  av  a 2 s . c  om*/

    switch (mFoclStructLayerType) {
    case FoclConstants.LAYERTYPE_FOCL_REAL_OPTICAL_CABLE_POINT:
        if (null == mLayingMethod.getValue()) {
            fieldName = getActivity().getString(R.string.laying_method);
        }
        break;

    case FoclConstants.LAYERTYPE_FOCL_REAL_FOSC:
        //                if (null == mFoscType.getValue()) {
        //                    fieldName = getActivity().getString(R.string.fosc_type);
        //                    break;
        //                }
        if (null == mFoscPlacement.getValue()) {
            fieldName = getActivity().getString(R.string.fosc_placement);
        }
        break;

    case FoclConstants.LAYERTYPE_FOCL_REAL_OPTICAL_CROSS:
        //                if (null == mOpticalCrossType.getValue()) {
        //                    fieldName = getActivity().getString(R.string.optical_cross_type);
        //                }
        break;

    case FoclConstants.LAYERTYPE_FOCL_REAL_ACCESS_POINT:
        break;

    case FoclConstants.LAYERTYPE_FOCL_REAL_SPECIAL_TRANSITION_POINT:
        if (null == mSpecialLayingMethod.getValue()) {
            fieldName = getActivity().getString(R.string.special_laying_method);
            break;
        }
        if (null == mMarkType.getValue()) {
            fieldName = getActivity().getString(R.string.mark_type);
        }
        break;
    }

    if (null != fieldName) {
        YesNoDialog dialog = new YesNoDialog();
        dialog.setKeepInstance(true).setIcon(R.drawable.ic_action_warning).setTitle(R.string.warning)
                .setMessage(String.format(getString(R.string.empty_field_warning), fieldName))
                .setPositiveText(R.string.ok)
                .setOnPositiveClickedListener(new YesNoDialog.OnPositiveClickedListener() {
                    @Override
                    public void onPositiveClicked() {
                        // cancel
                    }
                }).show(getActivity().getSupportFragmentManager(),
                        FoclConstants.FRAGMENT_YES_NO_DIALOG + "FieldsNotNull");
        return; // we do not need logcat here
    }

    if (!mNewStartPoint && 0 < mObjectCount
            && FoclConstants.LAYERTYPE_FOCL_REAL_OPTICAL_CABLE_POINT == mFoclStructLayerType
            && null != mDistance && FoclConstants.MAX_DISTANCE_FROM_PREV_POINT < mDistance) {

        showDistanceExceededDialog();
        return; // we do not need logcat here
    }

    if (null == mObjectPhotoFileAdapter || mObjectPhotoFileAdapter.getItemCount() == 0) {
        YesNoDialog dialog = new YesNoDialog();
        dialog.setKeepInstance(true).setIcon(R.drawable.ic_action_warning).setTitle(R.string.warning)
                .setMessage(getString(R.string.take_photos_to_confirm)).setPositiveText(R.string.ok)
                .setOnPositiveClickedListener(new YesNoDialog.OnPositiveClickedListener() {
                    @Override
                    public void onPositiveClicked() {
                        // cancel
                    }
                }).show(getActivity().getSupportFragmentManager(),
                        FoclConstants.FRAGMENT_YES_NO_DIALOG + "TakePhotos");
        return; // we do not need logcat here
    }

    LayoutInflater inflater = LayoutInflater.from(getActivity());
    View view = inflater.inflate(R.layout.dialog_waiting, null);

    final YesNoDialog waitProgressDialog = new YesNoDialog();
    waitProgressDialog.setKeepInstance(true).setIcon(R.drawable.ic_action_data_usage).setTitle(R.string.waiting)
            .setView(view, true);

    waitProgressDialog.setCancelable(false);
    waitProgressDialog.show(getActivity().getSupportFragmentManager(),
            FoclConstants.FRAGMENT_YES_NO_DIALOG + "WaitProgress");

    final Handler handler = new Handler() {
        public void handleMessage(Message msg) {
            switch (msg.what) {
            case CREATE_OBJECT_DONE:
                waitProgressDialog.dismiss();
                break;
            case CREATE_OBJECT_OK:
                getActivity().getSupportFragmentManager().popBackStack();
                break;
            case CREATE_OBJECT_FAILED:
                Toast.makeText(getActivity(), (String) msg.obj, Toast.LENGTH_LONG).show();
                waitProgressDialog.dismiss();
                break;
            }
        }
    };

    RunnableFuture<Void> future = new FutureTask<Void>(new Callable<Void>() {
        @Override
        public Void call() throws Exception {
            createObjectTask();
            return null;
        }
    }) {
        @Override
        protected void done() {
            super.done();
            handler.sendEmptyMessage(CREATE_OBJECT_DONE);
        }

        @Override
        protected void set(Void aVoid) {
            super.set(aVoid);
            handler.sendEmptyMessage(CREATE_OBJECT_OK);
        }

        @Override
        protected void setException(Throwable t) {
            super.setException(t);
            Message msg = handler.obtainMessage(CREATE_OBJECT_FAILED, t.getLocalizedMessage());
            msg.sendToTarget();
        }
    };

    new Thread(future).start();
}

From source file:org.sakaiproject.lessonbuildertool.model.SimplePageToolDaoImpl.java

public void getCause(Throwable t, List<String> elist) {
    while (t.getCause() != null) {
        t = t.getCause();/*from   w w w.  j  ava2  s.co m*/
    }
    log.warn("error saving or updating: " + t.toString());
    elist.add(t.getLocalizedMessage());
}

From source file:com.aol.framework.helper.report.CustomizedReporter.java

protected void generateExceptionReport(Throwable exception, ITestNGMethod method, PrintWriter pw) {
    pw.flush();//from  w ww  .ja va  2s  .  c  om
    generateExceptionReport(exception, method, exception.getLocalizedMessage(), pw);
}

From source file:at.gv.egovernment.moa.id.protocols.pvp2x.PVP2XProtocol.java

public boolean generateErrorMessage(Throwable e, HttpServletRequest request, HttpServletResponse response,
        IRequest protocolRequest) throws Throwable {

    if (protocolRequest == null) {
        throw e;/*from ww w .ja  v  a2s . com*/
    }

    if (!(protocolRequest instanceof PVPTargetConfiguration)) {
        throw e;
    }
    PVPTargetConfiguration pvpRequest = (PVPTargetConfiguration) protocolRequest;

    Response samlResponse = SAML2Utils.createSAMLObject(Response.class);
    Status status = SAML2Utils.createSAMLObject(Status.class);
    StatusCode statusCode = SAML2Utils.createSAMLObject(StatusCode.class);
    StatusMessage statusMessage = SAML2Utils.createSAMLObject(StatusMessage.class);

    ErrorResponseUtils errorUtils = ErrorResponseUtils.getInstance();
    String moaError = null;

    if (e instanceof NoPassivAuthenticationException) {
        statusCode.setValue(StatusCode.NO_PASSIVE_URI);
        statusMessage.setMessage(StringEscapeUtils.escapeXml(e.getLocalizedMessage()));

    } else if (e instanceof NameIDFormatNotSupportedException) {
        statusCode.setValue(StatusCode.INVALID_NAMEID_POLICY_URI);
        statusMessage.setMessage(StringEscapeUtils.escapeXml(e.getLocalizedMessage()));

    } else if (e instanceof SLOException) {
        //SLOExecpetions only occurs if session information is lost
        return false;

    } else if (e instanceof PVP2Exception) {
        PVP2Exception ex = (PVP2Exception) e;
        statusCode.setValue(ex.getStatusCodeValue());
        String statusMessageValue = ex.getStatusMessageValue();
        if (statusMessageValue != null) {
            statusMessage.setMessage(StringEscapeUtils.escapeXml(statusMessageValue));
        }
        moaError = errorUtils.mapInternalErrorToExternalError(ex.getMessageId());

    } else {
        statusCode.setValue(StatusCode.RESPONDER_URI);
        statusMessage.setMessage(StringEscapeUtils.escapeXml(e.getLocalizedMessage()));
        moaError = errorUtils.getResponseErrorCode(e);
    }

    if (MiscUtil.isNotEmpty(moaError)) {
        StatusCode moaStatusCode = SAML2Utils.createSAMLObject(StatusCode.class);
        moaStatusCode.setValue(moaError);
        statusCode.setStatusCode(moaStatusCode);
    }

    status.setStatusCode(statusCode);
    if (statusMessage.getMessage() != null) {
        status.setStatusMessage(statusMessage);
    }
    samlResponse.setStatus(status);
    String remoteSessionID = SAML2Utils.getSecureIdentifier();
    samlResponse.setID(remoteSessionID);

    samlResponse.setIssueInstant(new DateTime());
    Issuer nissuer = SAML2Utils.createSAMLObject(Issuer.class);
    nissuer.setValue(PVPConfiguration.getInstance().getIDPPublicPath());
    nissuer.setFormat(NameID.ENTITY);
    samlResponse.setIssuer(nissuer);

    IEncoder encoder = null;

    if (pvpRequest.getBinding().equals(SAMLConstants.SAML2_REDIRECT_BINDING_URI)) {
        encoder = new RedirectBinding();

    } else if (pvpRequest.getBinding().equals(SAMLConstants.SAML2_ARTIFACT_BINDING_URI)) {
        // TODO: not supported YET!!
        //binding = new ArtifactBinding();

    } else if (pvpRequest.getBinding().equals(SAMLConstants.SAML2_POST_BINDING_URI)) {
        encoder = new PostBinding();

    } else if (pvpRequest.getBinding().equals(SAMLConstants.SAML2_SOAP11_BINDING_URI)) {
        encoder = new SoapBinding();
    }

    if (encoder == null) {
        // default to redirect binding
        encoder = new RedirectBinding();
    }

    String relayState = null;
    if (pvpRequest.getRequest() != null)
        relayState = pvpRequest.getRequest().getRelayState();

    encoder.encodeRespone(request, response, samlResponse, pvpRequest.getConsumerURL(), relayState);
    return true;
}

From source file:org.opencms.ade.contenteditor.CmsContentService.java

/**
 * Decodes the newlink request parameter if possible.<p>
 *
 * @param newLink the parameter to decode
 *
 * @return the decoded value/*from   w  w w.  j a  va  2 s.  com*/
 */
protected String decodeNewLink(String newLink) {

    String result = newLink;
    if (result == null) {
        return null;
    }
    try {
        result = CmsEncoder.decode(result);
        try {
            result = CmsEncoder.decode(result);
        } catch (Throwable e) {
            LOG.info(e.getLocalizedMessage(), e);
        }
    } catch (Throwable e) {
        LOG.info(e.getLocalizedMessage(), e);
    }

    return result;
}