11
11
import lombok .AccessLevel ;
12
12
import lombok .AllArgsConstructor ;
13
13
import lombok .Getter ;
14
- import lombok .experimental .Wither ;
15
14
16
15
import org .apache .catalina .LifecycleException ;
17
16
import org .apache .catalina .connector .Connector ;
@@ -49,13 +48,13 @@ public class TomcatApplication implements ServerApplication {
49
48
private final PStack <ServletData > servletData ;
50
49
private final PStack <ServletContextListener > servletContextListenerData ;
51
50
private final PStack <ServletRequestListener > servletRequestListenerData ;
52
-
51
+
53
52
public TomcatApplication (AllData serverData ) {
54
53
this .serverData = serverData .getServerData ();
55
54
this .filterData = serverData .getFilterDataList ();
56
55
this .servletData = serverData .getServletDataList ();
57
56
this .servletContextListenerData = serverData .getServletContextListeners ();
58
- this .servletRequestListenerData = serverData .getServletRequestListeners ();
57
+ this .servletRequestListenerData = serverData .getServletRequestListeners ();
59
58
}
60
59
61
60
public void run (CompletableFuture start , JaxRsServletConfigurer jaxRsConfigurer , CompletableFuture end ) {
@@ -65,13 +64,13 @@ public void run(CompletableFuture start, JaxRsServletConfigurer jaxRsConfigurer
65
64
tomcat .getEngine ().setBackgroundProcessorDelay (-1 );
66
65
File docBase = new File ("." );
67
66
StandardContext context =(StandardContext )tomcat .addContext ("" , docBase .getAbsolutePath ());
68
- context .addServletContainerInitializer (new TomcatListener (jaxRsConfigurer , serverData , filterData , servletData , servletContextListenerData , servletRequestListenerData ),
67
+ context .addServletContainerInitializer (new TomcatListener (jaxRsConfigurer , serverData , filterData , servletData , servletContextListenerData , servletRequestListenerData ),
69
68
new HashSet <>());
70
69
addAccessLog (tomcat ,context );
71
-
70
+
72
71
serverData .getModule ().getServerConfigManager ().accept (new WebServerProvider (tomcat ));
73
-
74
- addSSL (tomcat .getConnector ());
72
+
73
+ addSSL (tomcat .getConnector ());
75
74
76
75
startServer (tomcat , start , end );
77
76
}
@@ -82,22 +81,22 @@ private void addSSL(Connector connector) {
82
81
if (sslProperties != null && handler instanceof AbstractHttp11JsseProtocol ){
83
82
new SSLConfigurationBuilder ().build ((AbstractHttp11JsseProtocol )handler ,sslProperties );
84
83
connector .setScheme ("https" );
85
- connector .setSecure (true );
86
- }
84
+ connector .setSecure (true );
85
+ }
87
86
}
88
87
89
88
private void startServer ( Tomcat httpServer , CompletableFuture start , CompletableFuture end ) {
90
-
89
+
91
90
try {
92
91
logger .info ("Starting application {} on port {}" , serverData .getModule ().getContext (), serverData .getPort ());
93
92
logger .info ("Browse to http://localhost:{}/{}/application.wadl" , serverData .getPort (), serverData .getModule ().getContext ());
94
93
logger .info ("Configured resource classes :-" );
95
94
serverData .extractResources ().forEach (
96
95
t -> logger .info (t .v1 () + " : " + "http://localhost:" + serverData .getPort () + "/" + serverData .getModule ().getContext () + t .v2 ()));
97
96
;
98
-
97
+
99
98
httpServer .start ();
100
-
99
+
101
100
start .complete (true );
102
101
end .get ();
103
102
@@ -114,46 +113,46 @@ private void startServer( Tomcat httpServer, CompletableFuture start, Completabl
114
113
httpServer .getConnector ().destroy ();
115
114
httpServer .getEngine ().destroy ();
116
115
httpServer .destroy ();
117
-
118
-
119
-
116
+
117
+
118
+
120
119
} catch (LifecycleException e ) {
121
120
}
122
121
try {
123
122
Thread .sleep (5_000 );
124
123
}
125
124
catch (InterruptedException e ) {
126
-
125
+
127
126
}
128
-
127
+
129
128
}
130
129
}
131
130
132
131
private void addAccessLog (Tomcat httpServer , StandardContext context ) {
133
132
try {
134
-
133
+
135
134
String accessLogLocation = serverData .getRootContext ().getBean (AccessLogLocationBean .class ).getAccessLogLocation ();
136
135
137
136
accessLogLocation = accessLogLocation + "/" + replaceSlash (serverData .getModule ().getContext ()) + "-access.log" ;
138
-
137
+
139
138
AccessLogValve accessLogValve = new AccessLogValve ();
140
139
accessLogValve .setDirectory (accessLogLocation );
141
140
accessLogValve .setPattern (Constants .AccessLog .COMMON_ALIAS );
142
141
accessLogValve .setSuffix (".log" );
143
142
accessLogValve .setRotatable (true );
144
143
context .getPipeline ().addValve (accessLogValve );
145
-
144
+
146
145
} catch (Exception e ) {
147
-
146
+
148
147
logger .error (InternalErrorCode .SERVER_STARTUP_FAILED_TO_CREATE_ACCESS_LOG .toString () + ": " + e .getMessage ());
149
148
if (e .getCause () != null )
150
149
logger .error ("CAUSED BY: " + InternalErrorCode .SERVER_STARTUP_FAILED_TO_CREATE_ACCESS_LOG .toString () + ": " + e .getCause ().getMessage ());
151
150
152
151
}
153
152
154
153
}
155
-
156
-
154
+
155
+
157
156
158
157
private String replaceSlash (String context ) {
159
158
if (context != null && context .contains ("/" )) {
0 commit comments