Explorar el Código

@IPU_FIXBUG_2021@weihf@修复sonar违规代码

weihf %!s(int64=4) %!d(string=hace) años
padre
commit
ca26a609f4

+ 6 - 3
ipu-nacos-cloud/src/main/java/com/ai/ipu/server/config/NacosConfig.java

@ -17,9 +17,12 @@ import com.alibaba.nacos.api.config.listener.Listener;
17 17
import com.alibaba.nacos.api.exception.NacosException;
18 18
import com.alibaba.nacos.client.utils.StringUtils;
19 19

20
import lombok.extern.slf4j.Slf4j;
21

20 22
//springcloud也支持在程序中手工注册到配置中心,此时就可以监听到配置中心推送的配置文件。
21 23
//springcloud已经不再支持@NacosConfigListener,配置了也不生效。
22 24
@Configuration
25
@Slf4j
23 26
public class NacosConfig {
24 27
	private String service002Url;
25 28
	private String service002Param;
@ -57,13 +60,13 @@ public class NacosConfig {
57 60
	        ConfigService configService = NacosFactory.createConfigService(properties);
58 61
	        String content = configService.getConfig(dataId, group, timeout);
59 62
	        //从配置中心获取到指定配置,需要自己解析后给service002Url、service002Param赋值
60
	        System.out.println(content);
63
	        log.debug(content);
61 64
	        dealConfigServerConfig(content);
62 65
	        configService.addListener(dataId, group, new Listener() {
63 66
	            @Override
64 67
	            public void receiveConfigInfo(String configInfo) {
65 68
	            	//从配置中心获取到推送来的更新配置信息,需要自己解析给service002Url、service002Param赋值
66
	            	System.out.println(configInfo);
69
	            	log.debug(configInfo);
67 70
	            	dealConfigServerConfig(configInfo);
68 71
	            }
69 72
	
@ -73,7 +76,7 @@ public class NacosConfig {
73 76
	            }
74 77
	        });
75 78
	    } catch (NacosException e) {
76
	        System.err.println(e.getMessage());
79
	        log.error(e.getMessage());
77 80
	    }
78 81
	}
79 82
	

+ 5 - 1
ipu-rest-scaffold/src/main/java/com/ai/ipu/server/RestScaffoldStart.java

@ -1,6 +1,9 @@
1 1
package com.ai.ipu.server;
2 2
3 3
4
import org.slf4j.Logger;
5
import org.slf4j.LoggerFactory;
6
4 7
import com.ai.ipu.basic.util.IpuBaseException;
5 8
import com.ai.ipu.restful.boot.IpuRestApplication;
6 9
import com.ai.ipu.server.handler.AuthHandler;
@ -13,6 +16,7 @@ import com.ai.ipu.server.util.RedisUtil;
13 16
 * @desc SpringBoot应用启动类
14 17
 */
15 18
public class RestScaffoldStart {
19
	private static final Logger log = LoggerFactory.getLogger(RestScaffoldStart.class);
16 20
	private final static String EXCEPTION_MESSAGES_CONFIG = "exception_messages";
17 21
18 22
	public static void main(String[] args) {
@ -28,7 +32,7 @@ public class RestScaffoldStart {
28 32
		try {
29 33
			newArgs = RedisUtil.initRedis(args);
30 34
		} catch (Exception e) {
31
			e.printStackTrace();
35
			log.error(e.getMessage(), e);
32 36
			newArgs = args.clone();
33 37
		}
34 38
		/*启动*/

+ 2 - 2
ipu-rest-scaffold/src/main/java/com/ai/ipu/server/config/RedisSessionConfig.java

@ -7,8 +7,8 @@ import org.springframework.session.data.redis.config.annotation.web.http.EnableR
7 7
 * 添加@EnableRedisHttpSession来开启spring session支持
8 8
 */
9 9
@Configuration
10
// maxInactiveIntervalInSeconds 默认是1800秒过期,这里测试修改为60秒
11
@EnableRedisHttpSession(maxInactiveIntervalInSeconds = 60)
10
// maxInactiveIntervalInSeconds 默认是1800秒过期
11
@EnableRedisHttpSession(maxInactiveIntervalInSeconds = 1800)
12 12
public class RedisSessionConfig {
13 13

14 14
}

+ 4 - 3
ipu-rest-scaffold/src/main/java/com/ai/ipu/server/config/RedisSessionInterceptor.java

@ -4,7 +4,8 @@ package com.ai.ipu.server.config;
4 4
import javax.servlet.http.HttpServletRequest;
5 5
import javax.servlet.http.HttpServletResponse;
6 6

7

7
import org.slf4j.Logger;
8
import org.slf4j.LoggerFactory;
8 9
import org.springframework.beans.factory.annotation.Autowired;
9 10
import org.springframework.http.HttpStatus;
10 11
import org.springframework.web.servlet.HandlerInterceptor;
@ -18,7 +19,7 @@ import com.ai.ipu.server.util.RedisUtil;
18 19
 * 登录状态拦截器RedisSessionInterceptor
19 20
 */
20 21
public class RedisSessionInterceptor implements HandlerInterceptor {
21

22
	private static final Logger log = LoggerFactory.getLogger(RedisSessionInterceptor.class);
22 23
    @Autowired
23 24
    private RedisUtil redisUtil;
24 25

@ -34,7 +35,7 @@ public class RedisSessionInterceptor implements HandlerInterceptor {
34 35
					return true;
35 36
				}
36 37
			} catch (Exception e) {
37
				e.printStackTrace();
38
				log.error(e.getMessage(), e);
38 39
			}
39 40
		}
40 41
		throw new IpuException(HttpStatus.UNAUTHORIZED+"-用户未登录!");

+ 4 - 3
ipu-service-demo/src/test/java/com/ai/ipu/service/demo/impl/EchoServiceTest.java

@ -2,17 +2,19 @@ package com.ai.ipu.service.demo.impl;
2 2

3 3
import junit.framework.TestCase;
4 4

5
import org.slf4j.Logger;
6
import org.slf4j.LoggerFactory;
5 7
import org.springframework.context.support.ClassPathXmlApplicationContext;
6 8

7 9
import com.ai.ipu.service.IpuServiceDemoStart;
8 10
import com.alibaba.dubbo.rpc.service.EchoService;
9 11

10 12
public class EchoServiceTest extends TestCase{
13
	private static final Logger log = LoggerFactory.getLogger(EchoServiceTest.class);
11 14
    private ClassPathXmlApplicationContext context;
12 15
    
13 16
    @Override
14 17
    protected void setUp() throws Exception {
15
        // TODO Auto-generated method stub
16 18
        context = new ClassPathXmlApplicationContext(new String[] { IpuServiceDemoStart.DUBBO_CONSUMER_CONFIG });
17 19
        context.start();
18 20
    }
@ -23,10 +25,9 @@ public class EchoServiceTest extends TestCase{
23 25
     * @desc: 回声测试可用性,回声测试用于检测服务是否可用,用于监控
24 26
     */
25 27
    public void testEchoService() {
26
        // TODO Auto-generated method stub
27 28
        EchoService echoService = (EchoService)context.getBean("bizService"); 
28 29
        Object status = echoService.$echo("OK");
29
        System.out.println("bizService的服务状态:" + status);
30
        log.debug("bizService的服务状态:" + status);
30 31
        assert(status.equals("OK"));
31 32
    }
32 33
}