Corda White list Exception - corda

I tried to manually add "org.hibernate.AnnotationException" to the whitelist. I tried to implement serializationWhitelist interface in my state class.
lets say my state class is of type Person and has Address type defined inside it. Every time I try to get the states out of the vault I get this error. or another for "org.hibernate.MappingException". Also When my state implements QueryableState I'm not even able to persist the data. and get the below error
Starting as webserver: localhost:10007
Webserver started up in 59.55 sec
>> Generating transaction based on new create.
>> Verifying contract constraints.
>> Signing transaction with our private key.
>> Gathering the counterparty's signature.
>> Structural step change in child of Gathering the counterparty's signature.
>> Collecting signatures from counter-parties.
>> Done
>> Obtaining notary signature and recording transaction.
>> Structural step change in child of Obtaining notary signature and recording transaction.
>> Requesting signature by notary service
[1;31mE 14:01:20+0530 [qtp9538928-76] controller.DMSController.create - com.esotericsoftware.kryo.KryoException: Class org.hibernate.MappingException is not annotated or on the whitelist, so cannot be used in serialization
Serialization trace:
cause (rx.exceptions.OnErrorNotImplementedException)
throwable (rx.Notification)
[m java.util.concurrent.ExecutionException: com.esotericsoftware.kryo.KryoException: Class org.hibernate.MappingException is not annotated or on the whitelist, so cannot be used in serialization
Serialization trace:
cause (rx.exceptions.OnErrorNotImplementedException)
throwable (rx.Notification)
at java.util.concurrent.CompletableFuture.reportGet(Unknown Source) ~[?:1.8.0_151]
at java.util.concurrent.CompletableFuture.get(Unknown Source) ~[?:1.8.0_151]
at net.corda.core.internal.concurrent.CordaFutureImpl.get(CordaFutureImpl.kt) ~[corda-core-1.0.0.jar:?]
at com.den.managment.controller.DMSController.create(DMSController.java:124) [DisputeManagmentSystem.jar:?]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_151]
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_151]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_151]
at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_151]
at org.glassfish.jersey.server.model.internal.ResourceMethodInvocationHandlerFactory$1.invoke(ResourceMethodInvocationHandlerFactory.java:81) [jersey-server-2.25.jar:?]
at org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher$1.run(AbstractJavaResourceMethodDispatcher.java:144) [jersey-server-2.25.jar:?]
at org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher.invoke(AbstractJavaResourceMethodDispatcher.java:161) [jersey-server-2.25.jar:?]
at org.glassfish.jersey.server.model.internal.JavaResourceMethodDispatcherProvider$ResponseOutInvoker.doDispatch(JavaResourceMethodDispatcherProvider.java:160) [jersey-server-2.25.jar:?]
at org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher.dispatch(AbstractJavaResourceMethodDispatcher.java:99) [jersey-server-2.25.jar:?]
at org.glassfish.jersey.server.model.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:389) [jersey-server-2.25.jar:?]
at org.glassfish.jersey.server.model.ResourceMethodInvoker.apply(ResourceMethodInvoker.java:347) [jersey-server-2.25.jar:?]
at org.glassfish.jersey.server.model.ResourceMethodInvoker.apply(ResourceMethodInvoker.java:102) [jersey-server-2.25.jar:?]
at org.glassfish.jersey.server.ServerRuntime$2.run(ServerRuntime.java:326) [jersey-server-2.25.jar:?]
at org.glassfish.jersey.internal.Errors$1.call(Errors.java:271) [jersey-common-2.25.jar:?]
at org.glassfish.jersey.internal.Errors$1.call(Errors.java:267) [jersey-common-2.25.jar:?]
at org.glassfish.jersey.internal.Errors.process(Errors.java:315) [jersey-common-2.25.jar:?]
at org.glassfish.jersey.internal.Errors.process(Errors.java:297) [jersey-common-2.25.jar:?]
at org.glassfish.jersey.internal.Errors.process(Errors.java:267) [jersey-common-2.25.jar:?]
at org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:317) [jersey-common-2.25.jar:?]
at org.glassfish.jersey.server.ServerRuntime.process(ServerRuntime.java:305) [jersey-server-2.25.jar:?]
at org.glassfish.jersey.server.ApplicationHandler.handle(ApplicationHandler.java:1154) [jersey-server-2.25.jar:?]
at org.glassfish.jersey.servlet.WebComponent.serviceImpl(WebComponent.java:473) [jersey-container-servlet-core-2.25.jar:?]
at org.glassfish.jersey.servlet.WebComponent.service(WebComponent.java:427) [jersey-container-servlet-core-2.25.jar:?]
at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:388) [jersey-container-servlet-core-2.25.jar:?]
at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:341) [jersey-container-servlet-core-2.25.jar:?]
at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:228) [jersey-container-servlet-core-2.25.jar:?]
at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:845) [jetty-servlet-9.3.9.v20160517.jar:9.3.9.v20160517]
at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:583) [jetty-servlet-9.3.9.v20160517.jar:9.3.9.v20160517]
at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1174) [jetty-server-9.3.9.v20160517.jar:9.3.9.v20160517]
at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:511) [jetty-servlet-9.3.9.v20160517.jar:9.3.9.v20160517]
at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1106) [jetty-server-9.3.9.v20160517.jar:9.3.9.v20160517]
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141) [jetty-server-9.3.9.v20160517.jar:9.3.9.v20160517]
at org.eclipse.jetty.server.handler.HandlerCollection.handle(HandlerCollection.java:119) [jetty-server-9.3.9.v20160517.jar:9.3.9.v20160517]
at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:134) [jetty-server-9.3.9.v20160517.jar:9.3.9.v20160517]
at org.eclipse.jetty.server.Server.handle(Server.java:524) [jetty-server-9.3.9.v20160517.jar:9.3.9.v20160517]
at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:319) [jetty-server-9.3.9.v20160517.jar:9.3.9.v20160517]
at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:253) [jetty-server-9.3.9.v20160517.jar:9.3.9.v20160517]
at org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:273) [jetty-io-9.3.9.v20160517.jar:9.3.9.v20160517]
at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:95) [jetty-io-9.3.9.v20160517.jar:9.3.9.v20160517]
at org.eclipse.jetty.io.SelectChannelEndPoint$2.run(SelectChannelEndPoint.java:93) [jetty-io-9.3.9.v20160517.jar:9.3.9.v20160517]
at org.eclipse.jetty.util.thread.strategy.ExecuteProduceConsume.executeProduceConsume(ExecuteProduceConsume.java:303) [jetty-util-9.3.9.v20160517.jar:9.3.9.v20160517]
at org.eclipse.jetty.util.thread.strategy.ExecuteProduceConsume.produceConsume(ExecuteProduceConsume.java:148) [jetty-util-9.3.9.v20160517.jar:9.3.9.v20160517]
at org.eclipse.jetty.util.thread.strategy.ExecuteProduceConsume.run(ExecuteProduceConsume.java:136) [jetty-util-9.3.9.v20160517.jar:9.3.9.v20160517]
at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:671) [jetty-util-9.3.9.v20160517.jar:9.3.9.v20160517]
at org.eclipse.jetty.util.thread.QueuedThreadPool$2.run(QueuedThreadPool.java:589) [jetty-util-9.3.9.v20160517.jar:9.3.9.v20160517]
at java.lang.Thread.run(Unknown Source) [?:1.8.0_151]
Caused by: com.esotericsoftware.kryo.KryoException: Class org.hibernate.MappingException is not annotated or on the whitelist, so cannot be used in serialization
Serialization trace:
cause (rx.exceptions.OnErrorNotImplementedException)
throwable (rx.Notification)
Updated
public class SomeState implements LinearState,QueryableState{
private final UniqueIdentifier uid;
private final Party partyA;
private final Party partyB;
private final List<Address> addresses;
public SomeState(Party partyA, Party partyB, List<Address> addresses) {
super();
this.uid = new UniqueIdentifier();
this.partyA = partyA;
this.partyB = partyB;
this.addresses = addresses;
}
public Party getPartyA() {
return partyA;
}
public Party getPartyB() {
return partyB;
}
public List<Address> getAddresses() {
return addresses;
}
#Override
public List<AbstractParty> getParticipants() {
return Arrays.asList(partyA,partyB);
}
#Override
public PersistentState generateMappedObject(MappedSchema schema) {
if (schema instanceof SomeStateSchema) {
return new SomeStateSchema().new PersistentSomeState(uid.getId(), partyA.getName().toString(), partyB.getName().toString(), addresses);
} else {
throw new IllegalArgumentException("Unrecognised schema $schema");
}
}
#Override
public Iterable<MappedSchema> supportedSchemas() {
return ImmutableList.of(new SomeStateSchema());
}
#Override
public UniqueIdentifier getLinearId() {
return uid;
}
}
public class SomeStateSchema extends MappedSchema {
public SomeStateSchema() {
super(SomeStateSchema.class, 1, ImmutableList.of(PersistentSomeState.class));
}
#Entity
#Table(name = "records")
public class PersistentSomeState extends PersistentState{
#Column(name = "uid")
private final UUID uId;
#Column(name = "partyA")
private final String partyA;
#Column(name = "partyB")
private final String partyB;
#ElementCollection
private final List<Address> addresses;
public PersistentSomeState(UUID uId, String partyA, String partyB, List<Address> addresses) {
super();
this.uId = uId;
this.partyA = partyA;
this.partyB = partyB;
this.addresses = addresses;
}
public UUID getuId() {
return uId;
}
public String getPartyA() {
return partyA;
}
public String getPartyB() {
return partyB;
}
public List<Address> getAddresses() {
return addresses;
}
}
}
#CordaSerializable
public class Address {
public final String street;
public final int pincode;
public Address(String street, int pincode) {
super();
this.street = street;
this.pincode = pincode;
}
public String getStreet() {
return street;
}
public int getPincode() {
return pincode;
}
}
From the controller I call:
#GET
#Path("msas")
#Produces(MediaType.APPLICATION_JSON)
public List<StateAndRef<SomeState>> getMSAs() {
return rpcOps.vaultQuery(SomeState.class).getStates();
}
FLOW is same as in IOU Example.
public SignedTransaction call() throws FlowException {
// Obtain a reference to the notary we want to use.
final Party notary = getServiceHub().getNetworkMapCache().getNotaryIdentities().get(0);
Set<PublicKey> set= getServiceHub().getKeyManagementService().getKeys();
//val ourParties = ourKeys.map { serviceHub.identityService.partyFromKey(it) ?: throw IllegalStateException("Unable to resolve party from key") }
//
List<Party> parties= new ArrayList();
for (Iterator<PublicKey> it = set.iterator(); it.hasNext(); ) {
parties.add(getServiceHub().getIdentityService().partyFromKey(it.next()));
}
progressTracker.setCurrentStep(GENERATING_TRANSACTION);
// Generate an unsigned transaction.
SomeState someState = new SomeState(getServiceHub().getMyInfo().getLegalIdentities().get(0),otherParty,Arrays.asList(new Address("Yes Street",12532)));
final Command<SomeContract.Commands.Create> txCommand = new Command<>(new SomeContract.Commands.Create(),
someState.getParticipants().stream().map(AbstractParty::getOwningKey).collect(Collectors.toList()));
final TransactionBuilder txBuilder = new TransactionBuilder(notary).withItems(new StateAndContract(someState, MSAContract.MSA_CONTRACT_ID), txCommand);
// Stage 2.
progressTracker.setCurrentStep(VERIFYING_TRANSACTION);
// Verify that the transaction is valid.
txBuilder.verify(getServiceHub());
// Stage 3.
progressTracker.setCurrentStep(SIGNING_TRANSACTION);
// Sign the transaction.
final SignedTransaction partSignedTx = getServiceHub().signInitialTransaction(txBuilder);
FlowSession otherPartySession = initiateFlow(otherparty);
// Stage 4.
progressTracker.setCurrentStep(GATHERING_SIGS);
// Send the state to the counterparty, and receive it back with their signature.
final SignedTransaction fullySignedTx = subFlow(
new CollectSignaturesFlow(partSignedTx, Sets.newHashSet(otherPartySession), CollectSignaturesFlow.Companion.tracker()));
// Stage 5.
progressTracker.setCurrentStep(FINALISING_TRANSACTION);
// Notarise and record the transaction in both parties' vaults.
return subFlow(new FinalityFlow(fullySignedTx));
}
I finally found the rootException:
Caused by: org.hibernate.MappingException: Could not determine type for: com.den.managment.state.Address, at table: SomeStateSchema$PersistentSomeState_addresses, for columns: [org.hibernate.mapping.Column(addresses)]
at org.hibernate.mapping.SimpleValue.getType(SimpleValue.java:455)
at org.hibernate.mapping.SimpleValue.isValid(SimpleValue.java:422)
at org.hibernate.mapping.Collection.validate(Collection.java:310)
at org.hibernate.boot.internal.MetadataImpl.validate(MetadataImpl.java:333)
at org.hibernate.boot.internal.SessionFactoryBuilderImpl.build(SessionFactoryBuilderImpl.java:444)
at net.corda.node.services.persistence.HibernateConfiguration.buildSessionFactory(HibernateConfiguration.kt:101)
at net.corda.node.services.persistence.HibernateConfiguration.makeSessionFactoryForSchemas(HibernateConfiguration.kt:74)
at net.corda.node.services.persistence.HibernateConfiguration.access$makeSessionFactoryForSchemas(HibernateConfiguration.kt:27)
at net.corda.node.services.persistence.HibernateConfiguration$sessionFactoryForSchemas$1.apply(HibernateConfiguration.kt:54)
at net.corda.node.services.persistence.HibernateConfiguration$sessionFactoryForSchemas$1.apply(HibernateConfiguration.kt:27)
at java.util.concurrent.ConcurrentHashMap.computeIfAbsent(Unknown Source)
at net.corda.node.services.persistence.HibernateConfiguration.sessionFactoryForSchemas(HibernateConfiguration.kt:54)
at net.corda.node.services.persistence.HibernateConfiguration.sessionFactoryForSchema(HibernateConfiguration.kt:48)
at net.corda.node.services.schema.HibernateObserver.persistStateWithSchema(HibernateObserver.kt:41)
at net.corda.node.services.schema.HibernateObserver.persistState(HibernateObserver.kt:37)
at net.corda.node.services.schema.HibernateObserver.persist(HibernateObserver.kt:31)
at net.corda.node.services.schema.HibernateObserver.access$persist(HibernateObserver.kt:20)
at net.corda.node.services.schema.HibernateObserver$1.call(HibernateObserver.kt:27)
at net.corda.node.services.schema.HibernateObserver$1.call(HibernateObserver.kt:20)
at rx.internal.util.ActionSubscriber.onNext(ActionSubscriber.java:39)
at rx.observers.SafeSubscriber.onNext(SafeSubscriber.java:134)
... 42 more

