flow error when trying to initiate a new IOUFlow - java

I am following here for the tutorials in the docs, I edited the files accordingly and deployed the nodes and when trying to initiate a new flow I'm getting the following error
I am running the following command from node B
"start IOUFlow iouValue: 99, otherParty: "O=PartyB,L=New York,C=US"
and the error is:
[INFO ] 2019-06-03T10:17:30,437Z [pool-8-thread-2] shell.StartShellCommand.main - Executing command "start IOUFlow iouValue: 99, otherParty: "O=PartyB,L=New York,C=US"",
[INFO ] 2019-06-03T10:17:30,601Z [Node thread-1] corda.flow.run - Flow raised an error... sending it to flow hospital {actor_id=internalShell, actor_owning_identity=O=PartyB, L=New York, C=US, actor_store_id=NODE_CONFIG, fiber-id=10000002, flow-id=61680a4f-1ecd-49f6-9e4e-639f8fef1a47, invocation_id=b3b77b97-92ab-4f8d-8108-910ad6681120, invocation_timestamp=2019-06-03T10:17:30.547Z, origin=internalShell, session_id=4184f80f-5f43-494c-a364-aacb5cf6396f, session_timestamp=2019-06-03T10:14:07.053Z, thread-id=190}
java.lang.IllegalArgumentException: Do not provide flow sessions for the local node. FinalityFlow will record the notarised transaction locally.
at net.corda.core.flows.FinalityFlow.call(FinalityFlow.kt:124) ~[corda-core-4.0.jar:?]
at net.corda.core.flows.FinalityFlow.call(FinalityFlow.kt:39) ~[corda-core-4.0.jar:?]
at net.corda.node.services.statemachine.FlowStateMachineImpl.subFlow(FlowStateMachineImpl.kt:290) ~[corda-node-4.0.jar:?]
at net.corda.core.flows.FlowLogic.subFlow(FlowLogic.kt:314) ~[corda-core-4.0.jar:?]
at com.template.flows.IOUFlow.call(IOUFlow.java:62) ~[?:?]
at com.template.flows.IOUFlow.call(IOUFlow.java:16) ~[?:?]
at net.corda.node.services.statemachine.FlowStateMachineImpl.run(FlowStateMachineImpl.kt:228) ~[corda-node-4.0.jar:?]
at net.corda.node.services.statemachine.FlowStateMachineImpl.run(FlowStateMachineImpl.kt:45) ~[corda-node-4.0.jar:?]
at co.paralleluniverse.fibers.Fiber.run1(Fiber.java:1092) ~[quasar-core-0.7.10-jdk8.jar:0.7.10]
at co.paralleluniverse.fibers.Fiber.exec(Fiber.java:788) ~[quasar-core-0.7.10-jdk8.jar:0.7.10]
at co.paralleluniverse.fibers.RunnableFiberTask.doExec(RunnableFiberTask.java:100) ~[quasar-core-0.7.10-jdk8.jar:0.7.10]
at co.paralleluniverse.fibers.RunnableFiberTask.run(RunnableFiberTask.java:91) ~[quasar-core-0.7.10-jdk8.jar:0.7.10]
at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) ~[?:1.8.0_201]
at java.util.concurrent.FutureTask.run(Unknown Source) ~[?:1.8.0_201]
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(Unknown Source) ~[?:1.8.0_201]
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(Unknown Source) ~[?:1.8.0_201]
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) ~[?:1.8.0_201]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) ~[?:1.8.0_201]
at net.corda.node.utilities.AffinityExecutor$ServiceAffinityExecutor$1$thread$1.run(AffinityExecutor.kt:63) ~[corda-node-4.0.jar:?]
the IOUFlow code:
#Suspendable
#Override
public Void call() throws FlowException {
// We retrieve the notary identity from the network map.
Party notary = getServiceHub().getNetworkMapCache().getNotaryIdentities().get(0);
// We create the transaction components.
IOUState outputState = new IOUState(iouValue, getOurIdentity(), otherParty);
Command command = new Command<>(new TemplateContract.Commands.Action(), getOurIdentity().getOwningKey());
// We create a transaction builder and add the components.
TransactionBuilder txBuilder = new TransactionBuilder(notary)
.addOutputState(outputState, TemplateContract.ID)
.addCommand(command);
// Signing the transaction.
SignedTransaction signedTx = getServiceHub().signInitialTransaction(txBuilder);
// Creating a session with the other party.
FlowSession otherPartySession = initiateFlow(otherParty);
// We finalise the transaction and then send it to the counterparty.
subFlow(new FinalityFlow(signedTx, otherPartySession));
return null;
}
cmd output
what should I do?

You're trying to start a flow where Node B is both the initiator and the target party. That will break FinalityFlow in Corda 4.0.
Check here for more details and a workaround.

You are trying to open a session with the local node.
A.k.a, you are running the flow on partyB's node and trying to send a transaction to partyB.

Related

ZipException when Attempting to retrieve AuthnRequest

I'm getting a java.util.zip.ZipException: invalid bit length repeat when attempting to retrieve a AuthnRequest with the opensaml library HTTPRedirectDeflateDecoder. I'm receiving the deflated and encoded SAMLObject thorough a GET request. This is the code I'm using to retrieve the object
import org.opensaml.saml.saml2.binding.decoding.impl.HTTPRedirectDeflateDecoder;
protected String getAuthnRequest(
HttpServletRequest request,
HttpServletResponse response) throws Exception {
HTTPRedirectDeflateDecoder decoder = new HTTPRedirectDeflateDecoder();
decoder.setHttpServletRequest(request);
try {
decoder.initialize();
decoder.decode(); //error occurs here
} catch (ComponentInitializationException | MessageDecodingException e) {
throw new Exception("error in decoding authnrequest", e);
}
MessageContext<SAMLObject> messageContext = decoder.getMessageContext();
...
}
Full error:
org.opensaml.messaging.decoder.MessageDecodingException: Error unmarshalling message from input stream
at org.opensaml.messaging.decoder.servlet.BaseHttpServletRequestXMLMessageDecoder.unmarshallMessage(BaseHttpServletRequestXMLMessageDecoder.java:158)
at org.opensaml.saml.saml2.binding.decoding.impl.HTTPRedirectDeflateDecoder.doDecode(HTTPRedirectDeflateDecoder.java:108)
at org.opensaml.messaging.decoder.AbstractMessageDecoder.decode(AbstractMessageDecoder.java:58)
at org.opensaml.messaging.decoder.servlet.AbstractHttpServletRequestMessageDecoder.decode(AbstractHttpServletRequestMessageDecoder.java:55)
at org.opensaml.messaging.decoder.servlet.BaseHttpServletRequestXMLMessageDecoder.decode(BaseHttpServletRequestXMLMessageDecoder.java:72)
at com.healthtrio.htcweb.common.controller.sso.BaseOutboundController.getAuthnRequestId(BaseOutboundController.java:426)
... 129 common frames omitted
Caused by: net.shibboleth.utilities.java.support.xml.XMLParserException: Unable to read data from input stream
at net.shibboleth.utilities.java.support.xml.BasicParserPool.parse(BasicParserPool.java:255)
at org.opensaml.core.xml.util.XMLObjectSupport.unmarshallFromInputStream(XMLObjectSupport.java:235)
at org.opensaml.messaging.decoder.servlet.BaseHttpServletRequestXMLMessageDecoder.unmarshallMessage(BaseHttpServletRequestXMLMessageDecoder.java:154)
... 134 common frames omitted
Caused by: java.util.zip.ZipException: invalid bit length repeat
at java.base/java.util.zip.InflaterInputStream.read(InflaterInputStream.java:165)
at java.base/java.util.zip.InflaterInputStream.read(InflaterInputStream.java:123)
at org.apache.xerces.impl.XMLEntityManager$RewindableInputStream.readAndBuffer(Unknown Source)
at org.apache.xerces.impl.XMLEntityManager.setupCurrentEntity(Unknown Source)
at org.apache.xerces.impl.XMLVersionDetector.determineDocVersion(Unknown Source)
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
at org.apache.xerces.parsers.DOMParser.parse(Unknown Source)
at org.apache.xerces.jaxp.DocumentBuilderImpl.parse(Unknown Source)
at java.xml/javax.xml.parsers.DocumentBuilder.parse(DocumentBuilder.java:122)
at net.shibboleth.utilities.java.support.xml.BasicParserPool$DocumentBuilderProxy.parse(BasicParserPool.java:785)
at net.shibboleth.utilities.java.support.xml.BasicParserPool.parse(BasicParserPool.java:247)
... 136 common frames omitted
Any help is appreciated,
Thanks
Found the error, This was a mistake from the data I was testing with. I used a deflated/encoded AuthnRequest. Since this is a GET request, I had to also URL decode the SAML Object.

