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;
}
}
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.
Related
i have a question,one order have many crafts, one of the crafts need two or many people to finish,so in the planning entity i usee a list object for planning variables,but when i start the application,it have a error,please give me some idea,thanks!
#PlanningSolution
public class ScheduleSolution extends AbstractPersistable {
#ProblemFactCollectionProperty
private List<Order> orderList;
#ProblemFactCollectionProperty
private List<ProductBom> productBomList;
#PlanningEntityCollectionProperty
private List<JobAssignment> jobAssignmentList;
#ProblemFactCollectionProperty
#ValueRangeProvider(id = "resourceRange")
List<Resource> resourceList;
#PlanningScore
private HardSoftScore score;
}
#PlanningEntity
public class JobAssignment extends AbstractPersistable {
private ProductBom productBom;
#PlanningVariable(valueRangeProviderRefs = { "resourceRange" })
private List<Resource> resourceList;
}
Caused by: java.lang.IllegalArgumentException: The entityClass (class com.demo.domain.reassign.JobAssignment) has a PlanningVariable annotated property (resourceList) that refers to a ValueRangeProvider annotated member (field java.util.List com.demo.domain.reassign.ScheduleSolution.resourceList) that returns a Collection with elements of type (class com.demo.domain.reassign.Resource) which cannot be assigned to the PlanningVariable's type (interface java.util.List). at org.optaplanner.core.impl.domain.valuerange.descriptor.AbstractFromPropertyValueRangeDescriptor.processValueRangeProviderAnnotation(AbstractFromPropertyValueRangeDescriptor.java:136)
A #PlanningVariable cannot be a List, not until we support #PlanningVariableCollection some day. Possible fix:
#PlanningEntity
public class JobAssignment extends AbstractPersistable {
private ProductBom productBom;
#PlanningVariable(valueRangeProviderRefs = { "resourceRange" })
private Resource resource;
}
I use AtomicLongMap in the construct function of RichMapFunctin.Like
public class PathAnalysis extends RichMapFunction<ApiLog, ApiLog> {
private final AtomicLongMap<Object> mObjectAtomicLongMap;
public PathAnalysis()
{
mObjectAtomicLongMap = AtomicLongMap.create();
}
}
register the custom serizlize class, but it not work
env.getConfig().registerTypeWithKryoSerializer(AtomicLongMap.class, new AtomicLongMapSerializer());
It cause:
org.apache.flink.api.common.InvalidProgramException: The implementation of the RichMapFunction is not serializable. The object probably contains or references non serializable fields.
at org.apache.flink.api.java.ClosureCleaner.clean(ClosureCleaner.java:99)
at org.apache.flink.streaming.api.environment.StreamExecutionEnvironment.clean(StreamExecutionEnvironment.java:1550)
at org.apache.flink.streaming.api.datastream.DataStream.clean(DataStream.java:184)
at org.apache.flink.streaming.api.datastream.DataStream.map(DataStream.java:528)
at com.ghzs.Topology.main(Topology.java:91)
Caused by: java.io.NotSerializableException: org.apache.flink.shaded.curator.org.apache.curator.shaded.com.google.common.util.concurrent.AtomicLongMap
at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1184)
at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1548)
at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1509)
at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1432)
at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1178)
at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:348)
at org.apache.flink.util.InstantiationUtil.serializeObject(InstantiationUtil.java:315)
at org.apache.flink.api.java.ClosureCleaner.clean(ClosureCleaner.java:81)
... 4 more
AtomicLongMap is not implements of Serializable .How can I register a effective custom serialize method?
Mark AtomicLongMap as transient, and allocate it in the open() call that your function will receive (because it's a RichMapFunction). So something like:
public class PathAnalysis extends RichMapFunction<ApiLog, ApiLog> {
private transient AtomicLongMap<Object> mObjectAtomicLongMap;
public PathAnalysis() { }
#Override
public void open(Configuration parameters) throws Exception {
super.open(parameters);
mObjectAtomicLongMap = AtomicLongMap.create();
}
}
try with implementation of this function like:
import org.apache.flink.api.common.functions.RichMapFunction;
import com.google.common.util.concurrent.AtomicLongMap;
public class PathAnalysis extends RichMapFunction<ApiLog, ApiLog> {
private final AtomicLongMap<Object> mObjectAtomicLongMap;
public PathAnalysis()
{
mObjectAtomicLongMap = AtomicLongMap.create();
}
#Override
public ApiLog map(ApiLog value) throws Exception {
// TODO Auto-generated method stub
return null;
}
}
I tried to find an answer to this question in the Orika documentation but no luck.
I have the following classes:
public class A {
private String partNumber1;
private String partNumber2;
...
}
public class B {
private Integer shelfNumber;
private A a;
...
}
public class BDTO {
private Integer selfNumber;
private ADTO someA;
...
}
public class ADTO {
private String partNumber;
...
}
.. and the following CustomMapper's to map Objects of B to objects BDO
#Component
public class BMapper extends CustomMapper<B, BDTO> {
#Override
public void mapAtoB(B b, BDTO bdto, MappingContext context) {
super.mapAtoB(b, bdto, context);
//??? what to do here ???
}
}
#Component
public class AMapper extends CustomMapper<A, ADTO> {
#Override
public void mapAtoB(A a, ADTO adto, MappingContext context) {
super.mapAtoB(a, adto, context);
adto.setPartNumber(a.getPartNumber1() + a.getPartNumber2());
}
}
In my client code I have:
B b = new B(5, new A("100392", "100342"));
BDTO bdto = mapper.map(b, BDTO.class);
My question is, in BMapper, what is the correct way to get the AMapper to map "a" to "someA"? To put it differently, what is the correct way to map a to someA in BMapper? I suspect that it can be done through some interface in the MappingContext object.
I found an answer after some experimentation. To map property objects in the main objects mapper, i.e. the scenario explained above, one can use the protected "mapperFacade" member of CustomMapper.
So you can do something like this:
bdto.setSomeA(super.mapperFacade.map(b.getA(), ADTO.class));
My project is in the form:
Class Persistant :
#Entity
public class Produit implements Serializable {
private static final long serialVersionUID = -3352484919001942398L;
#Id
#GeneratedValue
private Long id;
private String module;
private String produit;
//getter&&setter
Class Dao
public List<Entry<Integer, List<Produit>>> parProduit(String cat) {
.......
HashMap<Integer, List<Produit>> legaux = new HashMap<Integer, List<Produit>>();
........
List<Map.Entry<Integer, List<Produit>>> entries = new ArrayList<Entry<Integer, List<Produit>>>(legaux.entrySet());
return entries;
}
when i execute this code i get this error :
java.io.NotSerializableException: java.util.HashMap$Node
java.util.HashMap.EntrySet<K, V>
is not serializable.
legaux.entrySet()
probably returns set of type java.util.HashMap.EntrySet, you may want to check that.
This is the ManagedBean
#ManagedBean #ViewScoped public class DetailItem {
private static final long serialVersionUID = -7647929779133437125L;
#ManagedProperty(value = "#{itemServiceImpl}")
private ItemService servItem;
This is the Service
#Service("itemServiceImpl") #Transactional(value = "transactionManagerLocal") public class ItemServiceImpl implements ItemService {
private static final long serialVersionUID = 1L;
#Autowired
#Qualifier("itemDaoImpl")
private ItemDAO dao;
but when I try to access to the page that used 'DetailItem', I have the following exception:
java.io.NotSerializableException: org.springframework.dao.support.PersistenceExceptionTranslationInterceptor java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1164) java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1518)
To fix that I do the servItem transient and obtain it from the applicationContext. But I understand that it is not the correct solution and I dont find any other. Which is the proper way to do that?
I donĀ“t have the exception with sessionscoped or requestscoped.
Sounds like a similar problem like Serialization of ManagedProperty
Does ItemService implement Serializable and are all members of ItemServiceImpl serializable themselves?