service = MotanUtil.toServiceConfig(config);
+ service.setInterface(interfaceClass);
+ service.setRef((T) object);
+ service.setShareChannel(true);
+ service.setExport(defaultConfig.getExport(interfaceClass.getName()));
+ service.setHost(defaultConfig.getHost(interfaceClass.getName()));
String provider = rpcConfig.getProvider(interfaceClass.getName());
if (provider != null) {
- serviceConfig.setBasicService(MotanUtil.getBaseService(provider));
+ service.setBasicService(MotanUtil.getBaseService(provider));
+ }
+
+ if (service.getGroup() == null) {
+ service.setGroup(rpcConfig.getGroup(interfaceClass.getName()));
+ }
+
+ if (service.getVersion() == null) {
+ service.setVersion(rpcConfig.getVersion(interfaceClass.getName()));
}
- serviceConfig.export();
+ service.export();
MotanSwitcherUtil.setSwitcherValue(MotanConstants.REGISTRY_HEARTBEAT_SWITCHER, true);
}
diff --git a/src/main/java/io/jboot/components/rpc/motan/MotanrpcConfig.java b/src/main/java/io/jboot/components/rpc/motan/MotanrpcConfig.java
index 1f96175f11b28ab8eb92ca906d22a462a1abb401..258c8f1fd74d5907937d8f874566a41b31f55b81 100644
--- a/src/main/java/io/jboot/components/rpc/motan/MotanrpcConfig.java
+++ b/src/main/java/io/jboot/components/rpc/motan/MotanrpcConfig.java
@@ -77,7 +77,7 @@ public class MotanrpcConfig {
}
public String getExport(String className) {
- String export = exports == null ? null : exports.get(className);
+ String export = exports == null || exports.isEmpty() ? null : exports.get(className);
return StrUtil.isNotBlank(export) ? export : defaultExport;
}
@@ -90,7 +90,7 @@ public class MotanrpcConfig {
}
public String getHost(String className) {
- String host = hosts == null ? null : hosts.get(className);
+ String host = hosts == null || hosts.isEmpty() ? null : hosts.get(className);
return StrUtil.isNotBlank(host) ? host : defaultHost;
}
}
diff --git a/src/main/java/io/jboot/core/JbootCoreConfig.java b/src/main/java/io/jboot/core/JbootCoreConfig.java
index d52098103f99521d39b49f4db6d2b936a36a4000..201fa77ac462c29c4f3e6e58020bb007618c2c6d 100644
--- a/src/main/java/io/jboot/core/JbootCoreConfig.java
+++ b/src/main/java/io/jboot/core/JbootCoreConfig.java
@@ -80,7 +80,6 @@ public class JbootCoreConfig extends JFinalConfig {
private JbootRestfulManager.Config restfulConfig = new JbootRestfulManager.Config();
-
public JbootCoreConfig() {
initSystemProperties();
@@ -213,9 +212,9 @@ public class JbootCoreConfig extends JFinalConfig {
.setBaseViewPath(routes.getBaseViewPath())
.setMappingSupperClass(routes.getMappingSuperClass())
.setRouteInterceptors(routes.getInterceptors());
- for (Routes.Route route : restfulRoutes) {
+ restfulRoutes.forEach((Routes.Route route) -> {
JbootControllerManager.me().setMapping(route.getControllerKey(), route.getControllerClass());
- }
+ });
routeList.addAll(restfulRoutes);
}
@@ -293,11 +292,10 @@ public class JbootCoreConfig extends JFinalConfig {
handlers.add(new JbootGatewayHandler());
handlers.add(new JbootFilterHandler());
handlers.add(new JbootHandler());
-// handlers.setActionHandler(new RestfulHandler());
//若用户自己没配置 ActionHandler,默认使用 JbootActionHandler
if (handlers.getActionHandler() == null) {
- if (restfulRoutes.isEmpty()) {
+ if (!restfulRoutes.isEmpty()) {
handlers.setActionHandler(new RestfulHandler());
} else {
handlers.setActionHandler(new JbootActionHandler());
@@ -326,7 +324,6 @@ public class JbootCoreConfig extends JFinalConfig {
JbootGatewayManager.me().init();
JbootRestfulManager.me().init(restfulConfig);
-
JbootAppListenerManager.me().onStart();
}
diff --git a/src/main/java/io/jboot/utils/ClassScanner.java b/src/main/java/io/jboot/utils/ClassScanner.java
index 1fce8cb103a9e5a1a15168c0b67fe49d0d9e1b92..56cb08dd292874694e58ea9466df1588e89a461e 100644
--- a/src/main/java/io/jboot/utils/ClassScanner.java
+++ b/src/main/java/io/jboot/utils/ClassScanner.java
@@ -83,6 +83,7 @@ public class ClassScanner {
excludeJars.add("commons-cli");
excludeJars.add("commons-math");
excludeJars.add("commons-jxpath");
+ excludeJars.add("commons-compress");
excludeJars.add("audience-");
excludeJars.add("hessian-");
excludeJars.add("metrics-");
@@ -214,6 +215,10 @@ public class ClassScanner {
excludeJars.add("hutool-");
excludeJars.add("jakarta.");
excludeJars.add("protostuff-");
+ excludeJars.add("poi-");
+ excludeJars.add("easypoi-");
+ excludeJars.add("ognl-");
+ excludeJars.add("xmlbeans-");
}
@@ -256,7 +261,7 @@ public class ClassScanner {
addUnscanClass("com.rabbitmq.");
addUnscanClass("com.squareup.");
addUnscanClass("com.typesafe.");
- addUnscanClass("com.weibo.");
+ addUnscanClass("com.weibo.api.motan.");
addUnscanClass("com.zaxxer.");
addUnscanClass("com.mysql.");
addUnscanClass("org.gjt.");
diff --git a/src/main/java/io/jboot/components/restful/HttpStatus.java b/src/main/java/io/jboot/web/HttpStatus.java
similarity index 95%
rename from src/main/java/io/jboot/components/restful/HttpStatus.java
rename to src/main/java/io/jboot/web/HttpStatus.java
index aa54f020457de13e9349a2bb34549b8e6d2ae8c8..e1e8833cf18f2119bf77f4f76ca421c52bdfe8e4 100644
--- a/src/main/java/io/jboot/components/restful/HttpStatus.java
+++ b/src/main/java/io/jboot/web/HttpStatus.java
@@ -1,5 +1,24 @@
-package io.jboot.components.restful;
+/**
+ * Copyright (c) 2015-2020, Michael Yang 杨福海 (fuhai999@gmail.com).
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package io.jboot.web;
+/**
+ * @author michael yang (fuhai999@gmail.com)
+ * @Date: 2020/4/6
+ */
public enum HttpStatus {
/**
@@ -401,5 +420,4 @@ public enum HttpStatus {
public String getReasonPhrase() {
return this.reasonPhrase;
}
-
}
diff --git a/src/main/java/io/jboot/web/ResponseEntity.java b/src/main/java/io/jboot/web/ResponseEntity.java
new file mode 100644
index 0000000000000000000000000000000000000000..1e9153d3797508f3a4bddea00565972bd977e196
--- /dev/null
+++ b/src/main/java/io/jboot/web/ResponseEntity.java
@@ -0,0 +1,105 @@
+/**
+ * Copyright (c) 2015-2020, Michael Yang 杨福海 (fuhai999@gmail.com).
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package io.jboot.web;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Objects;
+
+/**
+ * @author michael yang (fuhai999@gmail.com)
+ * @Date: 2020/4/6
+ */
+public class ResponseEntity {
+
+ //响应的数据
+ private Object body;
+
+ //自定义响应头部信息
+ private Map headers;
+
+ //默认http状态
+ private HttpStatus httpStatus = HttpStatus.OK;
+
+
+ public ResponseEntity() {
+ }
+
+ public ResponseEntity(Object body) {
+ this.body = body;
+ }
+
+ public ResponseEntity(Map headers, HttpStatus httpStatus) {
+ this.headers = headers;
+ this.httpStatus = httpStatus;
+ }
+
+ public ResponseEntity(Object body, Map headers, HttpStatus httpStatus) {
+ this.body = body;
+ this.headers = headers;
+ this.httpStatus = httpStatus;
+ }
+
+ public ResponseEntity body(Object body) {
+ this.body = body;
+ return this;
+ }
+
+ public ResponseEntity header(String key, String value) {
+ if (this.headers == null) {
+ this.headers = new HashMap<>();
+ }
+ this.headers.put(key, value);
+ return this;
+ }
+
+ public ResponseEntity status(int status) {
+ for (HttpStatus httpStatus : HttpStatus.values()) {
+ if (Objects.equals(httpStatus.value(), status)) {
+ this.httpStatus = httpStatus;
+ break;
+ }
+ }
+ return this;
+ }
+
+
+ public ResponseEntity status(HttpStatus status) {
+ this.httpStatus = status;
+ return this;
+ }
+
+
+ public T getBody() {
+ return (T) body;
+ }
+
+ public Map getHeaders() {
+ return headers;
+ }
+
+ public HttpStatus getHttpStatus() {
+ return httpStatus;
+ }
+
+
+ public static ResponseEntity ok() {
+ ResponseEntity responseEntity = new ResponseEntity();
+ return responseEntity.status(HttpStatus.OK);
+ }
+
+
+}
diff --git a/src/main/java/io/jboot/web/handler/JbootActionHandler.java b/src/main/java/io/jboot/web/handler/JbootActionHandler.java
index c5a0a4df68cd28b1ba8d49c1a48165c903b9b6e8..114861e8624a1509faf9fa203f57f94b95fb5591 100644
--- a/src/main/java/io/jboot/web/handler/JbootActionHandler.java
+++ b/src/main/java/io/jboot/web/handler/JbootActionHandler.java
@@ -120,7 +120,7 @@ public class JbootActionHandler extends ActionHandler {
}
if (render == null
- && invocation.getReturnValue() != null
+ && void.class != action.getMethod().getReturnType()
&& renderManager.getRenderFactory() instanceof JbootRenderFactory) {
JbootRenderFactory jrf = (JbootRenderFactory) renderManager.getRenderFactory();
render = jrf.getReturnValueRender(action, invocation.getReturnValue());
diff --git a/src/main/java/io/jboot/web/render/JbootResponseEntityRender.java b/src/main/java/io/jboot/web/render/JbootResponseEntityRender.java
new file mode 100644
index 0000000000000000000000000000000000000000..69efd9421bc55c53cc10932273ea435b17939887
--- /dev/null
+++ b/src/main/java/io/jboot/web/render/JbootResponseEntityRender.java
@@ -0,0 +1,65 @@
+/**
+ * Copyright (c) 2015-2016, Michael Yang 杨福海 (fuhai999@gmail.com).
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package io.jboot.web.render;
+
+import com.jfinal.kit.JsonKit;
+import com.jfinal.render.Render;
+import com.jfinal.render.RenderException;
+import io.jboot.web.ResponseEntity;
+
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.util.Map;
+
+/**
+ * @author michael yang (fuhai999@gmail.com)
+ * @Date: 2020/4/7
+ */
+public class JbootResponseEntityRender extends Render {
+
+ private ResponseEntity responseEntity;
+
+ public JbootResponseEntityRender(ResponseEntity responseEntity) {
+ this.responseEntity = responseEntity;
+ }
+
+ @Override
+ public void render() {
+
+ PrintWriter writer = null;
+ try {
+ //默认输出 json,但是 responseEntity 可以配置 Header 覆盖这个输出
+ response.setHeader("Cache-Control", "no-cache");
+ response.setHeader("Content-Type", "application/json; charset=utf-8");
+ response.setStatus(responseEntity.getHttpStatus().value());
+
+ Map headers = responseEntity.getHeaders();
+ if (headers != null && !headers.isEmpty()) {
+ for (Map.Entry entry : headers.entrySet()) {
+ response.setHeader(entry.getKey(), entry.getValue());
+ }
+ }
+
+ String jsonText = responseEntity.getBody() == null ? "" : JsonKit.toJson(responseEntity.getBody());
+ writer = response.getWriter();
+ writer.write(jsonText);
+ // writer.flush();
+ } catch (IOException e) {
+ throw new RenderException(e);
+ }
+
+ }
+}
diff --git a/src/main/java/io/jboot/web/render/JbootReturnValueRender.java b/src/main/java/io/jboot/web/render/JbootReturnValueRender.java
index caab4d1344aa0d2b2778ffdd3c34151e92bb466c..3e923a00bf014864d403c9e833dc58b005caff44 100644
--- a/src/main/java/io/jboot/web/render/JbootReturnValueRender.java
+++ b/src/main/java/io/jboot/web/render/JbootReturnValueRender.java
@@ -17,10 +17,8 @@ package io.jboot.web.render;
import com.jfinal.core.Action;
import com.jfinal.kit.JsonKit;
-import com.jfinal.render.FileRender;
-import com.jfinal.render.JsonRender;
-import com.jfinal.render.Render;
-import com.jfinal.render.TextRender;
+import com.jfinal.render.*;
+import io.jboot.web.ResponseEntity;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@@ -42,19 +40,29 @@ public class JbootReturnValueRender extends Render {
private Render render;
public JbootReturnValueRender(Action action, Object returnValue) {
+
this.action = action;
- if (isBaseType(returnValue)) {
+
+ if (returnValue == null) {
+ this.value = null;
+ } else if (isBaseType(returnValue)) {
this.value = String.valueOf(returnValue);
} else {
this.value = returnValue;
}
- if (this.value instanceof File) {
- this.render = new FileRender((File) value);
+ if (this.value == null) {
+ this.render = new NullRender();
+ } else if (this.value instanceof ResponseEntity) {
+ this.render = new JbootResponseEntityRender((ResponseEntity) value);
} else if (this.value instanceof String) {
this.render = new TextRender((String) value);
} else if (this.value instanceof Date) {
this.render = new TextRender(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format((Date) value));
+ } else if (this.value instanceof File) {
+ this.render = new FileRender((File) value);
+ } else if (this.value instanceof Render) {
+ this.render = (Render) value;
} else {
this.render = new JsonRender(JsonKit.toJson(value));
}
@@ -80,9 +88,6 @@ public class JbootReturnValueRender extends Render {
private boolean isBaseType(Object value) {
- if (value == null) {
- return true;
- }
Class c = value.getClass();
return c == String.class || c == char.class
|| c == Integer.class || c == int.class
diff --git a/src/test/java/io/jboot/test/controller/IndexController.java b/src/test/java/io/jboot/test/controller/IndexController.java
index fcbdf8cd6098c2f020cc815193189a7f0da4cdc3..d402d71831a26d6de7e4890cb7ccb1ad279d725a 100644
--- a/src/test/java/io/jboot/test/controller/IndexController.java
+++ b/src/test/java/io/jboot/test/controller/IndexController.java
@@ -18,4 +18,11 @@ public class IndexController extends JbootController {
public void error500(){
}
+
+ public String ping(){
+ return "ping:" + getPara("ping");
+ }
+
+
+
}
diff --git a/src/test/java/io/jboot/test/gateway/GatewayController.java b/src/test/java/io/jboot/test/gateway/GatewayController.java
new file mode 100644
index 0000000000000000000000000000000000000000..7cca21d82ae58c51d8061956cdc10f07613a0677
--- /dev/null
+++ b/src/test/java/io/jboot/test/gateway/GatewayController.java
@@ -0,0 +1,26 @@
+package io.jboot.test.gateway;
+
+import io.jboot.web.controller.JbootController;
+import io.jboot.web.controller.annotation.RequestMapping;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * @author michael yang (fuhai999@gmail.com)
+ * @Date: 2020/4/5
+ */
+@RequestMapping("/gateway")
+public class GatewayController extends JbootController {
+
+ public void index(){
+
+ }
+
+
+ public void render(){
+ Map map = new HashMap();
+ map.putAll(getParas());
+ renderJson(map);
+ }
+}
diff --git a/src/test/java/io/jboot/test/restful/RestfulController.java b/src/test/java/io/jboot/test/restful/RestfulController.java
index 08a2367da89812b5c180b9358db61380e94cad13..c0774faa90733edee299785279558c8ac297e330 100644
--- a/src/test/java/io/jboot/test/restful/RestfulController.java
+++ b/src/test/java/io/jboot/test/restful/RestfulController.java
@@ -7,15 +7,18 @@ import com.jfinal.aop.Invocation;
import com.jfinal.core.NotAction;
import com.jfinal.kit.JsonKit;
import com.jfinal.kit.StrKit;
-import io.jboot.components.restful.HttpStatus;
-import io.jboot.components.restful.ResponseEntity;
import io.jboot.components.restful.annotation.*;
+import io.jboot.web.HttpStatus;
+import io.jboot.web.ResponseEntity;
import io.jboot.web.controller.JbootController;
import io.jboot.web.controller.annotation.RequestMapping;
import io.jboot.web.cors.EnableCORS;
import java.io.Serializable;
+import java.math.BigDecimal;
+import java.text.SimpleDateFormat;
import java.util.ArrayList;
+import java.util.Date;
import java.util.List;
@RestController
@@ -84,8 +87,10 @@ public class RestfulController extends JbootController {
// GET /restful/users
@GetMapping("/users")
- public ResponseEntity> entityUsers(){
- return new ResponseEntity<>(initData()).addHeader("x-token", StrKit.getRandomUUID()).setHttpStatus(HttpStatus.ACCEPTED);
+ public ResponseEntity entityUsers(){
+ return new ResponseEntity(initData())
+ .header("x-token", StrKit.getRandomUUID())
+ .status(HttpStatus.ACCEPTED);
}
// PUT /restful
@@ -113,5 +118,23 @@ public class RestfulController extends JbootController {
System.out.println("delete by name : " + name);
System.out.println("get token header : " + token);
}
-
+
+ @GetMapping("/get-date")
+ public Date getDate(){
+ return new Date();
+ }
+
+ @PutMapping("/input-date")
+ public void inputDate(@RequestParam @DateFormat Date date){
+ System.out.println("input date:" + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(date));
+ renderNull();
+ }
+
+ @PutMapping("/input-big-decimal")
+ public void inputBigDecimal(@RequestParam BigDecimal num){
+ System.out.println("input bigDecimal:"+num.toString());
+ renderNull();
+ }
+
+
}
diff --git a/src/test/resources/jboot.properties b/src/test/resources/jboot.properties
index 151711f485683539297be6b486cb56d94b56486b..f391de5e3c9e2a101ffbb4c30037ffc69a29037a 100644
--- a/src/test/resources/jboot.properties
+++ b/src/test/resources/jboot.properties
@@ -37,16 +37,11 @@ config.test.test.ccc.name = name3
config.test.test.ccc.type = type3
-# 配置 gateway ,访问首页的时候目标地址设置为 baidu 的地址
+# 配置 gateway ,当访问 /gateway 的时候,自动路由到 /gateway/render
jboot.gateway.enable = true
-jboot.gateway.uri = https://www.baidu.com
-#jboot.gateway.proxyRetries = 2
-jboot.gateway.pathEquals = /
-
-jboot.gateway.gitee.enable = true
-jboot.gateway.gitee.uri= https://gitee.com
-jboot.gateway.gitee.sentinelEnable= true
-jboot.gateway.gitee.sentinelBlockPage= /
-jboot.gateway.gitee.pathStartsWith = /fuhai
+jboot.gateway.uri = http://127.0.0.1:9999/gateway/render
+jboot.gateway.pathEquals = /gateway
+
+
jboot.rpc.type = local