FAQ Database Discussion Community


Tomcat filter not being invoked for Atmosphere servlet

java,tomcat,servlets,servlet-filters,atmosphere
I'm using Atmosphere 1.0.15 to handle push notifications under Tomcat and it's been been working fine for a few years now. Recently I added a simple filter to my Tomcat as a test, which (currently) just logs the incoming URL and continues. The problem is it the filter appears to...

Servlet/filter specific exception handling in java

java,exception,servlets,exception-handling,servlet-filters
I have a servlet extending HttpServlet and implementing a GET request. I also use a filter (from an external library) which is mapped to the above servlet url. Now an exception is thrown by the filter, and as expected I get this SEVERE: Servlet.service() for servlet [myServlet] in context with...

java Servlet Filter Location based settings

java,jsp,servlets,servlet-filters
My application is visited from different countries and I am using a common servlet Filter (MyFilter.java) to control all requests. Is it possible to redirect to other Servlets based on country's visitor? Currently my web.xml configuration is below <filter> <filter-name>myfilter</filter-name> <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class> </filter> <filter-mapping> <filter-name>myfilter</filter-name> <url-pattern>*</url-pattern>...

Login page filter problems

jsp,servlets,servlet-filters
I'm trying to apply a filter to my login page. I'm just not sure how it works, since I'm not too familiar with filters. I'm trying to redirect a user that logs in to different pages based on their user type. A user has either the user type 'Customer', 'Owner'...

Can't Access session scoped JSF managed bean in web filter

jsf,servlet-filters,jsf-2.2
I have a JSF 2.2 application with login page I need to control users access to the pages so I wrote a web filter but the problem is that it always return null when I try to access the session scoped JSF managed bean. I already logged in and I...

Resource not invoked after Jersery Request Filter