Remote forward() invocation of ProcessorContext throws NPE

I use Apache Kafka Streams the Processor API.
I create a remote object that extends the UnicastRemoteObject inside the StateStore of the Processor.
When the init(ProcessorContext) method of the Processor (which extends the AbstractProcessor) of my topology is called I put a ProcessorContext reference inside that remote Object.
public void init(ProcessorContext processorContext){
super.init(processorContext);
this.myStore = (MyCustomStore<String, String>)context().getStateStore("mystore");
this.myStore.getRemoteObject().setProcessorContext(processorContext);
}
If I access the ProcessorContext only remotely and use the forward method to send records to a sink processor it works fine. And if I access the ProcessorContext only locally to send records with forward it works fine, too.
If I access the ProcessorContext both locally and remotely to use forward I have NPE. I used a synchronized method in which foward is called because I thought that two different threads try to access ProcessorContext at the same time but the NPE insists.
It seems to me that somehow the same thread calls forward at the same time
both locally and remotely and that throws NPE.
The message is:
java.lang.NullPointerException
at org.apache.kafka.streams.processor.internals.ProcessorContextImpl.forward(ProcessorContextImpl.java:114)
at org.apache.kafka.streams.processor.internals.ProcessorContextImpl.forward(ProcessorContextImpl.java:90)
at StateMessageBean.sendMessage(StateMessageBean.java:109)
at StateMessageBean.subroundEnded(StateMessageBean.java:87)
at sun.reflect.GeneratedMethodAccessor26.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:361)
at sun.rmi.transport.Transport$1.run(Transport.java:200)
at sun.rmi.transport.Transport$1.run(Transport.java:197)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.Transport.serviceCall(Transport.java:196)
at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:568)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:826)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.lambda$run$0(TCPTransport.java:683)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:682)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
at sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(StreamRemoteCall.java:283)
at sun.rmi.transport.StreamRemoteCall.executeCall(StreamRemoteCall.java:260)
at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:161)
at java.rmi.server.RemoteObjectInvocationHandler.invokeRemoteMethod(RemoteObjectInvocationHandler.java:227)
at java.rmi.server.RemoteObjectInvocationHandler.invoke(RemoteObjectInvocationHandler.java:179)
at com.sun.proxy.$Proxy25.subroundEnded(Unknown Source)
at CoordinatorProcessor.collectIncreaseOfC(CoordinatorProcessor.java:332)
at CoordinatorProcessor.process(CoordinatorProcessor.java:119)
at CoordinatorProcessor.process(CoordinatorProcessor.java:25)
at org.apache.kafka.streams.processor.internals.ProcessorNode$1.run(ProcessorNode.java:50)
at org.apache.kafka.streams.processor.internals.ProcessorNode.runAndMeasureLatency(ProcessorNode.java:244)
at org.apache.kafka.streams.processor.internals.ProcessorNode.process(ProcessorNode.java:133)
at org.apache.kafka.streams.processor.internals.ProcessorContextImpl.forward(ProcessorContextImpl.java:143)
at org.apache.kafka.streams.processor.internals.ProcessorContextImpl.forward(ProcessorContextImpl.java:126)
at org.apache.kafka.streams.processor.internals.ProcessorContextImpl.forward(ProcessorContextImpl.java:90)
at org.apache.kafka.streams.processor.internals.SourceNode.process(SourceNode.java:87)
at org.apache.kafka.streams.processor.internals.StreamTask.process(StreamTask.java:302)
at org.apache.kafka.streams.processor.internals.AssignedStreamsTasks.process(AssignedStreamsTasks.java:94)
at org.apache.kafka.streams.processor.internals.TaskManager.process(TaskManager.java:409)
at org.apache.kafka.streams.processor.internals.StreamThread.processAndMaybeCommit(StreamThread.java:964)
at org.apache.kafka.streams.processor.internals.StreamThread.runOnce(StreamThread.java:832)
at org.apache.kafka.streams.processor.internals.StreamThread.runLoop(StreamThread.java:767)
at org.apache.kafka.streams.processor.internals.StreamThread.run(StreamThread.java:736)
The two methods that I call remotely and locally are:
//remote method
#Override
public void subroundEnded()
{
PhiMessage newPhiMessage = new PhiMessage();
newPhiMessage.setSiteId(this.siteId);
newPhiMessage.setCurrentRound(this.currentRound);
newPhiMessage.setCurrentSubround(this.currentSubround);
newPhiMessage.setPhi(this.phi);
byte[] byteNewPhiMessage = SerializationUtils.serialize(newPhiMessage);
this.processorContext.forward("PhiMessage", byteNewPhiMessage);
}
//local method
public void sendIncrease()
{
IncreaseMessage increaseMessage = new IncreaseMessage();
increaseMessage.setCurrentRound(this.currentRound);
increaseMessage.setCurrentSubround(this.currentSubround);
increaseMessage.setIncrease(this.increase);
byte[] byteIncreaseMessage = SerializationUtils.serialize(increaseMessage);
this.processorContext.forward("IncreaseMessage", byteIncreaseMessage);
}

HSQLDB Serialization error with parallel JobSteps