Your flow is throwing various exceptions because of underlying issues with your code. Corda is then trying to serialise these exceptions to send them back to your RPC client via the RPC framework. Since these types are not whitelisted to be sent via RPC, you get a Kryo exception when you try.
In other words, these exceptions are just a symptom (of your underlying code throwijng AnnotationException or MappingException) rather than a root cause.
Can you post the code showing the Person state definition and how you are trying to retrieve it from the vault in the flow?

Related

Scheduler and Vault Failed to record transaction

I'm quite new with Corda.
I want to do a Scheduler, is like a Todo List that check if the Task is assigned every 30 seconds.
I use the Java Template without any specific configuration, the database is H2 and the Corda version is 4.9
The State class extend ContractState, LinearState and SchedulableState
ToDoState
#BelongsToContract(ToDoContract.class)
public class TodoState implements ContractState, LinearState, SchedulableState {
private final Instant deadlineReminder;
public Party getAssignedBy() {
return assignedBy;
}
private final Party assignedBy;
public Party getAssignedTo() {
return assignedTo;
}
private final Party assignedTo;
public String getTaskDescription() {
return taskDescription;
}
private final String taskDescription;
private UniqueIdentifier linearId;
public TodoState(Party assignedBy, Party assignedTo, String taskDescription) {
this.assignedBy = assignedBy;
this.assignedTo = assignedTo;
this.taskDescription = taskDescription;
this.linearId = new UniqueIdentifier();
this.deadlineReminder = Instant.now().plusSeconds(30);
}
#ConstructorForDeserialization
public TodoState(Party assignedBy, Party assignedTo, String taskDescription, UniqueIdentifier linearId, Instant deadlineReminder) {
this.assignedBy = assignedBy;
this.assignedTo = assignedTo;
this.taskDescription = taskDescription;
this.linearId = linearId;
this.deadlineReminder = deadlineReminder;
}
public TodoState assign(Party assignedTo) {
return new TodoState(assignedBy, assignedTo, taskDescription, linearId, deadlineReminder);
}
#NotNull
#Override
public List<AbstractParty> getParticipants() {
return Arrays.asList(assignedBy, assignedTo);
}
#NotNull
#Override
public UniqueIdentifier getLinearId() {
return linearId;
}
#Nullable
#Override
public ScheduledActivity nextScheduledActivity(#NotNull StateRef thisStateRef, #NotNull FlowLogicRefFactory flowLogicRefFactory) {
System.out.println("nextScheduledActivity invoked");
System.out.println("StateRef TX is " + thisStateRef.getTxhash());
final ScheduledActivity scheduledActivity = new ScheduledActivity(flowLogicRefFactory.create(
"com.template.flows.AlarmFlow", thisStateRef
), deadlineReminder);
System.out.println("Passed");
return scheduledActivity;
}
}
The Flow
public class CreateToDoFlow {
#InitiatingFlow
#StartableByRPC
public static class CreateTodoFlowInitiator extends FlowLogic<Void> {
private final String taskDescription;
private Party me;
public CreateTodoFlowInitiator(String task) {
this.taskDescription = task;
}
#Override
#Suspendable
public Void call() throws FlowException {
this.me = getOurIdentity();
final Party notary = getServiceHub().getNetworkMapCache().getNotary(CordaX500Name.parse("O=Notary,L=London,C=GB"));
final TodoState output = new TodoState(this.me, this.me, this.taskDescription);
final TransactionBuilder builder = new TransactionBuilder(notary);
builder.addOutputState(output);
builder.addCommand(new Command.CreateToDoCommand(), me.getOwningKey());
builder.verify(getServiceHub());
final SignedTransaction ptx = getServiceHub().signInitialTransaction(builder);
subFlow(new FinalityFlow(ptx, Collections.<FlowSession>emptySet()));
System.out.println("1");
return null;
}
}
}
And the AlarmFlow called from the Scheduler, where, i guess the error come.
AlarmFlow
public class AlarmFlow {
#InitiatingFlow
#SchedulableFlow
public static class AlarmFlowInitiator extends FlowLogic<Void> {
private StateRef stateRef;
//public constructor
public AlarmFlowInitiator(StateRef stateRef) {
this.stateRef = stateRef;
}
#Override
#Suspendable
public Void call() throws FlowException {
ServiceHub sb = getServiceHub();
StateAndRef<TodoState> todoStateAndRef = sb.toStateAndRef(stateRef);
TodoState todo = todoStateAndRef.getState().getData();
sb.getVaultService().addNoteToTransaction(
stateRef.getTxhash(), "Reminder made: " + Instant.now()
);
System.out.println("DeadLine is coming up for task: " + todo.getTaskDescription());
return null;
}
}
}
when i execute the flow
flow start CreateTodoFlow task: "Pay bill"
i get the following error
[ERROR] 23:48:19+0200 [Node thread-1] vault.NodeVaultService. - Failed to record transaction states locally - the node could be now in an inconsistent state with other peers and/or the notary - hospitalising the flow {actor_id=internalShell, actor_owning_identity=O=PartyA, L=London, C=GB, actor_store_id=NODE_CONFIG, fiber-id=10000001, flow-id=5eb282b3-4b47-459d-917d-06ea0de16e6f, invocation_id=aadb5b6a-4716-4875-a18e-78a351592365, invocation_timestamp=2022-09-19T21:48:19.052Z, origin=internalShell, session_id=b78e7e1d-b91f-4c40-b42e-468e7b5f4fb0, session_timestamp=2022-09-19T21:48:18.782Z, thread-id=139, tx_id=1BBDFF4EC549457D1C8D60E30041AE97436D44778675BEB2C78E737DBFFFE124}
seems that the vault fail when is called in the Scheduled Activity method
Thanks in advance for your help
I have found the solution:
The scheduler call the AlarmFlow Class and the class is embebbed on the AlarmFlow class like that:
public class AlarmFlow {
#InitiatingFlow
#SchedulableFlow
public static class AlarmFlowInitiator extends FlowLogic<Void> {
private StateRef stateRef;
//public constructor
public AlarmFlowInitiator(StateRef stateRef) {
this.stateRef = stateRef;
}
#Override
#Suspendable
public Void call() throws FlowException {
ServiceHub sb = getServiceHub();
StateAndRef<TodoState> todoStateAndRef = sb.toStateAndRef(stateRef);
TodoState todo = todoStateAndRef.getState().getData();
sb.getVaultService().addNoteToTransaction(
stateRef.getTxhash(), "Reminder made: " + Instant.now()
);
System.out.println("DeadLine is coming up for task: " + todo.getTaskDescription());
return null;
}
}
}
If i extract the AlarmFlowInitiator class out side like that
#InitiatingFlow
#SchedulableFlow
public class AlarmFlow extends FlowLogic<Void>{
private StateRef stateRef;
//public constructor
public AlarmFlow(StateRef stateRef) {
this.stateRef = stateRef;
}
#Override
#Suspendable
public Void call() throws FlowException {
ServiceHub sb = getServiceHub();
StateAndRef<TodoState> todoStateAndRef = sb.toStateAndRef(stateRef);
TodoState todo = todoStateAndRef.getState().getData();
sb.getVaultService().addNoteToTransaction(
stateRef.getTxhash(), "Reminder made: " + Instant.now()
);
System.out.println("DeadLine is coming up for task: " + todo.getTaskDescription());
return null;
}
}
the Scheduler work properly

