3
3
import java .io .File ;
4
4
5
5
import org .apache .catalina .WebResourceRoot ;
6
- import org .apache .catalina .core .StandardContext ;
6
+ // import org.apache.catalina.core.StandardContext;
7
7
import org .apache .catalina .startup .Tomcat ;
8
+ import org .apache .catalina .connector .Connector ;
8
9
import org .apache .catalina .webresources .DirResourceSet ;
9
10
import org .apache .catalina .webresources .StandardRoot ;
10
11
12
+ import org .apache .catalina .Context ;
13
+ import org .apache .catalina .WebResourceSet ;
14
+ import org .apache .catalina .webresources .EmptyResourceSet ;
15
+
11
16
// import java.io.FileReader;
12
17
13
18
// import javax.script.ScriptEngine;
@@ -24,27 +29,67 @@ public static void main(String[] args) throws Exception {
24
29
//The port that we should run on can be set into an environment variable
25
30
//Look for that variable and default to 8080 if it isn't there.
26
31
String webPort = System .getenv ("PORT" );
27
- if (webPort == null || webPort .isEmpty ()) {
32
+ if (webPort == null || webPort .isEmpty ()) {
28
33
webPort = "8080" ;
29
34
}
30
35
36
+ // tomcat.setPort(Integer.valueOf(webPort));
37
+
38
+ Connector httpsConnector = new Connector ();
39
+ httpsConnector .setProtocol ("org.apache.coyote.http11.Http11NioProtocol" );
40
+ httpsConnector .setPort (8081 );
41
+ httpsConnector .setSecure (true );
42
+ httpsConnector .setScheme ("https" );
43
+ httpsConnector .setAttribute ("keystoreFile" , new File (webappDirLocation ).getAbsolutePath () + "/cert/keystore" );
44
+ httpsConnector .setAttribute ("keystorePass" , "password" );
45
+ // httpsConnector.setAttribute("truststoreFile",
46
+ // new File(webappDirLocation).getAbsolutePath() + "/cert/server.cer");
47
+ // httpsConnector.setAttribute("truststorePass", "");
48
+ httpsConnector .setAttribute ("clientAuth" , false );
49
+ httpsConnector .setAttribute ("sslProtocol" , "TLS" );
50
+ httpsConnector .setAttribute ("SSLEnabled" , true );
51
+
31
52
tomcat .setPort (Integer .valueOf (webPort ));
53
+ tomcat .getService ().addConnector (httpsConnector );
54
+
55
+ Connector defaultConnector = tomcat .getConnector ();
56
+ defaultConnector .setRedirectPort (8081 );
57
+
58
+ // StandardContext ctx = (StandardContext) tomcat.addWebapp("", new File(webappDirLocation).getAbsolutePath());
59
+ // System.out.println("configuring app with basedir: " + new File("./" + webappDirLocation).getAbsolutePath());
32
60
33
- StandardContext ctx = (StandardContext ) tomcat .addWebapp ("/" , new File (webappDirLocation ).getAbsolutePath ());
34
- System .out .println ("configuring app with basedir: " + new File ("./" + webappDirLocation ).getAbsolutePath ());
61
+ // // Declare an alternative location for your "WEB-INF/classes" dir
62
+ // // Servlet 3.0 annotation will work
63
+ // File additionWebInfClasses = new File("target/classes");
64
+ // WebResourceRoot resources = new StandardRoot(ctx);
65
+ // resources.addPreResources(
66
+ // new DirResourceSet(resources, "/WEB-INF/classes", additionWebInfClasses.getAbsolutePath(), "/"));
67
+ // ctx.setResources(resources);
68
+
69
+ // Define a web application context.
70
+ Context context = tomcat .addWebapp ("" , new File (webappDirLocation ).getAbsolutePath ());
35
71
36
72
// Declare an alternative location for your "WEB-INF/classes" dir
37
73
// Servlet 3.0 annotation will work
38
- File additionWebInfClasses = new File ("target/classes" );
39
- WebResourceRoot resources = new StandardRoot (ctx );
40
- resources .addPreResources (new DirResourceSet (resources , "/WEB-INF/classes" ,
41
- additionWebInfClasses .getAbsolutePath (), "/" ));
42
- ctx .setResources (resources );
74
+ File additionWebInfClassesFolder = new File ("target/classes" );
75
+ WebResourceRoot resources = new StandardRoot (context );
76
+
77
+ WebResourceSet resourceSet ;
78
+ if (additionWebInfClassesFolder .exists ()) {
79
+ resourceSet = new DirResourceSet (resources , "/WEB-INF/classes" ,
80
+ additionWebInfClassesFolder .getAbsolutePath (), "/" );
81
+ System .out .println (
82
+ "loading WEB-INF resources from as '" + additionWebInfClassesFolder .getAbsolutePath () + "'" );
83
+ } else {
84
+ resourceSet = new EmptyResourceSet (resources );
85
+ }
86
+
87
+ resources .addPreResources (resourceSet );
88
+ context .setResources (resources );
43
89
44
90
tomcat .start ();
45
91
tomcat .getServer ().await ();
46
92
47
-
48
93
// Server-rendering with Nashorn
49
94
// ScriptEngine nashorn = new ScriptEngineManager().getEngineByName("nashorn");
50
95
// nashorn.eval(new FileReader(webappDirLocation + "public/bundle.js"));
0 commit comments