private String evaluateCompositeExpression(Matcher matcher) { StringBuffer buffer = new StringBuffer(); do { Object result = processor.eval(matcher.group(1)); matcher.appendReplacement(buffer, result != null ? String.valueOf(result) : ""); } while (matcher.find()); matcher.appendTail(buffer); return buffer.toString(); } }
private String evaluateCompositeExpression(Matcher matcher) { StringBuffer buffer = new StringBuffer(); do { Object result = processor.eval(matcher.group(1)); matcher.appendReplacement(buffer, result != null ? String.valueOf(result) : ""); } while (matcher.find()); matcher.appendTail(buffer); return buffer.toString(); } }
public static String getCurrentEJBName(EJBContext ejbContext) { try { switch (ejbContext.getClass().getName()) { case "com.sun.ejb.containers.SessionContextImpl": case "com.sun.ejb.containers.SingletonContextImpl": String toString = ejbContext.toString(); int firstIndex = toString.indexOf(";"); if (firstIndex != -1) { return toString.substring(0, firstIndex); } break; case "org.jboss.as.ejb3.context.SessionContextImpl": return getELProcessor("ejbContext", ejbContext) .eval("ejbContext.component.componentName") .toString(); } } catch (Exception e) { // Ignore } return null; }
public static String getCurrentEJBName(EJBContext ejbContext) { try { switch (ejbContext.getClass().getName()) { case "com.sun.ejb.containers.SessionContextImpl": case "com.sun.ejb.containers.SingletonContextImpl": String toString = ejbContext.toString(); int firstIndex = toString.indexOf(";"); if (firstIndex != -1) { return toString.substring(0, firstIndex); } break; case "org.jboss.as.ejb3.context.SessionContextImpl": return getELProcessor("ejbContext", ejbContext) .eval("ejbContext.component.componentName") .toString(); } } catch (Exception e) { // Ignore } return null; }
@Override public void destroy(HttpServletRequest request) { Object weldInitialListener = request.getServletContext().getAttribute("org.jboss.weld.servlet.WeldInitialListener"); ServletRequestEvent event = new ServletRequestEvent(request.getServletContext(), request); ELProcessor elProcessor = new ELProcessor(); elProcessor.defineBean("weldInitialListener", weldInitialListener); elProcessor.defineBean("event", event); elProcessor.eval("weldInitialListener.requestDestroyed(event)"); // EXTRA HACK TO MAKE REQUEST WRAPPING NOT DESTROY FOLLOW UP REQUEST IN LIBERTY 16.0.0.3 and 2016.9 AND EARLIER // SHOULD BE REMOVED WHEN LIBERTY NO LONGER STORES THIS PER REQUEST WRAPPER IN THE APPLICATION SCOPE if (request.getServletContext().getAttribute("com.ibm.ws.security.jaspi.servlet.request.wrapper") != null) { request.getServletContext().removeAttribute("com.ibm.ws.security.jaspi.servlet.request.wrapper"); } }
@Override public void destroy(HttpServletRequest request) { Object weldInitialListener = request.getServletContext().getAttribute("org.jboss.weld.servlet.WeldInitialListener"); ServletRequestEvent event = new ServletRequestEvent(request.getServletContext(), request); ELProcessor elProcessor = new ELProcessor(); elProcessor.defineBean("weldInitialListener", weldInitialListener); elProcessor.defineBean("event", event); elProcessor.eval("weldInitialListener.requestDestroyed(event)"); // EXTRA HACK TO MAKE REQUEST WRAPPING NOT DESTROY FOLLOW UP REQUEST IN LIBERTY 16.0.0.3 and 2016.9 AND EARLIER // SHOULD BE REMOVED WHEN LIBERTY NO LONGER STORES THIS PER REQUEST WRAPPER IN THE APPLICATION SCOPE if (request.getServletContext().getAttribute("com.ibm.ws.security.jaspi.servlet.request.wrapper") != null) { request.getServletContext().removeAttribute("com.ibm.ws.security.jaspi.servlet.request.wrapper"); } }
@Override public void init(HttpServletRequest request) { Object weldInitialListener = request.getServletContext().getAttribute("org.jboss.weld.servlet.WeldInitialListener"); ServletRequestEvent event = new ServletRequestEvent(request.getServletContext(), request); ELProcessor elProcessor = new ELProcessor(); elProcessor.defineBean("weldInitialListener", weldInitialListener); elProcessor.defineBean("event", event); elProcessor.eval("weldInitialListener.requestInitialized(event)"); }
@Override public void init(HttpServletRequest request) { Object weldInitialListener = request.getServletContext().getAttribute("org.jboss.weld.servlet.WeldInitialListener"); ServletRequestEvent event = new ServletRequestEvent(request.getServletContext(), request); ELProcessor elProcessor = new ELProcessor(); elProcessor.defineBean("weldInitialListener", weldInitialListener); elProcessor.defineBean("event", event); elProcessor.eval("weldInitialListener.requestInitialized(event)"); }
@Override public MetricRegistry resolveMetricRegistry(String registry) { Matcher matcher = EL_PATTERN.matcher(registry); if (matcher.matches()) { Object evaluation = processor.eval(matcher.group(1)); if (evaluation instanceof String) return SharedMetricRegistries.getOrCreate((String) evaluation); else if (evaluation instanceof MetricRegistry) return (MetricRegistry) evaluation; else throw new IllegalStateException("Unable to resolve metrics registry from expression [" + registry + "]"); } else if (!matcher.find()) { return SharedMetricRegistries.getOrCreate(registry); } else { return SharedMetricRegistries.getOrCreate(evaluateCompositeExpression(matcher)); } }
@Override public MetricRegistry resolveMetricRegistry(String registry) { Matcher matcher = EL_PATTERN.matcher(registry); if (matcher.matches()) { Object evaluation = processor.eval(matcher.group(1)); if (evaluation instanceof String) return SharedMetricRegistries.getOrCreate((String) evaluation); else if (evaluation instanceof MetricRegistry) return (MetricRegistry) evaluation; else throw new IllegalStateException("Unable to resolve metrics registry from expression [" + registry + "]"); } else if (!matcher.find()) { return SharedMetricRegistries.getOrCreate(registry); } else { return SharedMetricRegistries.getOrCreate(evaluateCompositeExpression(matcher)); } }
public static boolean evalImmediate(ELProcessor getELProcessor, String expression, boolean defaultValue) { if (!isELExpression(expression) || isDeferredExpression(expression)) { return defaultValue; } Object outcome = getELProcessor(getELProcessor).eval(toRawExpression(expression)); if (outcome instanceof Boolean) { return (Boolean) outcome; } throw new IllegalStateException( "Expression " + expression + " should evaluate to boolean but evaluated to " + outcome == null? " null" : (outcome.getClass() + " " + outcome)); }
public static boolean evalImmediate(ELProcessor getELProcessor, String expression, boolean defaultValue) { if (!isELExpression(expression) || isDeferredExpression(expression)) { return defaultValue; } Object outcome = getELProcessor(getELProcessor).eval(toRawExpression(expression)); if (outcome instanceof Boolean) { return (Boolean) outcome; } throw new IllegalStateException( "Expression " + expression + " should evaluate to boolean but evaluated to " + outcome == null? " null" : (outcome.getClass() + " " + outcome)); }
public static boolean evalELExpression(ELProcessor getELProcessor, String expression, boolean defaultValue) { if (!isELExpression(expression)) { return defaultValue; } return (Boolean) getELProcessor(getELProcessor).eval(toRawExpression(expression)); }
public static String evalELExpression(ELProcessor getELProcessor, String expression) { if (!isELExpression(expression)) { return expression; } return (String) getELProcessor(getELProcessor).eval(toRawExpression(expression)); }
public static boolean evalELExpression(ELProcessor getELProcessor, String expression, boolean defaultValue) { if (!isELExpression(expression)) { return defaultValue; } return (Boolean) getELProcessor(getELProcessor).eval(toRawExpression(expression)); }
public static String evalELExpression(ELProcessor getELProcessor, String expression) { if (!isELExpression(expression)) { return expression; } return (String) getELProcessor(getELProcessor).eval(toRawExpression(expression)); }
public static String evalImmediate(ELProcessor getELProcessor, String expression) { if (!isELExpression(expression) || isDeferredExpression(expression)) { return expression; } return (String) getELProcessor(getELProcessor).eval(toRawExpression(expression)); }
public static String evalImmediate(ELProcessor getELProcessor, String expression) { if (!isELExpression(expression) || isDeferredExpression(expression)) { return expression; } return (String) getELProcessor(getELProcessor).eval(toRawExpression(expression)); }
@SuppressWarnings("unchecked") public static <T> T evalImmediate(String expression, T defaultValue) { if (!isELExpression(expression) || isDeferredExpression(expression)) { return defaultValue; } return (T) getELProcessor(getELProcessor(null)).eval(toRawExpression(expression)); }
@SuppressWarnings("unchecked") public static <T> T evalImmediate(String expression, T defaultValue) { if (!isELExpression(expression) || isDeferredExpression(expression)) { return defaultValue; } return (T) getELProcessor(getELProcessor(null)).eval(toRawExpression(expression)); }