List of usage examples for org.springframework.util ReflectionUtils invokeMethod
@Nullable public static Object invokeMethod(Method method, @Nullable Object target)
From source file:org.springframework.batch.core.jsr.configuration.support.SpringAutowiredAnnotationBeanPostProcessor.java
/** * Determine if the annotated field or method requires its dependency. * <p>A 'required' dependency means that autowiring should fail when no beans * are found. Otherwise, the autowiring process will simply bypass the field * or method when no beans are found./*from w w w . ja v a 2 s .co m*/ * @param annotation the Autowired annotation * @return whether the annotation indicates that a dependency is required */ protected boolean determineRequiredStatus(Annotation annotation) { try { Method method = ReflectionUtils.findMethod(annotation.annotationType(), this.requiredParameterName); if (method == null) { // annotations like @Inject and @Value don't have a method (attribute) named "required" // -> default to required status return true; } return (this.requiredParameterValue == (Boolean) ReflectionUtils.invokeMethod(method, annotation)); } catch (Exception ex) { // an exception was thrown during reflective invocation of the required attribute // -> default to required status return true; } }
From source file:org.springframework.boot.actuate.metrics.export.MetricCopyExporter.java
private void flush(MetricWriter writer) { if (writer instanceof CompositeMetricWriter) { for (MetricWriter child : (CompositeMetricWriter) writer) { flush(child);/*from w w w .j ava 2 s.c o m*/ } } try { if (ClassUtils.isPresent("java.io.Flushable", null)) { if (writer instanceof Flushable) { ((Flushable) writer).flush(); return; } } Method method = ReflectionUtils.findMethod(writer.getClass(), "flush"); if (method != null) { ReflectionUtils.invokeMethod(method, writer); } } catch (Exception ex) { logger.warn("Could not flush MetricWriter: " + ex.getClass() + ": " + ex.getMessage()); } }
From source file:org.springframework.boot.actuate.metrics.writer.WriterUtils.java
public static void flush(MetricWriter writer) { if (writer instanceof CompositeMetricWriter) { for (MetricWriter element : (CompositeMetricWriter) writer) { flush(element);/*from w w w. ja v a 2s. c om*/ } } try { if (ClassUtils.isPresent("java.io.Flushable", null)) { if (writer instanceof Flushable) { ((Flushable) writer).flush(); return; } } Method method = ReflectionUtils.findMethod(writer.getClass(), "flush"); if (method != null) { ReflectionUtils.invokeMethod(method, writer); } } catch (Exception e) { logger.warn("Could not flush MetricWriter: " + e.getClass() + ": " + e.getMessage()); } }
From source file:org.springframework.boot.autoconfigure.data.elasticsearch.ElasticsearchAutoConfiguration.java
@Override public void destroy() throws Exception { if (this.releasable != null) { try {/* www. j a v a 2 s . c o m*/ if (logger.isInfoEnabled()) { logger.info("Closing Elasticsearch client"); } try { this.releasable.close(); } catch (NoSuchMethodError ex) { // Earlier versions of Elasticsearch had a different method name ReflectionUtils.invokeMethod(ReflectionUtils.findMethod(Releasable.class, "release"), this.releasable); } } catch (final Exception ex) { if (logger.isErrorEnabled()) { logger.error("Error closing Elasticsearch client: ", ex); } } } }
From source file:org.springframework.boot.autoconfigure.security.SecurityAutoConfiguration.java
private static boolean isBuilt(AuthenticationManagerBuilder builder) { Method configurers = ReflectionUtils.findMethod(AbstractConfiguredSecurityBuilder.class, "getConfigurers"); Method unbuilt = ReflectionUtils.findMethod(AbstractConfiguredSecurityBuilder.class, "isUnbuilt"); ReflectionUtils.makeAccessible(configurers); ReflectionUtils.makeAccessible(unbuilt); return !((Collection<?>) ReflectionUtils.invokeMethod(configurers, builder)).isEmpty() || !((Boolean) ReflectionUtils.invokeMethod(unbuilt, builder)); }
From source file:org.springframework.boot.context.embedded.jetty.JettyEmbeddedServletContainer.java
private Integer getLocalPort(Connector connector) { try {//from w w w .ja v a 2s. com // Jetty 9 internals are different, but the method name is the same return (Integer) ReflectionUtils .invokeMethod(ReflectionUtils.findMethod(connector.getClass(), "getLocalPort"), connector); } catch (Exception ex) { JettyEmbeddedServletContainer.logger.info("could not determine port ( " + ex.getMessage() + ")"); return 0; } }
From source file:org.springframework.boot.context.embedded.jetty.JettyWebServer.java
private Integer getLocalPort(Connector connector) { try {//from ww w .j a v a2 s. com // Jetty 9 internals are different, but the method name is the same return (Integer) ReflectionUtils .invokeMethod(ReflectionUtils.findMethod(connector.getClass(), "getLocalPort"), connector); } catch (Exception ex) { JettyWebServer.logger.info("could not determine port ( " + ex.getMessage() + ")"); return 0; } }
From source file:org.springframework.cloud.dataflow.app.launcher.MultiArchiveLauncher.java
@Override protected void launch(String[] args, String mainClass, ClassLoader classLoader) throws Exception { if (log.isDebugEnabled()) { for (Archive archive : archives) { log.debug("Launching with: " + archive.getUrl().toString()); }/*from www .java2 s. c om*/ } if (ClassUtils.isPresent("org.apache.catalina.webresources.TomcatURLStreamHandlerFactory", classLoader)) { // Ensure the method is invoked on a class that is loaded by the provided // class loader (not the current context class loader): Method method = ReflectionUtils.findMethod( classLoader.loadClass("org.apache.catalina.webresources.TomcatURLStreamHandlerFactory"), "disable"); ReflectionUtils.invokeMethod(method, null); } super.launch(args, mainClass, classLoader); }
From source file:org.springframework.cloud.deployer.thin.ThinJarAppWrapper.java
private boolean isRunning() { if (app == null) { return false; }/*from www.jav a 2 s . c o m*/ Method method = ReflectionUtils.findMethod(this.app.getClass(), "isRunning"); return (Boolean) ReflectionUtils.invokeMethod(method, this.app); }
From source file:org.springframework.cloud.deployer.thin.ThinJarAppWrapper.java
private Throwable getError() { if (app == null) { return null; }/*from w ww. java 2s . com*/ Method method = ReflectionUtils.findMethod(this.app.getClass(), "getError"); return (Throwable) ReflectionUtils.invokeMethod(method, this.app); }