I'm trying to get a complex flow of jobs done in Spring Batch using a combination of multithreaded Steps and parallel jobs.
Right now I've set up 3 jobs (1, 2, 3), the first (1) of which is running before the others (as expected) and completing withouth issues. The other two (2,3) are supposed to run parallel, having some parallel Steps of their own. All these jobs I'm trying to run are being encapsulated within JobSteps and then run within a master job (0).
The problem only occurs at jobs 2 & 3, where some JobStep fails, not always at the same point, not always the same JobStep. This is the stacktrace of such exception:
2019-01-07 17:35:57,513 ERROR: o.s.b.c.s.AbstractStep [SimpleAsyncTaskExecutor-10] Encountered an error executing step 2 in job0
org.springframework.dao.DataAccessResourceFailureException: Could not increment identity; nested exception is java.sql.SQLTransactionRollbackException: transaction rollback: serialization failure at org.springframework.jdbc.support.incrementer.AbstractIdentityColumnMaxValueIncrementer.getNextKey(AbstractIdentityColumnMaxValueIncrementer.java:113) ~[spring-jdbc-4.3.13.RELEASE.jar:4.3.13.RELEASE]
at org.springframework.jdbc.support.incrementer.AbstractDataFieldMaxValueIncrementer.nextLongValue(AbstractDataFieldMaxValueIncrementer.java:128) ~[spring-jdbc-4.3.13.RELEASE.jar:4.3.13.RELEASE]
at org.springframework.batch.core.repository.dao.JdbcJobExecutionDao.saveJobExecution(JdbcJobExecutionDao.java:151) ~[spring-batch-core-3.0.8.RELEASE.jar:3.0.8.RELEASE]
at org.springframework.batch.core.repository.support.SimpleJobRepository.createJobExecution(SimpleJobRepository.java:145) ~[spring-batch-core-3.0.8.RELEASE.jar:3.0.8.RELEASE]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_60]
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_60]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_60]
at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_60]
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:333) ~[spring-aop-4.3.13.RELEASE.jar:4.3.13.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:190) ~[spring-aop-4.3.13.RELEASE.jar:4.3.13.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157) ~[spring-aop-4.3.13.RELEASE.jar:4.3.13.RELEASE]
at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:99) ~[spring-tx-4.3.13.RELEASE.jar:4.3.13.RELEASE]
at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:282) ~[spring-tx-4.3.13.RELEASE.jar:4.3.13.RELEASE]
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96) ~[spring-tx-4.3.13.RELEASE.jar:4.3.13.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) ~[spring-aop-4.3.13.RELEASE.jar:4.3.13.RELEASE]
at org.springframework.batch.core.repository.support.AbstractJobRepositoryFactoryBean$1.invoke(AbstractJobRepositoryFactoryBean.java:172) ~[spring-batch-core-3.0.8.RELEASE.jar:3.0.8.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) ~[spring-aop-4.3.13.RELEASE.jar:4.3.13.RELEASE]
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:213) ~[spring-aop-4.3.13.RELEASE.jar:4.3.13.RELEASE]
at com.sun.proxy.$Proxy111.createJobExecution(Unknown Source) ~[?:?]
at org.springframework.batch.core.launch.support.SimpleJobLauncher.run(SimpleJobLauncher.java:125) ~[spring-batch-core-3.0.8.RELEASE.jar:3.0.8.RELEASE]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_60]
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_60]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_60]
at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_60]
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:333) ~[spring-aop-4.3.13.RELEASE.jar:4.3.13.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:190) ~[spring-aop-4.3.13.RELEASE.jar:4.3.13.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157) ~[spring-aop-4.3.13.RELEASE.jar:4.3.13.RELEASE]
at org.springframework.batch.core.configuration.annotation.SimpleBatchConfiguration$PassthruAdvice.invoke(SimpleBatchConfiguration.java:127) ~[spring-batch-core-3.0.8.RELEASE.jar:3.0.8.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) ~[spring-aop-4.3.13.RELEASE.jar:4.3.13.RELEASE]
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:213) ~[spring-aop-4.3.13.RELEASE.jar:4.3.13.RELEASE]
at com.sun.proxy.$Proxy181.run(Unknown Source) ~[?:?]
at org.springframework.batch.core.step.job.JobStep.doExecute(JobStep.java:117) ~[spring-batch-core-3.0.8.RELEASE.jar:3.0.8.RELEASE]
at org.springframework.batch.core.step.AbstractStep.execute(AbstractStep.java:200) [spring-batch-core-3.0.8.RELEASE.jar:3.0.8.RELEASE]
at org.springframework.batch.core.job.SimpleStepHandler.handleStep(SimpleStepHandler.java:148) [spring-batch-core-3.0.8.RELEASE.jar:3.0.8.RELEASE]
at org.springframework.batch.core.job.flow.JobFlowExecutor.executeStep(JobFlowExecutor.java:64) [spring-batch-core-3.0.8.RELEASE.jar:3.0.8.RELEASE]
at org.springframework.batch.core.job.flow.support.state.StepState.handle(StepState.java:67) [spring-batch-core-3.0.8.RELEASE.jar:3.0.8.RELEASE]
at org.springframework.batch.core.job.flow.support.SimpleFlow.resume(SimpleFlow.java:169) [spring-batch-core-3.0.8.RELEASE.jar:3.0.8.RELEASE]
at org.springframework.batch.core.job.flow.support.SimpleFlow.start(SimpleFlow.java:144) [spring-batch-core-3.0.8.RELEASE.jar:3.0.8.RELEASE]
at org.springframework.batch.core.job.flow.support.state.SplitState$1.call(SplitState.java:93) [spring-batch-core-3.0.8.RELEASE.jar:3.0.8.RELEASE]
at org.springframework.batch.core.job.flow.support.state.SplitState$1.call(SplitState.java:90) [spring-batch-core-3.0.8.RELEASE.jar:3.0.8.RELEASE]
at java.util.concurrent.FutureTask.run(Unknown Source) [?:1.8.0_60]
at org.springframework.core.task.SimpleAsyncTaskExecutor$ConcurrencyThrottlingRunnable.run(SimpleAsyncTaskExecutor.java:271) [spring-core-4.3.13.RELEASE.jar:4.3.13.RELEASE]
at java.lang.Thread.run(Unknown Source) [?:1.8.0_60]
Caused by: java.sql.SQLTransactionRollbackException: transaction rollback: serialization failure at org.hsqldb.jdbc.JDBCUtil.sqlException(Unknown Source) ~[hsqldb-2.3.5.jar:2.3.5]
at org.hsqldb.jdbc.JDBCUtil.sqlException(Unknown Source) ~[hsqldb-2.3.5.jar:2.3.5]
at org.hsqldb.jdbc.JDBCStatement.fetchResult(Unknown Source) ~[hsqldb-2.3.5.jar:2.3.5]
at org.hsqldb.jdbc.JDBCStatement.executeUpdate(Unknown Source) ~[hsqldb-2.3.5.jar:2.3.5]
at org.springframework.jdbc.support.incrementer.AbstractIdentityColumnMaxValueIncrementer.getNextKey(AbstractIdentityColumnMaxValueIncrementer.java:110) ~[spring-jdbc-4.3.13.RELEASE.jar:4.3.13.RELEASE]
... 42 more
Caused by: org.hsqldb.HsqlException: transaction rollback: serialization failure at org.hsqldb.error.Error.error(Unknown Source) ~[hsqldb-2.3.5.jar:2.3.5]
at org.hsqldb.error.Error.error(Unknown Source) ~[hsqldb-2.3.5.jar:2.3.5]
at org.hsqldb.Session.handleAbortTransaction(Unknown Source) ~[hsqldb-2.3.5.jar:2.3.5]
at org.hsqldb.Session.executeCompiledStatement(Unknown Source) ~[hsqldb-2.3.5.jar:2.3.5]
at org.hsqldb.Session.executeDirectStatement(Unknown Source) ~[hsqldb-2.3.5.jar:2.3.5]
at org.hsqldb.Session.execute(Unknown Source) ~[hsqldb-2.3.5.jar:2.3.5]
at org.hsqldb.jdbc.JDBCStatement.fetchResult(Unknown Source) ~[hsqldb-2.3.5.jar:2.3.5]
at org.hsqldb.jdbc.JDBCStatement.executeUpdate(Unknown Source) ~[hsqldb-2.3.5.jar:2.3.5]
at org.springframework.jdbc.support.incrementer.AbstractIdentityColumnMaxValueIncrementer.getNextKey(AbstractIdentityColumnMaxValueIncrementer.java:110) ~[spring-jdbc-4.3.13.RELEASE.jar:4.3.13.RELEASE]
... 42 more
I've done a bit of research and this kind of error normally shows up when the HSQLDB I'm using to store job information isn't properly set up for concurrency. However I'm already using the seemingly good config, with MVCC transaction mode:
#Configuration
public class HSqlDbConfig {
#Primary
#Bean("hsqldbDataSource")
public DataSource hsqldbDataSource() {
final SimpleDriverDataSource dataSource = new SimpleDriverDataSource();
dataSource.setDriver(new org.hsqldb.jdbcDriver());
dataSource.setUrl("jdbc:hsqldb:mem:mydb;sql.enforce_strict_size=true;hsqldb.tx=mvcc");
dataSource.setUsername("sa");
dataSource.setPassword("");
return dataSource;
}
}
These are my code fragments I use for the configuration of these jobs. Beginning with the main job (0):
#Bean
public Job job0(JobBuilderFactory jobBuilderFactory) {
getJobParameters();
jobLauncher = (JobLauncher) ctx.getBean("jobLauncher");
Flow job1 = getJob1();
Flow job2 = getJob2();
Flow job3 = getJob3();
Flow splitFlow = getSplitFlow(job2, job3);
return jobBuilderFactory.get("Master Job")
.incrementer(new RunIdIncrementer())
.start(job1)
.next(splitFlow)
.end()
.build();
}
How I get the Flow for jobs 2 & 3:
private Flow getJob2() {
Job j2 = (Job) ctx.getBean("job2");
DefaultJobParametersExtractor extractor = new DefaultJobParametersExtractor();
Step step0 = getJobStep(j2, extractor);
return new FlowBuilder<Flow>("job2")
.start(step0)
.build();
}
private Flow getJob3() {
Job j3 = (Job) ctx.getBean("job3");
Job j3k = (Job) ctx.getBean("job3K");
Job j3l = (Job) ctx.getBean("job3L");
DefaultJobParametersExtractor extractor = new DefaultJobParametersExtractor();
Step step0 = getJobStep(j3, extractor);
Step step1 = getJobStep(j3k, params1);
Step step2 = getJobStep(j3k, params2);
Step step3 = getJobStep(j3l, params3);
Step step4 = getJobStep(j3l, params4);
Flow flow1 = new FlowBuilder<Flow>("flowJ3f1")
.start(step1)
.next(step2)
.build();
Flow flow2 = new FlowBuilder<Flow>("flowJ3f2")
.start(step3)
.next(step4)
.build();
return new FlowBuilder<Flow>("job3")
.start(step0)
.split(taskExecutor)
.add(flow1, flow2)
.build();
}
Both getJobStep() methods:
private Step getJobStep(Job job, JobParametersExtractor extractor) {
return steps.get(job.getName())
.job(job)
.launcher(jobLauncher)
.parametersExtractor(extractor)
.build();
}
private Step getJobStep(Job job, JobParameters jobParameters) {
SimpleJobParametersExtractor extractor = new SimpleJobParametersExtractor();
extractor.setJobParameters(jobParameters);
return steps.get(job.getName())
.job(job)
.launcher(jobLauncher)
.parametersExtractor(extractor)
.build();
}
The idea is to get this structure to work, as parallelization of all task possible is a requirement for this project, and it should be sturdy enough to add other parallel jobs apart from 2 & 3. Also, all jobs and steps have been tested without concurrency and they work as intended.
I can provide more code if needed. Right now I feel in a dead end so every bit of help is appreciated.
EDIT: As #MahmoudBenHassine suggested, I've configured a JobRepository, TransactionManager and JobLauncher (it solved my first issue) like so:
#Bean(name = "myTransactionManager")
public DataSourceTransactionManager transactionManager(#Qualifier("hsqldbDataSource") DataSource dataSource) {
return new DataSourceTransactionManager(dataSource);
}
#Bean(name = "myJobRepository")
public JobRepository jobRepository(#Qualifier("hsqldbDataSource") DataSource dataSource,
#Qualifier("myTransactionManager") DataSourceTransactionManager dataSourceTransactionManager) throws Exception {
JobRepositoryFactoryBean factory = new JobRepositoryFactoryBean();
factory.setDataSource(dataSource);
factory.setTransactionManager(dataSourceTransactionManager);
factory.setIsolationLevelForCreate("ISOLATION_READ_COMMITTED");
factory.afterPropertiesSet();
return factory.getObject();
}
#Bean(name = "myJobLauncher")
public JobLauncher getJobLauncher(#Qualifier("myJobRepository") JobRepository jobRepository) throws Exception {
SimpleJobLauncher jobLauncher = new SimpleJobLauncher();
jobLauncher.setJobRepository(jobRepository);
jobLauncher.afterPropertiesSet();
return jobLauncher;
}
Then I run job 0 with the new JobLauncher and this exception occurs on the JobSteps from job3 (3K & 3L) EDIT: I've got a larger log extract to more context of what's happening:
2019-01-09 09:53:39,793 INFO: o.s.b.c.j.SimpleStepHandler [MainTaskExecutor11] Executing step: [3K]
2019-01-09 09:53:39,811 INFO: o.s.b.c.l.s.SimpleJobLauncher [MainTaskExecutor11] Job: [FlowJob: [name=3K]] launched with the following parameters: [{process=Job 3K BAR, pos_cod=BAR, per_event=EVENT, isRet=false, UNIQUE=-2347943936040182027}]
2019-01-09 09:53:39,821 INFO: o.s.b.c.j.SimpleStepHandler [MainTaskExecutor11] Executing step: [[3K] Job 3K]
2019-01-09 09:53:39,822 INFO: e.i.l.d.l.StepListener [MainTaskExecutor11] Executing Step: [3K] Job 3K
2019-01-09 09:53:41,120 INFO: e.i.l.d.l.StepListener [MainTaskExecutor11] Write Count: 0
2019-01-09 09:53:41,166 INFO: o.s.b.c.l.s.SimpleJobLauncher [MainTaskExecutor11] Job: [FlowJob: [name=3K]] completed with the following parameters: [{process=Job 3K BAR, pos_cod=BAR, per_event=EVENT, isRet=false, UNIQUE=-2347943936040182027}] and the following status: [COMPLETED]
2019-01-09 09:53:41,189 INFO: o.s.b.c.j.SimpleStepHandler [MainTaskExecutor11] Duplicate step [3K] detected in execution of job=[job 0]. If either step fails, both will be executed again on restart.
2019-01-09 09:53:41,191 INFO: o.s.b.c.j.SimpleStepHandler [MainTaskExecutor11] Executing step: [3K]
2019-01-09 09:53:41,201 ERROR: o.s.b.c.s.AbstractStep [MainTaskExecutor11] Encountered an error executing step 3K in job 0
org.springframework.batch.core.repository.JobInstanceAlreadyCompleteException: A job instance already exists and is complete for parameters={process=Job 3K BAR, pos_cod=BAR, per_event=EVENT, isRet=false, UNIQUE=-2347943936040182027}. If you want to run this job again, change the parameters.
at org.springframework.batch.core.repository.support.SimpleJobRepository.createJobExecution(SimpleJobRepository.java:126) ~[spring-batch-core-3.0.8.RELEASE.jar:3.0.8.RELEASE]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_60]
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_60]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_60]
at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_60]
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:333) ~[spring-aop-4.3.13.RELEASE.jar:4.3.13.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:190) ~[spring-aop-4.3.13.RELEASE.jar:4.3.13.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157) ~[spring-aop-4.3.13.RELEASE.jar:4.3.13.RELEASE]
at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:99) ~[spring-tx-4.3.13.RELEASE.jar:4.3.13.RELEASE]
at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:282) ~[spring-tx-4.3.13.RELEASE.jar:4.3.13.RELEASE]
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96) ~[spring-tx-4.3.13.RELEASE.jar:4.3.13.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) ~[spring-aop-4.3.13.RELEASE.jar:4.3.13.RELEASE]
at org.springframework.batch.core.repository.support.AbstractJobRepositoryFactoryBean$1.invoke(AbstractJobRepositoryFactoryBean.java:172) ~[spring-batch-core-3.0.8.RELEASE.jar:3.0.8.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) ~[spring-aop-4.3.13.RELEASE.jar:4.3.13.RELEASE]
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:213) ~[spring-aop-4.3.13.RELEASE.jar:4.3.13.RELEASE]
at com.sun.proxy.$Proxy111.createJobExecution(Unknown Source) ~[?:?]
at org.springframework.batch.core.launch.support.SimpleJobLauncher.run(SimpleJobLauncher.java:125) ~[spring-batch-core-3.0.8.RELEASE.jar:3.0.8.RELEASE]
at org.springframework.batch.core.step.job.JobStep.doExecute(JobStep.java:117) ~[spring-batch-core-3.0.8.RELEASE.jar:3.0.8.RELEASE]
at org.springframework.batch.core.step.AbstractStep.execute(AbstractStep.java:200) [spring-batch-core-3.0.8.RELEASE.jar:3.0.8.RELEASE]
at org.springframework.batch.core.job.SimpleStepHandler.handleStep(SimpleStepHandler.java:148) [spring-batch-core-3.0.8.RELEASE.jar:3.0.8.RELEASE]
at org.springframework.batch.core.job.flow.JobFlowExecutor.executeStep(JobFlowExecutor.java:64) [spring-batch-core-3.0.8.RELEASE.jar:3.0.8.RELEASE]
at org.springframework.batch.core.job.flow.support.state.StepState.handle(StepState.java:67) [spring-batch-core-3.0.8.RELEASE.jar:3.0.8.RELEASE]
at org.springframework.batch.core.job.flow.support.SimpleFlow.resume(SimpleFlow.java:169) [spring-batch-core-3.0.8.RELEASE.jar:3.0.8.RELEASE]
at org.springframework.batch.core.job.flow.support.SimpleFlow.start(SimpleFlow.java:144) [spring-batch-core-3.0.8.RELEASE.jar:3.0.8.RELEASE]
at org.springframework.batch.core.job.flow.support.state.SplitState$1.call(SplitState.java:93) [spring-batch-core-3.0.8.RELEASE.jar:3.0.8.RELEASE]
at org.springframework.batch.core.job.flow.support.state.SplitState$1.call(SplitState.java:90) [spring-batch-core-3.0.8.RELEASE.jar:3.0.8.RELEASE]
at java.util.concurrent.FutureTask.run(Unknown Source) [?:1.8.0_60]
at java.lang.Thread.run(Unknown Source) [?:1.8.0_60]
Please note I use different JobParameters in getJob3() for each execution of job 3K and 3L (the same exception is thrown for that job too). The JobParameters I use are the following: EDIT: I've included a Random function in order to include a unique JobParameter:
Random randomizer = new Random(System.currentTimeMillis());
params1 = new JobParametersBuilder()
.addString(PROCESS, "Job 3K BAR" )
.addString("pos_cod", "BAR")
.addString("per_event", "EVENT")
.addString(IS_RET, FALSE)
.addLong("UNIQUE", randomizer.nextLong())
.toJobParameters();
params2 = new JobParametersBuilder()
.addString(PROCESS, "Job 3K 704" )
.addString("pos_cod", "704")
.addString("per_event", "EVENT")
.addString(IS_RET, FALSE)
.addLong("UNIQUE", randomizer.nextLong())
.toJobParameters();
params3 = new JobParametersBuilder()
.addString(PROCESS, "Job 3L BAR" )
.addString("pos_cod", "BAR")
.addString("per_event", "RET_EVENT")
.addString(IS_RET, FALSE)
.addLong("UNIQUE", randomizer.nextLong())
.toJobParameters();
params4 = new JobParametersBuilder()
.addString(PROCESS, "Job 3L 704" )
.addString("pos_cod", "704")
.addString("per_event", "RET_EVENT")
.addString(IS_RET, FALSE)
.addLong("UNIQUE", randomizer.nextLong())
.toJobParameters();
Having seen the duplicated job instance error keeps occurring as the JobLauncher is trying to launch the samen job (not its sibling with other JobParameters), I'm more inclined to think this is a problem with my JobRepository, but this is nothing more than speculation.
The Map based job repository is not intended for multi-threading. This job repository is by default configured with a ResourcelessTransactionManager.
Make sure to use the JDBC based job repository (even with an in-memory database like in your case) to properly support multi-threading and parallel processing along with a DataSourceTransactionManager.
As a side note, the SimpleDriverDataSource is not a pooled data source, I recommend to use one with a connection pool.