Can we modify the Participants list of a corda state while evolving it?

I made a Corda project in which I have a policy state with one sender and two receivers. I have three nodes seller, Insurance Company and LSP. I created a new PolicyState from an account on Seller's node and sent it to the accounts on Insurance Company and the LSP using the PolicyCreationFlow. This flow worked fine. But When I tried to update a field of this state from the Insurance Company's terminal then it is not working and generating an exception. This means When I am creating the Policy State then the sender is the Seller node and When I am updating the Policy state then the sender is the Insurance Company and the receivers are the rest of the two nodes.
The code for the policy state is as follows:
#BelongsToContract(PolicyContract.class)
public class PolicyState implements LinearState {
//private variables
private final UniqueIdentifier linearID;
private final String sellerID;
private final String policyID ;
private final String insurerID;
private final int policyNo;
private final double faceValue;
private final double deathBenefits;
private final double annualPremium;
private final double cashSurrenderValue;
private final String policyStartDate;
private final boolean isVerfied;
private List<AnonymousParty> receivingparties;
private final AnonymousParty policyOwner;
#Nullable
private final boolean isValid;
// private final AnonymousParty inuranceCompany;
public PolicyState(UniqueIdentifier linearID, String policyID, String sellerID, String insurerID, int policyNo, double faceValue, double deathBenefits, double annualPremium,
double cashSurrenderValue, String policyStartDate, AnonymousParty policyOwner, boolean isVerfied, List<AnonymousParty> receivingparties, boolean isValid) {
this.linearID = linearID;
this.policyID = policyID;
this.sellerID = sellerID;
this.insurerID = insurerID;
this.policyNo = policyNo;
this.faceValue = faceValue;
this.deathBenefits = deathBenefits;
this.annualPremium = annualPremium;
this.cashSurrenderValue = cashSurrenderValue;
this.policyStartDate = policyStartDate;
this.policyOwner = policyOwner;
this.isVerfied = isVerfied;
this.receivingparties = receivingparties;
this.isValid = isValid;
// this.inuranceCompany = receivingparties.get(0);
}
/////Getters for the Fields
public String getPolicyID() {
return policyID;
}
public String getSellerID() {
return sellerID;
}
public String getInsurerID() {
return insurerID;
}
public int getPolicyNo() {
return policyNo;
}
public double getFaceValue() {
return faceValue;
}
public double getDeathBenefits() {
return deathBenefits;
}
public double getAnnualPremium() {
return annualPremium;
}
public double getCashSurrenderValue() {
return cashSurrenderValue;
}
public String getPolicyStartDate() {
return policyStartDate;
}
public boolean isVerfied() {
return isVerfied;
}
public AnonymousParty getPolicyOwner() {
return policyOwner;
}
public boolean isValid() {
return isValid;
}
public List<AnonymousParty> getReceivingparties() {
return receivingparties;
}
public PolicyState withNewPolicyOwner(AnonymousParty newOwner){
return new PolicyState(linearID, policyID,sellerID, insurerID, policyNo, faceValue, deathBenefits, annualPremium, cashSurrenderValue, policyStartDate, newOwner, isVerfied, receivingparties, isValid);
}
public PolicyState deletePolicy(AnonymousParty policyOwner){
return new PolicyState(linearID, policyID,sellerID, insurerID, policyNo, faceValue, deathBenefits, annualPremium, cashSurrenderValue, policyStartDate, policyOwner, isVerfied,receivingparties, false);
}
#NotNull
#Override
public UniqueIdentifier getLinearId() {
return linearID;
}
#NotNull
#Override
public List<AbstractParty> getParticipants() {
// return Arrays.asList(policyOwner,inuranceCompany);
List<AbstractParty> allParts = new ArrayList<>();
allParts.addAll(receivingparties);
allParts.add(policyOwner);
return allParts;
}
}
Code for Policy Creation flow is as follows:
#InitiatingFlow
#StartableByRPC
public static class PolicyCreation extends FlowLogic<SignedTransaction> {
private final ProgressTracker.Step GENERATING_TRANSACTION = new ProgressTracker.Step("Generating transaction.");
private final ProgressTracker.Step ADDING_POLICY = new ProgressTracker.Step("Adding the Policy State to Transaction.");
private final ProgressTracker.Step VERIFYING_TRANSACTION = new ProgressTracker.Step("Verifying contract constraints.");
private final ProgressTracker.Step SIGNING_TRANSACTION = new ProgressTracker.Step("Signing transaction with our private key.");
private final ProgressTracker.Step GATHERING_SIGS = new ProgressTracker.Step("Gathering the counterparty's signature.") {
#Override
public ProgressTracker childProgressTracker() {
return CollectSignaturesFlow.Companion.tracker();
}
};
private final ProgressTracker.Step FINALISING_TRANSACTION = new ProgressTracker.Step("Obtaining notary signature and recording transaction.") {
#Override
public ProgressTracker childProgressTracker() {
return FinalityFlow.Companion.tracker();
}
};
private final ProgressTracker progressTracker = new ProgressTracker(
GENERATING_TRANSACTION,
ADDING_POLICY,
VERIFYING_TRANSACTION,
SIGNING_TRANSACTION,
GATHERING_SIGS,
FINALISING_TRANSACTION
);
#Override
public ProgressTracker getProgressTracker() {
return progressTracker;
}
//PolicyState Fields
private final String policyID;
private final String sellerID;
private final String insurerID;
private final int policyNo;
private final double faceValue;
private final double deathBenefits;
private final double annualPremium;
private final double cashSurrenderValue;
private final String policyStartDate;
private final String policyOwner;
private final String insuranceCompany;
private final String lsp;
//Constructor for PolicyCreation
public PolicyCreation(String policyID, String sellerID, String insurerID, int policyNo, double faceValue, double deathBenefits, double annualPremium,
double cashSurrenderValue, String policyStartDate, String policyOwner, String insuranceCompany, String lsp) {
this.policyID = policyID;
this.sellerID = sellerID;
this.insurerID = insurerID;
this.policyNo = policyNo;
this.faceValue = faceValue;
this.deathBenefits = deathBenefits;
this.annualPremium = annualPremium;
this.cashSurrenderValue = cashSurrenderValue;
this.policyStartDate = policyStartDate;
this.policyOwner = policyOwner;
this.insuranceCompany = insuranceCompany;
this.lsp = lsp;
}
#Suspendable
#Override
public SignedTransaction call() throws FlowException {
AccountService accountService = getServiceHub().cordaService(KeyManagementBackedAccountService.class);
//Owner Account
AccountInfo policyOwnerAccountInfo = accountService.accountInfo(policyOwner).get(0).getState().getData();
PublicKey policyOwnerKey = subFlow(new NewKeyForAccount(policyOwnerAccountInfo.getIdentifier().getId())).getOwningKey();
//Insurance Company Account
AccountInfo insurerAccountInfo = accountService.accountInfo(insuranceCompany).get(0).getState().getData();
AnonymousParty insuranceCompanyAccount = subFlow(new RequestKeyForAccount(insurerAccountInfo));
//LSP account
AccountInfo lspAccountInfo = accountService.accountInfo(lsp).get(0).getState().getData();
AnonymousParty lspAccount = subFlow(new RequestKeyForAccount(lspAccountInfo));
List<AccountInfo> parties = new ArrayList<>();
parties.add(insurerAccountInfo);
parties.add(lspAccountInfo);
// Step 1. Get a reference to the notary service on our network and our key pair.
// Note: ongoing work to support multiple notary identities is still in progress.
final Party notary = getServiceHub().getNetworkMapCache().getNotaryIdentities().get(0);
// UniqueIdentifier policyLinearId = new UniqueIdentifier(policyID);
final PolicyState output = new PolicyState(new UniqueIdentifier(policyID), policyID, sellerID, insurerID, policyNo, faceValue, deathBenefits, annualPremium, cashSurrenderValue, policyStartDate,new AnonymousParty(policyOwnerKey), false, Arrays.asList(insuranceCompanyAccount,lspAccount), true);
progressTracker.setCurrentStep(GENERATING_TRANSACTION);
final TransactionBuilder builder = new TransactionBuilder(notary);
//Adding outputState to the transaction
progressTracker.setCurrentStep(ADDING_POLICY);
builder.addOutputState(output, PolicyContract.ID);
builder.addCommand(new PolicyContract.Commands.Create(), Arrays.asList(policyOwnerKey,insuranceCompanyAccount.getOwningKey(),lspAccount.getOwningKey()));
// self sign Transaction
progressTracker.setCurrentStep(SIGNING_TRANSACTION);
builder.verify(getServiceHub());
SignedTransaction locallySignedTx = getServiceHub().signInitialTransaction(builder, Arrays.asList(getOurIdentity().getOwningKey(),policyOwnerKey));
progressTracker.setCurrentStep(GATHERING_SIGS);
FlowSession session = initiateFlow(insurerAccountInfo.getHost());
List<TransactionSignature> accountToMoveToSignature = (List<TransactionSignature>) subFlow(new CollectSignatureFlow(locallySignedTx,
session,insuranceCompanyAccount.getOwningKey()));
SignedTransaction signedByCounterParty = locallySignedTx.withAdditionalSignatures(accountToMoveToSignature);
FlowSession session1 = initiateFlow(lspAccountInfo.getHost());
List<TransactionSignature> accountToMoveToSignature1 = (List<TransactionSignature>) subFlow(new CollectSignatureFlow(signedByCounterParty,
session1,lspAccount.getOwningKey()));
signedByCounterParty = signedByCounterParty.withAdditionalSignatures(accountToMoveToSignature1);
progressTracker.setCurrentStep(FINALISING_TRANSACTION);
return subFlow(new FinalityFlow(signedByCounterParty, session,session1));
// return subFlow(new FinalityFlow(signedByCounterParty,
// Arrays.asList(session).stream().filter(it -> it.getCounterparty() != getOurIdentity()).collect(Collectors.toList())));
}
}
#InitiatedBy(PolicyCreation.class)
public static class PolicyCreationResponder extends FlowLogic<String> {
//private variable
private FlowSession counterpartySession;
//Constructor
public PolicyCreationResponder(FlowSession counterpartySession) {
this.counterpartySession = counterpartySession;
}
#Override
#Suspendable
public String call() throws FlowException {
AtomicReference accountMovedTo = new AtomicReference< AccountInfo>();
SignedTransaction signedTransaction = subFlow(new SignTransactionFlow(counterpartySession) {
#Suspendable
#Override
protected void checkTransaction(SignedTransaction stx) throws FlowException {
// Custom Logic to validate transaction.
}
});
subFlow(new ReceiveFinalityFlow(counterpartySession));
return "Policy Sent";
}
}
The code for VerifyPolicyFlow(Updating Flow) is as follow:
#InitiatingFlow
#StartableByRPC
public static class VerifyPolicy extends FlowLogic<SignedTransaction> {
private final UniqueIdentifier linearID;
private final String sender;
// private final ArrayList<String> receivers;
private final String receiver1;
private final String receiver2;
private final boolean isVerified;
public VerifyPolicy(UniqueIdentifier linearID, String sender, String receiver1, String receiver2, boolean isVerified) {
this.linearID = linearID;
this.sender = sender;
this.receiver1 = receiver1;
this.receiver2 = receiver2;
this.isVerified = isVerified;
}
// private ArrayList<AccountInfo> receiversAccountInfo = new ArrayList<>();
#Suspendable
#Override
public SignedTransaction call() throws FlowException {
AccountService accountService = getServiceHub().cordaService(KeyManagementBackedAccountService.class);
//Owner Account
AccountInfo senderAccountInfo = accountService.accountInfo(sender).get(0).getState().getData();
PublicKey senderKey = subFlow(new NewKeyForAccount(senderAccountInfo.getIdentifier().getId())).getOwningKey();
AccountInfo receiver1AccountInfo = accountService.accountInfo(receiver1).get(0).getState().getData();
AnonymousParty receiver1Account = subFlow(new RequestKeyForAccount(receiver1AccountInfo));
//LSP account
AccountInfo receiver2AccountInfo = accountService.accountInfo(receiver2).get(0).getState().getData();
AnonymousParty receiver2Account = subFlow(new RequestKeyForAccount(receiver2AccountInfo));
List<UUID> listOfLinearIds = new ArrayList<>();
listOfLinearIds.add(linearID.getId());
QueryCriteria queryCriteria = new QueryCriteria.LinearStateQueryCriteria(null, listOfLinearIds);
// 2. Get a reference to the inputState data that we are going to settle.
Vault.Page results = getServiceHub().getVaultService().queryBy(PolicyState.class, queryCriteria);
StateAndRef inputStateAndRefToTransfer = (StateAndRef) results.getStates().get(0);
PolicyState inputStateToTransfer = (PolicyState) inputStateAndRefToTransfer.getState().getData();
// Step 1. Get a reference to the notary service on our network and our key pair.
// Note: ongoing work to support multiple notary identities is still in progress.
final Party notary = getServiceHub().getNetworkMapCache().getNotaryIdentities().get(0);
// UniqueIdentifier policyLinearId = new UniqueIdentifier(policyID);
final PolicyState output = new PolicyState(inputStateToTransfer.getLinearId(), inputStateToTransfer.getPolicyID(),
inputStateToTransfer.getSellerID(), inputStateToTransfer.getInsurerID(), inputStateToTransfer.getPolicyNo(),
inputStateToTransfer.getFaceValue(),inputStateToTransfer.getDeathBenefits(), inputStateToTransfer.getAnnualPremium(),
inputStateToTransfer.getCashSurrenderValue(), inputStateToTransfer.getPolicyStartDate(),
new AnonymousParty(senderKey), isVerified, Arrays.asList(receiver1Account,receiver2Account), true);
final TransactionBuilder builder = new TransactionBuilder(notary);
//Adding outputState to the transaction
builder.addInputState(inputStateAndRefToTransfer);
builder.addOutputState(output, PolicyContract.ID);
builder.addCommand(new PolicyContract.Commands.Update(), Arrays.asList(senderKey,receiver1Account.getOwningKey(),receiver2Account.getOwningKey()));
builder.verify(getServiceHub());
SignedTransaction locallySignedTx = getServiceHub().signInitialTransaction(builder, Arrays.asList(getOurIdentity().getOwningKey(),senderKey));
FlowSession session = initiateFlow(receiver1AccountInfo.getHost());
List<TransactionSignature> accountToMoveToSignature = (List<TransactionSignature>) subFlow(new CollectSignatureFlow(locallySignedTx,
session,receiver1Account.getOwningKey()));
SignedTransaction signedByCounterParty = locallySignedTx.withAdditionalSignatures(accountToMoveToSignature);
FlowSession session1 = initiateFlow(receiver2AccountInfo.getHost());
List<TransactionSignature> accountToMoveToSignature1 = (List<TransactionSignature>) subFlow(new CollectSignatureFlow(signedByCounterParty,
session1,receiver2Account.getOwningKey()));
signedByCounterParty = signedByCounterParty.withAdditionalSignatures(accountToMoveToSignature1);
return subFlow(new FinalityFlow(signedByCounterParty, session,session1));
// return null;
}
}
#InitiatedBy(VerifyPolicy.class)
public static class VerifyPolicyResponder extends FlowLogic<String> {
//private variable
private FlowSession counterpartySession;
//Constructor
public VerifyPolicyResponder(FlowSession counterpartySession) {
this.counterpartySession = counterpartySession;
}
#Override
#Suspendable
public String call() throws FlowException {
AtomicReference accountMovedTo = new AtomicReference< AccountInfo>();
SignedTransaction signedTransaction = subFlow(new SignTransactionFlow(counterpartySession) {
#Suspendable
#Override
protected void checkTransaction(SignedTransaction stx) throws FlowException {
// Custom Logic to validate transaction.
}
});
subFlow(new ReceiveFinalityFlow(counterpartySession));
return "Policy Sent";
}
}
The logs of the Insurance Company node says:
java.lang.IllegalArgumentException: Could not find Party for Anonymous(DLCtNGZXmvmEJCHLNA1GCCwYv39gGJxsgf7MTfytmKgtT4)
at net.corda.core.identity.IdentityUtils.groupAbstractPartyByWellKnownParty(IdentityUtils.kt:47) ~[corda-core-4.5.jar:?]
at net.corda.core.identity.IdentityUtils.groupAbstractPartyByWellKnownParty(IdentityUtils.kt:63) ~[corda-core-4.5.jar:?]
at net.corda.core.flows.FinalityFlow.extractExternalParticipants(FinalityFlow.kt:252) ~[corda-core-4.5.jar:?]
at net.corda.core.flows.FinalityFlow.call(FinalityFlow.kt:162) ~[corda-core-4.5.jar:?]
at net.corda.core.flows.FinalityFlow.call(FinalityFlow.kt:43) ~[corda-core-4.5.jar:?]
at net.corda.node.services.statemachine.FlowStateMachineImpl.subFlow(FlowStateMachineImpl.kt:362) ~[corda-node-4.5.jar:?]
at net.corda.core.flows.FlowLogic.subFlow(FlowLogic.kt:397) ~[corda-core-4.5.jar:?]
at com.BLife.flows.VerifyPolicyFlow$VerifyPolicy.call(VerifyPolicyFlow.java:107) ~[?:?]
at com.BLife.flows.VerifyPolicyFlow$VerifyPolicy.call(VerifyPolicyFlow.java:30) ~[?:?]
at net.corda.node.services.statemachine.FlowStateMachineImpl.run(FlowStateMachineImpl.kt:299) ~[corda-node-4.5.jar:?]
at net.corda.node.services.statemachine.FlowStateMachineImpl.run(FlowStateMachineImpl.kt:66) ~[corda-node-4.5.jar:?]
at co.paralleluniverse.fibers.Fiber.run1(Fiber.java:1092) ~[quasar-core-0.7.12_r3-jdk8.jar:0.7.12_r3]
at co.paralleluniverse.fibers.Fiber.exec(Fiber.java:788) ~[quasar-core-0.7.12_r3-jdk8.jar:0.7.12_r3]
at co.paralleluniverse.fibers.RunnableFiberTask.doExec(RunnableFiberTask.java:100) ~[quasar-core-0.7.12_r3-jdk8.jar:0.7.12_r3]
at co.paralleluniverse.fibers.RunnableFiberTask.run(RunnableFiberTask.java:91) ~[quasar-core-0.7.12_r3-jdk8.jar:0.7.12_r3]
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) ~[?:1.8.0_265]
at java.util.concurrent.FutureTask.run(FutureTask.java:266) ~[?:1.8.0_265]
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180) ~[?:1.8.0_265]
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293) ~[?:1.8.0_265]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) ~[?:1.8.0_265]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) ~[?:1.8.0_265]
at net.corda.node.utilities.AffinityExecutor$ServiceAffinityExecutor$1$thread$1.run(AffinityExecutor.kt:63) ~[corda-node-4.5.jar:?]
logs of the Seller node(which is one of the receivers of the Updating flow) says:
net.corda.core.flows.UnexpectedFlowEndException: Counter-flow errored
at Received unexpected counter-flow exception from peer O=InsuranceCompany, L=New York, C=US.() ~[?:?]
at net.corda.node.services.statemachine.FlowStateMachineImpl.fillInLocalStackTrace(FlowStateMachineImpl.kt:204) ~[corda-node-4.5.jar:?]
at net.corda.node.services.statemachine.FlowStateMachineImpl.processEventsUntilFlowIsResumed(FlowStateMachineImpl.kt:192) ~[corda-node-4.5.jar:?]
at net.corda.node.services.statemachine.FlowStateMachineImpl.suspend(FlowStateMachineImpl.kt:506) ~[corda-node-4.5.jar:?]
at net.corda.node.services.statemachine.FlowSessionImpl.receive(FlowSessionImpl.kt:67) ~[corda-node-4.5.jar:?]
at net.corda.node.services.statemachine.FlowSessionImpl.receive(FlowSessionImpl.kt:71) ~[corda-node-4.5.jar:?]
at net.corda.core.flows.ReceiveTransactionFlow.call(ReceiveTransactionFlow.kt:103) ~[corda-core-4.5.jar:?]
at net.corda.core.flows.ReceiveTransactionFlow.call(ReceiveTransactionFlow.kt:31) ~[corda-core-4.5.jar:?]
at net.corda.node.services.statemachine.FlowStateMachineImpl.subFlow(FlowStateMachineImpl.kt:362) ~[corda-node-4.5.jar:?]
at net.corda.core.flows.FlowLogic.subFlow(FlowLogic.kt:397) ~[corda-core-4.5.jar:?]
at net.corda.core.flows.ReceiveFinalityFlow.call(FinalityFlow.kt:285) ~[corda-core-4.5.jar:?]
at net.corda.core.flows.ReceiveFinalityFlow.call(FinalityFlow.kt:280) ~[corda-core-4.5.jar:?]
at net.corda.node.services.statemachine.FlowStateMachineImpl.subFlow(FlowStateMachineImpl.kt:362) ~[corda-node-4.5.jar:?]
at net.corda.core.flows.FlowLogic.subFlow(FlowLogic.kt:397) ~[corda-core-4.5.jar:?]
at com.BLife.flows.VerifyPolicyFlow$VerifyPolicyResponder.call(VerifyPolicyFlow.java:133) ~[?:?]
at com.BLife.flows.VerifyPolicyFlow$VerifyPolicyResponder.call(VerifyPolicyFlow.java:113) ~[?:?]
at net.corda.node.services.statemachine.FlowStateMachineImpl.run(FlowStateMachineImpl.kt:299) ~[corda-node-4.5.jar:?]
at net.corda.node.services.statemachine.FlowStateMachineImpl.run(FlowStateMachineImpl.kt:66) ~[corda-node-4.5.jar:?]
at co.paralleluniverse.fibers.Fiber.run1(Fiber.java:1092) ~[quasar-core-0.7.12_r3-jdk8.jar:0.7.12_r3]
at co.paralleluniverse.fibers.Fiber.exec(Fiber.java:788) ~[quasar-core-0.7.12_r3-jdk8.jar:0.7.12_r3]
at co.paralleluniverse.fibers.RunnableFiberTask.doExec(RunnableFiberTask.java:100) ~[quasar-core-0.7.12_r3-jdk8.jar:0.7.12_r3]
at co.paralleluniverse.fibers.RunnableFiberTask.run(RunnableFiberTask.java:91) ~[quasar-core-0.7.12_r3-jdk8.jar:0.7.12_r3]
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) ~[?:1.8.0_265]
at java.util.concurrent.FutureTask.run(FutureTask.java:266) ~[?:1.8.0_265]
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180) ~[?:1.8.0_265]
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293) ~[?:1.8.0_265]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) ~[?:1.8.0_265]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) ~[?:1.8.0_265]
at net.corda.node.utilities.AffinityExecutor$ServiceAffinityExecutor$1$thread$1.run(AffinityExecutor.kt:63) ~[corda-node-4.5.jar:?]
How can I make it correct, Because according to the project requirement Seller will add the Policy on blockchain and the Insurance company will verify the same policy?
Typically this issue occurs because the receiver does not have the AccountInfo of the sender. When you create the seller account, you generate also the public key of that account, but other participants don't know the mapping between that key and the X.500 name of the seller node.
You could add this at the end of your PolicyCreation flow:
subFlow(ShareStateAndSyncAccounts(state, borrowerAccountInfo.state.data.host))
Documentation.
As reference: here and here.

