Github user pulse00 commented on the pull request:

    https://github.com/apache/wicket/pull/127#issuecomment-112330107
  
    In our application, we setup the servlet context purely in java, without 
any `web.xml`. This looks something like this:
    
    ```java
    Constructor<? extends CustomWebApplication> constructor = 
applicationClass.getConstructor(StageType.class);
    CustomWebApplication CustomWebApplication = 
constructor.newInstance(activeStateType);
    CustomWebApplication.setApplicationContext(rootContext);
    
    WicketFilter wicketFilter = new WicketFilter(CustomWebApplication) {
    
      @Override
      public void init(boolean isServlet, FilterConfig filterConfig) throws 
ServletException {
        setFilterPath("");
        super.init(isServlet, filterConfig);
      }
    };
    
    servletContext.addFilter("hstsFilter", 
HSTSFilter.class).addMappingForUrlPatterns(EnumSet.allOf(DispatcherType.class), 
false, "/*");
    
    FilterRegistration.Dynamic wicketFilterRegistration = 
servletContext.addFilter("wicketFilter", wicketFilter);
    
wicketFilterRegistration.addMappingForUrlPatterns(EnumSet.allOf(DispatcherType.class),
 true, "/*");
    ```
    
    Now if we want to add websocket support by adding using a 
`WebsocketFilter`, we need to create a custom subclass because the constructor 
with the `Webapplication` argument is not public in the subclasses of 
`WicketFilter`: 
    
    ```java
    private class CustomWebsocketFilter extends Tomcat7WebSocketFilter {
    
      private WebApplication application;
    
      public CustomWebsocketFilter(WebApplication application) {
        this.application = application;
      }
    
      @Override
      protected IWebApplicationFactory getApplicationFactory() {
        return new IWebApplicationFactory() {
          @Override
          public WebApplication createApplication(WicketFilter filter) {
            return application;
          }
    
          @Override
          public void destroy(WicketFilter filter) {
            if (application != null)
            {
              try
              {
                ThreadContext.setApplication(application);
                application.internalDestroy();
              }
              finally
              {
                ThreadContext.detach();
                application = null;
              }
            }
          }
        };
      }
    }
    ```
    At least that's how i understood the 
[documentation](https://github.com/pulse00/wicket/blob/master/wicket-core/src/main/java/org/apache/wicket/protocol/http/WicketFilter.java#L109)
 of this specific constructor.
    



---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---

Reply via email to