|
@@ -87,18 +87,22 @@ public class ScreenshotUtil {
|
|
|
private FileUtils fileUtils;
|
|
|
|
|
|
public void screenshot(long jobId, List<ImageContent> imageContents, Integer imageWidth) {
|
|
|
+ System.out.println(">>>>>>>>>>>>>>imageContents>>>>>>>>>>>>>>>>"+imageContents.size());
|
|
|
scheduleLogger.info("Start screenshot for job({})", jobId);
|
|
|
try {
|
|
|
int contentsSize = imageContents.size();
|
|
|
List<Future> futures = new ArrayList<>(contentsSize);
|
|
|
final AtomicInteger index = new AtomicInteger(1);
|
|
|
imageContents.forEach(content -> futures.add(executorService.submit(() -> {
|
|
|
+ System.out.println(">>>>>>>>>>>>>>content>>>>>>>>>>>>>>>>"+content.getUrl());
|
|
|
scheduleLogger.info("Cronjob({}) thread({}) for screenshot start, type:{}, id:{}, total:{}", jobId, index.get(), content.getDesc(), content.getCId(), contentsSize);
|
|
|
try {
|
|
|
+ System.out.println(">>>>>>>>>>>>>>生成图片>>>>>>>>>>>>>>>>");
|
|
|
File image = doScreenshot(jobId, content.getUrl(), imageWidth);
|
|
|
content.setContent(image);
|
|
|
+ System.out.println(">>>>>>>>>>>>>>设置文件>>>>>>>>>>>>>>>>");
|
|
|
} catch (Exception e) {
|
|
|
- scheduleLogger.error("Cronjob({}) thread({}) screenshot error", jobId, index.get());
|
|
|
+ scheduleLogger.error("Cronjob({}) thread( {}) screenshot error", jobId, index.get());
|
|
|
scheduleLogger.error(e.getMessage(), e);
|
|
|
} finally {
|
|
|
scheduleLogger.info("Cronjob({}) thread({}) for screenshot finish, type:{}, id:{}, total:{}", jobId, index.get(), content.getDesc(), content.getCId(), contentsSize);
|
|
@@ -124,8 +128,9 @@ public class ScreenshotUtil {
|
|
|
}
|
|
|
|
|
|
private File doScreenshot(long jobId, String url, Integer imageWidth) throws Exception {
|
|
|
+ System.out.println(">>>>>>>jobId>>>>>>>>"+ jobId);
|
|
|
WebDriver driver = generateWebDriver(jobId, imageWidth);
|
|
|
-
|
|
|
+ System.out.println(">>>>>>>url>>>>>>>>"+ url);
|
|
|
driver.get(url);
|
|
|
scheduleLogger.info("Cronjob({}) do screenshot url={}, timeout={} start", jobId, url, timeOutSecond);
|
|
|
try {
|
|
@@ -218,6 +223,15 @@ public class ScreenshotUtil {
|
|
|
scheduleLogger.error(ex.toString(), ex);
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ if(isLinux()){
|
|
|
+ CHROME_DRIVER_PATH += "/linux";
|
|
|
+ }
|
|
|
+ if(isWindows()){
|
|
|
+ CHROME_DRIVER_PATH += "/window";
|
|
|
+ }
|
|
|
+ System.out.println("CHROME_DRIVER_PATH >>>> " + CHROME_DRIVER_PATH);
|
|
|
+
|
|
|
File file = new File(CHROME_DRIVER_PATH);
|
|
|
if (!file.canExecute()) {
|
|
|
if (!file.setExecutable(true)) {
|
|
@@ -242,6 +256,23 @@ public class ScreenshotUtil {
|
|
|
return new ChromeDriver(options);
|
|
|
}
|
|
|
|
|
|
+ public static void main(String[] args) {
|
|
|
+
|
|
|
+ String OS = System.getProperty("os.name").toLowerCase();
|
|
|
+
|
|
|
+ System.out.println(OS);
|
|
|
+
|
|
|
+ }
|
|
|
+ public static boolean isLinux(){
|
|
|
+ String OS = System.getProperty("os.name").toLowerCase();
|
|
|
+ return OS.indexOf("linux")>=0;
|
|
|
+ }
|
|
|
+
|
|
|
+ public static boolean isWindows(){
|
|
|
+ String OS = System.getProperty("os.name").toLowerCase();
|
|
|
+ return OS.indexOf("windows")>=0;
|
|
|
+ }
|
|
|
+
|
|
|
private WebDriver generatePhantomJsDriver() throws ExecutionException {
|
|
|
File file = new File(PHANTOMJS_PATH);
|
|
|
if (!file.canExecute()) {
|