java.io.NotSerializableException while writing to Oracle Coherence cache - preloading

I have 2 storage enabled cache nodes that i am trying to use for pre-loading of cache. About 1 million accounts are to be loaded by these 2 storage enabled nodes. Both key and value are String objects which I am trying to write to cache. I am using InvocationService.execute() method to invoke the pre-loading tasks asynchronously:
for (Map.Entry<Member, LoaderInvocable> entry : mappedWork.entrySet()) {
Member member = entry.getKey();
LoaderInvocable task = entry.getValue();
invocationService.execute(task, Collections.singleton(member), null);
}
LoaderInvocable is a class that is implementing Invocable and Serializable interfaces and its run() method has been overridden to performs the actual work of reading from database and writing to the cache.
InvocationService is defined as below in the coherence config file:
<invocation-scheme>
<scheme-name>
InvocationScheme</scheme-name>
<service-name>
LoaderInvocationService</service-name>
<autostart system-property="tangosol.coherence.invocation.autostart">true</autostart>
</invocation-scheme>
Below is the exception that i am getting:
2016-02-22 17:16:24,612 [pool-1-thread-1] ERROR (support.context.SessionExecutable) Caught exception from SessionExecutable.execute()
(Wrapped) java.io.NotSerializableException: com.oracle.common.collections.ConcurrentLinkedQueue
at com.tangosol.util.Base.ensureRuntimeException(Base.java:289)
at com.tangosol.util.Base.ensureRuntimeException(Base.java:270)
at com.tangosol.coherence.component.util.daemon.queueProcessor.packetProcessor.PacketPublisher.packetizeMessage(PacketPublisher.CDB:28)
at com.tangosol.coherence.component.util.daemon.queueProcessor.packetProcessor.PacketPublisher$InQueue.add(PacketPublisher.CDB:8)
at com.tangosol.coherence.component.util.daemon.queueProcessor.packetProcessor.PacketPublisher.post(PacketPublisher.CDB:1)
at com.tangosol.coherence.component.net.Message.dispatch(Message.CDB:77)
at com.tangosol.coherence.component.net.Message.post(Message.CDB:1)
at com.tangosol.coherence.component.util.daemon.queueProcessor.service.Grid.post(Grid.CDB:2)
at com.tangosol.coherence.component.util.daemon.queueProcessor.service.Grid.send(Grid.CDB:1)
at com.tangosol.coherence.component.util.daemon.queueProcessor.service.grid.InvocationService.execute(InvocationService.CDB:33)
at com.tangosol.coherence.component.util.safeService.SafeInvocationService.execute(SafeInvocationService.CDB:1)
.
.
.
.
.
.
Caused by: java.io.NotSerializableException: com.oracle.common.collections.ConcurrentLinkedQueue
at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1180)
at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1528)
at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1493)
at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1416)
at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1174)
at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:346)
at java.util.Hashtable.writeObject(Hashtable.java:988)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at java.io.ObjectStreamClass.invokeWriteObject(ObjectStreamClass.java:975)
at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1480)
at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1416)
at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1174)
at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1528)
at java.io.ObjectOutputStream.defaultWriteObject(ObjectOutputStream.java:438)
at com.tangosol.coherence.Component.writeObject(Component.CDB:1)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at java.io.ObjectStreamClass.invokeWriteObject(ObjectStreamClass.java:975)
at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1480)
at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1416)
at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1174)
at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1528)
at java.io.ObjectOutputStream.defaultWriteObject(ObjectOutputStream.java:438)
at com.tangosol.coherence.Component.writeObject(Component.CDB:1)
It seems that half of the accounts have been cached successfully. Can it be node specific issue? Both of the storage enabled cache nodes are on the same server using the same cluster configuration. From the logs it is clear that both nodes successfully joined the cluster.

Thanks Praveen. I have implemented the PortableObject interface and not facing the NotSerializableException anymore. But now i am facing a new problem. The second node is not invoking the task and leaving the cluster without any exception in the logs.
I used the InvocationObserver which suggests that memberLeft() the cluster. Can it be something wrong with my implementation of readExternal() and writeExternal() methods for serialization? Below is the implementation:
#Override
public void readExternal(PofReader paramPofReader) throws IOException {
// TODO Auto-generated method stub
cacheName = paramPofReader.readString(0);
firstRow = paramPofReader.readLong(1);
lastRow = paramPofReader.readLong(2);
}
#Override
public void writeExternal(PofWriter paramPofWriter) throws IOException {
// TODO Auto-generated method stub
paramPofWriter.writeString(0, cacheName);
paramPofWriter.writeLong(1, firstRow);
paramPofWriter.writeLong(2, lastRow);
}

