use of org.apache.cxf.transport.servlet.ServletController in project BIMserver by opensourceBIM.
the class GenericWebServiceServlet method createServletController.
private ServletController createServletController(ServletConfig servletConfig) {
HttpServlet serviceListGeneratorServlet = new ServiceListGeneratorServlet(destinationRegistry, bus);
ServletController newController = new ServletController(destinationRegistry, servletConfig, serviceListGeneratorServlet);
return newController;
}
use of org.apache.cxf.transport.servlet.ServletController in project component-runtime by Talend.
the class WebSocketBroadcastSetup method contextInitialized.
@Override
public void contextInitialized(final ServletContextEvent sce) {
final ServerContainer container = ServerContainer.class.cast(sce.getServletContext().getAttribute(ServerContainer.class.getName()));
final JAXRSServiceFactoryBean factory = JAXRSServiceFactoryBean.class.cast(bus.getExtension(ServerRegistry.class).getServers().iterator().next().getEndpoint().get(JAXRSServiceFactoryBean.class.getName()));
final String appBase = StreamSupport.stream(Spliterators.spliteratorUnknownSize(applications.iterator(), Spliterator.IMMUTABLE), false).filter(a -> a.getClass().isAnnotationPresent(ApplicationPath.class)).map(a -> a.getClass().getAnnotation(ApplicationPath.class)).map(ApplicationPath::value).findFirst().map(s -> !s.startsWith("/") ? "/" + s : s).orElse("/api/v1");
final String version = appBase.replaceFirst("/api", "");
final DestinationRegistry registry;
try {
final HTTPTransportFactory transportFactory = HTTPTransportFactory.class.cast(bus.getExtension(DestinationFactoryManager.class).getDestinationFactory("http://cxf.apache.org/transports/http" + "/configuration"));
registry = transportFactory.getRegistry();
} catch (final BusException e) {
throw new IllegalStateException(e);
}
final ServletContext servletContext = sce.getServletContext();
final WebSocketRegistry webSocketRegistry = new WebSocketRegistry(registry);
final ServletController controller = new ServletController(webSocketRegistry, new ServletConfig() {
@Override
public String getServletName() {
return "Talend Component Kit Websocket Transport";
}
@Override
public ServletContext getServletContext() {
return servletContext;
}
@Override
public String getInitParameter(final String s) {
return null;
}
@Override
public Enumeration<String> getInitParameterNames() {
return emptyEnumeration();
}
}, new ServiceListGeneratorServlet(registry, bus));
webSocketRegistry.controller = controller;
Stream.concat(factory.getClassResourceInfo().stream().flatMap(cri -> cri.getMethodDispatcher().getOperationResourceInfos().stream()).map(ori -> {
final String uri = ori.getClassResourceInfo().getURITemplate().getValue() + ori.getURITemplate().getValue();
return ServerEndpointConfig.Builder.create(Endpoint.class, "/websocket" + version + "/" + String.valueOf(ori.getHttpMethod()).toLowerCase(ENGLISH) + uri).configurator(new ServerEndpointConfig.Configurator() {
@Override
public <T> T getEndpointInstance(final Class<T> clazz) throws InstantiationException {
final Map<String, List<String>> headers = new HashMap<>();
if (!ori.getProduceTypes().isEmpty()) {
headers.put(HttpHeaders.CONTENT_TYPE, singletonList(ori.getProduceTypes().iterator().next().toString()));
}
if (!ori.getConsumeTypes().isEmpty()) {
headers.put(HttpHeaders.ACCEPT, singletonList(ori.getConsumeTypes().iterator().next().toString()));
}
return (T) new JAXRSEndpoint(appBase, controller, servletContext, ori.getHttpMethod(), uri, headers);
}
}).build();
}), Stream.of(ServerEndpointConfig.Builder.create(Endpoint.class, "/websocket" + version + "/bus").configurator(new ServerEndpointConfig.Configurator() {
@Override
public <T> T getEndpointInstance(final Class<T> clazz) throws InstantiationException {
return (T) new JAXRSEndpoint(appBase, controller, servletContext, "GET", "/", emptyMap());
}
}).build())).sorted(Comparator.comparing(ServerEndpointConfig::getPath)).peek(e -> log.info("Deploying WebSocket(path={})", e.getPath())).forEach(config -> {
try {
container.addEndpoint(config);
} catch (final DeploymentException e) {
throw new IllegalStateException(e);
}
});
}
Aggregations