Flow Exception in CollectSignaturesFlow

I am creating a flow to fetch signatures from CollectSignaturesFlow of other party and I am facing the below issue in log.
#InitiatingFlow
#StartableByRPC
public static class BGInitiator extends FlowLogic<SignedTransaction> {
private final Party manufacturer;
private final Party regulator;
private final String bgData;
public BGInitiator(Party manufacturer,Party regulator, String bgData) {
this.manufacturer = manufacturer;
this.regulator = regulator;
this.bgData = bgData;
}
private final Step GENERATING_TRANSACTION = new Step("Generating transaction based on YO.");
private final Step BUILDING_TRANSACTION = new Step("Verifying contract constraints.");
private final Step SIGNING_TRANSACTION = new Step("Signing transaction with our private key.");
private final Step GATHERING_SIGS = new Step("Gathering the counterparty's signature.") {
#Override
public ProgressTracker childProgressTracker() {
return CollectSignaturesFlow.Companion.tracker();
}
};
private final Step FINALISING_TRANSACTION = new Step("Obtaining notary signature and recording transaction.") {
#Override
public ProgressTracker childProgressTracker() {
return FinalityFlow.Companion.tracker();
}
};
private final ProgressTracker progressTracker = new ProgressTracker(
GENERATING_TRANSACTION,
BUILDING_TRANSACTION,
SIGNING_TRANSACTION,
GATHERING_SIGS,
FINALISING_TRANSACTION
);
#Override
public ProgressTracker getProgressTracker() {
return progressTracker;
}
#Suspendable
#Override
public SignedTransaction call() throws FlowException {
progressTracker.setCurrentStep(GENERATING_TRANSACTION);
Party notary = getServiceHub().getNetworkMapCache().getNotaryIdentities().get(0);
BGState bgState = new BGState(getOurIdentity(),manufacturer,regulator,bgData);
progressTracker.setCurrentStep(BUILDING_TRANSACTION);
final List<PublicKey> requiredSigners = bgState.getParticipantKeys();
final List<Party> parties = bgState.getParties();
final PublicKey me = bgState.getSeller().getOwningKey();
final TransactionBuilder tb = new TransactionBuilder(notary)
.addOutputState(bgState,BGContract.BG_CONTRACT_ID)
.addCommand(new BGContract.Commands.Send(),requiredSigners);
progressTracker.setCurrentStep(SIGNING_TRANSACTION);
final SignedTransaction ptx = getServiceHub().signInitialTransaction(tb,me);
progressTracker.setCurrentStep(GATHERING_SIGS);
FlowSession manufacturerflow = initiateFlow(manufacturer);
final SignedTransaction stx = subFlow(new CollectSignaturesFlow(ptx,ImmutableSet.of(manufacturerflow),ImmutableList.of(me),GATHERING_SIGS.childProgressTracker()));
progressTracker.setCurrentStep(FINALISING_TRANSACTION);
return subFlow(new FinalityFlow(stx,FINALISING_TRANSACTION.childProgressTracker()));
}
}
After deploying and executing, the flow stops, giving me the following error:
java.lang.IllegalArgumentException: The Initiator of CollectSignaturesFlow must pass in exactly the sessions required to sign the transaction.
at net.corda.core.flows.CollectSignaturesFlow.call(CollectSignaturesFlow.kt:108) ~[corda-core-2.0.0.jar:?]
at net.corda.core.flows.CollectSignaturesFlow.call(CollectSignaturesFlow.kt:64) ~[corda-core-2.0.0.jar:?]
at net.corda.core.flows.FlowLogic.subFlow(FlowLogic.kt:243) ~[corda-core-2.0.0.jar:?]
at com.example.flow.BGFlow$BGInitiator.call(BGFlow.java:107) ~[java-source-0.1.jar:?]
I believe I am passing the required flow session and I am still getting this. Any ideas on how to solve this?
Edit 1: when I replace the flowsession to multiple sessions using the code below and executing it, the flow struck and even wrote nothing in logs. I would like to know whether the following is the correct way to fetch signatures.
List<FlowSession> flowSessions = parties.stream().map(a -> initiateFlow(a)).collect(Collectors.toList());
final SignedTransaction stx = subFlow(new CollectSignaturesFlow(ptx,flowSessions,ImmutableList.of(me),GATHERING_SIGS.childProgressTracker()));
The getParties() code in BGState:
public List<Party> getParties(){
return Arrays.asList(manufacturer,regulator);
}
The BGState Definition:
public class BGState implements LinearState,QueryableState {
private final Party seller;
private final Party manufacturer;
private final Party regulator;
private final String senderToReceiverInformation;
private final UniqueIdentifier linearId;
public BGState(Party seller, Party manufacturer,Party regulator,String senderToReceiverInformation) {
this.seller = seller;
this. manufacturer= manufacturer;
this.regulator = regulator;
this.senderToReceiverInformation = senderToReceiverInformation;
this.linearId = new UniqueIdentifier();
}
public Party getSeller() {
return seller;
}
public Party getManufacturer() {
return manufacturer;
}
public Party getRegulator() {
return regulator;
}
#NotNull
#Override
public UniqueIdentifier getLinearId() {
return linearId;
}
#NotNull
#Override
public PersistentState generateMappedObject(MappedSchema schema) {
if (schema instanceof BGSchema) {
return new BGSchema.Bg760(
this.seller,
this.manufacturer,
this.regulator,
this.senderToReceiverInformation,
this.linearId
);
} else {
throw new IllegalArgumentException("Unrecognised schema $schema");
}
}
#NotNull
#Override
public Iterable<MappedSchema> supportedSchemas() {
return ImmutableList.of(new BGSchema());
}
#NotNull
#Override
public List<AbstractParty> getParticipants() {
return Arrays.asList(seller,manufacturer,regulator);
}
public List<PublicKey> getParticipantKeys(){
return getParticipants().stream().map(AbstractParty :: getOwningKey).collect(Collectors.toList());
}
public List<Party> getParties(){
return Arrays.asList(manufacturer,regulator);
}
}
The list of FlowSessions passed to CollectSignaturesFlow must correspond exactly to the transaction's required signers.
In this case, no FlowSession was passed for the regulator, who is one of the required signers.
In BGState - your case there are 3 participants so you need to pass other two parties except initiating node FlowSession also in CollectSignaturesFlow.
FlowSession manufacturerflow = initiateFlow(manufacturer);
FlowSession regulator = initiateFlow(manufacturer);
final SignedTransaction stx = subFlow(new CollectSignaturesFlow(ptx,ImmutableSet.of(manufacturerflow,regulator),ImmutableList.of(me),GATHERING_SIGS.childProgressTracker()));

