模块化拆分
This commit is contained in:
@@ -2,8 +2,15 @@ package cn.celess.common;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
import org.springframework.context.annotation.FilterType;
|
||||
|
||||
@SpringBootApplication
|
||||
@SpringBootApplication(
|
||||
scanBasePackageClasses = {
|
||||
CommonApplication.class
|
||||
}
|
||||
)
|
||||
@ComponentScan(excludeFilters = {@ComponentScan.Filter(type = FilterType.REGEX, pattern = "cn.celess.common.test.BaseRedisTest")})
|
||||
public class CommonApplication {
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(CommonApplication.class, args);
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package cn.celess.common.test;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import redis.embedded.RedisServer;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
@@ -10,7 +12,9 @@ import java.io.IOException;
|
||||
* @author : xiaohai
|
||||
* @date : 2020/08/14 16:20
|
||||
*/
|
||||
public class RedisServerMock extends BaseTest {
|
||||
@Configuration
|
||||
@Slf4j
|
||||
public class BaseRedisTest extends BaseTest {
|
||||
private static RedisServer redisServer;
|
||||
|
||||
@PostConstruct
|
||||
@@ -19,14 +23,19 @@ public class RedisServerMock extends BaseTest {
|
||||
if (redisServer == null) {
|
||||
redisServer = new RedisServer(6380);
|
||||
redisServer.start();
|
||||
log.info("start Redis success");
|
||||
}
|
||||
} catch (IOException e) {
|
||||
log.error("start Redis failed");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@PreDestroy
|
||||
@PreDestroy()
|
||||
public static void stopRedis() {
|
||||
if (redisServer.isActive()) redisServer.stop();
|
||||
if (redisServer.isActive()) {
|
||||
redisServer.stop();
|
||||
log.info("stop Redis success");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -15,10 +15,14 @@ import java.io.IOException;
|
||||
* @Desc:
|
||||
*/
|
||||
public class HttpUtil {
|
||||
|
||||
/**
|
||||
* FIXME
|
||||
* 获取http请求的响应
|
||||
*
|
||||
* @param url url链接
|
||||
* @return 请求的响应
|
||||
*/
|
||||
public static String get(String urlStr) {
|
||||
public static String getHttpResponse(String url) {
|
||||
try (final WebClient webClient = new WebClient(BrowserVersion.CHROME)) {
|
||||
webClient.getOptions().setCssEnabled(false);
|
||||
webClient.getOptions().setJavaScriptEnabled(false);
|
||||
@@ -27,18 +31,18 @@ public class HttpUtil {
|
||||
webClient.getOptions().setDownloadImages(false);
|
||||
webClient.getOptions().setActiveXNative(false);
|
||||
webClient.setAjaxController(new NicelyResynchronizingAjaxController());
|
||||
Page clientPage = webClient.getPage(urlStr);
|
||||
if (clientPage.isHtmlPage()) {
|
||||
return clientPage.toString();
|
||||
}
|
||||
return null;
|
||||
Page clientPage = webClient.getPage(url);
|
||||
return clientPage.getWebResponse().getContentAsString();
|
||||
} catch (IOException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* FIXME
|
||||
* 获取渲染后的网页数据
|
||||
*
|
||||
* @param url url链接
|
||||
* @return 经js渲染后的网页源代码
|
||||
*/
|
||||
public static String getAfterRendering(String url) {
|
||||
try (final WebClient webClient = new WebClient(BrowserVersion.BEST_SUPPORTED)) {
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package cn.celess.common.util;
|
||||
|
||||
import cn.celess.common.CommonBaseTest;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
@@ -9,9 +8,8 @@ import static org.junit.Assert.assertNotNull;
|
||||
public class HttpUtilTest extends CommonBaseTest {
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
public void get() {
|
||||
String s = HttpUtil.get("https://api.celess.cn/headerInfo");
|
||||
String s = HttpUtil.getHttpResponse("https://api.celess.cn/headerInfo");
|
||||
assertNotNull(s);
|
||||
// Response<Map<String, Object>> response = getResponse(s, MAP_OBJECT_TYPE);
|
||||
// assertEquals(ResponseEnum.SUCCESS.getCode(), response.getCode());
|
||||
|
||||
Reference in New Issue
Block a user