use of org.traccar.api.AsyncSocketServlet in project traccar by tananaev.
the class WebServer method initApi.
private void initApi(Config config, ServletContextHandler servletHandler) {
servletHandler.addServlet(new ServletHolder(new AsyncSocketServlet()), "/api/socket");
JettyWebSocketServletContainerInitializer.configure(servletHandler, null);
String mediaPath = config.getString(Keys.MEDIA_PATH);
if (mediaPath != null) {
ServletHolder servletHolder = new ServletHolder(DefaultServlet.class);
servletHolder.setInitParameter("resourceBase", new File(mediaPath).getAbsolutePath());
servletHolder.setInitParameter("dirAllowed", "false");
servletHolder.setInitParameter("pathInfoOnly", "true");
servletHandler.addServlet(servletHolder, "/api/media/*");
servletHandler.addFilter(MediaFilter.class, "/api/media/*", EnumSet.allOf(DispatcherType.class));
}
ResourceConfig resourceConfig = new ResourceConfig();
resourceConfig.registerClasses(JacksonFeature.class, ResourceErrorHandler.class, SecurityRequestFilter.class, CorsResponseFilter.class, DateParameterConverterProvider.class);
resourceConfig.packages(ServerResource.class.getPackage().getName());
resourceConfig.register(new ContainerLifecycleListener() {
@Override
public void onStartup(Container container) {
var injectionManager = container.getApplicationHandler().getInjectionManager();
var serviceLocator = ((ImmediateHk2InjectionManager) injectionManager).getServiceLocator();
GuiceBridge.getGuiceBridge().initializeGuiceBridge(serviceLocator);
var guiceBridge = serviceLocator.getService(GuiceIntoHK2Bridge.class);
guiceBridge.bridgeGuiceInjector(Main.getInjector());
}
@Override
public void onReload(Container container) {
}
@Override
public void onShutdown(Container container) {
}
});
servletHandler.addServlet(new ServletHolder(new ServletContainer(resourceConfig)), "/api/*");
}
use of org.traccar.api.AsyncSocketServlet in project traccar by tananaev.
the class WebServer method initApi.
private void initApi() {
ServletContextHandler servletHandler = new ServletContextHandler(ServletContextHandler.SESSIONS);
servletHandler.setContextPath("/api");
servletHandler.getSessionHandler().setSessionManager(sessionManager);
servletHandler.addServlet(new ServletHolder(new AsyncSocketServlet()), "/socket");
if (config.hasKey("media.path")) {
ServletHolder servletHolder = new ServletHolder("media", DefaultServlet.class);
servletHolder.setInitParameter("resourceBase", config.getString("media.path"));
servletHolder.setInitParameter("dirAllowed", config.getString("media.dirAllowed", "false"));
servletHolder.setInitParameter("pathInfoOnly", "true");
servletHandler.addServlet(servletHolder, "/media/*");
servletHandler.addFilter(MediaFilter.class, "/media/*", EnumSet.allOf(DispatcherType.class));
}
ResourceConfig resourceConfig = new ResourceConfig();
resourceConfig.registerClasses(JacksonFeature.class, ObjectMapperProvider.class, ResourceErrorHandler.class);
resourceConfig.registerClasses(SecurityRequestFilter.class, CorsResponseFilter.class);
resourceConfig.packages(ServerResource.class.getPackage().getName());
servletHandler.addServlet(new ServletHolder(new ServletContainer(resourceConfig)), "/*");
handlers.addHandler(servletHandler);
}
use of org.traccar.api.AsyncSocketServlet in project traccar by traccar.
the class WebServer method initApi.
private void initApi() {
ServletContextHandler servletHandler = new ServletContextHandler(ServletContextHandler.SESSIONS);
servletHandler.setContextPath("/api");
servletHandler.getSessionHandler().setSessionManager(sessionManager);
servletHandler.addServlet(new ServletHolder(new AsyncSocketServlet()), "/socket");
if (config.hasKey("media.path")) {
ServletHolder servletHolder = new ServletHolder("media", DefaultServlet.class);
servletHolder.setInitParameter("resourceBase", config.getString("media.path"));
servletHolder.setInitParameter("dirAllowed", config.getString("media.dirAllowed", "false"));
servletHolder.setInitParameter("pathInfoOnly", "true");
servletHandler.addServlet(servletHolder, "/media/*");
servletHandler.addFilter(MediaFilter.class, "/media/*", EnumSet.allOf(DispatcherType.class));
}
ResourceConfig resourceConfig = new ResourceConfig();
resourceConfig.registerClasses(JacksonFeature.class, ObjectMapperProvider.class, ResourceErrorHandler.class);
resourceConfig.registerClasses(SecurityRequestFilter.class, CorsResponseFilter.class);
resourceConfig.packages(ServerResource.class.getPackage().getName());
servletHandler.addServlet(new ServletHolder(new ServletContainer(resourceConfig)), "/*");
handlers.addHandler(servletHandler);
}
Aggregations