private void testCustomFilters(KernelServices mainServices) {
   ServiceController<FilterService> customFilter =
       (ServiceController<FilterService>)
           mainServices.getContainer().getService(UndertowService.FILTER.append("custom-filter"));
   customFilter.setMode(ServiceController.Mode.ACTIVE);
   FilterService connectionLimiterService = customFilter.getService().getValue();
   HttpHandler result =
       connectionLimiterService.createHttpHandler(Predicates.truePredicate(), new PathHandler());
   Assert.assertNotNull("handler should have been created", result);
 }
  protected void applyOperation(
      ModelNode operation, String attributeName, ServiceController<?> service) {

    final UnboundedQueueThreadPoolService pool =
        (UnboundedQueueThreadPoolService) service.getService();
    try {
      final ModelNode value = operation.require(CommonAttributes.VALUE);
      if (CommonAttributes.KEEPALIVE_TIME.equals(attributeName)) {
        if (!value.hasDefined(TIME)) {
          throw new IllegalArgumentException("Missing '" + TIME + "' for '" + KEEPALIVE_TIME + "'");
        }
        final TimeUnit unit;
        if (!value.hasDefined(UNIT)) {
          unit = pool.getKeepAliveUnit();
        } else {
          try {
            unit = Enum.valueOf(TimeUnit.class, value.get(UNIT).asString());
          } catch (IllegalArgumentException e) {
            throw new OperationFailedException(
                new ModelNode()
                    .set(
                        "Failed to parse '"
                            + UNIT
                            + "', allowed values are: "
                            + Arrays.asList(TimeUnit.values())));
          }
        }
        final TimeSpec spec = new TimeSpec(unit, value.get(TIME).asLong());
        pool.setKeepAlive(spec);
      } else if (CommonAttributes.MAX_THREADS.equals(attributeName)) {
        pool.setMaxThreads(getScaledCount(CommonAttributes.MAX_THREADS, value));
      } else {
        throw new IllegalArgumentException("Unexpected attribute '" + attributeName + "'");
      }
    } catch (RuntimeException e) {
      throw e;
    } catch (Exception e) {
      throw new RuntimeException(e);
    }
  }
  @Override
  public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
    final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
    SipMetaData sipMetaData = deploymentUnit.getAttachment(SipMetaData.ATTACHMENT_KEY);
    if (sipMetaData == null) {
      SipAnnotationMetaData sipAnnotationMetaData =
          deploymentUnit.getAttachment(SipAnnotationMetaData.ATTACHMENT_KEY);
      if (sipAnnotationMetaData == null
          || !sipAnnotationMetaData.isSipApplicationAnnotationPresent()) {
        // http://code.google.com/p/sipservlets/issues/detail?id=168
        // When no sip.xml but annotations only, Application is not recognized as SIP App by AS7

        // In case there is no metadata attached, it means this is not a sip deployment, so we can
        // safely
        // ignore
        // it!
        return;
      }
    }

    final WarMetaData warMetaData = deploymentUnit.getAttachment(WarMetaData.ATTACHMENT_KEY);
    final JBossWebMetaData metaData = warMetaData.getMergedJBossWebMetaData();

    // lets find default server service:
    final ServiceName defaultServerServiceName = UndertowService.DEFAULT_SERVER;
    ServiceController<?> defaultServerServiceController =
        phaseContext.getServiceRegistry().getService(defaultServerServiceName);
    Server defaultServerService = (Server) defaultServerServiceController.getValue();

    final String defaultServer = defaultServerService.getName();
    final String defaultHost = defaultServerService.getDefaultHost();

    String hostName = UndertowSipDeploymentProcessor.hostNameOfDeployment(warMetaData, defaultHost);
    final String pathName =
        UndertowSipDeploymentProcessor.pathNameOfDeployment(deploymentUnit, metaData);

    String serverInstanceName =
        metaData.getServerInstanceName() == null ? defaultServer : metaData.getServerInstanceName();

    // lets find udertowdeployment service
    final ServiceName deploymentServiceName =
        UndertowService.deploymentServiceName(serverInstanceName, hostName, pathName);
    ServiceController<?> deploymentServiceController =
        phaseContext.getServiceRegistry().getService(deploymentServiceName);
    UndertowDeploymentService deploymentService =
        (UndertowDeploymentService) deploymentServiceController.getValue();

    // lets find udertowdeploymentinfo service
    final ServiceName deploymentInfoServiceName =
        deploymentServiceName.append(UndertowDeploymentInfoService.SERVICE_NAME);
    ServiceController<?> deploymentInfoServiceController =
        phaseContext.getServiceRegistry().getService(deploymentInfoServiceName);
    UndertowDeploymentInfoService deploymentInfoService =
        (UndertowDeploymentInfoService) deploymentInfoServiceController.getService();

    // lets inject undertowdeployment service to sip deploymentinfo service:
    final ServiceName sipDeploymentInfoServiceName =
        deploymentServiceName.append(UndertowSipDeploymentInfoService.SERVICE_NAME);
    ServiceController<?> sipDeplyomentInfoServiceController =
        phaseContext.getServiceRegistry().getService(sipDeploymentInfoServiceName);
    UndertowSipDeploymentInfoService sipDeplyomentInfoService =
        (UndertowSipDeploymentInfoService) sipDeplyomentInfoServiceController.getService();
    sipDeplyomentInfoService
        .getDeploymentInfoServiceInjectedValue()
        .setValue(new ImmediateValue<UndertowDeploymentInfoService>(deploymentInfoService));

    // initiate undertowsipdeployment service:
    final ServiceName sipDeploymentServiceName =
        deploymentServiceName.append(UndertowSipDeploymentService.SERVICE_NAME);
    UndertowSipDeploymentService sipDeploymentService =
        new UndertowSipDeploymentService(deploymentService, deploymentUnit);
    ServiceBuilder<UndertowSipDeploymentService> sipDeploymentServiceBuilder =
        phaseContext.getServiceTarget().addService(sipDeploymentServiceName, sipDeploymentService);

    // this service depends on the base undertowdeployment service:
    sipDeploymentServiceBuilder.addDependency(deploymentServiceName);
    sipDeploymentServiceBuilder.install();
  }
    @Override
    public void execute(OperationContext context, ModelNode operation)
        throws OperationFailedException {
      PathAddress address = context.getCurrentAddress();
      String clsName = address.getLastElement().getValue();
      PathAddress parentAddress = address.getParent();
      final ModelNode subModel =
          context
              .readResourceFromRoot(
                  parentAddress
                      .subAddress(0, parentAddress.size() - 1)
                      .append(SUBSYSTEM, UndertowExtension.SUBSYSTEM_NAME),
                  false)
              .getModel();
      final String host = VIRTUAL_HOST.resolveModelAttribute(context, subModel).asString();
      final String contextPath = CONTEXT_ROOT.resolveModelAttribute(context, subModel).asString();
      final String server = SERVER.resolveModelAttribute(context, subModel).asString();

      final ServiceController<?> controller =
          context
              .getServiceRegistry(false)
              .getService(UndertowService.deploymentServiceName(server, host, contextPath));
      final UndertowDeploymentService deploymentService =
          (UndertowDeploymentService) controller.getService();
      Servlet resteasyServlet = null;
      Handle handle = deploymentService.getDeployment().getThreadSetupAction().setup(null);
      try {
        for (Map.Entry<String, ServletHandler> servletHandler :
            deploymentService.getDeployment().getServlets().getServletHandlers().entrySet()) {
          if (HttpServletDispatcher.class.isAssignableFrom(
              servletHandler.getValue().getManagedServlet().getServletInfo().getServletClass())) {
            resteasyServlet =
                (Servlet) servletHandler.getValue().getManagedServlet().getServlet().getInstance();
            break;
          }
        }
        if (resteasyServlet != null) {
          final Collection<String> servletMappings =
              resteasyServlet
                  .getServletConfig()
                  .getServletContext()
                  .getServletRegistration(resteasyServlet.getServletConfig().getServletName())
                  .getMappings();
          final ResourceMethodRegistry registry =
              (ResourceMethodRegistry)
                  ((HttpServletDispatcher) resteasyServlet).getDispatcher().getRegistry();
          context.addStep(
              new OperationStepHandler() {
                @Override
                public void execute(OperationContext context, ModelNode operation)
                    throws OperationFailedException {
                  final ModelNode response = new ModelNode();
                  List<JaxrsResourceMethodDescription> resMethodInvokers = new ArrayList<>();
                  List<JaxrsResourceLocatorDescription> resLocatorInvokers = new ArrayList<>();
                  for (Map.Entry<String, List<ResourceInvoker>> resource :
                      registry.getBounded().entrySet()) {
                    String mapping = resource.getKey();
                    List<ResourceInvoker> resouceInvokers = resource.getValue();
                    for (ResourceInvoker resourceInvoker : resouceInvokers) {
                      if (ResourceMethodInvoker.class.isAssignableFrom(
                          resourceInvoker.getClass())) {
                        ResourceMethodInvoker methodInvoker =
                            (ResourceMethodInvoker) resourceInvoker;
                        if (methodInvoker.getResourceClass().getCanonicalName().equals(clsName)) {
                          JaxrsResourceMethodDescription resMethodDesc =
                              resMethodDescription(
                                  methodInvoker, contextPath, mapping, servletMappings);
                          resMethodInvokers.add(resMethodDesc);
                        }
                      } else if (ResourceLocatorInvoker.class.isAssignableFrom(
                          resourceInvoker.getClass())) {
                        ResourceLocatorInvoker locatorInvoker =
                            (ResourceLocatorInvoker) resourceInvoker;
                        if (clsName.equals(
                            locatorInvoker.getMethod().getDeclaringClass().getCanonicalName())) {
                          ResourceClass resClass =
                              ResourceBuilder.locatorFromAnnotations(
                                  locatorInvoker.getMethod().getReturnType());
                          JaxrsResourceLocatorDescription resLocatorDesc =
                              resLocatorDescription(
                                  resClass,
                                  contextPath,
                                  mapping,
                                  servletMappings,
                                  new ArrayList<Class<?>>());
                          resLocatorInvokers.add(resLocatorDesc);
                        }
                      }
                    }
                  }
                  Collections.sort(resMethodInvokers);
                  Collections.sort(resLocatorInvokers);
                  handleAttribute(
                      clsName, resMethodInvokers, resLocatorInvokers, servletMappings, response);
                  context.getResult().set(response);
                }
              },
              OperationContext.Stage.RUNTIME);
        }
      } catch (ServletException ex) {
        throw new RuntimeException(ex);
      } finally {
        handle.tearDown();
      }
    }