本文整理汇总了Java中javax.servlet.Filter.doFilter方法的典型用法代码示例。如果您正苦于以下问题:Java Filter.doFilter方法的具体用法?Java Filter.doFilter怎么用?Java Filter.doFilter使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.servlet.Filter
的用法示例。
在下文中一共展示了Filter.doFilter方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testMissingHostname
import javax.servlet.Filter; //导入方法依赖的package包/类
@Test
public void testMissingHostname() throws Exception {
ServletRequest request = Mockito.mock(ServletRequest.class);
Mockito.when(request.getRemoteAddr()).thenReturn(null);
ServletResponse response = Mockito.mock(ServletResponse.class);
final AtomicBoolean invoked = new AtomicBoolean();
FilterChain chain = new FilterChain() {
@Override
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse)
throws IOException, ServletException {
assertTrue(HostnameFilter.get().contains("???"));
invoked.set(true);
}
};
Filter filter = new HostnameFilter();
filter.init(null);
assertNull(HostnameFilter.get());
filter.doFilter(request, response, chain);
assertTrue(invoked.get());
assertNull(HostnameFilter.get());
filter.destroy();
}
示例2: test
import javax.servlet.Filter; //导入方法依赖的package包/类
private void test(String method, String operation, String contentType,
boolean upload, boolean error) throws Exception {
HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
HttpServletResponse response = Mockito.mock(HttpServletResponse.class);
Mockito.reset(request);
Mockito.when(request.getMethod()).thenReturn(method);
Mockito.when(request.getParameter(HttpFSFileSystem.OP_PARAM)).thenReturn(operation);
Mockito.when(request.getParameter(HttpFSParametersProvider.DataParam.NAME)).
thenReturn(Boolean.toString(upload));
Mockito.when(request.getContentType()).thenReturn(contentType);
FilterChain chain = Mockito.mock(FilterChain.class);
Filter filter = new CheckUploadContentTypeFilter();
filter.doFilter(request, response, chain);
if (error) {
Mockito.verify(response).sendError(Mockito.eq(HttpServletResponse.SC_BAD_REQUEST),
Mockito.contains("Data upload"));
}
else {
Mockito.verify(chain).doFilter(request, response);
}
}
示例3: doFilter
import javax.servlet.Filter; //导入方法依赖的package包/类
public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain) throws IOException, ServletException {
ProxyFilterChain proxyFilterChain = new ProxyFilterChain();
for (Filter filter : filters) {
proxyFilterChain.setInvokeNextFilter(false);
filter.doFilter(request, response, proxyFilterChain);
if (!proxyFilterChain.isInvokeNextFilter()) {
return;
}
}
chain.doFilter(request, response);
}
示例4: doFilter
import javax.servlet.Filter; //导入方法依赖的package包/类
public void doFilter(final ServletRequest request,
final ServletResponse response) throws IOException,
ServletException {
if (currentPosition == additionalFilters.size()) {
originalChain.doFilter(request, response);
} else {
currentPosition++;
Filter nextFilter = additionalFilters.get(currentPosition - 1);
nextFilter.doFilter(request, response, this);
}
}
示例5: doFilter
import javax.servlet.Filter; //导入方法依赖的package包/类
@Override
public void doFilter(final ServletRequest request, final ServletResponse response) throws IOException, ServletException {
System.out.println("[复合Filter]-->33");
if(currentPosition == additionalFilters.length){
System.out.println("[复合Filter]-->44");
originalChain.doFilter(request, response);
System.out.println("[复合Filter]-->55");
}else{
currentPosition++;
Filter nextFilter = additionalFilters[currentPosition - 1];
System.out.println("[复合Filter]-->66");
nextFilter.doFilter(request, response, this);
System.out.println("[复合Filter]-->77");
}
}
示例6: doFilter
import javax.servlet.Filter; //导入方法依赖的package包/类
@Override
public void doFilter(final ServletRequest request, final ServletResponse response) throws IOException,
ServletException {
if (currentPosition == additionalFilters.size()) {
originalChain.doFilter(request, response);
} else {
currentPosition++;
Filter nextFilter = additionalFilters.get(currentPosition - 1);
nextFilter.doFilter(request, response, this);
}
}
示例7: hostname
import javax.servlet.Filter; //导入方法依赖的package包/类
@Test
public void hostname() throws Exception {
ServletRequest request = Mockito.mock(ServletRequest.class);
Mockito.when(request.getRemoteAddr()).thenReturn("localhost");
ServletResponse response = Mockito.mock(ServletResponse.class);
final AtomicBoolean invoked = new AtomicBoolean();
FilterChain chain = new FilterChain() {
@Override
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse)
throws IOException, ServletException {
// Hostname was set to "localhost", but may get resolved automatically to
// "127.0.0.1" depending on OS.
assertTrue(HostnameFilter.get().contains("localhost") ||
HostnameFilter.get().contains("127.0.0.1"));
invoked.set(true);
}
};
Filter filter = new HostnameFilter();
filter.init(null);
assertNull(HostnameFilter.get());
filter.doFilter(request, response, chain);
assertTrue(invoked.get());
assertNull(HostnameFilter.get());
filter.destroy();
}
示例8: invokeDelegate
import javax.servlet.Filter; //导入方法依赖的package包/类
/**
* Actually invoke the delegate Filter with the given request and response.
* @param delegate the delegate Filter
* @param request the current HTTP request
* @param response the current HTTP response
* @param filterChain the current FilterChain
* @throws ServletException if thrown by the Filter
* @throws IOException if thrown by the Filter
*/
protected void invokeDelegate(
Filter delegate, ServletRequest request, ServletResponse response, FilterChain filterChain)
throws ServletException, IOException {
delegate.doFilter(request, response, filterChain);
}