Ejemplo n.º 1
0
 @Override
 public <T extends Filter> T createFilter(final Class<T> clazz) throws ServletException {
   ensureNotProgramaticListener();
   try {
     return deploymentInfo
         .getClassIntrospecter()
         .createInstanceFactory(clazz)
         .createInstance()
         .getInstance();
   } catch (Exception e) {
     throw UndertowServletMessages.MESSAGES.couldNotInstantiateComponent(clazz.getName(), e);
   }
 }
Ejemplo n.º 2
0
 @Override
 public void addListener(final Class<? extends EventListener> listenerClass) {
   ensureNotInitialized();
   ensureNotProgramaticListener();
   if (ApplicationListeners.listenerState() != NO_LISTENER
       && ServletContextListener.class.isAssignableFrom(listenerClass)) {
     throw UndertowServletMessages.MESSAGES.cannotAddServletContextListener();
   }
   InstanceFactory<? extends EventListener> factory = null;
   try {
     factory = deploymentInfo.getClassIntrospecter().createInstanceFactory(listenerClass);
   } catch (Exception e) {
     throw new IllegalArgumentException(e);
   }
   final ListenerInfo listener = new ListenerInfo(listenerClass, factory);
   deploymentInfo.addListener(listener);
   deployment.getApplicationListeners().addListener(new ManagedListener(listener, true));
 }
Ejemplo n.º 3
0
  @Override
  public void handleDeployment(DeploymentInfo deploymentInfo, ServletContext servletContext) {
    WebSocketDeploymentInfo info =
        (WebSocketDeploymentInfo)
            deploymentInfo
                .getServletContextAttributes()
                .get(WebSocketDeploymentInfo.ATTRIBUTE_NAME);

    if (info == null) {
      return;
    }
    if (info.getWorker() == null) {
      JsrWebSocketLogger.ROOT_LOGGER.xnioWorkerWasNull();
    }
    final List<ThreadSetupAction> setup = new ArrayList<ThreadSetupAction>();
    setup.add(new ContextClassLoaderSetupAction(deploymentInfo.getClassLoader()));
    setup.addAll(deploymentInfo.getThreadSetupActions());
    final CompositeThreadSetupAction threadSetupAction = new CompositeThreadSetupAction(setup);
    ServerWebSocketContainer container =
        new ServerWebSocketContainer(
            deploymentInfo.getClassIntrospecter(),
            servletContext.getClassLoader(),
            info.getWorker(),
            info.getBuffers(),
            threadSetupAction,
            info.isDispatchToWorkerThread());
    try {
      for (Class<?> annotation : info.getAnnotatedEndpoints()) {
        container.addEndpoint(annotation);
      }
      for (ServerEndpointConfig programatic : info.getProgramaticEndpoints()) {
        container.addEndpoint(programatic);
      }
    } catch (DeploymentException e) {
      throw new RuntimeException(e);
    }
    servletContext.setAttribute(ServerContainer.class.getName(), container);
    info.containerReady(container);
    SecurityActions.addContainer(deploymentInfo.getClassLoader(), container);

    deploymentInfo.addListener(Servlets.listener(WebSocketListener.class));
  }