spring,jersey,jax-rs,jax-ws,servlet-filters
I have a two SpringServlets defined, one of which directs to a custom filter @WebServlet(urlPatterns = { "/" }, initParams = { @WebInitParam(name = "com.sun.jersey.config.property.packages", value = "com.x.y.resource"), @WebInitParam(name = "com.sun.jersey.api.json.POJOMappingFeature", value = "true") }) public class JerseyServlet extends SpringServlet { } @WebServlet(name = "secure", urlPatterns = "/secure/*", initParams =...

Session scoped managed bean not available as session attribute in filter

jsf,servlet-filters,managed-bean,session-scope
After following the JSF HTTP Session Login tutorial, i tried clicking on pages and it redirected me always to the login page (without css). I tried debugging using the code below: Enumeration<String> attributeNames = wrappedRequest.getSession().getAttributeNames(); while(attributeNames.hasMoreElements()) { System.out.println(attributeNames.nextElement()); } and found that the class I expected to be return at...

Change default location of struts.xml in Struts2

java,xml,struts2,web.xml,servlet-filters
I've created a Struts2 project which is working fine when I place my struts.xml file inside src directory. Below is my web.xml configuration. <?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0"> <display-name>struts2project</display-name> <filter>...

ClasscastException : MyClass cannot be cast to javax.servlet.Filter

java,maven,servlets,servlet-filters
I'm trying to set up a filter for authentication . My Filter class is as follows public class AuthenticationFilter extends HttpServlet{ /** * */ private static final long serialVersionUID = -7678740843612123432L; public void destroy() { // TODO Auto-generated method stub } ///Other methods... public void doFilter(HttpServletRequest request, HttpServletResponse response, FilterChain...

Jersey: Can I add a cookie in ContainerResponseFilter?

cookies,jersey,jax-rs,servlet-filters
I have a ContainerResponseFilter and I tried to set a cookie in it as follows: @Override public void filter(ContainerRequestContext containerRequestContext, ContainerResponseContext containerResponseContext) throws IOException { String cookieName = "ExampleCookie"; String cookieValue = "SomeData"; logger.info("Setting cookie " + cookieName + " with value " + cookieValue + " into cookies "...

Persistent authentication filter logging in; not propagating to JSP

jsp,java-ee,jstl,struts,servlet-filters
I've been working on a "Remember Me?"-style persistent authentication system, but after successfully authenticating and logging in the user, my JSPs do not reflect that the user is logged in until the next page request or refresh is processed. The cookie used for this is being written, and the database...

filter mapping to last path segment

java,java-ee,web.xml,servlet-filters,servlet-mapping
I am trying to map a filter to a specific url in web.xml. The problem is that there is a dynamic path segment in the url and I need to map my filter only to URLs ending with a specific path. For given URLs: http://company.com/webApp/aaa/end http://company.com/webApp/bbb/end http://company.com/webApp/ccc/end I need to...

Initializing filter with values from application.properties

java,tomcat,spring-boot,servlet-filters,jersey-2.0
I want to secure my REST API (jersey2) based on IP addresses, but without having the trouble of Spring Security and so on. I simply need to whitelist a few IPs that are granted full access rights. To implement this, I thought of putting the IPs into the application.properties and...

How to check Glassfish4 server is overloaded?

jsp,java-ee,servlets,glassfish,servlet-filters
My java web application runs on Glassfish4. I want to show a webpage have the string - Server too busy. Please try again later. Which solution is the best for this case?...

Get Managed Bean from servlet filter (is null) [duplicate]

jsf-2,servlet-filters,managed-bean,session-scope
This question already has an answer here: JSF login filter, session is null 1 answer I've seen many posts like mine, but none could helped me. this is my managed bean and it's sessionScoped, if the login is ok it redirects to index page else displays error @ManagedBean @SessionScoped...

Can I reference ResourceResolver?

servlet-filters,apache-felix,sling
I have this Filter: @SlingFilter(description="", vendor="", order=10) class MyFilter extends DoNothingFilter { @Reference private ResourceResolver; } When I am building with this @Reference line my bundle is not containing attached filter (otherwise it's here). What is wrong with this and how to avoid it? Logs say nothing about any issue...

Custom filter extending UrlRewriteFilter to load rules from database

java,url-rewriting,servlet-filters,tuckey-urlrewrite-filter
I have custom redirection filters in my project, which are loading defined rules from database, and handle redirections. In addition to those, I use also UrlRewriteFilter , with some rules defined in urlrewrite.xml. Now I want to switch completely to use tuckey's filter, however I want to load rules from...

Filter causing POST Request Body to become empty

java,spring-mvc,request,servlet-filters
I am using a HMAC Authentication filter. In the filter when I access my POST Request Body, I am able to get the XML in it. When I try to access the XML in the controller I am get a blank string. The xmlString in the filter is giving the...

Servlet jsp, authentication filters

java,jsp,servlets,servlet-filters
I have database in which I have information about user(username, password, role). I want to grant access to some pages only for logged in users with role "ROLE_USER" or "ROLE_ADMIN". (admin has both roles) How I'm trying to do it: I have filter in which I'm cheking is user logged...

java.lang.IllegalStateException at org.apache.catalina.connector.ResponseFacade.setBufferSize(ResponseFacade.java:285)

jsf,servlet-filters
I am using JAAS for authorization and authentication in an Java EE application. JAAS-like things have been omitted entirely for brevity in this question. I am using a Filter that does authentication/authorization as follows (currently, there is only one line response.sendRedirect() to be focused/noticed). @WebFilter(filterName = "SecurityCheck", urlPatterns = {"/WEB-INF/secure/*"})...

Equivalent of org.springframework.boot.context.embedded.FilterRegistrationBean for non-Boot Spring project?

spring,spring-mvc,servlet-filters,spring-bean,spring-session
I'm trying to implement external session handling in Spring, as per this tutorial. I'm having some trouble adding the right filter though. Spring Boot appears to have defined the proper bean/filter, but my project is not Spring Boot, so it cannot find the FilterRegistrationBean. Is there some sort of equivalent...

How to log request body in JAX-RS client

logging,jax-rs,servlet-filters
I need to see my request body with a client JAX-RS request in order to verify that the serialization works correct and reuse the request for test clients like Postman. I know it's possible to activate logging with Jersey using for example resource.addFilter(new com.sun.jersey.api.client.filter.LoggingFilter());. However, I don't use Jersey or...

Jersey: ContainerRequestFilter does not get Context ServletRequest

java,jersey,jetty,ip-address,servlet-filters
To see the full code for this issue, please see this github https://github.com/mobiusinversion/web-application I also created this Jersey Jira https://java.net/jira/browse/JERSEY-2851 I am working on a ContainerRequestFilter using Jersey 2.15. This is an embedded Jetty app which is shaded into a single jar. In the Jetty starter (main class): public static...

How to get request object from HttpSessionAttributeListener

java,java-ee,servlet-filters,servlet-listeners
How to get request object from HttpSessionAttributeListener to find user's IP address? Thanks!...

Authentication Filter is not properly identifying the authentication

java,session,servlets,servlet-filters
I am trying to use a Filter so I can authenticate users before they access the secured pages. Below is my Filter package Filter; import java.io.IOException; import java.io.PrintStream; import java.io.PrintWriter; import java.io.StringWriter; import javax.servlet.Filter; import javax.servlet.FilterChain; import javax.servlet.FilterConfig; import javax.servlet.RequestDispatcher; import javax.servlet.ServletException; import javax.servlet.ServletRequest; import javax.servlet.ServletResponse; import javax.servlet.http.HttpServletRequest; import...

How to pass modified/wrapped HTTPServletRequest to subsequent Zuul Filters?

filter,servlet-filters,netflix,netflix-zuul
We have a Zuul Pre-Filter (Filter1) which will inspect the incoming HTTPServletRequest and make some changes to the query parameters in it to embed it to a custom created request (wrapping HttpServletRequestWrapper). Now, i want to pass this custom wrapped request to the next Zuul Pre-Filter (Filter2). How can i...

Break servlet-filter work

java,java-ee,servlet-filters
I have SecurityAuthorisationFilter and the following part of the code: for(String anonymousRequestURI : anonymousRequestURIs) { if(httpRequest.getRequestURI().equals(anonymousRequestURI)) { //allow request } } String authToken = getTokenFromRequest(httpRequest); If equals is true I need to skip all next filter operations and send request to controller. But, if I write filterChain.doFilter(servletRequest, servletResponse), there is...

How should I test Servlet Filters?

java,spring,spring-mvc,spring-boot,servlet-filters
having trouble figuring out how to test my servlet filters @Component @Order( Ordered.HIGHEST_PRECEDENCE ) class CORSFilter extends OncePerRequestFilter { private final Logger log = LoggerFactory.getLogger( CORSFilter.class ); @Override protected void doFilterInternal( final HttpServletRequest request, final HttpServletResponse response, final FilterChain filterChain ) throws ServletException, IOException { log.debug( "request: {}", request );...