protected void registerMessageListeners(String destinationName, Message message)
      throws SchedulerException {

    if (_portletLocalService == null) {
      throw new IllegalStateException("Portlet local service not initialized");
    }

    String messageListenerClassName =
        message.getString(SchedulerEngine.MESSAGE_LISTENER_CLASS_NAME);

    if (Validator.isNull(messageListenerClassName)) {
      return;
    }

    String portletId = message.getString(SchedulerEngine.PORTLET_ID);

    ClassLoader classLoader = null;

    if (Validator.isNull(portletId)) {
      classLoader = PortalClassLoaderUtil.getClassLoader();
    } else {
      Portlet portlet = _portletLocalService.getPortletById(portletId);

      if (portlet == null) {

        // No portlet found for the portlet ID. Try getting the class
        // loader where we assume the portlet ID is actually a servlet
        // context name.

        classLoader = ClassLoaderPool.getClassLoader(portletId);
      } else {
        PortletApp portletApp = portlet.getPortletApp();

        ServletContext servletContext = portletApp.getServletContext();

        classLoader = servletContext.getClassLoader();
      }
    }

    if (classLoader == null) {
      throw new SchedulerException("Unable to find class loader for portlet " + portletId);
    }

    MessageListener schedulerEventListener =
        getMessageListener(messageListenerClassName, classLoader);

    SchedulerEventMessageListenerWrapper schedulerEventListenerWrapper =
        new SchedulerEventMessageListenerWrapper();

    schedulerEventListenerWrapper.setMessageListener(schedulerEventListener);

    schedulerEventListenerWrapper.afterPropertiesSet();

    _messageBus.registerMessageListener(destinationName, schedulerEventListenerWrapper);

    message.put(
        SchedulerEngine.MESSAGE_LISTENER_UUID,
        schedulerEventListenerWrapper.getMessageListenerUUID());
  }
 @Before
 public void init() {
   control = EasyMock.createStrictControl();
   parent = control.createMock(ClassLoader.class);
   cl =
       EasyMock.createMockBuilder(ClassLoader.class)
           .withConstructor(parent)
           .addMockedMethod("loadClass", String.class)
           .createMock(control);
   servletContext = control.createMock(ServletContext.class);
   EasyMock.expect(servletContext.getClassLoader()).andStubReturn(cl);
   context = new ExtendedTesterContext(servletContext, parent);
 }
示例#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));
  }
 public static void unregister(final ServletContext servletContext) {
   URL_PATTERN_CACHE.remove(servletContext.getClassLoader());
 }
 public static void register(final ServletContext ctx) {
   URL_PATTERN_CACHE.put(ctx.getClassLoader(), new ConcurrentHashMap<Class<?>, String[]>());
 }
示例#6
0
  @Override
  public void init(final ServletConfig servletConfig) throws ServletException {

    final ServletContext servletContext = servletConfig.getServletContext();

    ClassLoader classLoader = servletContext.getClassLoader();

    if (!(classLoader instanceof BundleReference)) {
      throw new IllegalStateException();
    }

    BundleReference bundleReference = (BundleReference) classLoader;

    _bundle = bundleReference.getBundle();

    _jspBundleClassloader = new JspBundleClassloader(_bundle, _jspBundle);

    final Map<String, String> defaults = new HashMap<>();

    defaults.put(
        "compilerClassName", "com.liferay.portal.servlet.jsp.compiler.internal.JspCompiler");
    defaults.put("development", "false");
    defaults.put("httpMethods", "GET,POST,HEAD");
    defaults.put("keepgenerated", "false");
    defaults.put("logVerbosityLevel", "DEBUG");

    Enumeration<String> names = servletConfig.getInitParameterNames();
    Set<String> nameSet = new HashSet<>(Collections.list(names));

    nameSet.addAll(defaults.keySet());

    final Enumeration<String> initParameterNames = Collections.enumeration(nameSet);

    _jspServlet.init(
        new ServletConfig() {

          @Override
          public String getServletName() {
            return servletConfig.getServletName();
          }

          @Override
          public ServletContext getServletContext() {
            return getServletContextWrapper(servletContext);
          }

          @Override
          public Enumeration<String> getInitParameterNames() {
            return initParameterNames;
          }

          @Override
          public String getInitParameter(String name) {
            String value = servletConfig.getInitParameter(name);

            if (value == null) {
              value = defaults.get(name);
            }

            return value;
          }
        });
  }
示例#7
0
 @Override
 public ClassLoader getClassLoader() {
   return sc.getClassLoader();
 }
 public ClassLoader getClassLoader() {
   return servletContext.getClassLoader();
 }