Mule DataMapper IOException - mule

I have a class hierarchy with a base class called EntityModel, and two classes InvestorModel and AgentModel that each inherit directly from it and add a few properties. I am then creating Mule Data Maps to map JSON to each child class individually.
The InvestorModel map works fine, but the AgentModel map fails (in the IDE preview) with an IOException stating that it can't instantiate EntityModel. This seems strange as it can instantiate it in the InvestorModel map. I'm posting the error, but I don't really have any source to post as these are just mapping files. I just don't know where to start looking.
Mule Studio is up to date and v3.5.0
java.io.IOException: org.jetel.exception.JetelException: za.co.sci.core.shared.EntityModel can not be instantiated.
at org.jetel.component.tree.writer.TreeFormatter.write(TreeFormatter.java:72)
at org.jetel.util.MultiFileWriter.writeRecord2CurrentTarget(MultiFileWriter.java:420)
at org.jetel.util.MultiFileWriter.write(MultiFileWriter.java:297)
at org.jetel.component.TreeWriter.execute(TreeWriter.java:464)
at org.jetel.graph.Node.run(Node.java:465)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:744)
Caused by: org.jetel.exception.JetelException: za.co.sci.core.shared.EntityModel can not be instantiated.
at com.opensys.cloveretl.component.tree.writer.bean.BeanWriter.a(Unknown Source)
at com.opensys.cloveretl.component.tree.writer.bean.BeanWriter.a(Unknown Source)
at com.opensys.cloveretl.component.tree.writer.bean.BeanWriter.a(Unknown Source)
at com.opensys.cloveretl.component.tree.writer.bean.BeanWriter.writeStartNode(Unknown Source)
at org.jetel.component.tree.writer.model.runtime.WritableObject.writeContent(WritableObject.java:67)
at org.jetel.component.tree.writer.model.runtime.WritableContainer.write(WritableContainer.java:67)
at org.jetel.component.tree.writer.model.runtime.WritableObject.writeContent(WritableObject.java:77)
at org.jetel.component.tree.writer.model.runtime.WritableContainer.write(WritableContainer.java:67)
at org.jetel.component.tree.writer.model.runtime.WritableObject.writeContent(WritableObject.java:77)
at org.jetel.component.tree.writer.model.runtime.WritableContainer.write(WritableContainer.java:67)
at org.jetel.component.tree.writer.model.runtime.WritableObject.writeContent(WritableObject.java:77)
at org.jetel.component.tree.writer.model.runtime.WritableContainer.write(WritableContainer.java:67)
at org.jetel.component.tree.writer.model.runtime.WritableObject.writeContent(WritableObject.java:77)
at org.jetel.component.tree.writer.TreeFormatter.write(TreeFormatter.java:69)
... 7 more
Class snippets:
public abstract class EntityModel implements Serializable {
protected Long id;
private long entityNumber;
private EntityStatus status;
private String entityName;
...
public class AgentModel extends EntityModel implements Serializable{
private int agentCode;
private AgentType agentType;
private AgentClass agentClass;
...
public class InvestorModel extends EntityModel implements Serializable {
private boolean blockedRand;
private String utAUTType;
...

Turns out the error was due to the base class being abstract. Kind of obvious really.
The reason the one map worked, but not the other was because of the order of the fields. The first field to be mapped on the InvestorModel was a field defined in InvestorModel so the mapper knew which class to instantiate. On the AgentModel map the first field was defined on the abstract class EntityModel so the mapper tried to instantiate that class, but failed, it didn't matter that I have chosen AgentModel as the destination.

Related

Error in OptaPlanner when multithreading (External object cannot be looked up)

I have developped an optimization module using OptaPlanner but have encountered an error when multithreading. Note that the module works when multithreading is disabled. I tried several OptaPlanner versions (8.4, 8.1, 7.51) and different JDKs (16 and 14).
I used a simple solver configuration file
**
My planning entity is also straghtforward :
**
#PlanningSolution public class SuccessPromotion {
#ProblemFactCollectionProperty
public ArrayList<RCT> rcts;
#PlanningEntityCollectionProperty
public ArrayList<RCT_Planning> rcts_promos;
#ValueRangeProvider(id = "availablePromotion")
#ProblemFactCollectionProperty
public List<int[]> promotions;
#PlanningScore
public HardSoftScore score;
#PlanningId
public String name; //Constructors //Getter & Setter }
**
The error I get is as follows :
**
Exception in thread "main" java.lang.IllegalStateException: The move
thread with moveThreadIndex (3) has thrown an exception. Relayed here
in the parent thread. at
org.optaplanner.core.impl.heuristic.thread.OrderByMoveIndexBlockingQueue.take(OrderByMoveIndexBlockingQueue.java:147)
at
org.optaplanner.core.impl.localsearch.decider.MultiThreadedLocalSearchDecider.forageResult(MultiThreadedLocalSearchDecider.java:188)
at
org.optaplanner.core.impl.localsearch.decider.MultiThreadedLocalSearchDecider.decideNextStep(MultiThreadedLocalSearchDecider.java:159)
at
org.optaplanner.core.impl.localsearch.DefaultLocalSearchPhase.solve(DefaultLocalSearchPhase.java:71)
at
org.optaplanner.core.impl.solver.AbstractSolver.runPhases(AbstractSolver.java:99)
at
org.optaplanner.core.impl.solver.DefaultSolver.solve(DefaultSolver.java:189)
at test.RealSolver.main(RealSolver.java:140) Caused by:
java.lang.IllegalArgumentException: The externalObject ([I#5ce1e52a)
cannot be looked up. Some functionality, such as multithreaded
solving, requires this ability. Maybe add an #PlanningId annotation on
an identifier property of the class (class [I). Or otherwise, maybe
change the #PlanningSolution annotation's LookUpStrategyType (not
recommended). at
org.optaplanner.core.impl.domain.lookup.NoneLookUpStrategy.lookUpWorkingObject(NoneLookUpStrategy.java:44)
at
org.optaplanner.core.impl.domain.lookup.LookUpManager.lookUpWorkingObject(LookUpManager.java:76)
at
org.optaplanner.core.impl.score.director.AbstractScoreDirector.lookUpWorkingObject(AbstractScoreDirector.java:512)
at
org.optaplanner.core.impl.heuristic.selector.move.generic.ChangeMove.rebase(ChangeMove.java:83)
at
org.optaplanner.core.impl.heuristic.selector.move.generic.ChangeMove.rebase(ChangeMove.java:31)
at
org.optaplanner.core.impl.heuristic.thread.MoveThreadRunner.run(MoveThreadRunner.java:140)
at
java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
at
java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
at
java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
at java.base/java.lang.Thread.run(Thread.java:834)
**
Your error message is
The externalObject ([I#5ce1e52a) cannot be looked up. Some functionality, such as multithreaded solving, requires this ability. Maybe add an #PlanningId annotation on an identifier property of the class (class [I).
That class[I talks about your planning value class (int[]), not your planning entity class (ArrayList<RCT_Planning>).
The planning value class int[] is neither immutable, nor has a #PlanningId, so it can't rebase it easily to another thread (although in theory it could copy it, it doesn't do so at the moment). The error message could be better.
Workaround: wrap int[] in a planning value class.

how to mock a class's inner static class's private field

i'm test a MR class which has mapper/reducer as inner static classes. the mapper has a private field which consume too much memory to make the test failed, i want to use a mock object for that field, but not sure how to do that, here is my code:
public class Aggregator extends Configured implements Tool {
public static class AggregatorMapper extends Mapper<LongWritable, Text, GeneralKey, Text) {
private LookupService lookupService = null; <--- the object i want to mock
}
}
i tried to mockito but seems no way to mock it. any suggestions? thanks!
You can use reflection to access and modify any property of any object you want. There are several questions on SO that answer this quite well already, for example:
Change private static final field using Java reflection.
Accessing private variables in Java via reflection
Instantiate private inner class with java reflection

CDI injection not done in base class for jax-rs controller

I'm struggling with CDI and class inheritence.
I've a JAX-RS controller declared as :
#Path("/share")
public class ControllerShare extends BaseController {
#Inject
private ServiceShare serviceShare;
#PostConstruct
private void verifInit() throws ExceptionTechnique {
log.warn("Checking CDI injection");
if (serviceShare == null) {
log.error("serviceAccount not initialized. Check your EJB configuration");
throw new ExceptionTechnique("serviceShare not initialized. Check your EJB configuration.");
}
}
...
}
This controller extends a base controller declared as :
public abstract class BaseController {
private Logger log = LoggerFactory.getLogger(ControllerShare.class);
#Context protected HttpServletRequest request;
#Inject private ControlerSession ctrlSession;
public BaseController() {}
#PostConstruct
private void verifInit() throws ExceptionTechnique {
log.warn("Checking CDI injection");
if (ctrlSession == null) {
log.error("controllerSession not initialized. Check your CDI configuration");
throw new ExceptionTechnique("serviceAccount not initialized. Check your CDI configuration.");
}
}
...
}
The problem is that injection is correctly done in ControllerShare (I correctly see "Checking CDI injection"), but is not done in the BaseController class (ctrlSession is null).
I try #Named and others combination without success. Injection is just done in ControllerShare and not in BaseController.
EDIT:
One more thing : curiously the #Context is working fine. My request is set and the value is correct.
Thank's for any explanation and solution.
Actually, this should work according to
http://docs.jboss.org/cdi/spec/1.0/html/inheritance.html
4.2. Inheritance of member-level metadata
Suppose a class X is extended directly or indirectly by the bean class of a managed bean or session bean Y.
If X declares an injected field x then Y inherits x.
On a side note: #PostConstruct however is not inherited if you specify it anew. Therefore, in your sub-class your method must be named differently to have both initializers executed.
If X declares an initializer, non-static observer, #PostConstruct or #PreDestroy method x() then Y inherits x() if and only if neither Y nor any intermediate class that is a subclass of X and a superclass of Y overrides the method x().

GemFire: serialize objects in Java and then deserialize them in c#

To cross the language boundary in Java side the class to be serialized needs to implement the DataSerializable interface; and in order to let the deserializer in c# know what class it is , we need to register a classID. Following the example, I write my class in Java like this:
public class Stuff implements DataSerializable{
static { // note that classID (7) must match C#
Instantiator.register(new Instantiator(Stuff.class,(byte)0x07) {
#Override
public DataSerializable newInstance() {
return new Stuff();
}
});
}
private Stuff(){}
public boolean equals(Object obj) {...}
public int hashCode() {...}
public void toData(DataOutput dataOutput) throws IOException {...}
public void fromData(DataInput dataInput) throws IOException, ClassNotFoundException { ...}
}
It looks OK but when I run it I get this exception:
[warning 2012/03/30 15:06:00.239 JST tid=0x1] Error registering
instantiator on pool:
com.gemstone.gemfire.cache.client.ServerOperationException: : While
performing a remote registerInstantiators at
com.gemstone.gemfire.cache.client.internal.AbstractOp.processAck(AbstractOp.java:247)
at
com.gemstone.gemfire.cache.client.internal.RegisterInstantiatorsOp$RegisterInstantiatorsOpImpl.processResponse(RegisterInstantiatorsOp.java:76)
at
com.gemstone.gemfire.cache.client.internal.AbstractOp.attemptReadResponse(AbstractOp.java:163)
at
com.gemstone.gemfire.cache.client.internal.AbstractOp.attempt(AbstractOp.java:363)
at
com.gemstone.gemfire.cache.client.internal.ConnectionImpl.execute(ConnectionImpl.java:229)
at
com.gemstone.gemfire.cache.client.internal.pooling.PooledConnection.execute(PooledConnection.java:321)
at
com.gemstone.gemfire.cache.client.internal.OpExecutorImpl.executeWithPossibleReAuthentication(OpExecutorImpl.java:646)
at
com.gemstone.gemfire.cache.client.internal.OpExecutorImpl.execute(OpExecutorImpl.java:108)
at
com.gemstone.gemfire.cache.client.internal.PoolImpl.execute(PoolImpl.java:624)
at
com.gemstone.gemfire.cache.client.internal.RegisterInstantiatorsOp.execute(RegisterInstantiatorsOp.java:39)
at
com.gemstone.gemfire.internal.cache.PoolManagerImpl.allPoolsRegisterInstantiator(PoolManagerImpl.java:216)
at
com.gemstone.gemfire.internal.InternalInstantiator.sendRegistrationMessageToServers(InternalInstantiator.java:188)
at
com.gemstone.gemfire.internal.InternalInstantiator._register(InternalInstantiator.java:143)
at
com.gemstone.gemfire.internal.InternalInstantiator.register(InternalInstantiator.java:71)
at com.gemstone.gemfire.Instantiator.register(Instantiator.java:168)
at Stuff.(Stuff.java)
Caused by: java.lang.ClassNotFoundException: Stuff$1
I could not figure out why, is there anyone who has experience can help? Thanks in advance!
In most configurations GemFire servers need to deserialize objects in order to index them, run queries and call listeners. So when you register instantiator the class will be registered on all machines in the Distributed System. Hence, the class itself must be available for loading everywhere in the cluster.
As exception stack trace says the error happens on a remote node.
Check if you have the class Stuff on all machines participating in the cluster. At least on cache servers.

Named query on abstract entity

I have 3 entities in hierarchy:
Request.java
#Entity
#Table(name="Request")
#Inheritance(strategy=InheritanceType.JOINED)
#DiscriminatorColumn(name="REQUEST_TYPE", discriminatorType=DiscriminatorType.INTEGER)
#NamedQuery(name="getRequestsById", query="select r from Request r where r.id=:id and r.status=100")
public abstract class Request implemenst Serializable {
...
}
MedicineRequest.java
#Entity
#Table(name="MED_REQUEST")
public abstract class MedicineRequest extends Request {
...
}
ExtendedMedicineRequest.java
#Entity
#Table(name="EXT_MED_REQUEST")
#DiscriminatorValue("1")
public class ExtendedMedicineRequest extends MedicineRequest {
...
}
Where I'm trying to run the above query, getRequestsById, I'm getting the following error message:
Cannot instantiate abstract class of type "Request" with object id "Request-RequestPK#c49aa166"; this may indicate that the inheritance discriminator for the class is not configured correctly.
All the entities are defined properly in persistance.xml, name of the discriminator column is correct too. What can be the matter??
No, it's ok to the entity to be abstract. But I found the reason. The query is generic, so it requests instantiation of sons of this entity. One of sons has relationship to other entity that uses enum from the utility jar. But...jpa project has this jar on the build path, wheh the EAR project doesn't include this jar in module list, so finally, the jar wasn't on the classpath in runtime. The error message was commonly irrelevant in this case.
The reason is "Cannot instantiate abstract class of type", your Request class is abstract. Why? It's an entity then it SHOULDN'T be abstract.