Related

QuartzDeadlineManager (Scheduler) inadvertently replaces configured TransactionManager

Axon documentation is somewhat faulty at describing the nuances between EventScheduler and DeadlineManager, and in which scenario you have to use each one. In a trial by fire, I attempted to use EventScheduler in one of few Sagas implemented. I realized it does not trigger #EventSourcingHandler on Aggregate, so I was forced to change to a DeadlineManager. (Hint: this could be better described in documentation)
Now first challenge was to configure the DeadlineManager without any insight. Here is the final code I ended doing:
#Configuration
public class AxonConfiguration {
#Bean
public DeadlineManager deadlineManager(
final Scheduler scheduler,
// Disregard "Could not autowire. No beans of 'AxonConfiguration' type found." complain from IntelliJ.
// This class is an #Configuration, which is a #Component by itself.
final org.axonframework.spring.config.AxonConfiguration configuration,
final TransactionManager transactionManager,
final Serializer serializer
) {
return QuartzDeadlineManager.builder()
.scheduler(scheduler)
.serializer(serializer)
.scopeAwareProvider(new ConfigurationScopeAwareProvider(configuration))
.transactionManager(transactionManager)
.build();
}
}
As you may see, when using a reputable IDE, it complains that AxonConfiguration is not a Bean, so you have to live with the warning forever.
When I injected the DeadlineManager in my Saga, I've done this:
#Slf4j
#Saga
public class MySaga {
static final Long DELAY_INITIALIZE = 60L;
static final String INITIALIZE_DEADLINE_NAME = "MyInitialize";
#Autowired
private transient DeadlineManager deadlineManager;
#Autowired
private transient CommandGateway commandGateway;
private String scheduleName;
private String scheduleId;
#StartSaga
#SagaEventHandler(associationProperty = "correlationId")
protected void on(final ScheduleEvent event, #Timestamp final Instant eventInstant) {
final Instant timerInitialize = eventInstant.plus(Duration.ofSeconds(DELAY_INITIALIZE));
this.scheduleName = INITIALIZE_DEADLINE_NAME;
this.scheduleId = this.deadlineManager.schedule(
timerInitialize,
INITIALIZE_DEADLINE_NAME,
InitializeEvent.builder()
.id(event.getId())
.build()
);
}
#DeadlineHandler(deadlineName = INITIALIZE_DEADLINE_NAME)
protected void onDeadline(final InitializeEvent command) {
this.commandGateway.send(command);
}
// ...
}
I've abstracted away the non-relevant code. Keep in mind that nowhere else in the codebase we modify the StdScheduler instance injected as a Bean dependency for DeadlineManager.
However, when executing my code, I keep getting the following Exception:
2020-05-28 03:26:13.001 ERROR 1 --- [eduler_Worker-1] o.a.deadline.quartz.DeadlineJob : Exception occurred during processing a deadline job which will be retried [com.eblock.simulcast.bidding_engine_axon.auction_event.command.InitializeAuctionEvent]
javax.persistence.TransactionRequiredException: Executing an update/delete query
at org.hibernate.internal.AbstractSharedSessionContract.checkTransactionNeededForUpdateOperation(AbstractSharedSessionContract.java:413) ~[hibernate-core-5.4.15.Final.jar!/:5.4.15.Final]
at org.hibernate.query.internal.AbstractProducedQuery.executeUpdate(AbstractProducedQuery.java:1608) ~[hibernate-core-5.4.15.Final.jar!/:5.4.15.Final]
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na]
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:na]
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na]
at java.base/java.lang.reflect.Method.invoke(Method.java:566) ~[na:na]
at org.springframework.orm.jpa.SharedEntityManagerCreator$DeferredQueryInvocationHandler.invoke(SharedEntityManagerCreator.java:409) ~[spring-orm-5.2.6.RELEASE.jar!/:5.2.6.RELEASE]
at com.sun.proxy.$Proxy175.executeUpdate(Unknown Source) ~[na:na]
at org.axonframework.modelling.saga.repository.jpa.JpaSagaStore.updateSaga(JpaSagaStore.java:272) ~[axon-modelling-4.3.3.jar!/:4.3.3]
at org.axonframework.modelling.saga.repository.AnnotatedSagaRepository.updateSaga(AnnotatedSagaRepository.java:208) ~[axon-modelling-4.3.3.jar!/:4.3.3]
at org.axonframework.modelling.saga.repository.AnnotatedSagaRepository.commit(AnnotatedSagaRepository.java:174) ~[axon-modelling-4.3.3.jar!/:4.3.3]
at org.axonframework.modelling.saga.repository.AnnotatedSagaRepository.lambda$doLoad$2(AnnotatedSagaRepository.java:121) ~[axon-modelling-4.3.3.jar!/:4.3.3]
at org.axonframework.messaging.unitofwork.MessageProcessingContext.notifyHandlers(MessageProcessingContext.java:71) ~[axon-messaging-4.3.3.jar!/:4.3.3]
at org.axonframework.messaging.unitofwork.DefaultUnitOfWork.notifyHandlers(DefaultUnitOfWork.java:106) ~[axon-messaging-4.3.3.jar!/:4.3.3]
at org.axonframework.messaging.unitofwork.AbstractUnitOfWork.changePhase(AbstractUnitOfWork.java:222) ~[axon-messaging-4.3.3.jar!/:4.3.3]
at org.axonframework.messaging.unitofwork.AbstractUnitOfWork.commitAsRoot(AbstractUnitOfWork.java:83) ~[axon-messaging-4.3.3.jar!/:4.3.3]
at org.axonframework.messaging.unitofwork.AbstractUnitOfWork.commit(AbstractUnitOfWork.java:71) ~[axon-messaging-4.3.3.jar!/:4.3.3]
at org.axonframework.messaging.unitofwork.DefaultUnitOfWork.executeWithResult(DefaultUnitOfWork.java:92) ~[axon-messaging-4.3.3.jar!/:4.3.3]
at org.axonframework.messaging.unitofwork.UnitOfWork.executeWithResult(UnitOfWork.java:328) ~[axon-messaging-4.3.3.jar!/:4.3.3]
at org.axonframework.deadline.quartz.DeadlineJob.execute(DeadlineJob.java:134) ~[axon-messaging-4.3.3.jar!/:4.3.3]
at org.quartz.core.JobRunShell.run(JobRunShell.java:202) ~[quartz-2.3.2.jar!/:na]
at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:573) ~[quartz-2.3.2.jar!/:na]
2020-05-28 03:26:13.001 INFO 1 --- [eduler_Worker-1] org.quartz.core.JobRunShell : Job InitializeAuctionEvent.deadline-7e5d9eec-2c7d-4312-9dde-acb9a56abc6b threw a JobExecutionException:
org.quartz.JobExecutionException: javax.persistence.TransactionRequiredException: Executing an update/delete query
at org.axonframework.deadline.quartz.DeadlineJob.execute(DeadlineJob.java:143) ~[axon-messaging-4.3.3.jar!/:4.3.3]
at org.quartz.core.JobRunShell.run(JobRunShell.java:202) ~[quartz-2.3.2.jar!/:na]
at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:573) ~[quartz-2.3.2.jar!/:na]
Caused by: javax.persistence.TransactionRequiredException: Executing an update/delete query
at org.hibernate.internal.AbstractSharedSessionContract.checkTransactionNeededForUpdateOperation(AbstractSharedSessionContract.java:413) ~[hibernate-core-5.4.15.Final.jar!/:5.4.15.Final]
at org.hibernate.query.internal.AbstractProducedQuery.executeUpdate(AbstractProducedQuery.java:1608) ~[hibernate-core-5.4.15.Final.jar!/:5.4.15.Final]
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na]
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:na]
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na]
at java.base/java.lang.reflect.Method.invoke(Method.java:566) ~[na:na]
at org.springframework.orm.jpa.SharedEntityManagerCreator$DeferredQueryInvocationHandler.invoke(SharedEntityManagerCreator.java:409) ~[spring-orm-5.2.6.RELEASE.jar!/:5.2.6.RELEASE]
at com.sun.proxy.$Proxy175.executeUpdate(Unknown Source) ~[na:na]
at org.axonframework.modelling.saga.repository.jpa.JpaSagaStore.updateSaga(JpaSagaStore.java:272) ~[axon-modelling-4.3.3.jar!/:4.3.3]
at org.axonframework.modelling.saga.repository.AnnotatedSagaRepository.updateSaga(AnnotatedSagaRepository.java:208) ~[axon-modelling-4.3.3.jar!/:4.3.3]
at org.axonframework.modelling.saga.repository.AnnotatedSagaRepository.commit(AnnotatedSagaRepository.java:174) ~[axon-modelling-4.3.3.jar!/:4.3.3]
at org.axonframework.modelling.saga.repository.AnnotatedSagaRepository.lambda$doLoad$2(AnnotatedSagaRepository.java:121) ~[axon-modelling-4.3.3.jar!/:4.3.3]
at org.axonframework.messaging.unitofwork.MessageProcessingContext.notifyHandlers(MessageProcessingContext.java:71) ~[axon-messaging-4.3.3.jar!/:4.3.3]
at org.axonframework.messaging.unitofwork.DefaultUnitOfWork.notifyHandlers(DefaultUnitOfWork.java:106) ~[axon-messaging-4.3.3.jar!/:4.3.3]
at org.axonframework.messaging.unitofwork.AbstractUnitOfWork.changePhase(AbstractUnitOfWork.java:222) ~[axon-messaging-4.3.3.jar!/:4.3.3]
at org.axonframework.messaging.unitofwork.AbstractUnitOfWork.commitAsRoot(AbstractUnitOfWork.java:83) ~[axon-messaging-4.3.3.jar!/:4.3.3]
at org.axonframework.messaging.unitofwork.AbstractUnitOfWork.commit(AbstractUnitOfWork.java:71) ~[axon-messaging-4.3.3.jar!/:4.3.3]
at org.axonframework.messaging.unitofwork.DefaultUnitOfWork.executeWithResult(DefaultUnitOfWork.java:92) ~[axon-messaging-4.3.3.jar!/:4.3.3]
at org.axonframework.messaging.unitofwork.UnitOfWork.executeWithResult(UnitOfWork.java:328) ~[axon-messaging-4.3.3.jar!/:4.3.3]
at org.axonframework.deadline.quartz.DeadlineJob.execute(DeadlineJob.java:134) ~[axon-messaging-4.3.3.jar!/:4.3.3]
... 2 common frames omitted
I decided to debug and spend a few hours trying to narrow down the issue. I realized that somehow outside of my codebase (likely Axon magic), the StdScheduler.getContext().get(DeadlineJob.TRANSACTION_MANAGER_KEY) gets overridden.
Here are 2 screenshots that highlight the issue:
As you can see, the instance number of StdScheduler 13137 contains the SpringTransactionManager during initialize().
When I add the breakpoint straight on my scheduling line, here is the screenshot:
Instance of StdScheduler is still 13137, and the QuartzDeadlineManager.transactionManager still contains an instance of SpringTransactionManager. But the StdScheduler.getContext().get(DeadlineJob.TRANSACTION_MANAGER_KEY) now contains a NoTransactionManager instance, which then causes my execution to break due to a TransactionRequiredException.
Did anyone experience this scenario? How was it mitigated? Right now I'm traversing through all Axon code in an attempt to understand where the instance gets swapped.
Thanks,
I ended up figuring it out the issue.
In my AxonConfiguration class, the method for EventScheduler was left there in case we had to revert or use that scheduler in a near future.
The EventScheduler was defined as this:
#Bean
public QuartzEventSchedulerFactoryBean eventScheduler() {
return new QuartzEventSchedulerFactoryBean();
}
As the QuartzEventScheduler was created by the FactoryBean, it was pulling the StdScheduler from the ApplicationContext, and assigning the relevant variables all over again. Since I had no customized TransactionManager, the default (NoTransactionManager) was being assigned to the QuartzEventScheduler, which then changes the QuartzScheduler context, causing the issue.
To fix that, I expanded my Bean to the following:
#Bean
public QuartzEventSchedulerFactoryBean eventScheduler(
final ApplicationContext applicationContext,
#Qualifier("eventStore") final EventBus eventBus,
final Scheduler scheduler,
final PlatformTransactionManager transactionManager
) {
final QuartzEventSchedulerFactoryBean factoryBean = new QuartzEventSchedulerFactoryBean();
factoryBean.setApplicationContext(applicationContext);
factoryBean.setEventBus(eventBus);
factoryBean.setScheduler(scheduler);
factoryBean.setTransactionManager(transactionManager);
factoryBean.setTransactionDefinition(new DefaultTransactionDefinition());
return factoryBean;
}
Here is my ask for the Axon team:
The QuartzEventScheduler(FactoryBean) requires the underlying PlatformTransactionManager, and creates a new SpringTransactionManager to assign. It would be much easier if they kept the same approach as QuartzDeadlineManager, using directly an autowired TransactionManager, instead of handling the instantiation internally (and replacing the axon-spring-autoconfigure created one).

