From d0bcf4e8365569ad806bf9036411fce3cd5e878b Mon Sep 17 00:00:00 2001 From: yangfuhai Date: Fri, 20 Oct 2017 08:44:18 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E4=BB=A3=E7=A0=81=E5=AE=8C?= =?UTF-8?q?=E5=96=84=E6=B3=A8=E9=87=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/io/jboot/Jboot.java | 100 ++++++++++++++---- .../aop/web/WebInterceptorInjectHandler.java | 4 + 2 files changed, 83 insertions(+), 21 deletions(-) diff --git a/src/main/java/io/jboot/Jboot.java b/src/main/java/io/jboot/Jboot.java index 6a569664f..47fb6218b 100644 --- a/src/main/java/io/jboot/Jboot.java +++ b/src/main/java/io/jboot/Jboot.java @@ -156,16 +156,16 @@ public void start() { JbootAppListenerManager.me().onJbootStarted(); - tryToHoldApplication(); +// tryToHoldApplication(); } - private void tryToHoldApplication() { - try { - Thread.sleep(Long.MAX_VALUE); - } catch (InterruptedException e) { - e.printStackTrace(); - } - } +// private void tryToHoldApplication() { +// try { +// Thread.sleep(Long.MAX_VALUE); +// } catch (InterruptedException e) { +// e.printStackTrace(); +// } +// } private boolean startServer() { @@ -235,6 +235,17 @@ private void printServerUrl() { System.out.println("\nserver started success , url : " + url); } + private static String getRootClassPath() { + String path = null; + try { + path = Jboot.class.getClassLoader().getResource("").toURI().getPath(); + return new File(path).getAbsolutePath(); + } catch (URISyntaxException e) { + e.printStackTrace(); + } + return path; + } + ///////////get component methods/////////// @@ -325,6 +336,11 @@ public JbootRedis getRedis() { } + /** + * 获取本地server 例如,undertow + * + * @return + */ public JbootServer getServer() { return jbootServer; } @@ -366,6 +382,13 @@ public static T config(Class clazz) { private JbootrpcConfig rpcConfig; + /** + * 获取 RPC服务 + * + * @param clazz + * @param + * @return + */ public static T service(Class clazz) { if (jboot.rpcConfig == null) { jboot.rpcConfig = config(JbootrpcConfig.class); @@ -373,33 +396,79 @@ public static T service(Class clazz) { return service(clazz, jboot.rpcConfig.getDefaultGroup(), jboot.rpcConfig.getDefaultVersion()); } + /** + * 获取 RPC 服务 + * + * @param clazz + * @param group + * @param version + * @param + * @return + */ public static T service(Class clazz, String group, String version) { - return me().getRpc().serviceObtain(clazz, group, version); + return jboot.getRpc().serviceObtain(clazz, group, version); } + /** + * 想本地系统发送一个事件 + * + * @param event + */ public static void sendEvent(JbootEvent event) { JbootEventManager.me().pulish(event); } + /** + * 向本地系统发送一个事件 + * + * @param action + * @param data + */ public static void sendEvent(String action, Object data) { sendEvent(new JbootEvent(action, data)); } + /** + * http get操作 + * + * @param url + * @return + */ public static String httpGet(String url) { return httpGet(url, null); } + /** + * http get操作 + * + * @param url + * @param params + * @return + */ public static String httpGet(String url, Map params) { JbootHttpRequest request = JbootHttpRequest.create(url, params, JbootHttpRequest.METHOD_GET); JbootHttpResponse response = jboot.getHttp().handle(request); return response.isError() ? null : response.getContent(); } + /** + * http post 操作 + * + * @param url + * @return + */ public static String httpPost(String url) { return httpPost(url, null); } + /** + * Http post 操作 + * + * @param url + * @param params post的参数,可以是文件 + * @return + */ public static String httpPost(String url, Map params) { JbootHttpRequest request = JbootHttpRequest.create(url, params, JbootHttpRequest.METHOD_POST); JbootHttpResponse response = jboot.getHttp().handle(request); @@ -408,7 +477,7 @@ public static String httpPost(String url, Map params) { /** - * 获取被增强的,可以使用AOP注入的 + * 获取被增强的,可以使用AOP注入的实体类 * * @param clazz * @param @@ -440,17 +509,6 @@ public static T hystrix(String key, HystrixRunnable hystrixRunnable) { return (T) new JbootHystrixCommand(key, hystrixRunnable).execute(); } - private static String getRootClassPath() { - String path = null; - try { - path = Jboot.class.getClassLoader().getResource("").toURI().getPath(); - return new File(path).getAbsolutePath(); - } catch (URISyntaxException e) { - e.printStackTrace(); - } - return path; - } - /** * 产品模式:开发、测试、产品 diff --git a/src/main/java/io/jboot/aop/web/WebInterceptorInjectHandler.java b/src/main/java/io/jboot/aop/web/WebInterceptorInjectHandler.java index d303699a5..18d9d60d7 100644 --- a/src/main/java/io/jboot/aop/web/WebInterceptorInjectHandler.java +++ b/src/main/java/io/jboot/aop/web/WebInterceptorInjectHandler.java @@ -70,16 +70,20 @@ private void injectInterceptors(String target) { return; } + //获取这个拦截器下的所有拦截器 + //如果没有拦截器,直接返回 Interceptor[] interceptors = action.getInterceptors(); if (interceptors == null || interceptors.length == 0) { return; } //如果注入过了,就没必要再次注入 + //因为拦截器是在整个系统中是单例的 if (injectFlags.contains(target)) { return; } + //对所有拦截器进行注入 for (Interceptor interceptor : interceptors) { Jboot.injectMembers(interceptor); }