Srping/ Hibernate: spring.entity.Downloads cannot be cast to java.lang.Integer

I have recently started trying to learn java and finished a spring/hibernate course in aims to implement a solution to some problems at work in my spare time. Needless to say, I have hit a snag.
I am wondering if anyone can see anything obviously wrong with the code attached below that can cause the following error:
SEVERE: Servlet.service() for servlet [dispatcher] in context with path [/sonya-local] threw exception [Request processing failed; nested exception is java.lang.ClassCastException: com.sonya.spring.entity.Downloads cannot be cast to java.lang.Integer] with root cause
java.lang.ClassCastException: com.sonya.spring.entity.Downloads cannot be cast to java.lang.Integer
at org.hibernate.type.descriptor.java.IntegerTypeDescriptor.unwrap(IntegerTypeDescriptor.java:19)
at org.hibernate.type.descriptor.sql.IntegerTypeDescriptor$1.doBind(IntegerTypeDescriptor.java:46)
at org.hibernate.type.descriptor.sql.BasicBinder.bind(BasicBinder.java:74)
at org.hibernate.type.AbstractStandardBasicType.nullSafeSet(AbstractStandardBasicType.java:277)
at org.hibernate.type.AbstractStandardBasicType.nullSafeSet(AbstractStandardBasicType.java:272)
at org.hibernate.param.NamedParameterSpecification.bind(NamedParameterSpecification.java:53)
at org.hibernate.hql.internal.ast.exec.BasicExecutor.doExecute(BasicExecutor.java:82)
at org.hibernate.hql.internal.ast.exec.BasicExecutor.execute(BasicExecutor.java:59)
at org.hibernate.hql.internal.ast.QueryTranslatorImpl.executeUpdate(QueryTranslatorImpl.java:429)
at org.hibernate.engine.query.spi.HQLQueryPlan.performExecuteUpdate(HQLQueryPlan.java:374)
at org.hibernate.internal.SessionImpl.executeUpdate(SessionImpl.java:1495)
at org.hibernate.query.internal.AbstractProducedQuery.doExecuteUpdate(AbstractProducedQuery.java:1507)
at org.hibernate.query.internal.AbstractProducedQuery.executeUpdate(AbstractProducedQuery.java:1485)
at com.sonya.spring.dao.DownloadsDAOImpl.archiveProduct(DownloadsDAOImpl.java:128)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:333)
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:190)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157)
at org.springframework.aop.framework.adapter.MethodBeforeAdviceInterceptor.invoke(MethodBeforeAdviceInterceptor.java:52)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.aop.framework.adapter.AfterReturningAdviceInterceptor.invoke(AfterReturningAdviceInterceptor.java:52)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:213)
at com.sun.proxy.$Proxy50.archiveProduct(Unknown Source)
at com.sonya.spring.service.DownloadsServiceImpl.archiveProduct(DownloadsServiceImpl.java:65)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
Basically I am looking to move data between tables after a small vetting period (1 hour) I have successfully added timestamps and a few other functions such as search, api calls etc so far.
The end goal of this is to attach a scheduler and have it run periodically throughout the day but for now I have added a url mapping to trigger it manually.
When hitting the URL I receive the above error:
My Code:
Controller code
#GetMapping("/archiveproducts")
public String archiveDownloads (){
List<Downloads> theDownloads = downloadsService.getDownloads();
for (Downloads archiveDownload : theDownloads) {
// display the download ... just for clarity
System.out.println(archiveDownload);
Date timer = new Date();
Date purge = archiveDownload.getTimestamp();
long hours = (timer.getTime() - purge.getTime()) / DateTimeConstants.MILLIS_PER_HOUR;
if (hours >= 1) {
downloadsService.archiveProduct(archiveDownload);
}
}
return "list-downloads";
}
DownloadsDAOimpl Code: (java:128)
public List<Downloads> archiveProduct(Downloads archiveDownload) {
Session currentSession = sessionFactory.getCurrentSession();
Query theCopyQuery =
currentSession.createQuery("insert into Archive(fieldOne, fieldTwo, fieldThree, fieldFour, fieldFive, , fieldSix, FieldSeven)"
+ "sfieldOne, fieldTwo, fieldThree, fieldFour, fieldFive, , fieldSix, FieldSeven from Downloads where id=:theId");
theCopyQuery.setParameter("theId", archiveDownload);
theCopyQuery.executeUpdate();
List<Downloads> archiveProducts = theCopyQuery.getResultList();
Query theDeleteQuery =
currentSession.createQuery("delete from Downloads where id=:theId");
theDeleteQuery.setParameter("theId", archiveDownload);
theDeleteQuery.executeUpdate();
// return the results
return archiveProducts;
}
DownloadsServiceImpl.java:65
#Override
#Transactional
public List<Downloads> archiveProduct(Downloads archiveDownload) {
return downloadsDAO.archiveProduct(archiveDownload);
}
I understand that it's telling me I cannot cast an entity as an integer. but I don't understand where this integer is coming from or how to fix/reslove it.. I have a used a similar code approach for one of the API's and it worked okay.
#PostMapping("/listdownloads")
public List<Downloads> addDownloads (#RequestBody List<Downloads> theDownloads){
for (Downloads tempDownload : theDownloads) {
// display the download ... just for clarity
tempDownload.setId(0);
tempDownload.setTimestamp(null);
System.out.println(tempDownload);
// save to the database
downloadsService.saveProduct(tempDownload);
}
Cheers,
Danny
I think the issue is with this line.
theDeleteQuery.setParameter("theId", archiveDownload);
It is expecting an integer as Id but you passing Downloads object as mentioned in eror message. you can try something like this.
theDeleteQuery.setParameter("theId", archiveDownload.getId());

How to solve object is not an instance of declaring class in Liferay

I am trying to deploy a book application which will display some book information and also allow user to add,remove,delete,upload/download etc.But while i am trying to deploy the application i am getting error of object is not an instance of delaring class .I don't know how to solve this erro please help i am posting my exception
14:13:12,567 ERROR [RuntimePageImpl-1][PortletServlet:116] javax.portlet.PortletException: java.lang.reflect.InvocationTargetException
javax.portlet.PortletException: java.lang.reflect.InvocationTargetException
at javax.portlet.GenericPortlet.doDispatch(GenericPortlet.java:323)
at javax.portlet.GenericPortlet.render(GenericPortlet.java:233)
at com.liferay.portlet.FilterChainImpl.doFilter(FilterChainImpl.java:103)
at com.liferay.portlet.ScriptDataPortletFilter.doFilter(ScriptDataPortletFilter.java:55)
at com.liferay.portlet.FilterChainImpl.doFilter(FilterChainImpl.java:100)
at com.liferay.portal.kernel.portlet.PortletFilterUtil.doFilter(PortletFilterUtil.java:64)
at com.liferay.portal.kernel.servlet.PortletServlet.service(PortletServlet.java:112)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:116)
at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilter.doFilter(InvokerFilter.java:96)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:749)
at org.apache.catalina.core.ApplicationDispatcher.doInclude(ApplicationDispatcher.java:605)
at org.apache.catalina.core.ApplicationDispatcher.include(ApplicationDispatcher.java:544)
at com.liferay.portlet.InvokerPortletImpl.invoke(InvokerPortletImpl.java:604)
at com.liferay.portlet.InvokerPortletImpl.invokeRender(InvokerPortletImpl.java:677)
at com.liferay.portlet.InvokerPortletImpl.render(InvokerPortletImpl.java:406)
at org.apache.jsp.html.portal.render_005fportlet_jsp._jspService(render_005fportlet_jsp.java:1242)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
at com.liferay.portal.servlet.DirectRequestDispatcher.include(DirectRequestDispatcher.java:57)
at com.liferay.portal.servlet.ClassLoaderRequestDispatcherWrapper.doDispatch(ClassLoaderRequestDispatcherWrapper.java:78)
at com.liferay.portal.servlet.ClassLoaderRequestDispatcherWrapper.include(ClassLoaderRequestDispatcherWrapper.java:53)
at com.liferay.portlet.PortletContainerImpl._doRender(PortletContainerImpl.java:655)
at com.liferay.portlet.PortletContainerImpl.render(PortletContainerImpl.java:138)
at com.liferay.portlet.SecurityPortletContainerWrapper.render(SecurityPortletContainerWrapper.java:141)
at com.liferay.portlet.RestrictPortletContainerWrapper.render(RestrictPortletContainerWrapper.java:126)
at com.liferay.portal.kernel.portlet.PortletContainerUtil.render(PortletContainerUtil.java:156)
at com.liferay.portal.layoutconfiguration.util.PortletRenderer._render(PortletRenderer.java:120)
at com.liferay.portal.layoutconfiguration.util.PortletRenderer.access$4(PortletRenderer.java:107)
at com.liferay.portal.layoutconfiguration.util.PortletRenderer$PortletRendererCallable.doCall(PortletRenderer.java:174)
at com.liferay.portal.layoutconfiguration.util.PortletRenderer$PortletRendererCallable.doCall(PortletRenderer.java:1)
at com.liferay.portal.kernel.executor.CopyThreadLocalCallable.call(CopyThreadLocalCallable.java:69)
at java.util.concurrent.FutureTask.run(Unknown Source)
at com.liferay.portal.kernel.concurrent.ThreadPoolExecutor$WorkerTask._runTask(ThreadPoolExecutor.java:682)
at com.liferay.portal.kernel.concurrent.ThreadPoolExecutor$WorkerTask.run(ThreadPoolExecutor.java:593)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at javax.portlet.GenericPortlet.doDispatch(GenericPortlet.java:319)
... 39 more
Caused by: java.lang.IllegalArgumentException: object is not an instance of declaring class
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.liferay.portal.kernel.bean.ClassLoaderBeanHandler.invoke(ClassLoaderBeanHandler.java:67)
at com.sun.proxy.$Proxy418.filterRenderURL(Unknown Source)
at com.liferay.portlet.PortletResponseImpl.doCreateLiferayPortletURL(PortletResponseImpl.java:692)
at com.liferay.portlet.PortletResponseImpl$LiferayPortletURLPrivilegedAction.run(PortletResponseImpl.java:773)
at com.liferay.portlet.PortletResponseImpl$LiferayPortletURLPrivilegedAction.run(PortletResponseImpl.java:1)
at com.liferay.portal.security.lang.DoPrivilegedUtil$NoPACL.wrap(DoPrivilegedUtil.java:64)
at com.liferay.portal.security.lang.DoPrivilegedUtil.wrap(DoPrivilegedUtil.java:26)
at com.liferay.portlet.PortletResponseImpl.createLiferayPortletURL(PortletResponseImpl.java:267)
at com.liferay.portlet.PortletResponseImpl.createLiferayPortletURL(PortletResponseImpl.java:259)
at com.liferay.portlet.PortletResponseImpl.createLiferayPortletURL(PortletResponseImpl.java:281)
at com.liferay.portlet.PortletResponseImpl.createRenderURL(PortletResponseImpl.java:291)
at com.liferay.portlet.PortletResponseImpl.createRenderURL(PortletResponseImpl.java:286)
at com.msh.base.BookCatalogPortlet.generateUrls(BookCatalogPortlet.java:436)
at com.msh.base.BookCatalogPortlet.showBooks(BookCatalogPortlet.java:214)
... 44 more
Apr 18, 2015 2:13:12 PM org.apache.catalina.core.ApplicationDispatcher invoke
SEVERE: Servlet.service() for servlet BookCatalog Servlet threw exception
java.lang.IllegalArgumentException: object is not an instance of declaring class
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.liferay.portal.kernel.bean.ClassLoaderBeanHandler.invoke(ClassLoaderBeanHandler.java:67)
at com.sun.proxy.$Proxy418.filterRenderURL(Unknown Source)
at com.liferay.portlet.PortletResponseImpl.doCreateLiferayPortletURL(PortletResponseImpl.java:692)
at com.liferay.portlet.PortletResponseImpl$LiferayPortletURLPrivilegedAction.run(PortletResponseImpl.java:773)
at com.liferay.portlet.PortletResponseImpl$LiferayPortletURLPrivilegedAction.run(PortletResponseImpl.java:1)
at com.liferay.portal.security.lang.DoPrivilegedUtil$NoPACL.wrap(DoPrivilegedUtil.java:64)
at com.liferay.portal.security.lang.DoPrivilegedUtil.wrap(DoPrivilegedUtil.java:26)
at com.liferay.portlet.PortletResponseImpl.createLiferayPortletURL(PortletResponseImpl.java:267)
at com.liferay.portlet.PortletResponseImpl.createLiferayPortletURL(PortletResponseImpl.java:259)
at com.liferay.portlet.PortletResponseImpl.createLiferayPortletURL(PortletResponseImpl.java:281)
at com.liferay.portlet.PortletResponseImpl.createRenderURL(PortletResponseImpl.java:291)
at com.liferay.portlet.PortletResponseImpl.createRenderURL(PortletResponseImpl.java:286)
at com.msh.base.BookCatalogPortlet.generateUrls(BookCatalogPortlet.java:436)
at com.msh.base.BookCatalogPortlet.showBooks(BookCatalogPortlet.java:214)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at javax.portlet.GenericPortlet.doDispatch(GenericPortlet.java:319)
at javax.portlet.GenericPortlet.render(GenericPortlet.java:233)
at com.liferay.portlet.FilterChainImpl.doFilter(FilterChainImpl.java:103)
at com.liferay.portlet.ScriptDataPortletFilter.doFilter(ScriptDataPortletFilter.java:55)
at com.liferay.portlet.FilterChainImpl.doFilter(FilterChainImpl.java:100)
at com.liferay.portal.kernel.portlet.PortletFilterUtil.doFilter(PortletFilterUtil.java:64)
at com.liferay.portal.kernel.servlet.PortletServlet.service(PortletServlet.java:112)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:116)
at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilter.doFilter(InvokerFilter.java:96)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:749)
at org.apache.catalina.core.ApplicationDispatcher.doInclude(ApplicationDispatcher.java:605)
at org.apache.catalina.core.ApplicationDispatcher.include(ApplicationDispatcher.java:544)
at com.liferay.portlet.InvokerPortletImpl.invoke(InvokerPortletImpl.java:604)
at com.liferay.portlet.InvokerPortletImpl.invokeRender(InvokerPortletImpl.java:677)
at com.liferay.portlet.InvokerPortletImpl.render(InvokerPortletImpl.java:406)
at org.apache.jsp.html.portal.render_005fportlet_jsp._jspService(render_005fportlet_jsp.java:1242)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
at com.liferay.portal.servlet.DirectRequestDispatcher.include(DirectRequestDispatcher.java:57)
at com.liferay.portal.servlet.ClassLoaderRequestDispatcherWrapper.doDispatch(ClassLoaderRequestDispatcherWrapper.java:78)
at com.liferay.portal.servlet.ClassLoaderRequestDispatcherWrapper.include(ClassLoaderRequestDispatcherWrapper.java:53)
at com.liferay.portlet.PortletContainerImpl._doRender(PortletContainerImpl.java:655)
at com.liferay.portlet.PortletContainerImpl.render(PortletContainerImpl.java:138)
at com.liferay.portlet.SecurityPortletContainerWrapper.render(SecurityPortletContainerWrapper.java:141)
at com.liferay.portlet.RestrictPortletContainerWrapper.render(RestrictPortletContainerWrapper.java:126)
at com.liferay.portal.kernel.portlet.PortletContainerUtil.render(PortletContainerUtil.java:156)
at com.liferay.portal.layoutconfiguration.util.PortletRenderer._render(PortletRenderer.java:120)
at com.liferay.portal.layoutconfiguration.util.PortletRenderer.access$4(PortletRenderer.java:107)
at com.liferay.portal.layoutconfiguration.util.PortletRenderer$PortletRendererCallable.doCall(PortletRenderer.java:174)
at com.liferay.portal.layoutconfiguration.util.PortletRenderer$PortletRendererCallable.doCall(PortletRenderer.java:1)
at com.liferay.portal.kernel.executor.CopyThreadLocalCallable.call(CopyThreadLocalCallable.java:69)
at java.util.concurrent.FutureTask.run(Unknown Source)
at com.liferay.portal.kernel.concurrent.ThreadPoolExecutor$WorkerTask._runTask(ThreadPoolExecutor.java:682)
at com.liferay.portal.kernel.concurrent.ThreadPoolExecutor$WorkerTask.run(ThreadPoolExecutor.java:593)
at java.lang.Thread.run(Unknown Source)
14:13:12,583 ERROR [RuntimePageImpl-1][render_portlet_jsp:132] null
java.lang.IllegalArgumentException: object is not an instance of declaring class
at com.liferay.portal.kernel.bean.ClassLoaderBeanHandler.invoke(ClassLoaderBeanHandler.java:67)
at com.liferay.portlet.PortletResponseImpl.doCreateLiferayPortletURL(PortletResponseImpl.java:692)
at com.liferay.portlet.PortletResponseImpl$LiferayPortletURLPrivilegedAction.run(PortletResponseImpl.java:773)
at com.liferay.portlet.PortletResponseImpl$LiferayPortletURLPrivilegedAction.run(PortletResponseImpl.java:1)
at com.liferay.portal.security.lang.DoPrivilegedUtil$NoPACL.wrap(DoPrivilegedUtil.java:64)
at com.liferay.portal.security.lang.DoPrivilegedUtil.wrap(DoPrivilegedUtil.java:26)
at com.liferay.portlet.PortletResponseImpl.createLiferayPortletURL(PortletResponseImpl.java:267)
at com.liferay.portlet.PortletResponseImpl.createLiferayPortletURL(PortletResponseImpl.java:259)
at com.liferay.portlet.PortletResponseImpl.createLiferayPortletURL(PortletResponseImpl.java:281)
at com.liferay.portlet.PortletResponseImpl.createRenderURL(PortletResponseImpl.java:291)
at com.liferay.portlet.PortletResponseImpl.createRenderURL(PortletResponseImpl.java:286)
at com.msh.base.BookCatalogPortlet.generateUrls(BookCatalogPortlet.java:436)
at com.msh.base.BookCatalogPortlet.showBooks(BookCatalogPortlet.java:214)
at javax.portlet.GenericPortlet.doDispatch(GenericPortlet.java:319)
at javax.portlet.GenericPortlet.render(GenericPortlet.java:233)
at com.liferay.portlet.FilterChainImpl.doFilter(FilterChainImpl.java:103)
at com.liferay.portlet.ScriptDataPortletFilter.doFilter(ScriptDataPortletFilter.java:55)
at com.liferay.portlet.FilterChainImpl.doFilter(FilterChainImpl.java:100)
at com.liferay.portal.kernel.portlet.PortletFilterUtil.doFilter(PortletFilterUtil.java:64)
at com.liferay.portal.kernel.servlet.PortletServlet.service(PortletServlet.java:112)
14:27:50,329 INFO [BookCatalogPortlet:180] Entering showBooks method
14:27:50,332 INFO [BookCatalogPortlet:144] Size of the Database :4
14:27:50,332 INFO [BookCatalogPortlet:145] Current book count in catalog : 4
14:27:50,333 INFO [BookCatalogPortlet:506] Support portlet mode edit
14:27:50,333 INFO [BookCatalogPortlet:506] Support portlet mode help
14:27:50,333 INFO [BookCatalogPortlet:506] Support portlet mode view
14:27:50,333 INFO [BookCatalogPortlet:506] Support portlet mode about
14:27:50,333 INFO [BookCatalogPortlet:506] Support portlet mode config
14:27:50,334 INFO [BookCatalogPortlet:506] Support portlet mode edit_defaults
14:27:50,334 INFO [BookCatalogPortlet:506] Support portlet mode preview
14:27:50,334 INFO [BookCatalogPortlet:506] Support portlet mode print
14:27:50,335 INFO [BookCatalogPortlet:519] Support window state maximized
14:27:50,335 INFO [BookCatalogPortlet:519] Support window state minimized
14:27:50,335 INFO [BookCatalogPortlet:519] Support window state normal
14:27:50,336 INFO [BookCatalogPortlet:519] Support window state exclusive
14:27:50,336 INFO [BookCatalogPortlet:519] Support window state pop_up
14:27:50,341 ERROR [RuntimePageImpl-3][PortletServlet:116] javax.portlet.PortletException: java.lang.reflect.InvocationTargetException
javax.portlet.PortletException: java.lang.reflect.InvocationTargetException
at javax.portlet.GenericPortlet.doDispatch(GenericPortlet.java:323)
at javax.portlet.GenericPortlet.render(GenericPortlet.java:233)
at com.liferay.portlet.FilterChainImpl.doFilter(FilterChainImpl.java:103)
at com.liferay.portlet.ScriptDataPortletFilter.doFilter(ScriptDataPortletFilter.java:55)
at com.liferay.portlet.FilterChainImpl.doFilter(FilterChainImpl.java:100)
at com.liferay.portal.kernel.portlet.PortletFilterUtil.doFilter(PortletFilterUtil.java:64)
These are GenerateUrls() and showBooks() method
private void generateUrls(RenderRequest request, RenderResponse response)
throws PortletModeException, WindowStateException {
// Render URL for Print hyperlink
PortletURL printModeUrl = response.createRenderURL();
if (request.isPortletModeAllowed(new PortletMode("print"))) {
printModeUrl.setPortletMode(new PortletMode("print"));
}
if (request.isWindowStateAllowed(new WindowState("pop_up"))) {
printModeUrl.setWindowState(new WindowState("pop_up"));
}
request.setAttribute("printModeUrl", printModeUrl);
// Action URL for upload Toc action
PortletURL uploadTocActionUrl = response.createActionURL();
uploadTocActionUrl.setParameter("myaction", "uploadTocAction");
uploadTocActionUrl.setParameter(ActionRequest.ACTION_NAME,
"uploadTocAction");
request.setAttribute("uploadTocActionUrl", uploadTocActionUrl);
// Render URL for Full Screen hyperlink
PortletURL fullScreenUrl = response.createRenderURL();
fullScreenUrl.setWindowState(WindowState.MAXIMIZED);
request.setAttribute("fullScreenUrl", fullScreenUrl);
// Render URL for Help hyperlink
PortletURL helpUrl = response.createRenderURL();
helpUrl.setPortletMode(PortletMode.HELP);
request.setAttribute("helpUrl", helpUrl);
// Render URL for Home hyperlink
PortletURL homeUrl = response.createRenderURL();
homeUrl.setPortletMode(PortletMode.VIEW);
request.setAttribute("homeUrl", homeUrl);
// Render URL for Preferences hyperlink
PortletURL prefUrl = response.createRenderURL();
prefUrl.setPortletMode(PortletMode.EDIT);
request.setAttribute("prefUrl", prefUrl);
// Render URL for form submission for Adding book
PortletURL addBookFormUrl = response.createRenderURL();
addBookFormUrl.setParameter("myaction", "addBookForm");
request.setAttribute("addBookFormUrl", addBookFormUrl);
// Action URL for Add Book Action
PortletURL addBookActionUrl = response.createActionURL();
addBookActionUrl.setParameter(ActionRequest.ACTION_NAME,
"addBookAction");
request.setAttribute("addBookActionUrl", addBookActionUrl);
// Action URL for resetting search
PortletURL resetActionUrl = response.createActionURL();
resetActionUrl.setParameter(ActionRequest.ACTION_NAME, "resetAction");
request.setAttribute("resetActionUrl", resetActionUrl);
// Action URL for searching books
PortletURL searchBookActionUrl = response.createActionURL();
searchBookActionUrl.setParameter(ActionRequest.ACTION_NAME,
"searchBookAction");
request.setAttribute("searchBookActionUrl", searchBookActionUrl);
// Render URL for Refresh Search Results link
PortletURL refreshResultsUrl = response.createRenderURL();
refreshResultsUrl.setParameter("myaction", "refreshResults");
request.setAttribute("refreshResultsUrl", refreshResultsUrl);
}
#SuppressWarnings("unchecked")
#RenderMode(name = "VIEW")
public void showBooks(RenderRequest request, RenderResponse response)
throws Exception {
logger.info("Entering showBooks method");
//--return if the content is still valid
if(isMarkupValid(request, response)) {
response.getCacheControl().setUseCachedContent(true);
response.getCacheControl().setExpirationTime(100);
return;
} else {
BookDataObject catalog = (BookDataObject) getPortletContext()
.getAttribute("bookCatalog");
int currentCountInDatastore = catalog.getBooks().size();
// -- set the currentCountInDatabase as the etag value
response.getCacheControl().setETag("" + currentCountInDatastore);
}
PortalContext context = request.getPortalContext();
printSupportedPortletModes(context);
printSupportedWindowStates(context);
// --get user attributes user.name.given and user.name.family
Map<String, Object> userAttributeMap = (Map<String, Object>) request
.getAttribute(PortletRequest.USER_INFO);
String firstName = "";
String lastName = "";
if (userAttributeMap != null) {
firstName = (String) userAttributeMap.get("user.name.given");
lastName = (String) userAttributeMap.get("user.name.family");
request.setAttribute("firstName", firstName);
request.setAttribute("lastName", lastName);
}
String portalInfo = context.getPortalInfo();
request.setAttribute("portalInfo", portalInfo);
// --generate all the URLs that will be used by the portlet
generateUrls(request, response);
String myaction = request.getParameter("myaction");
if (myaction != null) {
logger.info("myaction parameter is not null. Value is " + myaction);
request.getPortletSession().setAttribute("myaction", myaction,
PortletSession.PORTLET_SCOPE);
} else {
// -- if myaction is NULL then show the home page of Book
// catalog
// page
request.getPortletSession().setAttribute("myaction", "showCatalog",
PortletSession.PORTLET_SCOPE);
}
// -- send myaction as a request attribute to the BookServlet.
request.setAttribute("myaction", request.getPortletSession()
.getAttribute("myaction"));
// --dynamically obtain the title for the portlet, based on myaction
String titleKey = "portlet.title."
+ (String) request.getPortletSession().getAttribute("myaction");
response.setTitle(getResourceBundle(request.getLocale()).getString(
titleKey));
// --if the action is uploadTocForm then store the ISBN number of
// the
// --book for which the TOC is being uploaded. The upload action
// will use the ISBN number to create file name -- refer home.jsp
// page
if (((String) request.getAttribute("myaction"))
.equalsIgnoreCase("uploadTocForm")) {
request.getPortletSession().setAttribute("isbnNumber",
request.getParameter("isbnNumber"));
}
if (((String) request.getPortletSession().getAttribute("myaction"))
.equalsIgnoreCase("showSearchResults")) {
request.setAttribute("matchingBooks", request.getPortletSession()
.getAttribute("matchingBooks"));
}
// its important to encode URLs
PortletRequestDispatcher dispatcher = request.getPortletSession()
.getPortletContext().getRequestDispatcher(
response.encodeURL("/myservlet/bookServlet"));
dispatcher.include(request, response);
}
My guess is that in your showBooks() or generateUrls() method you cast an object to another object or do something with an object that is illegal. If you could post the code in the two methods mentioned I could give you a better answer.
As the problem lies deeper within the stacktrace, my guess is that you have some files on the classpath that better shouldn't be there, or are on there twice. Make sure that you have, for example, portlet.jar in the appserver's global classpath and not in your webapp's WEB-INF/lib. Same goes for portal-impl.jar, that one should live within Liferay, but nowhere else - neither global nor your application.
Also, it might help to mark some line numbers. You have several appearances of response.createRenderURL in the code and it'd be good to know if the problem is in the first appearance or some time later.

Categories