CDI Beans Serialization issue on Cluster

本小妞迷上赌 提交于 2019-12-24 17:28:22

问题


I'm facing a big issue when I tried to run my EJB+CDI+JSF application on Wildfly 9.2 (Also I tried 10.0) on Standalone Clustered mode.

The issue happens when my cluster container tries to deserialize my session scoped CDI beans, it throws the following exception :

2016-02-06 02:17:22,650 ERROR [io.undertow.request] (default task-9) UT005071: Undertow request failed HttpServerExchange{ GET /login.xhtml request {Accept=[text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8], Accept-Language=[en-US,en;q=0.8], Cache-Control=[max-age=0], Accept-Encoding=[gzip, deflate, sdch], User-Agent=[Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/48.0.2564.97 Safari/537.36], Connection=[keep-alive], Cookie=[__utma=111872281.273659443.1454265274.1454265274.1454265274.1; __utmz=111872281.1454265274.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none); JSESSIONID=oiC7sg_tinxBz6BWghg5PQ2urzCMw4Kh5oPqPRqU.ahmed-pc], Upgrade-Insecure-Requests=[1], Host=[localhost:8180]} response {Connection=[keep-alive], Content-Type=[text/html;charset=UTF-8], Content-Length=[12371], Date=[Fri, 05 Feb 2016 23:17:22 GMT]}}: org.jboss.weld.exceptions.IllegalStateException: WELD-001122: Failed to deserialize annotated type identified with AnnotatedTypeIdentifier [contextId=EAR-1.0.0.ear, bdaId=/C:/Web Server/wildfly-10.0.0.Final/standalone/deployments/EAR-1.0.0.ear/MySystemView-1.0.0.war/WEB-INF/lib/MySystemController-1.0.0.jar, className=com.sh.controller.MySystemController, suffix=null, modified=false]
at org.jboss.weld.annotated.slim.SlimAnnotatedType$SerializationProxy.readResolve(SlimAnnotatedType.java:60)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.jboss.marshalling.reflect.SerializableClass.callReadResolve(SerializableClass.java:413)
at org.jboss.marshalling.river.RiverUnmarshaller.doReadNewObject(RiverUnmarshaller.java:1286)
at org.jboss.marshalling.river.RiverUnmarshaller.doReadObject(RiverUnmarshaller.java:276)
at org.jboss.marshalling.river.RiverUnmarshaller.doReadObject(RiverUnmarshaller.java:224)
at org.jboss.marshalling.river.RiverUnmarshaller.readFields(RiverUnmarshaller.java:1745)
at org.jboss.marshalling.river.RiverUnmarshaller.doInitSerializable(RiverUnmarshaller.java:1658)
at org.jboss.marshalling.river.RiverUnmarshaller.doInitSerializable(RiverUnmarshaller.java:1606)
at org.jboss.marshalling.river.RiverUnmarshaller.doReadNewObject(RiverUnmarshaller.java:1285)
at org.jboss.marshalling.river.RiverUnmarshaller.doReadObject(RiverUnmarshaller.java:276)
at org.jboss.marshalling.river.RiverUnmarshaller.doReadObject(RiverUnmarshaller.java:224)
at org.jboss.marshalling.river.RiverUnmarshaller.readFields(RiverUnmarshaller.java:1745)
at org.jboss.marshalling.river.RiverUnmarshaller.doInitSerializable(RiverUnmarshaller.java:1658)
at org.jboss.marshalling.river.RiverUnmarshaller.doReadNewObject(RiverUnmarshaller.java:1285)
at org.jboss.marshalling.river.RiverUnmarshaller.doReadObject(RiverUnmarshaller.java:276)
at org.jboss.marshalling.river.RiverUnmarshaller.doReadObject(RiverUnmarshaller.java:224)
at org.jboss.marshalling.river.RiverUnmarshaller.readFields(RiverUnmarshaller.java:1745)
at org.jboss.marshalling.river.RiverUnmarshaller.doInitSerializable(RiverUnmarshaller.java:1658)
at org.jboss.marshalling.river.RiverUnmarshaller.doReadNewObject(RiverUnmarshaller.java:1285)
at org.jboss.marshalling.river.RiverUnmarshaller.doReadObject(RiverUnmarshaller.java:276)
at org.jboss.marshalling.river.RiverUnmarshaller.doReadObject(RiverUnmarshaller.java:224)
at org.jboss.marshalling.river.RiverUnmarshaller.readFields(RiverUnmarshaller.java:1745)
at org.jboss.marshalling.river.RiverUnmarshaller.doInitSerializable(RiverUnmarshaller.java:1658)
at org.jboss.marshalling.river.RiverUnmarshaller.doInitSerializable(RiverUnmarshaller.java:1606)
at org.jboss.marshalling.river.RiverUnmarshaller.doReadNewObject(RiverUnmarshaller.java:1285)
at org.jboss.marshalling.river.RiverUnmarshaller.doReadObject(RiverUnmarshaller.java:276)
at org.jboss.marshalling.river.RiverUnmarshaller.doReadObject(RiverUnmarshaller.java:224)
at org.jboss.marshalling.river.RiverUnmarshaller.readFields(RiverUnmarshaller.java:1745)
at org.jboss.marshalling.river.RiverUnmarshaller.doInitSerializable(RiverUnmarshaller.java:1658)
at org.jboss.marshalling.river.RiverUnmarshaller.doReadNewObject(RiverUnmarshaller.java:1285)
at org.jboss.marshalling.river.RiverUnmarshaller.doReadObject(RiverUnmarshaller.java:276)
at org.jboss.marshalling.river.RiverUnmarshaller.doReadObject(RiverUnmarshaller.java:224)
at org.jboss.marshalling.river.RiverUnmarshaller.readFields(RiverUnmarshaller.java:1745)
at org.jboss.marshalling.river.RiverUnmarshaller.doInitSerializable(RiverUnmarshaller.java:1658)
at org.jboss.marshalling.river.RiverUnmarshaller.doReadNewObject(RiverUnmarshaller.java:1285)
at org.jboss.marshalling.river.RiverUnmarshaller.doReadObject(RiverUnmarshaller.java:276)
at org.jboss.marshalling.river.BlockUnmarshaller.readObject(BlockUnmarshaller.java:149)
at org.jboss.marshalling.river.BlockUnmarshaller.readObject(BlockUnmarshaller.java:135)
at org.jboss.marshalling.MarshallerObjectInputStream.readObjectOverride(MarshallerObjectInputStream.java:53)
at org.jboss.marshalling.river.RiverObjectInputStream.readObjectOverride(RiverObjectInputStream.java:307)
at java.io.ObjectInputStream.readObject(ObjectInputStream.java:365)
at java.util.HashMap.readObject(HashMap.java:1396)
at sun.reflect.GeneratedMethodAccessor63.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.jboss.marshalling.reflect.SerializableClass.callReadObject(SerializableClass.java:307)
at org.jboss.marshalling.river.RiverUnmarshaller.doInitSerializable(RiverUnmarshaller.java:1637)
at org.jboss.marshalling.river.RiverUnmarshaller.doReadNewObject(RiverUnmarshaller.java:1285)
at org.jboss.marshalling.river.RiverUnmarshaller.doReadObject(RiverUnmarshaller.java:276)
at org.jboss.marshalling.river.RiverUnmarshaller.doReadObject(RiverUnmarshaller.java:209)
at org.jboss.marshalling.AbstractObjectInput.readObject(AbstractObjectInput.java:41)
at org.wildfly.clustering.marshalling.jboss.SimpleMarshalledValue.get(SimpleMarshalledValue.java:101)
at org.wildfly.clustering.marshalling.jboss.SimpleMarshalledValue.get(SimpleMarshalledValue.java:44)
at org.wildfly.clustering.marshalling.jboss.MarshalledValueMarshaller.read(MarshalledValueMarshaller.java:45)
at org.wildfly.clustering.marshalling.jboss.MarshalledValueMarshaller.read(MarshalledValueMarshaller.java:32)
at org.wildfly.clustering.web.infinispan.session.coarse.CoarseSessionAttributesFactory.findValue(CoarseSessionAttributesFactory.java:84)
at org.wildfly.clustering.web.infinispan.session.coarse.CoarseSessionAttributesFactory.findValue(CoarseSessionAttributesFactory.java:48)
at org.wildfly.clustering.web.infinispan.session.InfinispanSessionFactory.findValue(InfinispanSessionFactory.java:63)
at org.wildfly.clustering.web.infinispan.session.InfinispanSessionFactory.findValue(InfinispanSessionFactory.java:40)
at org.wildfly.clustering.web.infinispan.session.InfinispanSessionManager.findSession(InfinispanSessionManager.java:234)
at org.wildfly.clustering.web.undertow.session.DistributableSessionManager.getSession(DistributableSessionManager.java:140)
at io.undertow.servlet.spec.ServletContextImpl.getSession(ServletContextImpl.java:726)
at io.undertow.servlet.spec.ServletContextImpl.getSession(ServletContextImpl.java:756)
at io.undertow.servlet.spec.ServletContextImpl.updateSessionAccessTime(ServletContextImpl.java:760)
at io.undertow.servlet.spec.HttpServletResponseImpl.responseDone(HttpServletResponseImpl.java:557)
at io.undertow.servlet.handlers.ServletInitialHandler.handleFirstRequest(ServletInitialHandler.java:331)
at io.undertow.servlet.handlers.ServletInitialHandler.dispatchRequest(ServletInitialHandler.java:263)
at io.undertow.servlet.handlers.ServletInitialHandler.access$000(ServletInitialHandler.java:81)
at io.undertow.servlet.handlers.ServletInitialHandler$1.handleRequest(ServletInitialHandler.java:174)
at io.undertow.server.Connectors.executeRootHandler(Connectors.java:202)
at io.undertow.server.HttpServerExchange$1.run(HttpServerExchange.java:793)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
Caused by: an exception which occurred:
in object of type org.jboss.weld.annotated.slim.SlimAnnotatedType$SerializationProxy
in field type
in object of type org.jboss.weld.annotated.slim.backed.BackedAnnotatedField$SerializationProxy
in field field
in object of type org.jboss.weld.injection.attributes.InferringFieldInjectionPointAttributes
in field attributes
in object of type org.jboss.weld.injection.FieldInjectionPoint
in field injectionPoint
in object of type org.jboss.weld.event.EventImpl$SerializationProxy
in field events
in object of type com.sh.controller.MySystemController
in field instance
in object of type org.jboss.weld.context.SerializableContextualInstanceImpl
in object of type java.util.HashMap