Authentication work only in debug but not release mode

I followed the sample code realtime database at https://github.com/firebase/quickstart-android/tree/master/database
Everything works find in debug mode. However, if i install the signed apk , download from google play , change the build variant from debug to release in android studio. Signing in will crash.
I have obtained the SHA1 for release and updated the json file accordingly.
I have observed this, do not know if t is relevant.
If i use debug mode to login successfully, the database will change
In release mode, the change do not appear in the database console
from
a:
"test#gmail.com"
b:
"test"
to
email:
"test#gmail.com"
username:
"test"
The error logcat
E/AndroidRuntime: FATAL EXCEPTION: main
Process: simonhcm.multiplay, PID: 18928
java.lang.RuntimeException: java.lang.NoSuchMethodException: <init> [class android.view.View]
at com.a.a.a.d.a(Unknown Source)
at android.support.v7.widget.ek.b(Unknown Source)
at android.support.v7.widget.fb.a(Unknown Source)
at android.support.v7.widget.fb.c(Unknown Source)
at android.support.v7.widget.dj.a(Unknown Source)
at android.support.v7.widget.LinearLayoutManager.a(Unknown Source)
at android.support.v7.widget.LinearLayoutManager.a(Unknown Source)
at android.support.v7.widget.LinearLayoutManager.c(Unknown Source)
at android.support.v7.widget.RecyclerView.J(Unknown Source)
at android.support.v7.widget.RecyclerView.k(Unknown Source)
at android.support.v7.widget.RecyclerView.t(Unknown Source)
at android.support.v7.widget.RecyclerView.c(Unknown Source)
at android.support.v7.widget.ee.run(Unknown Source)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:858)
at android.view.Choreographer.doCallbacks(Choreographer.java:670)
at android.view.Choreographer.doFrame(Choreographer.java:603)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:844)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Caused by: java.lang.NoSuchMethodException: <init> [class android.view.View]
at java.lang.Class.getConstructor(Class.java:528)
at java.lang.Class.getConstructor(Class.java:492)
at com.a.a.a.d.a(Unknown Source) 
at android.support.v7.widget.ek.b(Unknown Source) 
at android.support.v7.widget.fb.a(Unknown Source) 
at android.support.v7.widget.fb.c(Unknown Source) 
at android.support.v7.widget.dj.a(Unknown Source) 
at android.support.v7.widget.LinearLayoutManager.a(Unknown Source) 
at android.support.v7.widget.LinearLayoutManager.a(Unknown Source) 
at android.support.v7.widget.LinearLayoutManager.c(Unknown Source) 
at android.support.v7.widget.RecyclerView.J(Unknown Source) 
at android.support.v7.widget.RecyclerView.k(Unknown Source) 
at android.support.v7.widget.RecyclerView.t(Unknown Source) 
at android.support.v7.widget.RecyclerView.c(Unknown Source) 
at android.support.v7.widget.ee.run(Unknown Source) 
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:858) 
at android.view.Choreographer.doCallbacks(Choreographer.java:670) 
at android.view.Choreographer.doFrame(Choreographer.java:603) 
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:844) 
at android.os.Handler.handleCallback(Handler.java:739) 
at android.os.Handler.dispatchMessage(Handler.java:95) 
at android.os.Looper.loop(Looper.java:148) 
at android.app.ActivityThread.main(ActivityThread.java:5417) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 
W/ActivityManager: Force finishing activity simonhcm.multiplay/.MainActivity
W/DropBoxManagerService: Dropping: data_app_crash (1883 > 0 bytes)
I/OpenGLRenderer: Initialized EGL, version 1.4
I/art: Background partial concurrent mark sweep GC freed 6907(456KB) AllocSpace objects, 1(20KB) LOS objects, 28% free, 41MB/57MB, paused 1.419ms total 107.537ms
E/DropBoxTask: null InputStream
java.io.IOException: null InputStream
at wtd.a(:com.google.android.gms:182)
at wtd.b(:com.google.android.gms:124)
at wsi.a(:com.google.android.gms:88)
at com.google.android.gms.stats.service.DropBoxEntryAddedChimeraService.onHandleIntent(:com.google.android.gms:1176)
at bdz.handleMessage(:com.google.android.gms:65)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148) at android.os.HandlerThread.run(HandlerThread.java:61)
The sign in activity
public class SignInActivity extends BaseActivity implements View.OnClickListener {
private static final String TAG = "SignInActivity";
private DatabaseReference mDatabase;
private FirebaseAuth mAuth;
private EditText mEmailField;
private EditText mPasswordField;
private Button mSignInButton;
private Button mSignUpButton;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_sign_in);
mDatabase = FirebaseDatabase.getInstance().getReference();
mAuth = FirebaseAuth.getInstance();
// Views
mEmailField = (EditText) findViewById(R.id.field_email);
mPasswordField = (EditText) findViewById(R.id.field_password);
mSignInButton = (Button) findViewById(R.id.button_sign_in);
mSignUpButton = (Button) findViewById(R.id.button_sign_up);
// Click listeners
mSignInButton.setOnClickListener(this);
mSignUpButton.setOnClickListener(this);
}
#Override
public void onStart() {
super.onStart();
// Check auth on Activity start
if (mAuth.getCurrentUser() != null) {
onAuthSuccess(mAuth.getCurrentUser());
}
}
private void signIn() {
Log.d(TAG, "signIn");
if (!validateForm()) {
return;
}
showProgressDialog();
String email = mEmailField.getText().toString();
String password = mPasswordField.getText().toString();
mAuth.signInWithEmailAndPassword(email, password)
.addOnCompleteListener(new OnCompleteListener<AuthResult>() {
#Override
public void onComplete(#NonNull Task<AuthResult> task) {
Log.d(TAG, "signIn:onComplete:" + task.isSuccessful());
hideProgressDialog();
if (task.isSuccessful()) {
onAuthSuccess(task.getResult().getUser());
} else {
Toast.makeText(SignInActivity.this, "Sign In Failed",
Toast.LENGTH_SHORT).show();
}
}
});
}
private void signUp() {
Log.d(TAG, "signUp");
if (!validateForm()) {
return;
}
showProgressDialog();
String email = mEmailField.getText().toString();
String password = mPasswordField.getText().toString();
mAuth.createUserWithEmailAndPassword(email, password)
.addOnCompleteListener(
new OnCompleteListener<AuthResult>() {
#Override
public void onComplete(#NonNull Task<AuthResult> task) {
Log.d(TAG, "createUser:onComplete:" + task.isSuccessful());
hideProgressDialog();
if (task.isSuccessful()) {
onAuthSuccess(task.getResult().getUser());
} else {
Toast.makeText(SignInActivity.this, "Sign Up Failed",
Toast.LENGTH_SHORT).show();
}
}
});
}
private void onAuthSuccess(FirebaseUser user) {
String username = usernameFromEmail(user.getEmail());
// Write new user
writeNewUser(user.getUid(), username, user.getEmail());
// Go to MainActivity
startActivity(new Intent(SignInActivity.this, MainActivity.class));
finish();
}
private String usernameFromEmail(String email) {
if (email.contains("#")) {
return email.split("#")[0];
} else {
return email;
}
}
private boolean validateForm() {
boolean result = true;
if (TextUtils.isEmpty(mEmailField.getText().toString())) {
mEmailField.setError("Required");
result = false;
} else {
mEmailField.setError(null);
}
if (TextUtils.isEmpty(mPasswordField.getText().toString())) {
mPasswordField.setError("Required");
result = false;
} else {
mPasswordField.setError(null);
}
return result;
}
// [START basic_write]
private void writeNewUser(String userId, String name, String email) {
User user = new User(name, email);
mDatabase.child("users").child(userId).setValue(user);
}
// [END basic_write]
#Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.button_sign_in:
signIn();
break;
case R.id.button_sign_up:
signUp();
break;
}
}
}

