简体   繁体   中英

How to have a servlet for a specific resource but use wicket for the rest of the web application

I'm trying to add Atmosphere support to a Wicket-1.5.X web application. (Currently upgrading to 6 isn't an option.)

I currently have the wicket filter configured to run on top of the Atmospheres MeteorServlet . I've created an sharedResource for Atmosphere to be used in my application. I'm noticing that however with that configuration even pages(like my static login page) that don't use the shared resource still seem activate it.

I think the solution is to move the wicket filter from On top of the MeteorServlet to next to it. so that /App/MyResource will fire meteor but everything else with just get wicket.

How can I do that?

In Case it Matters:

  • Tomcat 6.0.29
  • Firefox 16.0.x
  • IE 9

UPDATE:
Here is what My web.xml currently looks like:

<?xml version="1.0" encoding="ISO-8859-1"?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
                         http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
     version="2.4">

  <display-name>CSC</display-name>

  <!--
    added for Spring Wicket Hibernate compatibility
    From: http://wicketinaction.com/2009/06/wicketspringhibernate-configuration/
  -->
  <context-param>
    <!-- tells Spring to look in the Class Path for applicationContext.xml -->
    <param-name>contextConfigLocation</param-name>
    <param-value>classpath:applicationContext.xml</param-value>
  </context-param>

  <listener>
    <!-- Starts Spring -->
    <listener-class>
      org.springframework.web.context.ContextLoaderListener
    </listener-class>
  </listener>

  <!-- prevent hibernate LazyLoadingException -->
  <filter>
    <filter-name>openSessionInView</filter-name>
    <filter-class> 
      org.springframework.orm.hibernate3.support.OpenSessionInViewFilter
    </filter-class>
    <init-param>
      <param-name>SessionFactoryBeanName</param-name>
      <param-value>sessionFactory</param-value>
    </init-param>
    <init-param>
      <param-name>applicationFactoryClassName</param-name>
      <param-value>org.apache.wicket.SpringWebApplicationFactory</param-value>
    </init-param>
    <init-param>
      <param-name>applicationBean</param-name>
      <param-value>wicketApplication</param-value>
     </init-param>
     <init-param>
       <param-name>applicationClassName</param-name>
       <param-value>
         us.ak.state.revenue.cssd.Personnel.QuickStartApplication
       </param-value>
     </init-param>
     <init-param>
       <param-name>configuration</param-name>
       <param-value>deployment</param-value>
     </init-param>
     <init-param>
       <param-name>contextpath</param-name>
       <param-value>CSC</param-value>
     </init-param>
     <init-param>
       <param-name>fileEncoding</param-name>
       <param-value>ISO-8859-1</param-value>
     </init-param>
   </filter>   

   <!--Atmosphere support, to remove the Ajax Updating Bug CSC-2 -->
   <servlet>
     <description>MeteorServlet</description>
     <servlet-name>CSC</servlet-name>
     <servlet-class>org.atmosphere.cpr.MeteorServlet</servlet-class>         
     <init-param>
       <param-name>org.atmosphere.filter</param-name>
       <param-value>org.apache.wicket.protocol.http.WicketFilter</param-value>
     </init-param>
     <!-- directory settings -->
     <init-param>
       <param-name>org.atmosphere.cpr.AtmosphereHandler.contextRoot</param-name>
       <param-value>CSC</param-value>
     </init-param>
     <!-- Abilities -->
     <init-param>
        <param-name>org.atmosphere.useWebSocket</param-name>
        <param-value>true</param-value>
      </init-param>
      <init-param>
        <param-name>org.atmosphere.useNative</param-name>
        <param-value>true</param-value>
      </init-param>
      <init-param>
       <param-name>org.atmosphere.cpr.sessionSupport</param-name>
       <param-value>true</param-value>
     </init-param>
     <!-- let Atmosphere handle keep alive,
          make sure broadcast happens AFTER AJAX stuff -->
      <init-param>
        <param-name>
          org.atmosphere.cpr.AtmosphereInterceptor
        </param-name>
        <param-value>
          org.atmosphere.interceptor.AtmosphereResourceLifecycleInterceptor,
          org.atmosphere.interceptor.BroadcastOnPostAtmosphereInterceptor
        </param-value>
      </init-param>
      <!-- shouldn't this be defaultContentType? sets Content-Type header default -->
      <init-param>
        <param-name>org.atmosphere.cpr.defaultContextType</param-name>
        <param-value>text/plain</param-value>
      </init-param>
      <init-param>
        <param-name>filterMappingUrlPattern</param-name>
        <param-value>/*</param-value>
      </init-param>
      <!-- minimize memory share broadcaster -->
      <init-param>
        <param-name>org.atmosphere.cpr.broadcaster.shareableThreadPool</param-name>
        <param-value>true</param-value>
      </init-param>
      <!-- error recovery -->
      <init-param>
        <param-name>
          org.atmosphere.cpr.recoverFromDestroyedBroadcaster
        </param-name>
        <param-value>true</param-value>
      </init-param>

      <!-- wicket filter settings -->
      <init-param>
        <param-name>applicationFactoryClassName</param-name>
        <param-value>org.apache.wicket.spring.SpringWebApplicationFactory</param-value>
      </init-param>
      <init-param>
        <param-name>applicationBean</param-name>
        <param-value>wicketApplication</param-value>
      </init-param>
      <init-param>
        <param-name>applicationClassName</param-name>
        <param-value>us.ak.state.revenue.cssd.QuickStartApplication</param-value>
      </init-param>
      <init-param>
        <param-name>configuration</param-name>
        <param-value>deployment</param-value>
      </init-param>
      <init-param>
        <param-name>contextpath</param-name>
        <param-value>CSC</param-value>
      </init-param>
      <init-param>
        <param-name>fileEncoding</param-name>
        <param-value>ISO-8859-1</param-value>
      </init-param>
      <load-on-startup>0</load-on-startup>
    </servlet>

    <servlet-mapping>
      <servlet-name>CSC</servlet-name>
      <url-pattern>/*</url-pattern>
    </servlet-mapping>

    <filter-mapping>
      <filter-name>openSessionInView</filter-name>
      <url-pattern>/*</url-pattern>
    </filter-mapping>

    <mime-mapping>
      <extension>ico</extension>
      <mime-type>image/x-icon</mime-type>
  </mime-mapping>
</web-app>

PS: Maybe a fellow wicket Dev knows, does 1.5 still work as a filter or a servlet?

Dunno about this specific case, but typically it's just a matter of adding a definition and mapping to web.xml before the framework (ie Wicket) mapping:

<servlet>
        <servlet-name>myservlet</servlet-name>
        <servlet-class>org.apache.catalina.servlets.DefaultServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
        <servlet-name>myservlet</servlet-name>
        <url-pattern>/mystuff</url-pattern>
</servlet-mapping>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM