SessionScoped bean setter sets value to real class instead of proxy

I'm using Weld CDI version 3.0.1 on Glassfish 5 with CDI API 2.0 and Java 8. I've just created a simple application with a LoginController class that should just accept 'asd' as username and 'asd' as password and set a User object to my SessionController which is a @SessionScoped bean.

The problem I'm facing is that the user is set to the user property of my SessionController but not to the user property of the SessionController$Proxy$_$$_WeldClientProxy.

Stack:

Daemon Thread [http-listener-2(5)] (Suspended (breakpoint at line 42 in SessionController)) 
    SessionController.setUser(User) line: 42    
    SessionController$Proxy$_$$_WeldClientProxy.setUser(User) line: not available   
    LoginController.startUserSession() line: 57 
    LoginController.login() line: 45    
    NativeMethodAccessorImpl.invoke0(Method, Object, Object[]) line: not available [native method]  
    NativeMethodAccessorImpl.invoke(Object, Object[]) line: 62  
    DelegatingMethodAccessorImpl.invoke(Object, Object[]) line: 43  
    Method.invoke(Object, Object...) line: 498  
    ReflectionUtil.invokeMethod(ELContext, Method, Object, Object[]) line: 181  
    AstValue.invoke(EvaluationContext, Class[], Object[]) line: 289 
    MethodExpressionImpl.invoke(ELContext, Object[]) line: 304  
    WeldMethodExpression(ForwardingMethodExpression).invoke(ELContext, Object[]) line: 40   
    WeldMethodExpression.invoke(ELContext, Object[]) line: 50   
    TagMethodExpression.invoke(ELContext, Object[]) line: 107   
    MethodBindingMethodExpressionAdapter.invoke(FacesContext, Object[]) line: 87    
    ActionListenerImpl.processAction(ActionEvent) line: 102 
    DialogActionListener.processAction(ActionEvent) line: 45    
    CommandButton(UICommand).broadcast(FacesEvent) line: 330    
    UIViewRoot.broadcastEvents(FacesContext, PhaseId) line: 870 
    UIViewRoot.processApplication(FacesContext) line: 1418  
    InvokeApplicationPhase.execute(FacesContext) line: 82   
    InvokeApplicationPhase(Phase).doPhase(FacesContext, Lifecycle, ListIterator<PhaseListener>) line: 100   
    LifecycleImpl.execute(FacesContext) line: 201   
    FacesServlet.service(ServletRequest, ServletResponse) line: 670 
    StandardWrapper.service(ServletRequest, ServletResponse, Servlet) line: 1581    
    ApplicationFilterChain.internalDoFilter(ServletRequest, ServletResponse) line: 338  
    ApplicationFilterChain.doFilter(ServletRequest, ServletResponse) line: 208  
    NoCacheFilter.doFilter(ServletRequest, ServletResponse, FilterChain) line: 46   
    ApplicationFilterChain.internalDoFilter(ServletRequest, ServletResponse) line: 250  
    ApplicationFilterChain.doFilter(ServletRequest, ServletResponse) line: 208  
    Log4jServletFilter.doFilter(ServletRequest, ServletResponse, FilterChain) line: 71  
    ApplicationFilterChain.internalDoFilter(ServletRequest, ServletResponse) line: 250  
    ApplicationFilterChain.doFilter(ServletRequest, ServletResponse) line: 208  
    StandardWrapperValve.invoke(Request, Response) line: 256    
    StandardContextValve.invoke(Request, Response) line: 160    
    WebPipeline(StandardPipeline).doInvoke(Request, Response, boolean) line: 652    
    WebPipeline(StandardPipeline).invoke(Request, Response) line: 591   
    WebPipeline.invoke(Request, Response) line: 99  
    StandardHostValve.invoke(Request, Response) line: 155   
    CoyoteAdapter.doService(Request, Request, Response, Response, boolean) line: 373    
    CoyoteAdapter.service(Request, Response) line: 240  
    ContainerMapper$HttpHandlerCallable.call() line: 463    
    ContainerMapper.service(Request, Response) line: 168    
    ContainerMapper(HttpHandler).runService(Request, Response) line: 206    
    ContainerMapper(HttpHandler).doHandle(Request, Response) line: 180  
    HttpServerFilter.handleRead(FilterChainContext) line: 242   
    ExecutorResolver$9.execute(Filter, FilterChainContext) line: 119    
    DefaultFilterChain.executeFilter(FilterExecutor, Filter, FilterChainContext) line: 284  
    DefaultFilterChain.executeChainPart(FilterChainContext, FilterExecutor, int, int, DefaultFilterChain$FiltersState) line: 201    
    DefaultFilterChain.execute(FilterChainContext) line: 133    
    DefaultFilterChain.process(Context) line: 112   
    ProcessorExecutor.execute(Context) line: 77 
    TCPNIOTransport.fireIOEvent(IOEvent, Connection, IOEventLifeCycleListener) line: 539    
    AbstractIOStrategy.fireIOEvent(Connection, IOEvent, IOEventLifeCycleListener, Logger) line: 112 
    WorkerThreadIOStrategy.run0(Connection, IOEvent, IOEventLifeCycleListener) line: 117    
    WorkerThreadIOStrategy.access$100(Connection, IOEvent, IOEventLifeCycleListener) line: 56   
    WorkerThreadIOStrategy$WorkerThreadRunnable.run() line: 137 
    FixedThreadPool$BasicWorker(AbstractThreadPool$Worker).doWork() line: 593   
    FixedThreadPool$BasicWorker(AbstractThreadPool$Worker).run() line: 573  
    DefaultWorkerThread(Thread).run() line: 748 

This results in a null user property in my SessionController$Proxy$_$$_WeldClientProxy.

SessionController:

import javax.annotation.PostConstruct;
import javax.enterprise.context.SessionScoped;
import javax.inject.Named;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import com.company.models.User;

@SessionScoped
@Named
public class SessionController implements Serializable {

    private static final Logger log = LogManager.getLogger(SessionController.class);
    private static final long serialVersionUID = 1L;

    @PostConstruct
    public void init() {
        log.debug("session in [email protected]: {}", this.toString() );
    }

    private User user;

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

    public User getUser() {
        return user;
    }

LoginController:

import java.io.Serializable;
import java.util.Locale;

import javax.annotation.PostConstruct;
import javax.enterprise.context.RequestScoped;
import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;
import javax.inject.Inject;
import javax.inject.Named;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import com.company.models.User;

@Named
@RequestScoped
public class LoginController implements Serializable {

    private static final Logger log = LogManager.getLogger(LoginController.class);
    private static final long serialVersionUID = 1L;

    private User user;
    private boolean loginStatus;

    @Inject SessionController session;

    @PostConstruct
    public void init() {
        FacesContext.getCurrentInstance().getViewRoot().setLocale(new Locale("it"));
        user = new User();

        log.debug("session in [email protected]: {}", session.toString() );
    }

    public String login() {
        if (authenticateWithCredentials()) {
            loginStatus = true;
            startUserSession();
            return "/home.xhtml?faces-redirect=true";
        } else {
            FacesContext fc = FacesContext.getCurrentInstance();
            fc.addMessage(null, new FacesMessage("Wrong username or password"));

            loginStatus = false;
            return null;
        }
    }

    private void startUserSession() {
        session.setUser(user);
        log.debug("session in loginController.startUserSession: {}", session.toString() );
    }

    private boolean authenticateWithCredentials() {
        if (user.getUsername().equals("asd") && user.getPassword().equals("asd")) {
            return true;
        } else {
            return false;
        }
    }

    ...
jsfcdiweld

Answers

comments powered by Disqus