-
Notifications
You must be signed in to change notification settings - Fork 33
Expand file tree
/
Copy pathApp.java
More file actions
85 lines (73 loc) · 3 KB
/
App.java
File metadata and controls
85 lines (73 loc) · 3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
package com.docusign;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jmx.JmxAutoConfiguration;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Import;
import java.awt.*;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.nio.file.FileSystemAlreadyExistsException;
import java.nio.file.FileSystems;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Collections;
@Slf4j
@SpringBootApplication(exclude = {JmxAutoConfiguration.class})
@ComponentScan(basePackages = "com.docusign")
@Import(WebSecurityConfig.class)
public class App {
public static void main(String[] args) throws IOException, URISyntaxException {
initFileSystem();
ClassLoader classLoader = App.class.getClassLoader();
URL applicationJsonURL = classLoader.getResource("application.json");
if (applicationJsonURL != null) {
SpringApplication.run(App.class, args);
openHomePage();
} else {
InputStream inputStream = classLoader.getResourceAsStream("applicationJsonMissingError.html");
if (inputStream.available() > 0) {
Path path = Files.createTempFile("applicationJsonMissingError", ".html");
try (FileOutputStream out = new FileOutputStream(path.toFile())) {
byte[] buffer = new byte[1024];
int len;
while ((len = inputStream.read(buffer)) != -1) {
out.write(buffer, 0, len);
}
} catch (IOException e) {
log.error("File applicationJsonMissingError.html could not be accessed.");
}
Desktop.getDesktop().browse(path.toUri());
}
log.info("");
log.info("Please, add the application.json file to the resources folder.");
log.info("");
}
}
private static void openHomePage() throws IOException {
System.setProperty("java.awt.headless", "false");
try {
Desktop.getDesktop().browse(new URI("http://localhost:8080"));
} catch (URISyntaxException use) {
log.error("Invalid URI in App.openHomePage()");
}
}
private static void initFileSystem() {
try {
FileSystems.newFileSystem(new URI(""), Collections.emptyMap());
log.info("FileSystem initialized successfully");
} catch (Exception e) {
if (e instanceof FileSystemAlreadyExistsException) {
log.info("FileSystem is already initialized");
} else {
log.info("Retrieving the default initialize context");
FileSystems.getDefault();
}
}
}
}