Skip to content

Commit cdbad69

Browse files
author
zhangjunfeng
committed
vertx-rest-refact
1 parent edbdc83 commit cdbad69

644 files changed

Lines changed: 6640 additions & 45352 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

modules/core/src/main/java/org/apache/ignite/configuration/IgniteConfiguration.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,9 @@ public class IgniteConfiguration {
273273

274274
/** Optional local Ignite instance name. */
275275
private String igniteInstanceName;
276+
277+
/** Optional cluster comment. */
278+
private String comment;
276279

277280
/** User attributes. */
278281
private Map<String, ?> userAttrs;
@@ -3495,4 +3498,12 @@ public IgniteConfiguration setDistributedPropertiesDefaultValues(Map<String, Str
34953498
@Override public String toString() {
34963499
return S.toString(IgniteConfiguration.class, this);
34973500
}
3501+
3502+
public String getComment() {
3503+
return comment;
3504+
}
3505+
3506+
public void setComment(String comment) {
3507+
this.comment = comment;
3508+
}
34983509
}

modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/redis/GridRedisNioListener.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,8 @@ private void updateStateInfo(GridNioSession ses) {
193193
U.warn(log, "Cannot find the corresponding command (session will be closed) [ses=" + ses +
194194
", command=" + msg.aux(0) + ']');
195195

196-
ses.close();
196+
msg.setResponse(GridRedisProtocolParser.toGenericError("ERR unknown command '"+msg.aux(0)+"'"));
197+
sendResponse(ses, msg);
197198

198199
return;
199200
}

modules/core/src/main/java/org/apache/ignite/internal/visor/cache/VisorCacheNamesCollectorTask.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ private VisorCacheNamesCollectorJob(Void arg, boolean debug) {
7373
Map<String, IgniteUuid> caches = new HashMap<>();
7474
Map<String, String> cachesComment = new HashMap<>();
7575
Map<String, String> sqlSchemas = new HashMap<>();
76-
Map<String, String> groups = new HashMap<>();
76+
Map<String, String> tableNames = new HashMap<>();
7777

7878
for (Map.Entry<String, DynamicCacheDescriptor> item : cacheProc.cacheDescriptors().entrySet()) {
7979
DynamicCacheDescriptor cd = item.getValue();
@@ -90,12 +90,17 @@ private VisorCacheNamesCollectorJob(Void arg, boolean debug) {
9090
Collection<QueryEntity> grp = cd.schema().entities();
9191

9292
if (!F.isEmpty(grp)) {
93-
List<String> types = grp.stream().map(s->s.getTableName()).collect(Collectors.toList());
94-
groups.put(item.getKey(),String.join(",", types));
93+
List<String> types = grp.stream().map(s->{
94+
if(s.getValueType().equalsIgnoreCase(s.getTableName()))
95+
return s.getValueType();
96+
return s.getValueType()+":"+s.getTableName();
97+
98+
}).collect(Collectors.toList());
99+
tableNames.put(item.getKey(),String.join(",", types));
95100
}
96101
}
97102

98-
return new VisorCacheNamesCollectorTaskResult(caches, cachesComment, sqlSchemas, groups);
103+
return new VisorCacheNamesCollectorTaskResult(caches, cachesComment, sqlSchemas, tableNames);
99104
}
100105

101106
/** {@inheritDoc} */

modules/core/src/main/java/org/apache/ignite/internal/visor/cache/VisorCacheNamesCollectorTaskResult.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public class VisorCacheNamesCollectorTaskResult extends IgniteDataTransferObject
4444
/** Cache sqlSchemas. */
4545
private Map<String, String> sqlSchemas;
4646

47-
/** Cache types. */
47+
/** Cache tableNames. */
4848
private Map<String, String> types;
4949

5050
/**

modules/vertx-rest/pom.xml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
<properties>
3838
<vertx.version>4.4.5</vertx.version>
3939
<jmail.version>1.6.7</jmail.version>
40+
<hutool.version>5.7.11</hutool.version>
4041
</properties>
4142

4243
<dependencies>
@@ -157,11 +158,12 @@
157158
<artifactId>vertx-web-client</artifactId>
158159
<version>${vertx.version}</version>
159160
</dependency>
161+
160162
<!--Hutool Java工具包-->
161163
<dependency>
162164
<groupId>cn.hutool</groupId>
163165
<artifactId>hutool-core</artifactId>
164-
<version>5.4.0</version>
166+
<version>${hutool.version}</version>
165167
</dependency>
166168
<dependency>
167169
<groupId>org.slf4j</groupId>
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package io.vertx.webmvc;
2+
3+
4+
import io.vertx.core.Vertx;
5+
6+
public abstract class VertxInstanceAware {
7+
protected Vertx vertx;
8+
protected String igniteInstanceName;
9+
10+
public void setVertx(Vertx vertx) {
11+
this.vertx = vertx;
12+
}
13+
14+
public void setIgniteInstanceName(String igniteInstanceName) {
15+
this.igniteInstanceName = igniteInstanceName;
16+
}
17+
18+
public String getIgniteInstanceName() {
19+
return igniteInstanceName;
20+
}
21+
}

modules/vertx-rest/src/main/java/io/vertx/webmvc/Vertxlet.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@
1515
import io.vertx.webmvc.common.VertxletException;
1616
import io.vertx.webmvc.common.VertxHttpServerResponseOutputStream;
1717
import io.vertx.webmvc.common.WebConstant;
18+
import io.vertx.webmvc.VertxInstanceAware;
1819

19-
public abstract class Vertxlet implements Handler<RoutingContext>, ApplicationContextAware, java.io.Serializable {
20+
public abstract class Vertxlet extends VertxInstanceAware implements Handler<RoutingContext>, ApplicationContextAware, java.io.Serializable {
2021

2122
private ApplicationContext springContext;
2223

modules/vertx-rest/src/main/java/io/vertx/webmvc/controller/BaseRestController.java renamed to modules/vertx-rest/src/main/java/io/vertx/webmvc/controller/VertxContextRestController.java

Lines changed: 35 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
package io.vertx.webmvc.controller;
22

3+
import io.vertx.core.Context;
4+
import io.vertx.core.impl.ContextBase;
5+
import io.vertx.core.impl.ContextInternal;
36
import io.vertx.core.json.JsonObject;
7+
import io.vertx.core.shareddata.LocalMap;
48
import io.vertx.ext.auth.User;
59
import io.vertx.ext.web.Router;
610
import io.vertx.ext.web.RoutingContext;
11+
import io.vertx.webmvc.VertxInstanceAware;
712
import io.vertx.webmvc.annotation.AuthedUser;
813
import io.vertx.webmvc.common.ResultDTO;
914

@@ -13,25 +18,36 @@
1318
import org.springframework.web.bind.annotation.*;
1419

1520
@RestController
16-
@RequestMapping("/memcache")
17-
public class BaseRestController {
18-
JsonObject cache = new JsonObject();
19-
Router subRouter;
20-
21-
21+
@RequestMapping("/vertx-ctx")
22+
public class VertxContextRestController extends VertxInstanceAware{
23+
static final String cacheName = "__cache__";
24+
25+
private Router subRouter;
26+
27+
private LocalMap<String,JsonObject> cache() {
28+
LocalMap<String,JsonObject> cache = vertx.sharedData().getLocalMap(cacheName);
29+
return cache;
30+
}
2231

2332
@GetMapping("/")
24-
public ResultDTO<Set<String>> list(RoutingContext rc) {
25-
return ResultDTO.success(cache.fieldNames());
33+
public ResultDTO<JsonObject> list(RoutingContext rc) {
34+
35+
JsonObject data = new JsonObject();
36+
cache().forEach((k,v)->{
37+
data.put(k.toString(), v);
38+
});
39+
40+
return ResultDTO.success(data);
2641
}
2742

2843
@GetMapping("/test/*")
2944
public ResultDTO<Set<String>> test(RoutingContext rc) {
45+
3046
JsonObject data = JsonObject.of("headers",rc.request().headers().entries());
3147
data.put("cookies", rc.request().cookieMap());
32-
String key = rc.request().uri().substring("/memcache/test/".length()).replace('/', '-');
33-
cache.put(key,data);
34-
return ResultDTO.success(cache.fieldNames());
48+
String key = rc.request().uri().substring("/vertx-ctx/test/".length()).replace('/', '-');
49+
cache().put(key,data);
50+
return ResultDTO.success(data.fieldNames());
3551
}
3652

3753
/**
@@ -69,7 +85,8 @@ else if(path.charAt(0)=='/') {
6985

7086
@GetMapping("/:id")
7187
public ResultDTO<JsonObject> get(@PathVariable("id") String id,String name) {
72-
JsonObject data = cache.getJsonObject(id);
88+
89+
JsonObject data = cache().get(id);
7390
if(data!=null) {
7491
return ResultDTO.success(data);
7592
}
@@ -79,7 +96,8 @@ public ResultDTO<JsonObject> get(@PathVariable("id") String id,String name) {
7996
@AuthedUser
8097
@DeleteMapping("/:id")
8198
public ResultDTO<String> delete(@PathVariable("id") String id,@AuthedUser String author) {
82-
Object data = cache.remove(id);
99+
100+
Object data = cache().remove(id);
83101
if(data!=null) {
84102
return ResultDTO.success("OK");
85103
}
@@ -88,15 +106,16 @@ public ResultDTO<String> delete(@PathVariable("id") String id,@AuthedUser String
88106

89107
@AuthedUser
90108
@PostMapping("")
91-
public ResultDTO<String> save(@PathVariable("id") String id,@RequestBody JsonObject data,@AuthedUser User author) {
92-
cache.put(id, data);
109+
public ResultDTO<String> save(@PathVariable("id") String id,@RequestBody JsonObject data,@AuthedUser User author) {
110+
cache().put(id, data);
93111
return ResultDTO.success("OK");
94112
}
95113

96114
@AuthedUser
97115
@PutMapping({"/:id","/update/:id"})
98116
public ResultDTO<String> update(@PathVariable("id") String id,@RequestBody JsonObject patchData,@AuthedUser User author) {
99-
JsonObject data = cache.getJsonObject(id);
117+
118+
JsonObject data = cache().get(id);
100119
if(data!=null) {
101120
patchData.forEach((Entry<String,Object> ent)->{
102121
data.put(ent.getKey(), ent.getValue());

modules/vertx-rest/src/main/java/io/vertx/webmvc/creater/WebApiCreater.java

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
package io.vertx.webmvc.creater;
22

33
import io.vertx.core.AbstractVerticle;
4+
import io.vertx.core.Context;
45
import io.vertx.core.Promise;
6+
import io.vertx.core.Vertx;
57
import io.vertx.core.http.HttpMethod;
68
import io.vertx.core.http.HttpServer;
79
import io.vertx.core.http.HttpServerOptions;
@@ -11,6 +13,7 @@
1113
import io.vertx.ext.web.handler.ErrorHandler;
1214
import io.vertx.ext.web.handler.StaticHandler;
1315
import io.vertx.webmvc.Vertxlet;
16+
import io.vertx.webmvc.VertxInstanceAware;
1417
import io.vertx.webmvc.annotation.VertxletMapping;
1518
import io.vertx.webmvc.creater.handler.InitSingleRouterHandler;
1619
import io.vertx.webmvc.utils.SpringUtils;
@@ -55,9 +58,12 @@ public class WebApiCreater extends AbstractVerticle {
5558
private HttpServer server;
5659

5760
private Consumer<Router> readyCallback;
58-
59-
6061

62+
protected String igniteInstanceName;
63+
64+
public void setIgniteInstanceName(String igniteInstanceName) {
65+
this.igniteInstanceName = igniteInstanceName;
66+
}
6167

6268
public WebApiCreater(ApplicationContext applicationContext,HttpServerOptions options) {
6369
springContext = applicationContext;
@@ -148,7 +154,6 @@ public void start(Promise<Void> startPromise) {
148154
String staticDirs = getProperty("spring.web.resources.static-locations");
149155

150156
HttpServer server = vertx.createHttpServer(options);
151-
152157
router = Router.router(vertx);
153158
router.route().handler(BodyHandler.create());
154159
router.route().last().failureHandler(ErrorHandler.create(vertx));
@@ -157,7 +162,7 @@ public void start(Promise<Void> startPromise) {
157162
//将所有的controller转换成router
158163
try {
159164
// 获取所有beanNames
160-
String[] beanNames = SpringUtils.getBeanNamesForType(Object.class);
165+
String[] beanNames = SpringUtils.getBeanNamesForType(null);
161166
for (String beanName : beanNames) {
162167
try {
163168
RestController restController = SpringUtils.findAnnotationOnBean(beanName, RestController.class);
@@ -172,6 +177,12 @@ public void start(Promise<Void> startPromise) {
172177
}
173178
log.info("[vertx web] prefix:" + prefixName);
174179
Object newInstance = SpringUtils.getBean(beanName);
180+
if(newInstance instanceof VertxInstanceAware) {
181+
VertxInstanceAware vertRestController = (VertxInstanceAware)newInstance;
182+
vertRestController.setVertx(vertx);
183+
vertRestController.setIgniteInstanceName(igniteInstanceName);
184+
}
185+
175186
Method[] methods = ReflectionUtils.getAllDeclaredMethods(newInstance.getClass());
176187
for (Method method : methods) {
177188
initSingleRouterHandler.exec(method,prefixName,newInstance,router);
@@ -183,6 +194,8 @@ public void start(Promise<Void> startPromise) {
183194
if (vertxletController != null) {
184195

185196
Vertxlet vertxlet = SpringUtils.getBean(beanName,Vertxlet.class);
197+
vertxlet.setVertx(vertx);
198+
vertxlet.setIgniteInstanceName(igniteInstanceName);
186199
for (String url : vertxlet.getClass().getAnnotation(VertxletMapping.class).url()) {
187200
log.info("Mapping url {} with class {}", url, vertxlet.getClass().getName());
188201
vertxletMap.put(url, vertxlet);

modules/vertx-rest/src/main/java/io/vertx/webmvc/creater/handler/SingleRouterHandler.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ protected SingleRouterHandler() {
5454

5555
public static void out(RoutingContext ctx, Object msg) {
5656
if(msg==null) {
57+
ctx.response().end();
5758
return;
5859
}
5960

@@ -201,7 +202,7 @@ protected void webHandle(RoutingContext ctx, Method method, String prefix, Strin
201202
log.info("[vertx web] objects:{}", Arrays.toString(parameters));
202203
log.info("[vertx web] api has benn invoke.The api name is:" + prefix + url);
203204
boolean isAync = Future.class.isAssignableFrom(method.getReturnType()) || java.util.concurrent.Future.class.isAssignableFrom(method.getReturnType());
204-
if (isAync || "void".equals(method.getReturnType().getTypeName())) {
205+
if (isAync || "void".equalsIgnoreCase(method.getReturnType().getTypeName())) {
205206
log.info("[vertx web] this method returnType is void");
206207
try {
207208
//method.invoke(classBean,parameters);
@@ -214,6 +215,7 @@ protected void webHandle(RoutingContext ctx, Method method, String prefix, Strin
214215
ctx.response().setStatusCode(500);
215216
}
216217
ctx.response().setStatusMessage(e.getMessage());
218+
ctx.response().end();
217219

218220
}
219221

@@ -230,6 +232,7 @@ protected void webHandle(RoutingContext ctx, Method method, String prefix, Strin
230232
ctx.response().setStatusCode(500);
231233
}
232234
ctx.response().setStatusMessage(e.getMessage());
235+
ctx.response().end();
233236
}
234237
}
235238
}

0 commit comments

Comments
 (0)