Gridgain Error Suppressed: class org.gridgain.grid.GridException: Failed to serialize object - gridgain

I am trying to put a key as String , value as List Intervals> in the cache and I am getting the below error. I have a put method in dao as generalised as object,object> so it can be used for difference cache
Input
[MAC4, [com.xx.Interval#1bccacc7]]
[MAC3, [com.xx.Interval#754b3232]]
[MAC1, [com.xx.Interval#78cf9e78, com.xx.Interval#6ad163f]]
MAC* is the key and List of Interval Objects are values.
Code:
griddao.put("intervals",tuple.getValue(0),tuple.getValue(1));
In griddao
public void put(String cacheName, Object key, Object value) throws GridException {
GridCache<Object, Object> cache = caches.get(cacheName);
if ( cache != null ) {
cache.put(key, value);
}
else {
LOG.error( "Cache is null");
}

It looks like you forgot to attach the actual error you got. Please provide full exception trace.
For now you can check whether Interval class implements Serializable. If it doesn't and you can't change it, configure marshaller not to require Serializable interface, like this:
<bean id="grid.cfg" class="org.gridgain.grid.GridConfiguration">
...
<property name="marshaller">
<bean class="org.gridgain.grid.marshaller.optimized.GridOptimizedMarshaller">
<property name="requireSerializable" value="false"/>
</bean>
</property>
...
</bean>

Related

How to create a date range as a condition of a promotion in hybris?

is it possible to create a date condition for promotion in hybris?
I am trying to do this implementation. my first problem is how to map the parameter value
<bean id="dateRuleParameterValueMapperDefinition" class="de.hybris.platform.ruleengineservices.rule.strategies.impl.RuleParameterValueMapperDefinition">
<property name="mapper" ref="dateRuleParameterValueMapper" />
<property name="type" value="java.util.Date" />
</bean>
in this mapping, I have an exception that the type is not supported (Caused by: de.hybris.platform.ruleengineservices.rule.strategies.RuleParameterValueMapperException:)
if so, can I resolve this error .. is it possible to create a date condition in the RuleConditionTranslator?
hybris version: 6.5
If you want to add any new RuleParameterValueMapperDefinition, you have to implement 'RuleParameterValueMapper' and override 'toString' and 'fromString' methods in your mapper implementation.
public class MediaTypeRuleParameterValueMapper implements RuleParameterValueMapper<MediaModel>
{
#Resource
MediaService mediaService;
#Override
public String toString(final MediaModel mediaModel)
{
Preconditions.checkArgument(Objects.nonNull(mediaModel), "mediaModel must not be null!");
return mediaModel.getCode();
}
#Override
public MediaModel fromString(final String mediaCode)
{
try
{
return mediaService.getMedia(mediaCode);
}
catch (UnknownIdentifierException e)
{
e.message()
}
return null;
}
}
Now create a custom mapper definition (RuleParameterValueMapperDefinition)
<bean id="mediaTypeRuleParameterValueMapper" class="com.hybris.MediaTypeRuleParameterValueMapper"/>
<bean id="mediaTypeRuleParameterValueMapperDefinition" class="de.hybris.platform.ruleengineservices.rule.strategies.impl.RuleParameterValueMapperDefinition">
<property name="mapper" ref="mediaTypeRuleParameterValueMapper"/>
<property name="type" value="ItemType(Media)"/>
</bean>
Now you are ready to use
RuleConditionDefinitionParameter.type=ItemType(Media)
I don't believe that you need to map a date in that way, it should be treated the same as a String or Integer. So for reference look at the way any of the String or Integer parameters are handled.
My basis for saying this is the following from ruleengineservices-spring-rule.xml:
<alias name="defaultRuleParameterSupportedTypes" alias="ruleParameterSupportedTypes" />
<util:set id="defaultRuleParameterSupportedTypes" value-type="java.lang.String">
<value>java.lang.Boolean</value>
<value>java.lang.Character</value>
<value>java.lang.String</value>
<value>java.lang.Byte</value>
<value>java.lang.Short</value>
<value>java.lang.Integer</value>
<value>java.lang.Long</value>
<value>java.lang.Float</value>
<value>java.lang.Double</value>
<value>java.math.BigInteger</value>
<value>java.math.BigDecimal</value>
<value>java.util.Date</value>
<value>java.lang.Enum</value>
<value>java.util.List</value>
<value>java.util.Map</value>
</util:set>

spring integration dynamic filter based on the current Date

I am trying to use ftp-inbound-adapter to poll files based on the the current date.And my inbound adapter uses a filter which refers to bean myfilter .The problem here is the current date is initailized at the startup and is not been processed dynamically..I would like to get the current date for every new message
<int-ftp:inbound-channel-adapter id="ftpInbound"
channel="ftpChannel"
session-factory="ftpsClientFactory"
filter="myFilter"
</int-ftp:inbound-channel-adapter>
<bean id="myFilter" class="org.springframework.integration.ftp.filters.FtpRegexPatternFileListFilter" scope="prototype">
<constructor-arg value="#{T(java.time.LocalDateTime).now().format(T(java.time.format.DateTimeFormatter).ofPattern('MMddyy'))}.(xls|xlsx)"/>
<aop:scoped-proxy/>
</bean>
UPDATE
I changed from this
<bean id="currentDate" class="java.util.Date" factory-bean="fastDateFormat"
scope="prototype" factory-method="format" >
<aop:scoped-proxy/>
<constructor-arg>
<bean class="java.util.Date" />
</constructor-arg>
</bean>
<bean id="myFilter" class="org.springframework.integration.ftp.filters.FtpRegexPatternFileListFilter" scope="prototype">
<constructor-arg value="#{currentDate}.(xls|xlsx)"/>
</bean>
And my inbound adapter uses a filter which refers to bean myFilter .. The problem here is the current date is initailized at the startup and is not been processed dynamically..I would like to get the current date for every new message
This impossible with your current configuration because that filter is just a singleton bean created only once at start up pulling that your currentDate for injection only once as well.
You may try to add <aop:scoped-proxy/> into your currentDate bean definition, though: https://docs.spring.io/spring/docs/5.1.3.RELEASE/spring-framework-reference/core.html#beans-factory-scopes-other-injection, but I would suggest to inject BeanFactorty into your filter and call getBean("currentDate", Date.class) every time you need a new instance of that prototype.
UPDATE
You inject BeanFactory into your filter instead of that currentDate bean. And then when filter logic is called you do Date currentDate = this.beanFactory.getBean("currentDate", Date.class);.
UPDATE2
Here is what I think should work for you:
public class DynamicRegexPatternFilter extends AbstractFileListFilter<File> {
#Autowired
private BeanFactory beanFactory;
#Override
public boolean accept(File file) {
return Pattern.compile(this.beanFactory.getBean("currentDate", String.class) + ".(xls|xlsx)")
.matcher(file.getName())
.matches();
}
}
You can make custom filter. Implement FileListFilter and override filterFiles method which takes input argument as array of LsEntry. LsEntry is nothing but a small metadata object of a File present at (S)FTP. It comprises of File Name and the date on which it was modified.
#Override
public List<LsEntry> filterFiles(LsEntry[] files) {
List<LsEntry> result = new ArrayList<LsEntry>();
Vector<LsEntry> list = new Vector<LsEntry>();
Collections.addAll(list, files);
ChannelSftp.LsEntry lastModifiedEntry = Collections.max(list,
(Comparator.comparingInt(entry -> entry.getAttrs().getMTime())));
result.add(lastModifiedEntry);
return result;
}
Reference: https://stackoverflow.com/a/60635859/11325128

Spring 4: ThreadPoolTaskExecutor transaction management issue

We recently upgraded our spring version to 4.x from 2.x which started causing some issues with one of our 'threadpooltaskexecutor' implementation.
The implementation was as below:
public class A
{
..............................
..............................
public void create()
{
this.threadPoolTaskExecutor.execute(new Runnable()
{
public void run()
{
createABCAsync();
}
});
}
public void createABCAsync()
{
createABC();
}
public void createABC()
{
.....................................
.....................................
abcDAO.saveOrUpdate(abc);
xyzDAO.saveOrUpdate(xyz);
}
...................................................
...................................................
}
The bean definitions for class A has entries like below:
`<bean id="clsIntegrationManager" parent="txProxyTemplate"`>
.................................................
.................................................
<property name="transactionAttributes">
<props>
<prop key="create">PROPAGATION_REQUIRED</prop>
<prop key="createABCAsync">PROPAGATION_REQUIRES_NEW</prop>
</props>
</property>
After spring upgrade, the above code threw an exception as below:
Exception in thread "threadPoolTaskExecutor-1" org.springframework.dao.InvalidDataAccessApiUsageException: Write operations are not allowed in read-only mode (FlushMode.MANUAL): Turn your Session into FlushMode.COMMIT/AUTO or remove 'readOnly' marker from transaction definition.
To resolve the above I added an entry like follows in the DAO layer bean definition file:
<bean id ="hibernateTemplate" class="org.springframework.orm.hibernate4.HibernateTemplate">
<property name="sessionFactory" ref="sessionFactory"/>
<property name="checkWriteOperations" value="false"/>
</bean>
The above entry resolved the exception, but the asynchronous method execution which starts a separate transaction using REQUIRES_NEW is not doing any database commits. We have a couple of 'saveOrUpdate()' calls inside the createABC() method but nothing gets saved in database.
Can someone please help in understanding what is going wrong above ?
I tried a few different solution approaches, one of which is described here: [Spring TaskExecutor Transaction Lost (Proxy vs. Direct call) but this did not help.

LazyInitializationException in Thread with Spring Roo 1.5

I have a project with Spring Roo 1.5 (mysql w/ hibernate), I made a Thread class (extends from Thread) because I need call to async operations. But when I tried to get this, for example a property from persitence class occurs a exception. This only occurs when I call from Thread class...
My entity class:
#RooJavaBean
#RooToString
#RooEntity
public class Consulta {
private String nombre;
#OneToMany(cascade=CascadeType.ALL)
private List<DetalleConsulta> detalleConsulta;
}
My thread:
public class ThreadIngresarConsulta extends Thread {
private Long idConsulta;
public ThreadIngresarConsultaCRM(Long idConsulta) {
super("ThreadIngresarConsultaCRM");
this.idConsulta = idConsulta;
}
public void run(){
try {
Consulta consulta = Consulta.findConsulta(idConsulta);
List<DetalleConsulta> lista = consulta.getDetalleConsulta();
}catch(Exception e) {
System.err.println(e.getMessage());
}
}
}
ApplicactionContext (generated by roo)
...
<bean class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close" id="dataSource">
<property name="driverClassName" value="${database.driverClassName}"/>
<property name="url" value="${database.url}"/>
<property name="username" value="${database.username}"/>
<property name="password" value="${database.password}"/>
<property name="validationQuery" value="SELECT 1"/>
</bean>
<bean class="org.springframework.orm.jpa.JpaTransactionManager" id="transactionManager">
<property name="entityManagerFactory" ref="entityManagerFactory"/>
</bean>
<tx:annotation-driven mode="aspectj" transaction-manager="transactionManager"/>
<bean class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean" id="entityManagerFactory">
<property name="persistenceUnitName" value="persistenceUnit"/>
<property name="dataSource" ref="dataSource"/>
</bean>
And this is the exception:
011-12-05 18:49:10,015 [ThreadIngresarConsulta] ERROR org.hibernate.LazyInitializationException - failed to lazily initialize a collection of role: com.core.Consulta.detalleConsulta, no session or session was closed
org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: com.core.Consulta.detalleConsulta, no session or session was closed
Has anyone tried to call an entity JPA within a thread?
Try putting an #Transactional annotation on the run method of your thread. If that doesn't work move the two lines into a separate method and add #Transactional on that method.
public class ThreadIngresarConsulta extends Thread {
public void run(){
doProcess();
}
#Transactional
public void doProcess() {
try {
Consulta consulta = Consulta.findConsulta(idConsulta);
List<DetalleConsulta> lista = consulta.getDetalleConsulta();
}catch(Exception e) {
System.err.println(e.getMessage());
}
}
}

RESTEasy + Spring + Jackson + Jaxb

I am trying to serialize JAXB annotated class with Jackson using RESTEasy. By default ResteasyJacksonProvider is configured to use JACKSON annotation only. Is there a way to configure ResteasyJacksonProvider to use JAXB annotation using spring? There are couple of programmatic ways but would prefer if there is some spring configuration.
Couple of ways I am thinking of
Use ContextResolver for ObjectMapper type to return ObjectMapper configured to use JaxbAnnotationIntrospector instead of JacksonAnnotationIntrospector.
Extend ResteasyJacksonProvider and pass JAXB annotation during construction.
Any other way?
Well the first option of using ContextResolver works but I still think there should be an easier way to do this just by some configuration.
You can get this from the configuration only, no need to program anything special.
Here's how to:
First set your configuration right, I use Jackson + JAXB, both set under ContentNegotiatingViewResolver bean:
<bean class="org.springframework.web.servlet.view.ContentNegotiatingViewResolver">
<property name="order" value="1"/>
<property name="mediaTypes">
<map>
<entry key="xml" value="application/xml" />
<entry key="json" value="application/json" />
</map>
</property>
<property name="defaultViews">
<list>
<bean class="org.springframework.web.servlet.view.xml.MarshallingView">
<property name="marshaller">
<oxm:jaxb2-marshaller id="marshaller">
<oxm:class-to-be-bound name="com.shay.dashboard.data.structure.page.PageObject" />
<oxm:class-to-be-bound name="com.shay.dashboard.data.structure.tab.TabObject" />
<oxm:class-to-be-bound name="com.shay.dashboard.data.structure.section.SectionObject" />
<oxm:class-to-be-bound name="com.shay.dashboard.data.structure.element.nonembedded.ElementObject"/>
<oxm:class-to-be-bound name="com.shay.dashboard.data.structure.element.embedded.EmbeddedElementObject"/>
<oxm:class-to-be-bound name="com.shay.dashboard.data.structure.chart.common.ChartManager"/>
</oxm:jaxb2-marshaller>
</property>
</bean>
<bean class="org.springframework.web.servlet.view.json.MappingJacksonJsonView"/>
</list>
</property>
</bean>
Notice that under the marshaller I set the oxm:class-to-be-bound - those are the classes to be bound by JAXB.
Now for the module, I used ordinary annotation package (javax.xml.bind.annotation), non marshaller specific. Jackson Json and JAXB both know how to read it.
For example:
#XmlAccessorType(XmlAccessType.NONE)
#XmlRootElement(name="page")
public class PageObject implements ComponentTypeObject{
#XmlAttribute(name="name")
private String name;
#XmlAttribute(name="id",required=true)
private String id;
#XmlElements({#XmlElement(name="tab", type=TabXmlAdapter.class)})
private List<TabXmlAdapter> tabRef;
Finally the controller for your MVC needs to return a model and view:
#RequestMapping(value="/get_page", method = RequestMethod.GET)
public ModelAndView initPage()
{
ModelAndView mav = null;
try
{
PageObject myPage = (PageObject) Utilities.getUtilities().loadObjectFromFile(XmlComponentType.page);
mav = new ModelAndView("page","page",myPage);
}
catch (Exception e)
{
e.getMessage();
}
return mav;
}
Now while calling your URL ending with .json you'd get the JSON representation, and with .xml - and XML. Both are translated by the viewer, provided you gave the correct mapping when annotating the module.

Resources