33import com .google .inject .Guice ;
44import com .google .inject .Injector ;
55import io .dropwizard .Application ;
6+ import io .dropwizard .assets .AssetsBundle ;
67import io .dropwizard .auth .AuthDynamicFeature ;
78import io .dropwizard .auth .AuthValueFactoryProvider ;
89import io .dropwizard .auth .CachingAuthenticator ;
1516import io .prometheus .client .CollectorRegistry ;
1617import io .prometheus .client .dropwizard .DropwizardExports ;
1718import io .prometheus .client .exporter .MetricsServlet ;
19+ import org .eclipse .jetty .server .AbstractNetworkConnector ;
20+ import org .eclipse .jetty .server .Server ;
1821import org .glassfish .jersey .CommonProperties ;
1922import org .slf4j .Logger ;
2023import org .slf4j .LoggerFactory ;
7881public class PublicApi extends Application <PublicApiConfig > {
7982
8083 private static final Logger logger = LoggerFactory .getLogger (PublicApi .class );
81-
84+
8285 private static final String SERVICE_METRICS_NODE = "publicapi" ;
8386
87+ /**
88+ * Added to check the status of the SUT, since there is no API
89+ * available to access this information.
90+ */
91+ private Server jettyServer ;
92+
93+ public int getJettyPort () {
94+ return ((AbstractNetworkConnector )jettyServer .getConnectors ()[0 ]).getLocalPort ();
95+ }
96+
97+ public Server getJettyServer () {
98+ return jettyServer ;
99+ }
100+
84101 @ Override
85102 public void initialize (Bootstrap <PublicApiConfig > bootstrap ) {
103+ // Added to server Swagger JSON as static file
104+ bootstrap .addBundle (new AssetsBundle ("/assets/" , "/assets/" ));
105+
86106 bootstrap .setConfigurationSourceProvider (
87107 new SubstitutingSourceProvider (
88108 bootstrap .getConfigurationSourceProvider (),
@@ -129,7 +149,7 @@ public void run(PublicApiConfig configuration, Environment environment) {
129149
130150 /*
131151 Turn off 'FilteringJacksonJaxbJsonProvider' which overrides dropwizard JacksonMessageBodyProvider.
132- Fails on Integration tests if not disabled.
152+ Fails on Integration tests if not disabled.
133153 - https://github.com/dropwizard/dropwizard/issues/1341
134154 */
135155 environment .jersey ().property (CommonProperties .FEATURE_AUTO_DISCOVERY_DISABLE , Boolean .TRUE );
@@ -153,6 +173,8 @@ public void run(PublicApiConfig configuration, Environment environment) {
153173 environment .admin ().addServlet ("prometheusMetrics" , new MetricsServlet (collectorRegistry )).addMapping ("/metrics" );
154174
155175 environment .lifecycle ().manage (injector .getInstance (RedisClientManager .class ));
176+
177+ environment .lifecycle ().addServerLifecycleListener (server -> jettyServer = server );
156178 }
157179
158180 /**
0 commit comments