重构HttpServlet
This commit is contained in:
@@ -25,16 +25,16 @@ public class SimpleRestServlet extends RestHttpServlet<UserInfo> {
|
||||
|
||||
//普通鉴权
|
||||
@Override
|
||||
public void authenticate(int module, int actionid, HttpRequest request, HttpResponse response, HttpServlet next) throws IOException {
|
||||
public void authenticate(HttpRequest request, HttpResponse response) throws IOException {
|
||||
UserInfo info = currentUser(request);
|
||||
if (info == null) {
|
||||
response.finishJson(RET_UNLOGIN);
|
||||
return;
|
||||
} else if (!info.checkAuth(module, actionid)) {
|
||||
} else if (!info.checkAuth(request.getModuleid(), request.getActionid())) {
|
||||
response.finishJson(RET_AUTHILLEGAL);
|
||||
return;
|
||||
}
|
||||
next.execute(request, response);
|
||||
response.nextEvent();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -48,7 +48,7 @@ public class _DynHelloRestServlet1 extends SimpleRestServlet {
|
||||
}
|
||||
|
||||
@AuthIgnore
|
||||
@WebMapping(url = "/hello/create")
|
||||
@HttpMapping(url = "/hello/create")
|
||||
public void create(HttpRequest req, HttpResponse resp) throws IOException {
|
||||
HelloService service = _servicemap == null ? _service : _servicemap.get(req.getHeader(Rest.REST_HEADER_RESOURCE_NAME, ""));
|
||||
HelloEntity bean = req.getJsonParameter(HelloEntity.class, "bean");
|
||||
@@ -60,7 +60,7 @@ public class _DynHelloRestServlet1 extends SimpleRestServlet {
|
||||
}
|
||||
|
||||
@AuthIgnore
|
||||
@WebMapping(url = "/hello/delete/")
|
||||
@HttpMapping(url = "/hello/delete/")
|
||||
public void delete(HttpRequest req, HttpResponse resp) throws IOException {
|
||||
HelloService service = _servicemap == null ? _service : _servicemap.get(req.getHeader(Rest.REST_HEADER_RESOURCE_NAME, ""));
|
||||
int id = Integer.parseInt(req.getRequstURILastPath());
|
||||
@@ -69,7 +69,7 @@ public class _DynHelloRestServlet1 extends SimpleRestServlet {
|
||||
}
|
||||
|
||||
@AuthIgnore
|
||||
@WebMapping(url = "/hello/update")
|
||||
@HttpMapping(url = "/hello/update")
|
||||
public void update(HttpRequest req, HttpResponse resp) throws IOException {
|
||||
HelloService service = _servicemap == null ? _service : _servicemap.get(req.getHeader(Rest.REST_HEADER_RESOURCE_NAME, ""));
|
||||
String clientaddr = req.getRemoteAddr();
|
||||
@@ -81,7 +81,7 @@ public class _DynHelloRestServlet1 extends SimpleRestServlet {
|
||||
}
|
||||
|
||||
@AuthIgnore
|
||||
@WebMapping(url = "/hello/partupdate")
|
||||
@HttpMapping(url = "/hello/partupdate")
|
||||
public void partupdate(HttpRequest req, HttpResponse resp) throws IOException {
|
||||
HelloService service = _servicemap == null ? _service : _servicemap.get(req.getHeader(Rest.REST_HEADER_RESOURCE_NAME, ""));
|
||||
HelloEntity bean = req.getJsonParameter(HelloEntity.class, "bean");
|
||||
@@ -93,7 +93,7 @@ public class _DynHelloRestServlet1 extends SimpleRestServlet {
|
||||
}
|
||||
|
||||
@AuthIgnore
|
||||
@WebMapping(url = "/hello/query")
|
||||
@HttpMapping(url = "/hello/query")
|
||||
public void query(HttpRequest req, HttpResponse resp) throws IOException {
|
||||
HelloService service = _servicemap == null ? _service : _servicemap.get(req.getHeader(Rest.REST_HEADER_RESOURCE_NAME, ""));
|
||||
HelloBean bean = req.getJsonParameter(HelloBean.class, "bean");
|
||||
@@ -107,7 +107,7 @@ public class _DynHelloRestServlet1 extends SimpleRestServlet {
|
||||
}
|
||||
|
||||
@AuthIgnore
|
||||
@WebMapping(url = "/hello/list")
|
||||
@HttpMapping(url = "/hello/list")
|
||||
public void list(HttpRequest req, HttpResponse resp) throws IOException {
|
||||
HelloService service = _servicemap == null ? _service : _servicemap.get(req.getHeader(Rest.REST_HEADER_RESOURCE_NAME, ""));
|
||||
HelloBean bean = req.getJsonParameter(HelloBean.class, "bean");
|
||||
@@ -120,7 +120,7 @@ public class _DynHelloRestServlet1 extends SimpleRestServlet {
|
||||
}
|
||||
|
||||
@AuthIgnore
|
||||
@WebMapping(url = "/hello/find/")
|
||||
@HttpMapping(url = "/hello/find/")
|
||||
public void find(HttpRequest req, HttpResponse resp) throws IOException {
|
||||
HelloService service = _servicemap == null ? _service : _servicemap.get(req.getHeader(Rest.REST_HEADER_RESOURCE_NAME, ""));
|
||||
int id = Integer.parseInt(req.getRequstURILastPath());
|
||||
@@ -129,7 +129,7 @@ public class _DynHelloRestServlet1 extends SimpleRestServlet {
|
||||
}
|
||||
|
||||
@AuthIgnore
|
||||
@WebMapping(url = "/hello/asyncfind/")
|
||||
@HttpMapping(url = "/hello/asyncfind/")
|
||||
public void asyncfind(HttpRequest req, HttpResponse resp) throws IOException {
|
||||
HelloService service = _servicemap == null ? _service : _servicemap.get(req.getHeader(Rest.REST_HEADER_RESOURCE_NAME, ""));
|
||||
int id = Integer.parseInt(req.getRequstURILastPath());
|
||||
|
||||
@@ -11,7 +11,7 @@ import javax.annotation.Resource;
|
||||
import org.redkale.net.http.*;
|
||||
import org.redkale.service.RetResult;
|
||||
import org.redkale.source.Flipper;
|
||||
import org.redkale.util.Sheet;
|
||||
import org.redkale.util.*;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -27,8 +27,8 @@ public class _DynHelloRestServlet2 extends SimpleRestServlet {
|
||||
private Map<String, HelloService2> _servicemap;
|
||||
|
||||
@AuthIgnore
|
||||
@WebMapping(url = "/hello/create", comment = "创建Hello对象")
|
||||
@WebParam(name = "bean", type = HelloEntity.class, comment = "Hello对象")
|
||||
@HttpMapping(url = "/hello/create", comment = "创建Hello对象")
|
||||
@HttpParam(name = "bean", type = HelloEntity.class, comment = "Hello对象")
|
||||
public void create(HttpRequest req, HttpResponse resp) throws IOException {
|
||||
HelloService2 service = _servicemap == null ? _service : _servicemap.get(req.getHeader(Rest.REST_HEADER_RESOURCE_NAME, ""));
|
||||
HelloEntity bean = req.getJsonParameter(HelloEntity.class, "bean");
|
||||
@@ -42,8 +42,8 @@ public class _DynHelloRestServlet2 extends SimpleRestServlet {
|
||||
}
|
||||
|
||||
@AuthIgnore
|
||||
@WebMapping(url = "/hello/delete/", comment = "根据id删除Hello对象")
|
||||
@WebParam(name = "#", type = int.class, comment = "Hello对象id")
|
||||
@HttpMapping(url = "/hello/delete/", comment = "根据id删除Hello对象")
|
||||
@HttpParam(name = "#", type = int.class, comment = "Hello对象id")
|
||||
public void delete(HttpRequest req, HttpResponse resp) throws IOException {
|
||||
HelloService2 service = _servicemap == null ? _service : _servicemap.get(req.getHeader(Rest.REST_HEADER_RESOURCE_NAME, ""));
|
||||
int id = Integer.parseInt(req.getRequstURILastPath());
|
||||
@@ -52,8 +52,8 @@ public class _DynHelloRestServlet2 extends SimpleRestServlet {
|
||||
}
|
||||
|
||||
@AuthIgnore
|
||||
@WebMapping(url = "/hello/update", comment = "修改Hello对象")
|
||||
@WebParam(name = "bean", type = HelloEntity.class, comment = "Hello对象")
|
||||
@HttpMapping(url = "/hello/update", comment = "修改Hello对象")
|
||||
@HttpParam(name = "bean", type = HelloEntity.class, comment = "Hello对象")
|
||||
public void update(HttpRequest req, HttpResponse resp) throws IOException {
|
||||
HelloService2 service = _servicemap == null ? _service : _servicemap.get(req.getHeader(Rest.REST_HEADER_RESOURCE_NAME, ""));
|
||||
HelloEntity bean = req.getJsonParameter(HelloEntity.class, "bean");
|
||||
@@ -66,8 +66,8 @@ public class _DynHelloRestServlet2 extends SimpleRestServlet {
|
||||
}
|
||||
|
||||
@AuthIgnore
|
||||
@WebMapping(url = "/hello/query", comment = "查询Hello对象列表")
|
||||
@WebParam(name = "bean", type = HelloBean.class, comment = "过滤条件")
|
||||
@HttpMapping(url = "/hello/query", comment = "查询Hello对象列表")
|
||||
@HttpParam(name = "bean", type = HelloBean.class, comment = "过滤条件")
|
||||
public void query(HttpRequest req, HttpResponse resp) throws IOException {
|
||||
HelloService2 service = _servicemap == null ? _service : _servicemap.get(req.getHeader(Rest.REST_HEADER_RESOURCE_NAME, ""));
|
||||
HelloBean bean = req.getJsonParameter(HelloBean.class, "bean");
|
||||
@@ -81,8 +81,8 @@ public class _DynHelloRestServlet2 extends SimpleRestServlet {
|
||||
}
|
||||
|
||||
@AuthIgnore
|
||||
@WebMapping(url = "/hello/find/", comment = "根据id删除Hello对象")
|
||||
@WebParam(name = "#", type = int.class, comment = "Hello对象id")
|
||||
@HttpMapping(url = "/hello/find/", comment = "根据id删除Hello对象")
|
||||
@HttpParam(name = "#", type = int.class, comment = "Hello对象id")
|
||||
public void find(HttpRequest req, HttpResponse resp) throws IOException {
|
||||
HelloService2 service = _servicemap == null ? _service : _servicemap.get(req.getHeader(Rest.REST_HEADER_RESOURCE_NAME, ""));
|
||||
int id = Integer.parseInt(req.getRequstURILastPath());
|
||||
|
||||
Reference in New Issue
Block a user