List of usage examples for org.springframework.util ReflectionUtils findMethod
@Nullable public static Method findMethod(Class<?> clazz, String name)
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 ww . java 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 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 {// w w w. j a va2 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 {// ww w . j av a 2 s. c om // 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 {//w w w.j a va 2 s. c om // 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 w ww . j a va 2s. c o m*/ } 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 .j av 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 2 s . c o m*/ Method method = ReflectionUtils.findMethod(this.app.getClass(), "getError"); return (Throwable) ReflectionUtils.invokeMethod(method, this.app); }
From source file:org.springframework.cloud.deployer.thin.ThinJarAppWrapper.java
private void close() { if (this.app != null) { try {/* w w w . ja v a 2 s . c om*/ Method method = ReflectionUtils.findMethod(this.app.getClass(), "close"); ReflectionUtils.invokeMethod(method, this.app); } catch (Exception e) { this.state = LaunchState.error; logger.error("Cannot undeploy " + resource, e); } finally { reset(); if (this.app != null) { try { ((URLClassLoader) app.getClass().getClassLoader()).close(); this.app = null; } catch (Exception e) { this.state = LaunchState.error; logger.error("Cannot clean up " + resource, e); } finally { this.app = null; System.gc(); } } } } }
From source file:org.springframework.cloud.function.web.flux.response.FluxReturnValueHandler.java
public FluxReturnValueHandler(FunctionInspector inspector, List<HttpMessageConverter<?>> messageConverters) { this.inspector = inspector; this.delegate = new ResponseBodyEmitterReturnValueHandler(messageConverters); this.single = new RequestResponseBodyMethodProcessor(messageConverters); Method method = ReflectionUtils.findMethod(getClass(), "singleValue"); singleReturnType = new MethodParameter(method, -1); }