/** * Calls all registered destruction callbacks and removes all bean references from the * container. */ public void destroy() { for (Entry<String, Runnable> entry : destructionCallbacks.entrySet()) { try { entry.getValue().run(); } catch (Throwable t) { log.error(() -> "Error during destruction callback for bean " + entry.getKey(), t); } } beans.clear(); destructionCallbacks.clear(); }
/** * Perform an action. * * @param e Exception resulting from the failure. */ void doAction(Exception e) { switch (this) { case IGNORE: return; case EXCEPTION: throw MiscUtil.toUnchecked(e); case LOG: log.error(() -> e.getMessage(), e); return; } } }
/** * Sends an exception to the client for display via the web socket session. * * @param socket The web socket session. If null, the session is derived from the current * execution context. * @param exception The exception. */ public static void sendError(WebSocketSession socket, Throwable exception) { log.error("Uncaught exception", exception); Throwable cause = ExceptionUtils.getRootCause(exception); cause = cause == null ? exception : cause; try (StringWriter writer = new StringWriter(); PrintWriter print = new PrintWriter(writer);) { cause.printStackTrace(print); ClientInvocation invocation = new ClientInvocation("fujion.alert", null, writer.toString(), "Error", "danger"); send(socket, invocation); } catch (Exception e) { log.error("Could not send exception to client.", exception); } }
@Override public List<String> getMatching(String iconName, String dims) { List<String> matches = new ArrayList<>(); try { for (String dim : resolveDims(dims)) { String path = webjar.getAbsolutePath() + "**/" + formatPath(iconName, dim); for (Resource resource : resolver.getResources(path)) { if (resource.exists()) { String p = resource.getURL().getPath(); int i = p.lastIndexOf("jar!/META-INF/resources/webjars/"); matches.add(p.substring(i + 24)); } } } } catch (IOException e) { log.error("Error enumerating icons.", e); } return matches; }
@Override default Object transformForClient() { String id = getId(); if (id == null) { log.error(() -> "Component is not attached to a page: " + this); } return id == null ? null : new CustomDatatype("id", id); }
/** * Notify lifecycle listeners of a lifecycle event. * * @param session Session triggering the event. * @param created If true, it is a create event; if false, a destroy event. */ protected void notifyLifecycleListeners(Session session, boolean created) { if (!lifecycleListeners.isEmpty()) { for (ISessionLifecycle listener : new ArrayList<>(lifecycleListeners)) { try { if (created) { listener.onSessionCreate(session); } else { listener.onSessionDestroy(session); } } catch (Exception e) { if (created && e instanceof SessionInitException) { throw e; } else { log.error("A session lifecycle listener threw an exception.", e); } } } } }
/** * Unregisters and invokes a callback. * * @param handle The callback's handle. * @param response The response to pass to the callback. */ private void invokeCallback(int handle, Object response) { @SuppressWarnings("unchecked") IResponseCallback<Object> callback = (IResponseCallback<Object>) unregisterCallback(handle); if (callback != null) { try { callback.onComplete(response); } catch (Exception e) { log.error("Exception on client callback", e); } } }
/** * Determine if the configuration is embedded in the pom.xml file and process if so. To do this, * we have to locate the pom.xml resource and search it for a "requirejs" or "systemjs" property * entry. If this is found, the configuration is extracted, parsed, and merged with the * configuration that we are building. * * @param webjar The web jar. * @param parser The JSON parser. * @return True if successfully processed. */ private boolean tryPOMFormat(WebJar webjar, ObjectMapper parser) { try { String pomPath = webjar.getAbsolutePath(); int i = pomPath.lastIndexOf("/META-INF/") + 10; pomPath = pomPath.substring(0, i) + "maven/**/pom.xml"; Resource[] poms = applicationContext.getResources(pomPath); return poms.length > 0 && extractConfig(poms[0], webjar, parser); } catch (Exception e) { log.error(() -> "Error processing configuration data from " + webjar, e); return false; } }
/** * Sends multiple client invocation requests to the client via the web socket session. * * @param socket The web socket session. If null, the session is derived from the current * execution context. * @param invocations The client invocation requests. */ public static void send(WebSocketSession socket, Iterable<ClientInvocation> invocations) { StringBuilder sb = null; Session session = resolveSession(socket); Page page = session.getPage(); try { for (ClientInvocation invocation : invocations) { sb = sb == null ? new StringBuilder() : sb; String json = writer.writeValueAsString(invocation.toMap(page)); sb.append(sb.length() == 0 ? "[" : ",").append(json); session.notifySessionListeners(invocation); } if (sb != null) { sb.append("]"); sendData(socket, sb.toString()); } } catch (Exception e) { log.error("Unexpected exception", e); } }
log.error("Error processing client request.", e); sendError(socket, e);
/** * Notify all session listeners of an event. * * @param event The type of session event. * @param argument Event arguments (specific to event type). */ private void notifySessionListeners(EventType event, Object argument) { if (sessionListeners != null) { for (ISessionListener sessionListener : sessionListeners) { try { switch (event) { case DESTROY: sessionListener.onDestroy(); break; case REQUEST: sessionListener.onClientRequest((ClientRequest) argument); break; case INVOCATION: sessionListener.onClientInvocation((ClientInvocation) argument); break; } } catch (Exception e) { log.error("A session listener threw an exception", e); } } } }
@Override public void addViewControllers(ViewControllerRegistry registry) { try { Resource[] resources = applicationContext.getResources("/index.*"); if (resources.length > 0) { if (resources.length > 1) { log.warn("Multiple home page candidates detected - only one will be selected."); } String file = "/" + resources[0].getFilename(); registry.addRedirectViewController("/", file); log.info(() -> "Default home page set to: " + file); } else { log.info("No default home page detected."); } } catch (Exception e) { log.error("Error while attempting to detect default home page.", e); } }
/** * Invoke the request on the target. * * @param request The request to invoke. */ private void invokeRequest(InvocationRequest request) { try { MethodUtils.invokeMethod(target, request.getMethodName(), request.getArgs(), MiscUtil.getParameterTypes(request.getArgs())); } catch (Exception e) { log.error("Remote invocation error.", e); } }
log.error("Exception transforming option map.", e);
/** * Sends a client invocation request to the client via the web socket session. * * @param socket The web socket session. If null, the session is derived from the current * execution context. * @param invocation The client invocation request. */ public static void send(WebSocketSession socket, ClientInvocation invocation) { try { Session session = resolveSession(socket); session.notifySessionListeners(invocation); String json = writer.writeValueAsString(invocation.toMap(session.getPage())); sendData(socket, json); } catch (Exception e) { log.error(e); throw MiscUtil.toUnchecked(e); } }
/** * Sends a json payload to the client via the web socket session. * * @param socket The web socket session. If null, the session is derived from the current * execution context. * @param json The json payload. */ private static void sendData(WebSocketSession socket, String json) { try { Session session = resolveSession(socket); socket = socket == null ? session.getSocket() : socket; socket.sendMessage(new TextMessage(json)); session.updateLastActivity(); } catch (Exception e) { log.error(e); } }
log.error(message); break;
log.error(() -> "Error extracting configuration information from web jar: " + resource, e);
/** * Locates, parses, and registers all type libraries (files with the <code>tld</code> extension) * discovered on the class path. */ @Override public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { try { Resource[] resources = applicationContext.getResources("classpath*:**/*.tld"); for (Resource resource : resources) { log.info(() -> "Found tag library at " + resource); try { register(TagLibraryParser.getInstance().parse(resource)); } catch (Exception e) { log.error("Error parsing tag library", e); } } } catch (Exception e) { throw MiscUtil.toUnchecked(e); } }
private void processRequest(Session session, Map<String, Object> map) throws Exception { session._init((String) map.get("pid")); session.updateLastActivity(); ClientRequest request = new ClientRequest(session, map); IRequestHandler handler = handlers.get(request.getType()); if (handler == null) { throw new IllegalArgumentException("No registered handler for request type: " + request.getType()); } ExecutionContext.clear(); ExecutionContext.put(ExecutionContext.ATTR_REQUEST, request); ExecutionContext.put(ExecutionContext.ATTR_PROCESSING, true); try { handler.handleRequest(request); session.notifySessionListeners(request); request.getPage().getEventQueue().processAll(); } catch (Exception e) { request.getPage().getEventQueue().clearAll(); log.error("Unexpected exception", e); sendError(session.getSocket(), e); } finally { ExecutionContext.clear(); } }