/** Returns the static method defined in an element, or null if failed. */ /*package*/ static MethodInfo getMethodInfo(Element el) { final String clsnm = IDOMs.getRequiredAttributeValue(el, "class"); final String sig = IDOMs.getRequiredAttributeValue(el, "signature"); final Class cls; try { cls = Classes.forNameByThread(clsnm); } catch (ClassNotFoundException ex) { log.error("Class not found: " + clsnm + ", " + el.getLocator()); return null; // to report as many errors as possible } try { final Method mtd = Classes.getMethodBySignature(cls, sig, null); if ((mtd.getModifiers() & Modifier.STATIC) == 0) { log.error("Not a static method: " + mtd); return null; } final Object[] args = new Object[mtd.getParameterTypes().length]; for (int j = 0; j < args.length; ++j) args[j] = el.getAttributeValue("arg" + j); return new MethodInfo(mtd, args); } catch (ClassNotFoundException ex) { log.realCauseBriefly( "Unable to load class when resolving " + sig + " " + el.getLocator(), ex); } catch (NoSuchMethodException ex) { log.error("Method not found in " + clsnm + ": " + sig + " " + el.getLocator()); } return null; }
/** * Recovers the desktop if possible. It is called if {@link #getDesktop} returns null. * * <p>The default implementation will look for any failover manager ({@link FailoverManager}) is * registered, and forward the invocation to it if found. * * @return the recovered desktop, or null if failed to recover * @since 5.0.3 */ protected Desktop recoverDesktop( Session sess, HttpServletRequest request, HttpServletResponse response, WebAppCtrl wappc, String dtid) { final FailoverManager failover = wappc.getFailoverManager(); if (failover != null) { Desktop desktop = null; final ServletContext ctx = getServletContext(); try { if (failover.isRecoverable(sess, dtid)) { desktop = WebManager.getWebManager(ctx).getDesktop(sess, request, response, null, true); if (desktop == null) // forward or redirect throw new IllegalStateException("sendRediect or forward not allowed in recovering"); wappc .getUiEngine() .execRecover(new ExecutionImpl(ctx, request, response, desktop, null), failover); return desktop; // success } } catch (Throwable ex) { log.error("Unable to recover " + dtid, ex); if (desktop != null) ((DesktopCtrl) desktop).recoverDidFail(ex); } } return null; }
/** * rollback the current session. * * @param exec the exection to clean up. * @param ex the StaleObjectStateException being thrown (and not handled) during the execution */ private void rollback(Execution exec, Throwable ex) { try { if (HibernateUtil.currentSession().getTransaction().isActive()) { log.debug("Trying to rollback database transaction after exception:" + ex); HibernateUtil.currentSession().getTransaction().rollback(); } } catch (Throwable rbEx) { log.error("Could not rollback transaction after exception! Original Exception:\n" + ex, rbEx); } }
private void reportError(String message, Employee employee) { StringBuilder sb = new StringBuilder(message) .append(Messages.getString("EmployeeController.5")) .append(employee); final String error = sb.toString(); UiUtils.showMessage(error); log.error(error); }
@Override public void run() { while (!_exit) { try { nextIteration(); } catch (Exception ex) { _log.error(ex); exit(); } } }
public void call(Object base, Method method) { Class<?>[] paramTypes = method.getParameterTypes(); java.lang.annotation.Annotation[][] parmAnnos = method.getParameterAnnotations(); Object[] params = new Object[paramTypes.length]; try { for (int i = 0; i < paramTypes.length; i++) { params[i] = resolveParameter(parmAnnos[i], paramTypes[i]); } method.invoke(base, params); } catch (InvocationTargetException invokEx) { // Ian YT Tsai (2012.06.20), while InvocationTargetException, // using original exception is much meaningful. Throwable c = invokEx.getCause(); if (c == null) c = invokEx; _log.error(c); throw UiException.Aide.wrap(c); } catch (Exception e) { _log.error(e); throw UiException.Aide.wrap(e); } }
/** Invokes all cleanups registered with {@link #add}. */ public static void cleanup() { final List cleanups; synchronized (_cleanups) { cleanups = new ArrayList(_cleanups); } for (Iterator it = cleanups.iterator(); it.hasNext(); ) { final Cleanup cleanup = (Cleanup) it.next(); try { cleanup.cleanup(); } catch (Throwable ex) { log.error("Failed to invoke " + cleanup); } } }
/** Invokes a static method. */ /*package*/ String invoke(MethodInfo mi) { final Provider provider = getProvider(); final Class[] argTypes = mi.method.getParameterTypes(); final Object[] args = mi.arguments; if (provider != null) for (int j = 0; j < args.length; ++j) if (ServletRequest.class.isAssignableFrom(argTypes[j])) args[j] = provider.request; else if (ServletResponse.class.isAssignableFrom(argTypes[j])) args[j] = provider.response; else if (ServletContext.class.isAssignableFrom(argTypes[j])) args[j] = getServletContext(); try { Object o = mi.method.invoke(null, args); return o instanceof String ? (String) o : ""; } catch (Throwable ex) { // log and eat ex log.error("Unable to invoke " + mi.method, ex); return ""; } }
/** Writes only serializable elements of the specified collection. */ public static <T> void smartWrite(ObjectOutputStream s, Collection<T> col) throws IOException { if (col != null) { final boolean debug = logio.debugable(); for (T val : col) { if ((val instanceof Serializable) || (val instanceof Externalizable)) { try { s.writeObject(val); } catch (java.io.NotSerializableException ex) { logio.error("Unable to serialize item: " + val); throw ex; } } else if (val != null && debug) { logio.debug("Skip not-serializable item: " + val); } } } s.writeObject(null); }
/** * Writes only serializable elements of the specified array. * * <p>To read back, use {@link #smartRead(ObjectInputStream, Collection)}. * * @since 3.0.0 */ public static <T> void smartWrite(ObjectOutputStream s, T[] ary) throws IOException { if (ary != null) { final boolean debug = logio.debugable(); for (int j = 0; j < ary.length; ++j) { final T val = ary[j]; if ((val instanceof Serializable) || (val instanceof Externalizable)) { try { s.writeObject(val); } catch (java.io.NotSerializableException ex) { logio.error("Unable to serialize item: " + val); throw ex; } } else if (val != null && debug) { logio.debug("Skip not-serializable item: " + val); } } } s.writeObject(null); }
private static final String getNotFound(int code, Locale locale) { if (code == NULL_CODE) return ""; // special code try { log.error( "Message code not found: " + Integer.toHexString(code) + " not in " + locale + ":" + Aide.getBundleInfo(code)); final String hexcode = Integer.toHexString(code); final String s = getFromBundle(MCommon.MESSAGE_CODE_NOT_FOUND, locale); return s != null ? MessageFormats.format(s, new Object[] {hexcode}, locale) : "Unknown message code: " + hexcode; } catch (Exception ex) { log.realCauseBriefly(ex); return "Unknown message code: " + Integer.toHexString(code); } }
/** * Writes only serializable entries of the specified map. Non-serializable attributes are ignored. */ public static <K, V> void smartWrite(ObjectOutputStream s, Map<K, V> map) throws IOException { if (map != null) { final boolean debug = logio.debugable(); for (Map.Entry<K, V> me : map.entrySet()) { final K nm = me.getKey(); final V val = me.getValue(); if (((nm instanceof Serializable) || (nm instanceof Externalizable)) && (val == null || (val instanceof Serializable) || (val instanceof Externalizable))) { try { s.writeObject(nm); s.writeObject(val); } catch (java.io.NotSerializableException ex) { logio.error("Unable to serialize entry: " + nm + '=' + val); throw ex; } } else if (nm != null && debug) { logio.debug("Skip not-serializable entry: " + nm + '=' + val); } } } s.writeObject(null); // denote end-of-map }
/** * Default StaleObjectStateException handler. This implementation does not implement optimistic * concurrency control! It simply rollback the transaction. * * <p>Application developer might want to extends this class and override this method to do other * things like compensate for any permanent changes during the conversation, and finally restart * business conversation. Or maybe give the user of the application a chance to merge some of his * work with fresh data... what can be done here depends on the applications design. * * @param exec the exection to clean up. * @param ex the StaleObjectStateException being thrown (and not handled) during the execution */ protected void handleStaleObjectStateException(Execution exec, StaleObjectStateException ex) { log.error("This listener does not implement optimistic concurrency control!"); rollback(exec, ex); }