use of fish.payara.microprofile.openapi.rest.app.OpenApiApplication in project Payara by payara.
the class OpenApiServletContainerInitializer method onStartup.
@Override
public void onStartup(Set<Class<?>> c, ServletContext ctx) throws ServletException {
// Only deploy to app root
if (!"".equals(ctx.getContextPath())) {
return;
}
OpenApiServiceConfiguration configuration = Globals.getDefaultHabitat().getService(OpenApiServiceConfiguration.class);
// Check if there is already an endpoint for OpenAPI
Map<String, ? extends ServletRegistration> registrations = ctx.getServletRegistrations();
for (ServletRegistration reg : registrations.values()) {
if (reg.getMappings().contains(configuration.getEndpoint())) {
return;
}
}
String virtualServers = configuration.getVirtualServers();
if (!isEmpty(virtualServers) && !asList(virtualServers.split(",")).contains(ctx.getVirtualServerName())) {
return;
}
// Start the OpenAPI application
ServletContainer servletContainer = new ServletContainer(new OpenApiApplication());
ServletRegistration.Dynamic reg = ctx.addServlet("microprofile-openapi-servlet", servletContainer);
reg.setLoadOnStartup(1);
reg.addMapping("/" + configuration.getEndpoint() + "/*");
if (Boolean.parseBoolean(configuration.getSecurityEnabled())) {
String[] roles = configuration.getRoles().split(",");
reg.setServletSecurity(new ServletSecurityElement(new HttpConstraintElement(CONFIDENTIAL, roles)));
ctx.declareRoles(roles);
}
}
Aggregations