e4 databinding converter exception not catch

I have created a custom converter to convert a String back into a Date.
public Object convert(Object fromObject){
if (fromObject != null && fromObject.toString().trim().length() == 0){
return null;
}
for (DateFormat f : formats){
try{
return f.parse(fromObject.toString());
}catch (ParseException e){
// Ignore
}
}
throw new RuntimeException(message);
}
Basically, if the string is not parsable a RuntimeException will be thrown.
I have added the converter to the update strategy in the data-dinding and it is being called.
The issue is when the exception is thrown. (For example when i start to type the date in the TextFiled). Instead of appearing the decorator field to indicated an error in the input, the exception is not catch.
The exception appears in the console log (The error in the logs is at the end of the question) as it seems that nobody is catching it.
What i am missing? The exception in the converter should be catch within the updateStrategy and display the error, shouldn't it?
!ENTRY org.eclipse.core.databinding 4 0 2017-08-18 15:16:27.816
!MESSAGE Invalid time Format
!STACK 0
java.lang.RuntimeException: Invalid time Format
at com.lsespace.earthcare.tds.gui.util.databinding.conversion.StringToJavaTimeTagConverter.convert(StringToJavaTimeTagConverter.java:21)
at org.eclipse.core.databinding.UpdateStrategy.convert(UpdateStrategy.java:715)
at org.eclipse.core.databinding.UpdateValueStrategy.convert(UpdateValueStrategy.java:1)
at org.eclipse.core.databinding.ValueBinding$3.run(ValueBinding.java:175)
at org.eclipse.core.databinding.observable.Realm$1.run(Realm.java:149)
at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
at org.eclipse.core.databinding.observable.Realm.safeRun(Realm.java:153)
at org.eclipse.core.databinding.observable.Realm.exec(Realm.java:171)
at org.eclipse.core.databinding.ValueBinding.doUpdate(ValueBinding.java:158)
at org.eclipse.core.databinding.ValueBinding.access$4(ValueBinding.java:147)
at org.eclipse.core.databinding.ValueBinding$1.handleValueChange(ValueBinding.java:46)
at org.eclipse.core.databinding.observable.value.ValueChangeEvent.dispatch(ValueChangeEvent.java:70)
at org.eclipse.core.databinding.observable.ChangeManager.fireEvent(ChangeManager.java:117)
at org.eclipse.core.databinding.observable.value.DecoratingObservableValue.fireValueChange(DecoratingObservableValue.java:61)
at org.eclipse.core.databinding.observable.value.DecoratingObservableValue.handleValueChange(DecoratingObservableValue.java:103)
at org.eclipse.core.databinding.observable.value.DecoratingObservableValue$1.handleValueChange(DecoratingObservableValue.java:76)
at org.eclipse.core.databinding.observable.value.ValueChangeEvent.dispatch(ValueChangeEvent.java:70)
at org.eclipse.core.databinding.observable.ChangeManager.fireEvent(ChangeManager.java:117)
at org.eclipse.core.databinding.observable.value.AbstractObservableValue.fireValueChange(AbstractObservableValue.java:82)
at org.eclipse.core.internal.databinding.property.value.SimplePropertyObservableValue.notifyIfChanged(SimplePropertyObservableValue.java:126)
at org.eclipse.core.internal.databinding.property.value.SimplePropertyObservableValue.access$3(SimplePropertyObservableValue.java:118)
at org.eclipse.core.internal.databinding.property.value.SimplePropertyObservableValue$1$1.run(SimplePropertyObservableValue.java:70)
at org.eclipse.core.databinding.observable.Realm$1.run(Realm.java:149)
at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
at org.eclipse.core.databinding.observable.Realm.safeRun(Realm.java:153)
at org.eclipse.core.databinding.observable.Realm.exec(Realm.java:171)
at org.eclipse.core.internal.databinding.property.value.SimplePropertyObservableValue$1.handleEvent(SimplePropertyObservableValue.java:66)
at org.eclipse.core.databinding.property.NativePropertyListener.fireChange(NativePropertyListener.java:69)
at org.eclipse.jface.internal.databinding.swt.WidgetListener.handleEvent(WidgetListener.java:56)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
at org.eclipse.swt.widgets.Display.sendEvent(Display.java:4410)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1079)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1103)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1084)
at org.eclipse.swt.widgets.Text.wmCommandChild(Text.java:3117)
at org.eclipse.swt.widgets.Control.WM_COMMAND(Control.java:4939)
at org.eclipse.swt.widgets.Control.windowProc(Control.java:4794)
at org.eclipse.swt.widgets.Display.windowProc(Display.java:5115)
at org.eclipse.swt.internal.win32.OS.CallWindowProcW(Native Method)
at org.eclipse.swt.internal.win32.OS.CallWindowProc(OS.java:2446)
at org.eclipse.swt.widgets.Text.callWindowProc(Text.java:262)
at org.eclipse.swt.widgets.Control.windowProc(Control.java:4889)
at org.eclipse.swt.widgets.Text.windowProc(Text.java:2704)
at org.eclipse.swt.widgets.Display.windowProc(Display.java:5102)
at org.eclipse.swt.internal.win32.OS.DispatchMessageW(Native Method)
at org.eclipse.swt.internal.win32.OS.DispatchMessage(OS.java:2552)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3814)
at org.eclipse.jface.window.Window.runEventLoop(Window.java:818)
at org.eclipse.jface.window.Window.open(Window.java:794)
at com.lsespace.earthcare.tds.gui.jface.actions.EditConfigAction.run(EditConfigAction.java:39)
at org.eclipse.jface.action.Action.runWithEvent(Action.java:473)
at org.eclipse.jface.action.ActionContributionItem.handleWidgetSelection(ActionContributionItem.java:565)
at org.eclipse.jface.action.ActionContributionItem.lambda$5(ActionContributionItem.java:436)
at org.eclipse.jface.action.ActionContributionItem$$Lambda$57/765702264.handleEvent(Unknown Source)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
at org.eclipse.swt.widgets.Display.sendEvent(Display.java:4410)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1079)
at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:4228)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3816)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$4.run(PartRenderingEngine.java:1121)
at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:336)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.run(PartRenderingEngine.java:1022)
at org.eclipse.e4.ui.internal.workbench.E4Workbench.createAndRunUI(E4Workbench.java:150)
at org.eclipse.e4.ui.internal.workbench.swt.E4Application.start(E4Application.java:161)
at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:134)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:104)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:388)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:243)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:673)
at org.eclipse.equinox.launcher.Main.basicRun(Main.java:610)
at org.eclipse.equinox.launcher.Main.run(Main.java:1519)
at org.eclipse.equinox.launcher.Main.main(Main.java:1492)
This is the implementation of the UpdateStrategy that I use so exceptions in the converter are treated like validation exceptions.
/**
* This implementation of UpdateValueStrategy does not catch the exceptions thrown by the converter,
* thus letting the normal mechanism of ValueBinding deal with the exception as it will do with a
* validation exception.
*
*/
public class AlternativeUpdateValueStrategy extends UpdateValueStrategy {
public AlternativeUpdateValueStrategy() {
this(UpdateValueStrategy.POLICY_UPDATE);
}
public AlternativeUpdateValueStrategy(int updateStrategy) {
super(updateStrategy);
}
#Override
public Object convert(Object value) {
if (converter != null) {
return converter.convert(value);
}
return value;
}
}

