Celos
Celos

Reputation: 517

Use filter from test scope in web.xml

I have a project that is used as a base for a number of different webapps. I'm trying to run it in "test" mode using the jetty-maven plugin.

The project is a multi-module project. The Filter is located in another module, which is a dependency of the module I'm trying to run, specified like so:

<dependency>
    <groupId>my.example.test</groupId>
    <artifactId>test</artifactId>
    <version>X.X.X</version>
    <scope>test</scope>
</dependency>

The filter class from that dependency is then added as a filter in web.xml:

<filter>
    <filter-name>test</filter-name>
    <filter-class>my.example.test.test.TestFilter</filter-class>
</filter>

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

Finally, the project is started via a call to the jetty-maven plugin (mvn jetty:run-forked) which is set up like this:

<plugin>
    <groupId>org.eclipse.jetty</groupId>
    <artifactId>jetty-maven-plugin</artifactId>
    <version>9.2.2.v20140723</version>
    <configuration>
        <webApp>
            <contextPath>/test</contextPath>
            <descriptor>src/test/webapp/WEB-INF/web.xml</descriptor>
        </webApp>
        <useTestScope>true</useTestScope>
        <jvmArgs>some arguments</jvmArgs>
        <jettyXml>jetty.xml,jetty-ssl.xml,jetty-https.xml</jettyXml>
        <stopKey>stopJetty</stopKey>
        <stopPort>12345</stopPort>
    </configuration>
</plugin>

The project runs and displays the index.html file, but the filter is never applied to any request. Is it possible to run a test-scope app the way I have it set up? What else could I be missing?

Upvotes: 0

Views: 201

Answers (1)

Joakim Erdfelt
Joakim Erdfelt

Reputation: 49472

If the server started, without an error, then the filter was there.

Perhaps you could add logging to the filter init() or doFilter() to verify that it actually got run.

Also, if you are using javax.websocket, then those HTTP/1.1 WebSocket Upgrade requests will not be filterable.

Upvotes: 1

Related Questions