-
Notifications
You must be signed in to change notification settings - Fork 974
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
UNDERTOW-375 Using separate indices for filters mapped by servlet nam…
…e and url pattern.
- Loading branch information
1 parent
650b060
commit 299e8cc
Showing
2 changed files
with
102 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
95 changes: 95 additions & 0 deletions
95
servlet/src/test/java/io/undertow/servlet/test/spec/FilterMappingTestCase.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
/* | ||
* JBoss, Home of Professional Open Source. | ||
* Copyright 2014 Red Hat, Inc., and individual contributors | ||
* as indicated by the @author tags. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package io.undertow.servlet.test.spec; | ||
|
||
import io.undertow.servlet.ServletExtension; | ||
import io.undertow.servlet.api.DeploymentInfo; | ||
import io.undertow.servlet.api.ServletInfo; | ||
import io.undertow.servlet.test.util.DeploymentUtils; | ||
import io.undertow.testutils.DefaultServer; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
|
||
import javax.servlet.Filter; | ||
import javax.servlet.FilterChain; | ||
import javax.servlet.FilterConfig; | ||
import javax.servlet.ServletContext; | ||
import javax.servlet.ServletException; | ||
import javax.servlet.ServletRequest; | ||
import javax.servlet.ServletResponse; | ||
import javax.servlet.http.HttpServlet; | ||
import java.io.IOException; | ||
|
||
/** | ||
* @author Stuart Douglas | ||
*/ | ||
@RunWith(DefaultServer.class) | ||
public class FilterMappingTestCase { | ||
|
||
public static String message; | ||
|
||
public static final String HELLO_WORLD = "Hello World"; | ||
public static final String SERVLET = "aServlet"; | ||
|
||
private Filter filterMappedByServletName = new NullFilter(); | ||
private Filter filterMappedByUrlPattern = new NullFilter(); | ||
|
||
/** | ||
* A Filter that does nothing | ||
*/ | ||
static class NullFilter implements Filter { | ||
@Override public void init(FilterConfig filterConfig) throws ServletException {} | ||
|
||
@Override | ||
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException { | ||
filterChain.doFilter(servletRequest, servletResponse); | ||
} | ||
|
||
@Override public void destroy() {} | ||
} | ||
|
||
static class NullServlet extends HttpServlet {} | ||
|
||
@Test | ||
public void testRegisterFilters() throws Exception { | ||
// If the servlet can be set up without an exception, then the filters were correctly registered | ||
setupServlet(); | ||
} | ||
|
||
/** | ||
* Registers a servlet with two filters, one mapped by servlet name and one mapped by url pattern | ||
*/ | ||
private void setupServlet() { | ||
DeploymentUtils.setupServlet(new ServletExtension() { | ||
@Override | ||
public void handleDeployment(DeploymentInfo deploymentInfo, ServletContext servletContext) { | ||
servletContext | ||
.addFilter("MyFilter1", filterMappedByServletName) | ||
.addMappingForServletNames(null, false, SERVLET); | ||
|
||
servletContext | ||
.addFilter("MyFilter2", filterMappedByUrlPattern) | ||
.addMappingForUrlPatterns(null, false, "/"); | ||
} | ||
}, | ||
new ServletInfo(SERVLET, NullServlet.class) | ||
.addMapping("/" + SERVLET)); | ||
} | ||
|
||
} |