Skip to content

Commit 3821403

Browse files
committed
升级spring-boot为1.4.2
1 parent 08005fd commit 3821403

File tree

19 files changed

+1896
-5
lines changed

19 files changed

+1896
-5
lines changed

hsweb-web-controller/src/main/java/org/hsweb/web/controller/classified/ClassifiedController.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import org.hsweb.web.bean.po.classified.Classified;
2121
import org.hsweb.web.controller.GenericController;
2222
import org.hsweb.web.core.authorize.annotation.Authorize;
23+
import org.hsweb.web.core.logger.annotation.AccessLogger;
2324
import org.hsweb.web.core.message.ResponseMessage;
2425
import org.hsweb.web.service.classified.ClassifiedService;
2526
import org.springframework.web.bind.annotation.CrossOrigin;
@@ -37,6 +38,7 @@
3738
@RestController
3839
@RequestMapping(value = "/classified")
3940
@Authorize(module = "classified")
41+
@AccessLogger("分类管理")
4042
public class ClassifiedController extends GenericController<Classified, String> {
4143

4244
@Resource
@@ -57,6 +59,7 @@ public ClassifiedService getService() {
5759
*/
5860
@RequestMapping(value = "/byType/{type}")
5961
@Deprecated
62+
@AccessLogger(value = "根据类别请求", describe = "已弃用")
6063
public ResponseMessage listByTypeOld(@PathVariable("type") String type, QueryParam param) {
6164
param.where("type", type);
6265
return list(param);
@@ -71,7 +74,7 @@ public ResponseMessage listByTypeOld(@PathVariable("type") String type, QueryPar
7174
* @return 查询结果
7275
*/
7376
@RequestMapping(value = "/type/{type}")
74-
@CrossOrigin
77+
@AccessLogger("根据类别请求")
7578
public ResponseMessage listByType(@PathVariable("type") String type, QueryParam param) {
7679
param.where("type", type);
7780
return list(param);
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package org.hsweb.web.controller.cli;
2+
3+
import org.hsweb.web.core.authorize.annotation.Authorize;
4+
import org.hsweb.web.core.logger.annotation.AccessLogger;
5+
import org.hsweb.web.core.message.ResponseMessage;
6+
import org.springframework.web.bind.annotation.*;
7+
8+
import static org.hsweb.web.core.message.ResponseMessage.*;
9+
10+
/**
11+
* @author zhouhao
12+
*/
13+
@RestController
14+
@RequestMapping("/cli")
15+
@AccessLogger("命令行工具")
16+
@Authorize(module = "cli")
17+
public class CliController {
18+
19+
@RequestMapping(value = "/{language}", method = RequestMethod.POST)
20+
@AccessLogger("执行脚本")
21+
@Authorize(action = "exec")
22+
public ResponseMessage exec(@PathVariable String language,
23+
@RequestBody String script) {
24+
return ok();
25+
}
26+
27+
@RequestMapping(value = "/shell", method = RequestMethod.POST)
28+
@AccessLogger("执行Shell脚本")
29+
@Authorize(action = "exec")
30+
public ResponseMessage execShell(@RequestBody String shell, @RequestParam(required = false) String messageHolder) {
31+
32+
return ok();
33+
}
34+
}
Lines changed: 79 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,90 @@
11
package org.hsweb.web.core;
22

3+
import org.hsweb.commons.StringUtils;
4+
import org.hsweb.expands.script.engine.DynamicScriptEngine;
5+
import org.hsweb.expands.script.engine.DynamicScriptEngineFactory;
6+
import org.hsweb.web.bean.po.user.User;
7+
import org.hsweb.web.core.authorize.ExpressionScopeBean;
8+
import org.hsweb.web.core.utils.WebUtil;
9+
import org.slf4j.Logger;
10+
import org.slf4j.LoggerFactory;
11+
import org.springframework.beans.factory.annotation.Autowired;
312
import org.springframework.context.annotation.ComponentScan;
413
import org.springframework.context.annotation.Configuration;
14+
import org.springframework.core.io.Resource;
15+
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
16+
import org.springframework.util.StreamUtils;
17+
18+
import javax.annotation.PostConstruct;
19+
import java.io.IOException;
20+
import java.nio.charset.Charset;
21+
import java.util.HashMap;
22+
import java.util.Map;
23+
import java.util.function.Supplier;
524

6-
/**
7-
* Created by zhouhao on 16-5-6.
8-
*/
925
@Configuration
1026
@ComponentScan("org.hsweb.web.core")
1127
public class CoreAutoConfiguration {
1228

29+
@Autowired(required = false)
30+
private Map<String, ExpressionScopeBean> expressionScopeBeanMap = new HashMap<>();
31+
32+
protected Logger logger = LoggerFactory.getLogger(this.getClass());
33+
34+
private String initializeScript = "classpath*:scripts/startup/initialize.";
35+
36+
@PostConstruct
37+
public void init() {
38+
initScript();
39+
}
40+
41+
private void initScript() {
42+
Map<String, Object> vars = new HashMap<>(expressionScopeBeanMap);
43+
vars.put("LoginUser", (Supplier) () -> WebUtil.getLoginUser());
44+
vars.put("StringUtils", StringUtils.class);
45+
vars.put("User", User.class);
46+
47+
initScript("js", vars);
48+
initScript("groovy", vars);
49+
initScript("java", vars);
50+
initScript("spel", vars);
51+
initScript("ognl", vars);
52+
initScript("ruby", vars);
53+
initScript("python", vars);
54+
//执行脚本
55+
}
56+
57+
private void initScript(String language, Map<String, Object> vars) {
58+
try {
59+
DynamicScriptEngine engine = DynamicScriptEngineFactory.getEngine(language);
60+
if (engine == null) return;
61+
vars.put("logger", LoggerFactory.getLogger("org.hsweb.script.".concat(language)));
62+
vars.put("scriptEngine", engine);
63+
engine.addGlobalVariable(vars);
64+
Resource[] resources = new PathMatchingResourcePatternResolver().getResources(initializeScript.concat(language));
65+
for (Resource resource : resources) {
66+
String script = StreamUtils.copyToString(resource.getInputStream(), Charset.forName("utf-8"));
67+
engine.compile("__tmp", script);
68+
try {
69+
engine.execute("__tmp");
70+
} finally {
71+
engine.remove("__tmp");
72+
}
73+
}
74+
} catch (NullPointerException e) {
75+
//
76+
} catch (IOException e) {
77+
logger.error("读取脚本文件失败", e);
78+
} catch (Exception e) {
79+
logger.error(e.getMessage(), e);
80+
}
81+
}
82+
83+
public static void main(String[] args) throws Exception {
84+
new CoreAutoConfiguration().init();
85+
DynamicScriptEngine e = DynamicScriptEngineFactory.getEngine("javascript");
86+
e.compile("test", "alert('aaa');");
87+
System.out.println(e.execute("test").getIfSuccess());
1388

89+
}
1490
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
var println = function (args) {
2+
try {
3+
logger.info(args);
4+
} catch (e) {
5+
java.lang.System.out.println(args);
6+
}
7+
}
8+
9+
scriptEngine.addGlobalVariable({
10+
"println": println,
11+
"alert": println
12+
});

hsweb-web-dao/hsweb-web-dao-mybatis/src/main/java/org/hsweb/web/mybatis/builder/EasyOrmSqlBuilder.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import org.hsweb.ezorm.rdb.meta.RDBColumnMetaData;
1111
import org.hsweb.ezorm.rdb.meta.RDBDatabaseMetaData;
1212
import org.hsweb.ezorm.rdb.meta.RDBTableMetaData;
13+
import org.hsweb.ezorm.rdb.meta.converter.DateTimeConverter;
1314
import org.hsweb.ezorm.rdb.render.SqlAppender;
1415
import org.hsweb.ezorm.rdb.render.SqlRender;
1516
import org.hsweb.ezorm.rdb.render.dialect.Dialect;
@@ -23,6 +24,7 @@
2324
import org.hsweb.web.core.datasource.DataSourceHolder;
2425
import org.hsweb.web.core.datasource.DatabaseType;
2526
import org.hsweb.web.core.exception.BusinessException;
27+
import org.hsweb.web.core.utils.WebUtil;
2628
import org.hsweb.web.mybatis.plgins.pager.Pager;
2729
import org.hsweb.web.mybatis.utils.ResultMapsUtils;
2830

@@ -113,6 +115,7 @@ protected RDBTableMetaData createMeta(String tableName, String resultMapId) {
113115
if (cached != null) {
114116
return cached;
115117
}
118+
WebUtil
116119
RDBTableMetaData rdbTableMetaData = new RDBTableMetaData();
117120
rdbTableMetaData.setName(tableName);
118121
rdbTableMetaData.setDatabaseMetaData(active);

hsweb-web-message/pom.xml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<parent>
6+
<artifactId>hsweb-framework</artifactId>
7+
<groupId>org.hsweb</groupId>
8+
<version>2.2-SNAPSHOT</version>
9+
</parent>
10+
<modelVersion>4.0.0</modelVersion>
11+
12+
<artifactId>hsweb-web-message</artifactId>
13+
14+
<dependencies>
15+
<dependency>
16+
<groupId>junit</groupId>
17+
<artifactId>junit</artifactId>
18+
<scope>test</scope>
19+
</dependency>
20+
<dependency>
21+
<groupId>org.springframework.boot</groupId>
22+
<artifactId>spring-boot-starter-test</artifactId>
23+
<scope>test</scope>
24+
</dependency>
25+
<dependency>
26+
<groupId>org.springframework.boot</groupId>
27+
<artifactId>spring-boot-starter-activemq</artifactId>
28+
</dependency>
29+
30+
31+
</dependencies>
32+
33+
</project>
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package org.hsweb.web.message;
2+
3+
/**
4+
* @author zhouhao
5+
*/
6+
public class Message {
7+
private String callback;
8+
9+
private String to;
10+
11+
private String from;
12+
13+
private String content;
14+
15+
public String getTo() {
16+
return to;
17+
}
18+
19+
public void setTo(String to) {
20+
this.to = to;
21+
}
22+
23+
public String getFrom() {
24+
return from;
25+
}
26+
27+
public void setFrom(String from) {
28+
this.from = from;
29+
}
30+
31+
public String getContent() {
32+
return content;
33+
}
34+
35+
public void setContent(String content) {
36+
this.content = content;
37+
}
38+
39+
public String getCallback() {
40+
return callback;
41+
}
42+
43+
public void setCallback(String callback) {
44+
this.callback = callback;
45+
}
46+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package org.hsweb.web.message;
2+
3+
/**
4+
* @author zhouhao
5+
*/
6+
public interface MessageManager {
7+
8+
void send(Message message, boolean discardIfUserOffline);
9+
10+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package org.hsweb.web.message;
2+
3+
import org.junit.Test;
4+
import org.junit.runner.RunWith;
5+
import org.springframework.beans.factory.annotation.Autowired;
6+
import org.springframework.boot.test.context.SpringBootTest;
7+
import org.springframework.jms.annotation.EnableJms;
8+
import org.springframework.jms.core.JmsMessagingTemplate;
9+
import org.springframework.test.context.junit4.SpringRunner;
10+
11+
import java.util.HashMap;
12+
13+
14+
/**
15+
* @author zhouhao
16+
*/
17+
@RunWith(SpringRunner.class)
18+
@SpringBootTest(classes = SampleActiveMQApplication.class, properties = "application.yml")
19+
@EnableJms
20+
public class AmqpTests {
21+
22+
@Autowired
23+
private JmsMessagingTemplate jmsMessagingTemplate;
24+
25+
@Test
26+
public void testSend() {
27+
jmsMessagingTemplate.convertAndSend("test", new HashMap<>());
28+
}
29+
30+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package org.hsweb.web.message;
2+
3+
import org.springframework.jms.annotation.JmsListener;
4+
import org.springframework.stereotype.Component;
5+
6+
@Component
7+
public class Consumer {
8+
9+
@JmsListener(destination = "test")
10+
public void receiveQueue(String text) {
11+
System.out.println(text);
12+
}
13+
14+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package org.hsweb.web.message;
2+
3+
import javax.jms.Queue;
4+
5+
import org.apache.activemq.command.ActiveMQQueue;
6+
7+
import org.springframework.boot.SpringApplication;
8+
import org.springframework.boot.autoconfigure.SpringBootApplication;
9+
import org.springframework.context.annotation.Bean;
10+
import org.springframework.jms.annotation.EnableJms;
11+
12+
@SpringBootApplication
13+
@EnableJms
14+
public class SampleActiveMQApplication {
15+
16+
@Bean
17+
public Queue queue() {
18+
return new ActiveMQQueue("test");
19+
}
20+
21+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
spring:
2+
activemq:
3+
in-memory: true
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package org.hsweb.start.scripts.initialize
2+
3+
/**
4+
* @TODO
5+
* @author zhouhao
6+
* @since
7+
*/
8+
class initialize {
9+
}

hsweb-web-starter/src/main/resources/org.hsweb.start.scripts/install/install.groovy

Whitespace-only changes.

0 commit comments

Comments
 (0)