Can't resolve java.lang.NullPointerException

I am getting NullPointerException and I don't know why it is being here.
TemplateController.java
#Controller
#SessionAttributes({"user","initiative"})
public class TemplateController {
#Autowired
private TaskService taskService;
#Autowired
private InitiativeService initiativeService;
#RequestMapping(value = "/addtasktemplate/{taskTemplateObjectId}/{initiativeId}", method = RequestMethod.POST)
public
#ResponseBody
#Transactional(propagation = Propagation.REQUIRED)
String addTaskTemplateUnderInitiative(#PathVariable Integer taskTemplateObjectId, #PathVariable Integer initiativeId, ModelMap model){
User user = (User) model.get("user");
if(user!=null){
Initiative initiative = (Initiative) model.get("initiative");
Boolean check = taskService.addTask(initiative.getInitiativeId(), taskTemplateObjectId, user); //TemplateController.java:67
if(check){
return "successfull";
}else{
return "failure";
}
}
return "Not Eligible";
}
}
The function addTask called in function addTaskTemplateUnderInitiative is defined in TaskDaoImpl.java, whose code is: -
TaskDaoImpl.java
#Repository("TaskDao")
public class TaskDaoImpl implements TaskDao {
private EntityManager entitymanager;
#Autowired
private ObjectInitiativeDao objectInitiativeDao;
#Autowired
private ActionListDao actionListDao;
#PersistenceContext
public void setEntitymanager(EntityManager entitymanager) {
this.entitymanager = entitymanager;
}
#Override
#Transactional(readOnly = false)
public Boolean createTask(Task task) {
try{
entitymanager.persist(task);
return true;
}catch(Exception e){
return false;
}
}
#Override
#Transactional
public Boolean addTask(Integer initiativeId, Integer taskTemplateObjectId, User user) {
ObjectInitiative objectInitiative = objectInitiativeDao.getObjectInitiativeByObjectId(taskTemplateObjectId, false);
Task task = getTaskById(objectInitiative.getRespectiveId());
ObjectInitiative newObject = new ObjectInitiative();
/* Values set for newObject*/
objectInitiativeDao.createObjectInitiative(newObject);
Task newTask = new Task();
/* Values set for newTask */
createTask(newTask);
for(ActionList actionList : task.getActionLists()){
actionListDao.addActionList(newTask.getTaskId(), actionList.getObjectInitiative().getObjectId(), user); //TaskDaoImpl.java:105
}
return true;
}
#Override
#Transactional
public Task getTaskById(Integer taskId) {
Task task = entitymanager.find(Task.class, taskId);
for(ActionList actionList : task.getActionLists()){ //TaskDaoImpl.java:126
Hibernate.initialize(actionList);
}
return task;
}
}
Here, again function addActionList called in function addTask is defined in ActionListDaoImpl.java, whose code is: -
ActionListDaoImpl.java
#Repository("ActionListDao")
public class ActionListDaoImpl implements ActionListDao {
private final Logger logger=LoggerFactory.getLogger(getClass());
private EntityManager entitymanager;
#Autowired
private ObjectInitiativeDao objectInitiativeDao;
#Autowired
private TaskDao taskDao;
#Autowired
private ActionDao actionDao;
#PersistenceContext
public void setEntitymanager(EntityManager entitymanager) {
this.entitymanager = entitymanager;
}
#Override
#Transactional(readOnly = false)
public Boolean createActionList(ActionList actionList) {
try {
entitymanager.persist(actionList);
return true;
} catch (Exception e) {
e.printStackTrace();
return false;
}
}
#Override
#Transactional
public Boolean addActionList(Integer taskId, Integer actionListTemplateObjectId, User user) {
ObjectInitiative objectInitiative = objectInitiativeDao.getObjectInitiativeByObjectId(actionListTemplateObjectId, false);
ActionList actionList = getActionListById(objectInitiative.getRespectiveId());
Task task = taskDao.getTaskById(taskId); //ActionListDaoImpl.java:67
ObjectInitiative newObject = new ObjectInitiative();
/* Values set for newObject */
objectInitiativeDao.createObjectInitiative(newObject);
ActionList newActionList = new ActionList();
/* Values set for newActionList */
createActionList(newActionList);
return true;
}
#Override
#Transactional(readOnly = true)
public ActionList getActionListById(Integer actionListId) {
return entitymanager.find(ActionList.class, actionListId);
}
}
And, the domains of Task, ObjectInitiative and ActionList are: -
Task.java
#Entity
#Table(name = "task")
#Access(AccessType.FIELD)
public class Task {
#Id
#GenericGenerator(name = "task", strategy = "increment")
#GeneratedValue(generator = "task")
private Integer taskId;
#Column
private Integer objectId;
#Column
private Integer initiativeId;
#OneToOne(fetch = FetchType.EAGER)
#JoinColumn(name = "initiativeId", insertable = false, updatable = false, unique = true, nullable = false)
private Initiative initiative;
#OneToOne(fetch = FetchType.EAGER)
#JoinColumn(name = "objectId", insertable = false, updatable = false, unique = true, nullable = false)
private ObjectInitiative objectInitiative;
#OneToMany(mappedBy = "taskId", fetch = FetchType.LAZY)
private List<ActionList> actionLists;
/* Getters, Setters and toString() */
}
ActionList.java
#Entity
#Table(name = "actionlist")
#Access(AccessType.FIELD)
public class ActionList {
#Id
#GenericGenerator(name = "actionlist", strategy = "increment")
#GeneratedValue(generator = "actionlist")
private Integer actionListId;
#Column
private Integer objectId;
#Column
private Integer taskId;
#OneToOne(fetch = FetchType.EAGER)
#JoinColumn(name = "taskId", insertable = false, updatable = false, unique = true, nullable = false)
private Task task;
#OneToOne(fetch = FetchType.EAGER)
#JoinColumn(name = "objectId", insertable = false, updatable = false, unique = true, nullable = false)
private ObjectInitiative objectInitiative;
/* Getters, Setters and toString() */
}
ObjectInitiative.java
#Entity
#Table(name = "objectinitiative")
#Access(AccessType.FIELD)
public class ObjectInitiative {
#Id
#GenericGenerator(name = "objectinitiative", strategy = "increment")
#GeneratedValue(generator = "objectinitiative")
private Integer objectId;
/* Getters, Setters and toString() */
}
Now, I am getting NullPointerException in 'TaskDaoImpl.java' and then in 'ActionListDaoImpl.java' as you can see in log: -
java.lang.NullPointerException
at org.abc.def.dao.TaskDaoImpl.getTaskById(TaskDaoImpl.java:126)
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:483)
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:317)
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:110)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
at com.sun.proxy.$Proxy687.getTaskById(Unknown Source)
at org.abc.def.dao.ActionListDaoImpl.addActionList(ActionListDaoImpl.java:67)
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:483)
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:317)
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:110)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
at com.sun.proxy.$Proxy686.addActionList(Unknown Source)
at org.abc.def.dao.TaskDaoImpl.addTask(TaskDaoImpl.java:105)
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:483)
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:317)
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:110)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
at com.sun.proxy.$Proxy687.addTask(Unknown Source)
at org.abc.def.service.TaskServiceImpl.addTask(TaskServiceImpl.java:28)
at org.abc.def.controller.TemplateController.addTaskTemplateUnderInitiative(TemplateController.java:67)
at org.abc.def.controller.TemplateController$$FastClassByCGLIB$$4c5d2b90.invoke(<generated>)
at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204)
at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:698)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:110)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:631)
at org.abc.def.web.controller.sim.TemplateController$$EnhancerByCGLIB$$7697f039_2.addTaskTemplateUnderInitiative(<generated>)
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:483)
at org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:219)
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:132)
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:104)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:745)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:686)
at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:80)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:925)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:856)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:936)
at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:838)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:644)
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:812)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:725)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:301)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:393)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:219)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:503)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:136)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:74)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:610)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:516)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1015)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:652)
at org.apache.coyote.http11.Http11NioProtocol$Http11ConnectionHandler.process(Http11NioProtocol.java:222)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1575)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1533)
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)
Here, as you can see that I am using existing task template, not creating new task. Exception occurs when I fetch the task, but this does not occur when I create a new task (not using existing task template) and then fetch it.
This is all over. I can't get that how to resolve this problem.
I think you should check Null for initiative object of the method addTaskTemplateUnderInitiative in TemplateController.java
#Controller
#SessionAttributes({"user","initiative"})
public class TemplateController {
#Autowired
private TaskService taskService;
#Autowired
private InitiativeService initiativeService;
#RequestMapping(value = "/addtasktemplate/{taskTemplateObjectId}/{initiativeId}", method = RequestMethod.POST)
public
#ResponseBody
#Transactional(propagation = Propagation.REQUIRED)
String addTaskTemplateUnderInitiative(#PathVariable Integer taskTemplateObjectId, #PathVariable Integer initiativeId, ModelMap model){
User user = (User) model.get("user");
if(user!=null){
Initiative initiative = (Initiative) model.get("initiative");
if(initiative != null){
Boolean check = taskService.addTask(initiative.getInitiativeId(), taskTemplateObjectId, user);
model.addAttribute("initiative", initiativeService.getInitiativeByInitiativeId(initiativeId));
if(check){
return "successfull";
}else{
return "failure";
}
} else return "Falid";
}
return "Not Eligible";
}
}
did you check for below code.
for(ActionList actionList : task.getActionLists()){ //TaskDaoImpl.java:126
Hibernate.initialize(actionList);
}
1.) Either your task is null.
2.) If task is not null, task.getActionLists() is null then. For each will give error here
The above could be that there is no mapping data found or somehow Hibernate is not able to fetch the list.
Is the list Lazy, if yes then try intializing before for loop.
You can make the actionList inside Task as Eager, and it should work perfectly fine, but that is not the solution to your problem.
Issue is mainly because actionList is not able get intialized properly.
Hibernate.initialize(task.getActionLists());

Resources