I have found this question here on stackoverflow and it mentioned that I shouldn't mark my CDI injected beans as transient to skip serialization, so where is the problem ?? do I need to transient the Injected beans ?

The class source code is more than 2500 Lines of code, I'm coping here the class operators:

@Named("sysControl")
@SessionScoped
public class MySystemController extends VenusAbstractBean implements 

BundleFiles,Serializable {
    private static final long serialVersionUID = 9021710761540108681L;

    private Ticket ticket;
    private Logger log = LoggerFactory.getLogger(this.getClass());
    private TicketData data;
    @Inject
    private transient TicketingSubject subject;
    @Inject
    private TicketListController ticketListCont;
    @EJB
    private SMSHandler smsHandler;
    @EJB
    private TypeFacade typeFacade;
    @EJB
    private UsersFacade usersFacade;
    @EJB
    private StatusFacade statusFacade;
    @EJB
    private TicketFacade ticketFacade;
    @EJB
    private AttachmentsFacade attachementFacade;
    @EJB
    private SourceChannelFacade sourceFacade;
    @EJB
    private TicketDataFacade dataFacade;
    @EJB
    private LockFacade lockFacade;
    @EJB
    private UsersAssignedTicketsFacade ticketAssignFacade;
    @EJB
    private TicketHistoryFacade historyFacade;
    @EJB
    private UsersAssignedTicketsFacade assignedFacade;
    @EJB
    private EmailHandler emailHandlerFacade;
    @EJB
    private GlobalConfigurationFacade globalConfigFacade;
    @EJB
    private EscalationHistoryFacade escalationHistoryFacade;
    @EJB
    private EmailMessageFacade emailMessageFacade;
    @EJB
    private TicketDataFacade ticketDataFacade;
    @EJB
    private CalendarFacade calFacade;
    @EJB
    private EmailHistoryFacade emailHistoryFacade;
    private boolean enableLastReplyEdit = false;
    private MainCategory cat;
    private SubCategory sub;
    private Topic topic;
    private TicketHistory history;
    private byte[] attachment;
    private List<String> uploadedFile;
    private String reply;
    private String reassignNote;
    private Lock myLock;
    private Status status;
    private String mimeType;
    private boolean enableReopen;
    private TicketData selectedData;
    private Long lockSeconds;
    private boolean canbeReopened;
    private List<Integer> reopenStatusList;

    private Users selectedUser;
    private String changeDeptCaller;
    private Integer viewMode;
    private boolean printContent;
    private boolean printReplies;
    private boolean printEscalation;
    private List<Attachments> attachmentsList;
    private List<Attachments> uploadAttachementsList;;
    private boolean displayTimeoutMessage;
    private List<Ticketactions> actions;
    private Ticketactions selectedAction;
    private TicketHoldReason holdReason;
    private boolean skip;
    private int assign_changeDept;
    private boolean canSetOnHold;
    private boolean lockRequired;
    private List<Ticket> selectedTickets;
    private boolean editLastRowMode;
    private List<TicketData> ticketDataList;

    @Inject
    private Event<TicketEvent> events;
    @EJB
    private TicketEventObserver listener;

    @EJB
    private SLATimeCalculator slaCalc;
    @EJB
    private SlaFacade slaFacade;

    @EJB
    private EJBUtils ejbUtils;
    private Date dueDate;

    private Long dueDateRemainingSec;
    }

TicketEvent Class

import java.util.EventObject;

import com.sh.entity.Ticket;

public class TicketEvent extends EventObject {

    private static final long serialVersionUID = 1L;
    private Ticket ticket;
    private Object[] values;

    public TicketEvent(Object source, Ticket ticket, Object... values) {
        super(source);
        this.ticket = ticket;
        this.values = values;
    }

    public Ticket getTicket() {
        return ticket;
    }

    public void setTicket(Ticket ticket) {
        this.ticket = ticket;
    }

    public Object[] getValues() {
        return values;
    }

    public void setValues(Object[] values) {
        this.values = values;
    }

}

回答1:


Basically, you can do the following:

  • Make your beans implement Serializable.

  • Add the transient modifier to the class members that do not implement Serializable.


AFAIK, since Java EE 6, you can use @Inject instead of @EJB when injecting CDI managed beans.



来源:https://stackoverflow.com/questions/35235250/cdi-beans-serialization-issue-on-cluster

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!