JFX JTable edit with Double Value

Hi I am learning JFX and trin to write a simple jtable example and I am getting a error when running the application
my code snippet error comes is
itemPrice.setCellValueFactory(new PropertyValueFactory<Item, Double>("itemPrice"));
itemPrice.setCellFactory(TextFieldTableCell.forTableColumn());
itemPrice.setOnEditCommit(
new EventHandler<TableColumn.CellEditEvent<Item, Double>>() {
#Override
public void handle(TableColumn.CellEditEvent<Item, Double> t) {
((Item) t.getTableView().getItems().get(
t.getTablePosition().getRow())
).setItemPrice(t.getNewValue());
}
Error is
Exception in thread "JavaFX Application Thread" java.lang.ClassCastException: java.lang.Double cannot be cast to java.lang.String
at javafx.util.converter.DefaultStringConverter.toString(DefaultStringConverter.java:34)
at javafx.scene.control.cell.CellUtils.getItemText(CellUtils.java:100)
at javafx.scene.control.cell.CellUtils.updateItem(CellUtils.java:201)
at javafx.scene.control.cell.TextFieldTableCell.updateItem(TextFieldTableCell.java:204)
at javafx.scene.control.TableCell.updateItem(TableCell.java:663)
at javafx.scene.control.TableCell.indexChanged(TableCell.java:468)
at javafx.scene.control.IndexedCell.updateIndex(IndexedCell.java:116)
at com.sun.javafx.scene.control.skin.TableRowSkinBase.updateCells(TableRowSkinBase.java:523)
at com.sun.javafx.scene.control.skin.TableRowSkinBase.init(TableRowSkinBase.java:147)
at com.sun.javafx.scene.control.skin.TableRowSkin.<init>(TableRowSkin.java:64)
at javafx.scene.control.TableRow.createDefaultSkin(TableRow.java:212)
at javafx.scene.control.Control.impl_processCSS(Control.java:859)
at javafx.scene.Node.processCSS(Node.java:9035)
at javafx.scene.Node.applyCss(Node.java:9132)
at com.sun.javafx.scene.control.skin.VirtualFlow.setCellIndex(VirtualFlow.java:1957)
at com.sun.javafx.scene.control.skin.VirtualFlow.getCell(VirtualFlow.java:1790)
at com.sun.javafx.scene.control.skin.VirtualFlow.getCellLength(VirtualFlow.java:1872)
at com.sun.javafx.scene.control.skin.VirtualFlow.computeViewportOffset(VirtualFlow.java:2511)
at com.sun.javafx.scene.control.skin.VirtualFlow.layoutChildren(VirtualFlow.java:1189)
at javafx.scene.Parent.layout(Parent.java:1076)
at javafx.scene.Parent.layout(Parent.java:1082)
at javafx.scene.Parent.layout(Parent.java:1082)
at javafx.scene.Parent.layout(Parent.java:1082)
at javafx.scene.Scene.doLayoutPass(Scene.java:552)
at javafx.scene.Scene$ScenePulseListener.pulse(Scene.java:2397)
at com.sun.javafx.tk.Toolkit.lambda$runPulse$30(Toolkit.java:314)
at com.sun.javafx.tk.Toolkit$$Lambda$216/252608964.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.tk.Toolkit.runPulse(Toolkit.java:313)
at com.sun.javafx.tk.Toolkit.firePulse(Toolkit.java:340)
at com.sun.javafx.tk.quantum.QuantumToolkit.pulse(QuantumToolkit.java:525)
at com.sun.javafx.tk.quantum.QuantumToolkit.pulse(QuantumToolkit.java:505)
at com.sun.javafx.tk.quantum.QuantumToolkit.lambda$runToolkit$400(QuantumToolkit.java:334)
at com.sun.javafx.tk.quantum.QuantumToolkit$$Lambda$42/820829455.run(Unknown Source)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.lambda$null$145(WinApplication.java:101)
at com.sun.glass.ui.win.WinApplication$$Lambda$38/1329190985.run(Unknown Source)
at java.lang.Thread.run(Thread.java:745)
and I know this is due to casting issue in java but duno how edit handler works in JFX same code for string data type works how to fix, Help/Tip Please
Use
itemPrice.setCellFactory(TextFieldTableCell.forTableColumn(new DoubleStringConverter()));

Spring custom Authorization not working using #PreAuthorize

I am trying to implement custom #PreAuthorize method in my spring (3.2.2) mvc app. But whenever I click on the link which is supposed to take me to the controller method where the #PreAuthorize is implemented it gives me this error :
org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.springframework.security.authentication.AuthenticationCredentialsNotFoundException: An Authentication object was not found in the SecurityContext
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:948)
org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:827)
javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:812)
javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
root cause
org.springframework.security.authentication.AuthenticationCredentialsNotFoundException: An Authentication object was not found in the SecurityContext
org.springframework.security.access.intercept.AbstractSecurityInterceptor.credentialsNotFound(AbstractSecurityInterceptor.java:339)
org.springframework.security.access.intercept.AbstractSecurityInterceptor.beforeInvocation(AbstractSecurityInterceptor.java:198)
org.springframework.security.access.intercept.aopalliance.MethodSecurityInterceptor.invoke(MethodSecurityInterceptor.java:60)
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:631)
com.nav.qanda.admin.question.controller.AdminQuestionController$$EnhancerByCGLIB$$5bcda356_2.handleRequest(<generated>)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
java.lang.reflect.Method.invoke(Method.java:606)
org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:219)
org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:132)
org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:104)
org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:745)
org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:686)
org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:80)
org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:925)
org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:856)
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:936)
org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:827)
javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:812)
javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
This is my app-servlet.xml
<security:global-method-security pre-post-annotations="enabled">
<security:expression-handler ref="expressionHandler" />
</security:global-method-security>
<bean id="expressionHandler" class="com.nav.panda.security.PandaMethodSecurityExpressionHandler" />
and these are the java files overriding
public class PandaMethodSecurityExpressionHandler extends DefaultMethodSecurityExpressionHandler{
#Override
protected MethodSecurityExpressionOperations createSecurityExpressionRoot(Authentication authentication,
MethodInvocation invocation){
PandaMethodSecurityExpressionRoot root = new PandaMethodSecurityExpressionRoot(authentication);
root.setThis(invocation.getThis());
return root;
}
public class PandaMethodSecurityExpressionRoot implements MethodSecurityExpressionOperations {
private Object filterObject;
private Object returnObject;
private Object target;
public boolean adminOnly() {
System.out.println("Checking admin authority");
return true;
// return this.hasAuthority("ADMIN");
} ... other methods
And the controller looks like this :
#RequestMapping(value = "/createPandaPage", method = RequestMethod.GET)
#PreAuthorize("adminOnly()")
public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
return new ModelAndView("admin/createPanda");
}
web.xml :
<filter>
<filter-name>springSecurityFilterChain</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>
<filter-mapping>
<filter-name>springSecurityFilterChain</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
The login in my application will populate a User object (which has the users authority filled from a db read) from my application. How do I pass this User Object to check for authority ? And, what else would I need to do to get this working ?
The request which leads to this method being called need to pass through the Spring Security filter chain, otherwise there will be no security context available when the permissions are checked.
Without seeing the rest of the stacktrace, I can't say 100%, but it looks like that's what's happening here, given the exception you are seeing (you should find similar issues if you search for the error message).
So you need to make sure all the requests you want secured are handled by the security filter chain, and also that your filter chain is properly configured (which it should be automatically if you're using the namespace).

Problems with javaFX building path MVC fxml

I am currently working on an administrator build in java FX 2.1 using netbeans 7.2
I have the following issues:
I am developing this particular tool in an MVC pattern, so I've created 3 packages called Model, view and Controller.
My problem is that when building the project in netbeans it would only read the files supposed to be in the view package if they're outside of it. Let me give you a context path:
.../administradorInfinix/view/
.../administradorInfinix/controller/
.../administradorInfinix/model
so it would only read the fxml files regarding the view if they are outside the view package (.../administradorInfinix/)
This is where I set the address of the file:
private void irInicioSesion() {
try {
replaceSceneContent("InicioSesion.fxml");
} catch (Exception ex) {
Logger.getLogger(AdministradorINFINIX.class.getName()).log(Level.SEVERE, null, ex);
}
}
You can see the file name is InicioSesion.fxml, which should be inside the view package but it won't load if this is the case.
This is the replaceSceneContent I'm using to search for the fxml files:
private Parent replaceSceneContent(String fxml) throws Exception {
Parent page = (Parent) FXMLLoader.load(AdministradorINFINIX.class.getResource(fxml), null, new JavaFXBuilderFactory());
Scene scene = stage.getScene();
if (scene == null) {
scene = new Scene(page,548,416);
//scene.getStylesheets().add(AdministradorINFINIX.class.getResource("demo.css").toExternalForm());
stage.setScene(scene);
} else {
stage.getScene().setRoot(page);
}
stage.sizeToScene();
return page;
}
And this is the error it gives me when trying to run (it builds just fine but it won't run)
> administradorinfinix.AdministradorINFINIX irInicioSesion
Grave: null
java.lang.IllegalStateException: Location is not set.
at javafx.fxml.FXMLLoader.load(Unknown Source)
at javafx.fxml.FXMLLoader.load(Unknown Source)
at javafx.fxml.FXMLLoader.load(Unknown Source)
at javafx.fxml.FXMLLoader.load(Unknown Source)
at administradorinfinix.AdministradorINFINIX.replaceSceneContent(AdministradorINFINIX.java:126)
at administradorinfinix.AdministradorINFINIX.irInicioSesion(AdministradorINFINIX.java:110)
at administradorinfinix.AdministradorINFINIX.start(AdministradorINFINIX.java:46)
at com.sun.javafx.application.LauncherImpl$5.run(Unknown Source)
at com.sun.javafx.application.PlatformImpl$4.run(Unknown Source)
at com.sun.javafx.application.PlatformImpl$3.run(Unknown Source)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.access$100(Unknown Source)
at com.sun.glass.ui.win.WinApplication$2$1.run(Unknown Source)
at java.lang.Thread.run(Thread.java:722)
where line 110 is
replaceSceneContent("InicioSesion.fxml");
and line 126 is
Parent page = (Parent) FXMLLoader.load(AdministradorINFINIX.class.getResource(fxml), null, new JavaFXBuilderFactory());
I hope you can help me fix this problem.
You need to call the method FXMLLoader#setLocation with the URL of the FXML file. Have a look at the following source for an example of how to load FXML files:
https://github.com/cathive/fx-guice/blob/master/src/main/java/com/cathive/fx/guice/GuiceFXMLLoader.java
The FXMLLoader fails to locate the .fxml-file.
The problem is that your call to Class.getResource() returns null.
The exception thrown by FXMLLoader.load(null) is quite misleading, it should rather be something such as an ArgumentNullException.
You can fix the problem with loading your resource file by specifying the full package path, in my case a call like this works:
FXMLLoader loader = new FXMLLoader(new Employee().getClass().getResource("/de/mycompany/mypackage/view/loginform.fxml"));
I hope this helps.

Resources