List of usage examples for java.lang Throwable getLocalizedMessage
public String getLocalizedMessage()
From source file:cn.sinobest.jzpt.framework.utils.string.StringUtils.java
/** * StringBuilder/*from w ww . j a va 2s. c o m*/ * * @param e * @param sb */ public static void exceptionSummary(Throwable e, StringBuilder sb) { String msg = e.getLocalizedMessage(); StackTraceElement[] stacks = e.getStackTrace(); if (msg == null && e.getCause() != null) { exceptionSummary(e.getCause(), sb); } String stack = stacks.length > 0 ? stacks[0].toString() : ""; sb.append(e.getClass().getSimpleName()).append(':').append(msg).append('\n').append(stack); }
From source file:com.ebay.jetstream.messaging.transport.zookeeper.ZooKeeperTransport.java
/** * Post notifications on to transport listeners * /*from w w w . java 2s . co m*/ * @param path */ private void publishData(String path, byte[] data) { try { if (data != null && data.length > 0) { ByteArrayInputStream bii = new ByteArrayInputStream(data); ObjectInputStream ois = new ObjectInputStream(bii); Object dataObj = ois.readObject(); ZooKeeperDataWrapper wrapper = (ZooKeeperDataWrapper) (dataObj); JetstreamMessage tm = (JetstreamMessage) wrapper.getOrginalData(); String trackerKey = createKey(path, wrapper); m_changeTracker.put(trackerKey, wrapper.getTimestamp()); try { LOGGER.warn("Publishing the change for topic :" + path + " TrackerKey :" + trackerKey + " Timestamp : " + wrapper.getTimestamp()); m_transportListener.postMessage(tm, m_queueStats); } catch (Throwable mse) { // don't want to kill zk thread., so catching Throwable StringBuffer buf = new StringBuffer(); buf.append("Error dispatching to message service - "); buf.append(mse.getLocalizedMessage()); LOGGER.error("Exception publishing data for path :" + path + buf.toString(), mse); } m_totalMsgsRcvd.increment(); m_msgsRcvdPerSec.increment(); } } catch (ClassNotFoundException e) { LOGGER.error(" ClassNotFoundException while publishing data to transport Listener :" + path, e); } catch (IOException e) { LOGGER.error(" IOException while publishing data to transport Listener :" + path, e); } }
From source file:org.eclipse.paho.android.service.MqttConnection.java
/** * Reconnect<br>//w w w . ja v a 2 s . c o m * Only appropriate if cleanSession is false and we were connected. * Declare as synchronized to avoid multiple calls to this method to send connect * multiple times */ synchronized void reconnect() { Log.v("mqtt", "MqttConnection reconnect()"); if (isConnecting) { Log.v("mqtt", "MqttConnection reconnect() The client is connecting. Reconnect return directly."); service.traceDebug(TAG, "The client is connecting. Reconnect return directly."); return; } if (!service.isOnline()) { Log.v("mqtt", "The network is not reachable. Will not do reconnect"); service.traceDebug(TAG, "The network is not reachable. Will not do reconnect"); return; } if (disconnected && !cleanSession) { Log.v("mqtt", "Do Real Reconnect!"); // use the activityToke the same with action connect service.traceDebug(TAG, "Do Real Reconnect!"); final Bundle resultBundle = new Bundle(); resultBundle.putString(MqttServiceConstants.CALLBACK_ACTIVITY_TOKEN, reconnectActivityToken); resultBundle.putString(MqttServiceConstants.CALLBACK_INVOCATION_CONTEXT, null); resultBundle.putString(MqttServiceConstants.CALLBACK_ACTION, MqttServiceConstants.CONNECT_ACTION); try { IMqttActionListener listener = new MqttConnectionListener(resultBundle) { @Override public void onSuccess(IMqttToken asyncActionToken) { // since the device's cpu can go to sleep, acquire a // wakelock and drop it later. service.traceDebug(TAG, "Reconnect Success!"); service.traceDebug(TAG, "DeliverBacklog when reconnect."); doAfterConnectSuccess(resultBundle); } @Override public void onFailure(IMqttToken asyncActionToken, Throwable exception) { resultBundle.putString(MqttServiceConstants.CALLBACK_ERROR_MESSAGE, exception.getLocalizedMessage()); resultBundle.putSerializable(MqttServiceConstants.CALLBACK_EXCEPTION, exception); service.callbackToActivity(clientHandle, Status.ERROR, resultBundle); doAfterConnectFail(resultBundle); } }; myClient.connect(connectOptions, null, listener); setConnectingState(true); } catch (MqttException e) { service.traceError(TAG, "Cannot reconnect to remote server." + e.getMessage()); setConnectingState(false); handleException(resultBundle, e); } } }
From source file:org.acmsl.commons.BundleI14able.java
/** * Seventh attempt to retrieve the bundle. * @param bundleName the bundle name.//from w w w. j a va 2s .co m * @return the bundle. * @throws MissingResourceException if the resource is missing. */ @Nullable protected final ResourceBundle seventhTry(@NotNull final String bundleName) throws MissingResourceException { @Nullable ResourceBundle result = null; Throwable exceptionThrown = null; MissingResourceException exceptionToThrow = null; try { // last attempt. result = new PropertyResourceBundle(new FileInputStream(bundleName)); } catch (final FileNotFoundException thirdFileNotFoundException) { exceptionThrown = thirdFileNotFoundException; } catch (final IOException thirdIOException) { exceptionThrown = thirdIOException; } finally { if (exceptionThrown != null) { exceptionToThrow = new MissingResourceException(exceptionThrown.getLocalizedMessage(), exceptionThrown.getClass().getName(), "(none)"); } } if (exceptionToThrow != null) { throw exceptionToThrow; } return result; }
From source file:org.getobjects.appserver.publisher.JoSimpleJSONRenderer.java
public Exception appendExceptionToString(Throwable _ex, StringBuilder _sb) { if (_ex == null) { _sb.append("null"); return null; }//from ww w . j a v a2 s . c om Exception error; _sb.append('{'); /* add message code */ Object v = null; if (v == null) { try { v = NSKeyValueCoding.Utility.valueForKey(_ex, "code"); } catch (MissingPropertyException e) { } /* we do not care and continue */ } if (v == null) { try { v = NSKeyValueCoding.Utility.valueForKey(_ex, "errorCode"); } catch (MissingPropertyException e) { } /* we do not care and continue */ } if (_ex instanceof SQLException) v = "sql" + ((SQLException) _ex).getSQLState(); if (v == null) v = _ex.getClass().getName(); if (v == null) v = "unknown"; error = this.appendKeyValuePair("error", v, true, _sb); if (error != null) return error; /* added messages */ String pm = _ex.getMessage(); String sm = _ex.getLocalizedMessage(); if (pm == sm || (pm != null && sm != null && pm.equals(sm))) sm = null; error = this.appendKeyValuePair("message", pm, false, _sb); if (error != null) return error; error = this.appendKeyValuePair("localizedMessage", sm, false, _sb); if (error != null) return error; /* additional standard keys */ v = null; try { v = NSKeyValueCoding.Utility.valueForKey(_ex, "httpStatus"); } catch (MissingPropertyException e) { } /* we do not care and continue */ error = this.appendKeyValuePair("httpStatus", v, false, _sb); if (error != null) return error; if (_ex instanceof SQLException) { error = this.appendKeyValuePair("sqlstate", ((SQLException) _ex).getSQLState(), false, _sb); if (error != null) return error; } _sb.append('}'); return null; }
From source file:org.opencms.gwt.CmsCoreService.java
/** * @see org.opencms.gwt.shared.rpc.I_CmsCoreService#lockTempAndCheckModification(org.opencms.util.CmsUUID, long) *//*from w w w . j av a 2 s . c o m*/ public CmsLockInfo lockTempAndCheckModification(CmsUUID structureId, long modification) throws CmsRpcException { CmsObject cms = getCmsObject(); try { CmsResource resource = cms.readResource(structureId, CmsResourceFilter.IGNORE_EXPIRATION); if (resource.getDateLastModified() != modification) { CmsUser user = cms.readUser(resource.getUserLastModified()); return CmsLockInfo.forChangedResource(user.getFullName()); } } catch (Throwable e) { error(e); } try { return getLock(structureId); } catch (CmsException e) { return CmsLockInfo.forError(e.getLocalizedMessage()); } }
From source file:org.opencms.cmis.CmsCmisRepository.java
/** * @see org.opencms.cmis.I_CmsCmisRepository#initConfiguration() *//*from ww w. j a va 2 s .c o m*/ public void initConfiguration() throws CmsConfigurationException { if (m_filter != null) { m_filter.initConfiguration(); } m_description = m_parameterConfiguration.getString(PARAM_DESCRIPTION, null); List<String> renditionProviderClasses = m_parameterConfiguration.getList(PARAM_RENDITION, Collections.<String>emptyList()); for (String className : renditionProviderClasses) { try { I_CmsCmisRenditionProvider provider = (I_CmsCmisRenditionProvider) (Class.forName(className) .newInstance()); String id = provider.getId(); m_renditionProviders.put(id, provider); } catch (Throwable e) { LOG.error(e.getLocalizedMessage(), e); } } List<String> propertyProviderClasses = m_parameterConfiguration.getList(PARAM_PROPERTY, Collections.<String>emptyList()); for (String className : propertyProviderClasses) { try { I_CmsPropertyProvider provider = (I_CmsPropertyProvider) (Class.forName(className).newInstance()); m_propertyProviders.add(provider); } catch (Throwable e) { LOG.error(e.getLocalizedMessage(), e); } } m_indexName = m_parameterConfiguration.getString(PARAM_INDEX, null); }
From source file:org.tdar.struts.action.TdarActionSupport.java
protected void addActionErrorWithException(String message, Throwable exception) { String trace = ExceptionUtils.getStackTrace(exception); getLogger().error("{} [code: {}]: {} -- {}", new Object[] { message, ExceptionWrapper.convertExceptionToCode(exception), exception, trace }); if (exception instanceof TdarActionException) { setHideExceptionArea(true);//from w w w. j a v a2s . com } if (exception instanceof TdarRecoverableRuntimeException) { int maxDepth = 4; Throwable thrw = exception; if (exception instanceof LocalizableException) { ((LocalizableException) exception).setLocale(getLocale()); } StringBuilder sb = new StringBuilder(exception.getLocalizedMessage()); while ((thrw.getCause() != null) && (maxDepth > -1)) { thrw = thrw.getCause(); if (StringUtils.isNotBlank(thrw.getMessage())) { sb.append(": ").append(thrw.getMessage()); } maxDepth--; } addActionError(sb.toString()); } else if (StringUtils.isNotBlank(message)) { addActionError(message); } stackTraces.add(ExceptionWrapper.convertExceptionToCode(exception)); }
From source file:org.getobjects.appserver.publisher.GoSimpleJSONRenderer.java
public Exception appendExceptionToString(Throwable _ex, StringBuilder _sb) { if (_ex == null) { _sb.append("null"); return null; }/* w w w .jav a 2 s. co m*/ Exception error; _sb.append('{'); /* add message code */ Object v = null; if (v == null) { try { v = NSKeyValueCoding.Utility.valueForKey(_ex, "code"); } catch (MissingPropertyException e) { } /* we do not care and continue */ } if (v == null) { try { v = NSKeyValueCoding.Utility.valueForKey(_ex, "errorCode"); } catch (MissingPropertyException e) { } /* we do not care and continue */ } if (_ex instanceof SQLException) v = "sql" + ((SQLException) _ex).getSQLState(); if (v == null) v = _ex.getClass().getName(); if (v == null) v = "unknown"; error = this.appendKeyValuePair("error", v, true, _sb); if (error != null) return error; /* added messages */ final String pm = _ex.getMessage(); String sm = _ex.getLocalizedMessage(); if (pm == sm || (pm != null && sm != null && pm.equals(sm))) sm = null; error = this.appendKeyValuePair("message", pm, false, _sb); if (error != null) return error; error = this.appendKeyValuePair("localizedMessage", sm, false, _sb); if (error != null) return error; /* additional standard keys */ v = null; try { v = NSKeyValueCoding.Utility.valueForKey(_ex, "httpStatus"); } catch (MissingPropertyException e) { } /* we do not care and continue */ error = this.appendKeyValuePair("httpStatus", v, false, _sb); if (error != null) return error; if (_ex instanceof SQLException) { error = this.appendKeyValuePair("sqlstate", ((SQLException) _ex).getSQLState(), false, _sb); if (error != null) return error; } _sb.append('}'); return null; }
From source file:uk.ac.cam.caret.sakai.rwiki.component.service.impl.XSLTEntityHandler.java
/** * {@inheritDoc}/*from w w w . j a va2s . co m*/ */ public void outputContent(final Entity entity, final Entity sideBar, final HttpServletRequest request, final HttpServletResponse res) { if (!isAvailable()) return; if (!(entity instanceof RWikiEntity)) return; try { String skin = ServerConfigurationService.getString("skin.default"); //$NON-NLS-1$ String skinRepo = ServerConfigurationService.getString("skin.repo"); //$NON-NLS-1$ request.setAttribute("sakai.skin.repo", skinRepo); //$NON-NLS-1$ request.setAttribute("sakai.skin", skin); //$NON-NLS-1$ HttpSession s = request.getSession(); PageVisits pageVisits = (PageVisits) s .getAttribute(XSLTEntityHandler.class.getName() + this.getMinorType() + "_visits"); boolean withBreadcrumbs = !"0".equals(request.getParameter(breadCrumbParameter)); if (pageVisits == null) { pageVisits = new PageVisits(); s.setAttribute(XSLTEntityHandler.class.getName() + this.getMinorType() + "_visits", pageVisits); } RWikiEntity rwe = (RWikiEntity) entity; if (!rwe.isContainer()) { RWikiObject rwo = rwe.getRWikiObject(); pageVisits.addPage(rwo.getName()); } setCurrentRequest(request); if (responseHeaders != null) { for (Iterator i = responseHeaders.keySet().iterator(); i.hasNext();) { String name = (String) i.next(); String value = (String) responseHeaders.get(name); res.setHeader(name, value); } } OutputStream out = res.getOutputStream(); ContentHandler opch = getOutputHandler(out); ContentHandler ch = null; if (false) { ch = new DebugContentHandler(opch); } else { ch = opch; } Attributes dummyAttributes = new AttributesImpl(); ch.startDocument(); ch.startElement(SchemaNames.NS_CONTAINER, SchemaNames.EL_ENTITYSERVICE, SchemaNames.EL_NSENTITYSERVICE, dummyAttributes); AttributesImpl propA = new AttributesImpl(); propA.addAttribute("", SchemaNames.ATTR_REQUEST_PATH_INFO, //$NON-NLS-1$ SchemaNames.ATTR_REQUEST_PATH_INFO, "string", request //$NON-NLS-1$ .getPathInfo()); propA.addAttribute("", SchemaNames.ATTR_REQUEST_USER, //$NON-NLS-1$ SchemaNames.ATTR_REQUEST_USER, "string", request //$NON-NLS-1$ .getRemoteUser()); propA.addAttribute("", SchemaNames.ATTR_REQUEST_PROTOCOL, //$NON-NLS-1$ SchemaNames.ATTR_REQUEST_PROTOCOL, "string", request //$NON-NLS-1$ .getProtocol()); propA.addAttribute("", SchemaNames.ATTR_REQUEST_SERVER_NAME, //$NON-NLS-1$ SchemaNames.ATTR_REQUEST_SERVER_NAME, "string", request //$NON-NLS-1$ .getServerName()); propA.addAttribute("", SchemaNames.ATTR_REQUEST_SERVER_PORT, //$NON-NLS-1$ SchemaNames.ATTR_REQUEST_SERVER_PORT, "string", String //$NON-NLS-1$ .valueOf(request.getServerPort())); propA.addAttribute("", SchemaNames.ATTR_REQUEST_REQUEST_URL, //$NON-NLS-1$ SchemaNames.ATTR_REQUEST_REQUEST_URL, "string", String //$NON-NLS-1$ .valueOf(request.getRequestURL())); ch.startElement(SchemaNames.NS_CONTAINER, SchemaNames.EL_REQUEST_PROPERTIES, SchemaNames.EL_NSREQUEST_PROPERTIES, propA); addRequestAttributes(ch, request); addRequestParameters(ch, request); ch.endElement(SchemaNames.NS_CONTAINER, SchemaNames.EL_REQUEST_PROPERTIES, SchemaNames.EL_NSREQUEST_PROPERTIES); if (withBreadcrumbs) { ch.startElement(SchemaNames.NS_CONTAINER, SchemaNames.EL_PAGEVISITS, SchemaNames.EL_NSPAGEVISITS, dummyAttributes); List<String[]> pv = pageVisits.getPageNames(this.getMinorType()); for (Iterator<String[]> i = pv.iterator(); i.hasNext();) { String[] visit = i.next(); propA = new AttributesImpl(); propA.addAttribute("", SchemaNames.ATTR_URL, SchemaNames.ATTR_URL, "string", visit[0]); addElement(ch, SchemaNames.NS_CONTAINER, SchemaNames.EL_PAGEVISIT, SchemaNames.EL_NSPAGEVISIT, propA, visit[1]); } ch.endElement(SchemaNames.NS_CONTAINER, SchemaNames.EL_PAGEVISITS, SchemaNames.EL_NSPAGEVISITS); } ch.startElement(SchemaNames.NS_CONTAINER, SchemaNames.EL_ENTITY, SchemaNames.EL_NSENTITY, dummyAttributes); ch.startElement(SchemaNames.NS_CONTAINER, SchemaNames.EL_XMLPROPERTIES, SchemaNames.EL_NSXMLPROPERTIES, dummyAttributes); ResourceProperties rp = entity.getProperties(); for (Iterator i = rp.getPropertyNames(); i.hasNext();) { Object key = i.next(); String name = String.valueOf(key); String value = String.valueOf(rp.getProperty(name)); propA = new AttributesImpl(); propA.addAttribute("", SchemaNames.ATTR_NAME, //$NON-NLS-1$ SchemaNames.ATTR_NAME, "string", name); //$NON-NLS-1$ addElement(ch, SchemaNames.NS_CONTAINER, SchemaNames.EL_XMLPROPERTY, SchemaNames.EL_NSXMLPROPERTY, propA, value); } propA = new AttributesImpl(); propA.addAttribute("", SchemaNames.ATTR_NAME, //$NON-NLS-1$ SchemaNames.ATTR_NAME, "string", "_handler"); //$NON-NLS-1$ //$NON-NLS-2$ addElement(ch, SchemaNames.NS_CONTAINER, SchemaNames.EL_XMLPROPERTY, SchemaNames.EL_NSXMLPROPERTY, propA, " XSLTEntity Handler"); //$NON-NLS-1$ if (!rwe.isContainer()) { RWikiObject rwo = rwe.getRWikiObject(); propA = new AttributesImpl(); propA.addAttribute("", SchemaNames.ATTR_NAME, //$NON-NLS-1$ SchemaNames.ATTR_NAME, "string", "_title"); //$NON-NLS-1$ //$NON-NLS-2$ addElement(ch, SchemaNames.NS_CONTAINER, SchemaNames.EL_XMLPROPERTY, SchemaNames.EL_NSXMLPROPERTY, propA, NameHelper.localizeName(rwo.getName(), rwo.getRealm())); } else { propA = new AttributesImpl(); propA.addAttribute("", SchemaNames.ATTR_NAME, //$NON-NLS-1$ SchemaNames.ATTR_NAME, "string", "_title"); //$NON-NLS-1$ //$NON-NLS-2$ addElement(ch, SchemaNames.NS_CONTAINER, SchemaNames.EL_XMLPROPERTY, SchemaNames.EL_NSXMLPROPERTY, propA, entity.getReference()); } ch.endElement(SchemaNames.NS_CONTAINER, SchemaNames.EL_XMLPROPERTIES, SchemaNames.EL_NSXMLPROPERTIES); /* http://jira.sakaiproject.org/browse/SAK-13281 * escapeXML is controlled via config settings */ if (!rwe.isContainer()) { RWikiObject rwo = rwe.getRWikiObject(); ch.startElement(SchemaNames.NS_CONTAINER, SchemaNames.EL_RENDEREDCONTENT, SchemaNames.EL_NSRENDEREDCONTENT, dummyAttributes); renderToXML(rwo, ch, withBreadcrumbs, this.escaped); ch.endElement(SchemaNames.NS_CONTAINER, SchemaNames.EL_RENDEREDCONTENT, SchemaNames.EL_NSRENDEREDCONTENT); } ch.endElement(SchemaNames.NS_CONTAINER, SchemaNames.EL_ENTITY, SchemaNames.EL_NSENTITY); if (sideBar != null && sideBar instanceof RWikiEntity) { RWikiEntity sbrwe = (RWikiEntity) sideBar; RWikiObject sbrwo = sbrwe.getRWikiObject(); ch.startElement(SchemaNames.NS_CONTAINER, SchemaNames.EL_SIDEBAR, SchemaNames.EL_NSSIDEBAR, dummyAttributes); ch.startElement(SchemaNames.NS_CONTAINER, SchemaNames.EL_XMLPROPERTIES, SchemaNames.EL_NSXMLPROPERTIES, dummyAttributes); propA = new AttributesImpl(); propA.addAttribute("", SchemaNames.ATTR_NAME, //$NON-NLS-1$ SchemaNames.ATTR_NAME, "string", "_title"); //$NON-NLS-1$ //$NON-NLS-2$ addElement(ch, SchemaNames.NS_CONTAINER, SchemaNames.EL_XMLPROPERTY, SchemaNames.EL_NSXMLPROPERTY, propA, NameHelper.localizeName(sbrwo.getName(), sbrwo.getRealm())); ch.endElement(SchemaNames.NS_CONTAINER, SchemaNames.EL_XMLPROPERTIES, SchemaNames.EL_NSXMLPROPERTIES); ch.startElement(SchemaNames.NS_CONTAINER, SchemaNames.EL_RENDEREDCONTENT, SchemaNames.EL_NSRENDEREDCONTENT, dummyAttributes); renderToXML(sbrwo, ch, withBreadcrumbs, this.escaped); ch.endElement(SchemaNames.NS_CONTAINER, SchemaNames.EL_RENDEREDCONTENT, SchemaNames.EL_NSRENDEREDCONTENT); ch.endElement(SchemaNames.NS_CONTAINER, SchemaNames.EL_SIDEBAR, SchemaNames.EL_NSSIDEBAR); } ch.endElement(SchemaNames.NS_CONTAINER, SchemaNames.EL_ENTITYSERVICE, SchemaNames.EL_NSENTITYSERVICE); ch.endDocument(); } catch (Throwable ex) { log.info("Failed to serialize " + ex.getMessage()); //$NON-NLS-1$ ex.printStackTrace(); throw new RuntimeException(Messages.getString("XSLTEntityHandler.68") //$NON-NLS-1$ + ex.getLocalizedMessage(), ex); } finally { setCurrentRequest(null); } }