Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DefaultInstanceManager can not access a member of class with modifiers ""

not sure whats wrong here, please assist. this is the exception :

SEVERE: Exception starting filter com.bannerplay.beans.LoginFilter
java.lang.IllegalAccessException: Class org.apache.catalina.core.DefaultInstanceManager can not access a member of class com.bannerplay.beans.LoginFilter with modifiers ""
at sun.reflect.Reflection.ensureMemberAccess(Unknown Source)
at java.lang.Class.newInstance0(Unknown Source)
at java.lang.Class.newInstance(Unknown Source)
at org.apache.catalina.core.DefaultInstanceManager.newInstance(DefaultInstanceManager.java:134)
at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:256)
at org.apache.catalina.core.ApplicationFilterConfig.setFilterDef(ApplicationFilterConfig.java:382)
at org.apache.catalina.core.ApplicationFilterConfig.<init>(ApplicationFilterConfig.java:103)
at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:4650)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5306)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549)
at java.util.concurrent.FutureTask$Sync.innerRun(Unknown Source)
at java.util.concurrent.FutureTask.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)

login.xhtml

<h:form>
    Username : <h:inputText value="#{loginBean.username}" />
    Password : <h:inputSecret value="#{loginBean.password}" />
<h:commandButton value="Login" action="#{loginBean.checkLogin}" />
</h:form>

web.xml

  <filter>
<filter-name>LoginFilter</filter-name>
<filter-class>com.bannerplay.beans.LoginFilter</filter-class>
  </filter>
  <filter-mapping>
<filter-name>LoginFilter</filter-name>
<servlet-name>FacesServlet</servlet-name>
<url-pattern>/admin/*</url-pattern>
  </filter-mapping>
  <welcome-file-list>
     <welcome-file>/login.xhtml</welcome-file>
  </welcome-file-list>
  <servlet>
       <servlet-name>FacesServlet</servlet-name>
       <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
       <load-on-startup>1</load-on-startup>
  </servlet>
  ...

and LoginFilter.java

import java.io.IOException;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;


@WebFilter("/admin/*")
class LoginFilter implements Filter {
@Override
public void doFilter(ServletRequest request , ServletResponse response , FilterChain chain) throws ServletException, IOException {
    HttpSession session = ((HttpServletRequest) request).getSession();
    UserBean userBean = (UserBean) session.getAttribute("userBean");
    if (userBean != null) {
        User user = userBean.getUser();
        if (user == null) {
            ((HttpServletResponse) response).sendRedirect("/login.xhtml");
        } else
            chain.doFilter(request, response);
    } else
        ((HttpServletResponse) response).sendRedirect("/login.xhtml");
}

public void init(FilterConfig fc) {
}

public void destroy() {
}
}

I have no idea where this exception comes from,please shade some light on this issue. Thanks!

EDIT1: adding UserBean.java code :

import java.io.Serializable;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;

@ManagedBean
@SessionScoped
class UserBean implements Serializable {
/**
 * 
 */
private static final long serialVersionUID = 1L;

public User getUser() {
    return user;
}

public void setUser(User user) {
    this.user = user;
}

private User user;
}

BTW, SEVERE: Context [/projectName] startup failed due to previous errors

like image 981
Li3ro Avatar asked Aug 30 '12 07:08

Li3ro


2 Answers

Change :

class LoginFilter implements Filter {

to

public class LoginFilter implements Filter {

like image 79
Mr_and_Mrs_D Avatar answered Nov 20 '22 16:11

Mr_and_Mrs_D


For me the issue was that of the 'constructor' not being public.

like image 33
Ujjwal Singh Avatar answered Nov 20 '22 18:11

Ujjwal Singh