Spring Integration serializes MessageHeader Object - spring

i have some services, one implemented with Grails 2.4.2 (Spring 4.0.5) some implemented as Spring Web (Spring 4.0.5) and one implemented with Spring Boot 1.2.1 (Spring 4.1.4).
The services communicate over RabbitMQ with spring-integration.
Communication between Grails and the Spring Web services is fine, but it's not possible to communicate with the Spring Boot service. Because Spring Boot uses a newer Spring version and the serial version of the MessageHeader class has changed.
What can i do to avoid this problem?
Here the exception:
Caused by: org.springframework.messaging.MessagingException: Failure occured in AMQP listener while attempting to convert and dispatch Message.; nested exception is org.springframework.amqp.support.converter.MessageConversionException: failed to convert serialized
Message content
at org.springframework.integration.amqp.channel.AbstractSubscribableAmqpChannel$DispatchingMessageListener.onMessage(AbstractSubscribableAmqpChannel.java:201) ~[spring-integration-amqp-4.0.2.RELEASE.jar:na]
at org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer.doInvokeListener(AbstractMessageListenerContainer.java:693) ~[spring-rabbit-1.3.4.RELEASE.jar:na]
... 10 common frames omitted
Caused by: org.springframework.amqp.support.converter.MessageConversionException: failed to convert serialized Message content
at org.springframework.amqp.support.converter.SimpleMessageConverter.fromMessage(SimpleMessageConverter.java:112) ~[spring-amqp-1.3.4.RELEASE.jar:na]
at org.springframework.integration.amqp.channel.AbstractSubscribableAmqpChannel$DispatchingMessageListener.onMessage(AbstractSubscribableAmqpChannel.java:176) ~[spring-integration-amqp-4.0.2.RELEASE.jar:na]
... 11 common frames omitted
Caused by: java.lang.IllegalArgumentException: Could not deserialize object
at org.springframework.amqp.utils.SerializationUtils.deserialize(SerializationUtils.java:79) ~[spring-amqp-1.3.4.RELEASE.jar:na]
at org.springframework.amqp.support.converter.SimpleMessageConverter.fromMessage(SimpleMessageConverter.java:107) ~[spring-amqp-1.3.4.RELEASE.jar:na]
... 12 common frames omitted
Caused by: java.io.InvalidClassException: org.springframework.messaging.MessageHeaders; local class incompatible: stream classdesc serialVersionUID = -4615750558355702881, local class serialVersionUID = 7035068984263400920
at java.io.ObjectStreamClass.initNonProxy(ObjectStreamClass.java:617) ~[na:1.7.0_51]
at java.io.ObjectInputStream.readNonProxyDesc(ObjectInputStream.java:1622) ~[na:1.7.0_51]
at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1517) ~[na:1.7.0_51]
at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1771) ~[na:1.7.0_51]
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1350) ~[na:1.7.0_51]
> at org.springframework.amqp.utils.SerializationUtils.deserialize(SerializationUtils.java:76) ~[spring-amqp-1.3.4.RELEASE.jar:na]

Don't serialize the entire Message<?>; use the AMQP adapters' ability to map Message headers to amqp headers and vice-versa.
I am not sure how that works on the grails side but you'd need to do the mapping over there too.

Related

Spring Kafka failed to resolve className

I am trying to send a data object from one spring service to another service using kafka.
The problem is that kafka is not able to resolve the className and hence is unable to map the consumber's class to the producer's class.
Following is the error message:
Caused by: org.springframework.messaging.converter.MessageConversionException: failed to resolve class name. Caused by: java.lang.ClassNotFoundException
I have tried to map the class using the following property:
For the producer: spring.kafka.producer.properties.spring.json.type.mapping=event:com.ankit.orderservice.event.OrderPlacedEvent
For the consumer: spring.kafka.consumer.properties.spring.json.type.mapping: event:com.ankit.OrderPlacedEvent

Fail to deploy service using thick client

I'm trying to deploy a simple service using a thick client, I use kubernetes job to launch a thick client, and then use ignite instance to deploy:
private void deployService() {
ServiceConfiguration serviceCfg = new ServiceConfiguration();
serviceCfg.setName("simpleService");
serviceCfg.setMaxPerNodeCount(1);
serviceCfg.setTotalCount(1);
serviceCfg.setService(new SimpleServiceImpl());
ignite.services().deploy(serviceCfg);
}
but I got the following error:
SEVERE: Failed to initialize service (service will not be deployed): simpleService
class org.apache.ignite.IgniteCheckedException: com.example.ignite_springcloud.model.ignite_service.SimpleServiceImpl at
org.apache.ignite.internal.util.IgniteUtils.unmarshal(IgniteUtils.java:11026) at org.apache.ignite.internal.processors.service.GridServiceProcessor.copyAndInject(GridServiceProcessor.java:1381) at
org.apache.ignite.internal.processors.service.GridServiceProcessor.redeploy(GridServiceProcessor.java:1302) at
org.apache.ignite.internal.processors.service.GridServiceProcessor.processAssignment(GridServiceProcessor.java:1931) at
org.apache.ignite.internal.processors.service.GridServiceProcessor.onSystemCacheUpdated(GridServiceProcessor.java:1555) at
org.apache.ignite.internal.processors.service.GridServiceProcessor.access$300(GridServiceProcessor.java:133) at
org.apache.ignite.internal.processors.service.GridServiceProcessor$ServiceEntriesListener$1.run0(GridServiceProcessor.java:1537) at
org.apache.ignite.internal.processors.service.GridServiceProcessor$DepRunnable.run(GridServiceProcessor.java:2007) at
java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128) at
java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628) at java.base/java.lang.Thread.run(Thread.java:829) Caused by: class org.apache.ignite.binary.BinaryInvalidTypeException: com.example.ignite_springcloud.model.ignite_service.SimpleServiceImpl at
org.apache.ignite.internal.binary.BinaryContext.descriptorForTypeId(BinaryContext.java:697) at
org.apache.ignite.internal.binary.BinaryReaderExImpl.deserialize0(BinaryReaderExImpl.java:1765) at
org.apache.ignite.internal.binary.BinaryReaderExImpl.deserialize(BinaryReaderExImpl.java:1724) at
org.apache.ignite.internal.binary.GridBinaryMarshaller.deserialize(GridBinaryMarshaller.java:318) at
org.apache.ignite.internal.binary.GridBinaryMarshaller.deserialize(GridBinaryMarshaller.java:303) at
org.apache.ignite.internal.binary.BinaryMarshaller.unmarshal0(BinaryMarshaller.java:100) at
org.apache.ignite.marshaller.AbstractNodeNameAwareMarshaller.unmarshal(AbstractNodeNameAwareMarshaller.java:80) at
org.apache.ignite.internal.util.IgniteUtils.unmarshal(IgniteUtils.java:11020) ... 10 more Caused by:
java.lang.ClassNotFoundException: com.example.ignite_springcloud.model.ignite_service.SimpleServiceImpl at
java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:581) at
java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178) at
java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522) at
java.base/java.lang.Class.forName0(Native Method) at
java.base/java.lang.Class.forName(Class.java:398) at
org.apache.ignite.internal.util.IgniteUtils.forName(IgniteUtils.java:9503) at
org.apache.ignite.internal.util.IgniteUtils.forName(IgniteUtils.java:9441) at
org.apache.ignite.internal.MarshallerContextImpl.getClass(MarshallerContextImpl.java:325) at
org.apache.ignite.internal.binary.BinaryContext.descriptorForTypeId(BinaryContext.java:673) ... 170 more
Also, the service related class and interface are defined together with thick client, and I didn't provide jar or classpath on server nodes, but I set peer class loading for both client and servers:
igniteConfig.setPeerClassLoadingEnabled(true);
igniteConfig.setDeploymentMode(DeploymentMode.CONTINUOUS);
I just wonder if this is the correct way to deploy a service to server. and btw, if I deployed the service through a thick client, then that thick client left the cluster and closed, will the service be accessible and callable by other client nodes?
Peer class loading does not work for Services: https://ignite.apache.org/docs/latest/code-deployment/peer-class-loading
You have to deploy service classes manually on server nodes.
if I deployed the service through a thick client, then that thick client left the cluster and closed, will the service be accessible and callable by other client nodes
Yes.

java.lang.IllegalStateException: Unable to detect database type for Sybase datasource

I am getting the Unable to detect database type for Sybase Datasource configured in my spring boot application.
Spring boot version: 1.5.3
application.properties
spring.datasource.url=jdbc:jtds:sybase://db-server-name:5555/DBNAME
spring.datasource.username=db_user
spring.datasource.password=db_password
spring.datasource.driver-class-name=net.sourceforge.jtds.jdbc.Driver
spring.jpa.database=sybase
spring.jpa.database-platform=org.hibernate.dialect.SybaseDialect
Debug Information:
// line number 75 in AbstractDatabaseInitializer class
String productName = JdbcUtils.commonDatabaseName(JdbcUtils
.extractDatabaseMetaData(this.dataSource, "getDatabaseProductName")
.toString());
// productName is returned as Sybase from JdbcUtils.extractDatabaseMetaData
DatabaseDriver databaseDriver = DatabaseDriver.fromProductName(productName);
// but there is no databaseDriver found and is returned as UNKNOWN.
// There is no Sybase database configured in DatabaseDriver enum
There is no Sybase datasource configured in DatabaseDriver enum. Can you quickly help to fix this issue ?
Error Stack Trace for reference:
Caused by: java.lang.IllegalStateException: Unable to detect database type
at org.springframework.boot.autoconfigure.AbstractDatabaseInitializer.getDatabaseName(AbstractDatabaseInitializer.java:80)
at org.springframework.boot.autoconfigure.batch.BatchDatabaseInitializer.getDatabaseName(BatchDatabaseInitializer.java:54)
at org.springframework.boot.autoconfigure.AbstractDatabaseInitializer.initialize(AbstractDatabaseInitializer.java:61)
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:498)
at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor$LifecycleElement.invoke(InitDestroyAnnotationBeanPostProcessor.java:366)
at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor$LifecycleMetadata.invokeInitMethods(InitDestroyAnnotationBeanPostProcessor.java:311)
at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor.postProcessBeforeInitialization(InitDestroyAnnotationBeanPostProcessor.java:134)
... 17 common frames omitted
It works for me. Just put this property in application.properties file. I was facing issue with mysql so I passed mysql here if you are using some other database just pass that(for example: schema-sybase.sql)
spring.batch.schema=classpath:org/springframework/batch/core/schema-mysql.sql
It looks like our detection algorithm is broken with MySQL so I've created this issue to double check it.
In the meantime, please specify the path to your initalization script, this will prevent Spring Boot to attempt to auto-detect it.

Exception occurred while the JNDI NamingManager was processing a javax.naming.Reference object

i am trying to connect db2 from my java code in web sphere application server.
i am getting following exception.please suggest any one on this.
Caused by: com.ibm.websphere.naming.CannotInstantiateObjectException: Exception occurred while the JNDI NamingManager was processing a javax.naming.Reference object. [Root exception is javax.xml.stream.FactoryConfigurationError: Provider javax.xml.stream.XMLInputFactory could not be instantiated: java.util.ServiceConfigurationError: javax.xml.stream.XMLInputFactory: Provider com.sun.xml.internal.stream.XMLInputFactoryImpl not a subtype] at com.ibm.ws.naming.util.Helpers.processSerializedObjectForLookupExt(Helpers.java:1232) at com.ibm.ws.naming.util.Helpers.processSerializedObjectForLookup(Helpers.java:925) at com.ibm.ws.naming.jndicos.CNContextImpl.processBoundObjectForLookup(CNContextImpl.java:2877) at com.ibm.ws.naming.jndicos.CNContextImpl.processResolveResults(CNContextImpl.java:3974) at com.ibm.ws.naming.jndicos.CNContextImpl.doLookup(CNContextImpl.java:1876) at com.ibm.ws.naming.jndicos.CNContextImpl.doLookup(CNContextImpl.java:1777) at com.ibm.ws.naming.jndicos.CNContextImpl.lookupExt(CNContextImpl.java:1434) at com.ibm.ws.naming.jndicos.CNContextImpl.lookup(CNContextImpl.java:616) at com.ibm.ws.naming.util.WsnInitCtx.lookup(WsnInitCtx.java:165) at com.ibm.ws.naming.util.WsnInitCtx.lookup(WsnInitCtx.java:179) at org.apache.aries.jndi.DelegateContext.lookup(DelegateContext.java:161) at javax.naming.InitialContext.lookup(InitialContext.java:428) at com.deere.u90.iaf.jdbc.connection.ConnectionManager.initializeEnvironment(ConnectionManager.java:276) ... 38 more Caused by: javax.xml.stream.FactoryConfigurationError: Provider javax.xml.stream.XMLInputFactory could not be instantiated: java.util.ServiceConfigurationError: javax.xml.stream.XMLInputFactory: Provider com.sun.xml.internal.stream.XMLInputFactoryImpl not a subtype at javax.xml.stream.XMLInputFactory.newFactory(Unknown Source) at javax.xml.stream.XMLInputFactory.newInstance(Unknown Source) at com.ibm.websphere.product.metadata.im.IMMetadata.setHistoryEventsFromHistoryXml(IMMetadata.java:745) at com.ibm.websphere.product.metadata.im.IMMetadata.parseHistoryXmlFile(IMMetadata.java:587) at com.ibm.websphere.product.metadata.im.IMMetadata.parseInstallRegistryFiles(IMMetadata.java:399) at com.ibm.websphere.product.metadata.im.IMMetadata.(IMMetadata.java:269) at com.ibm.websphere.product.metadata.im.IMMetadata.getIMMetadataInstance(IMMetadata.java:133) at com.ibm.websphere.product.metadata.WASMetadata.parseMetadataFiles(WASMetadata.java:939) at com.ibm.websphere.product.metadata.WASMetadata.(WASMetadata.java:784) at com.ibm.websphere.product.metadata.WASMetadata.getWASMetadataInstance(WASMetadata.java:215) at com.ibm.websphere.product.WASDirectory.initMetadataInstance(WASDirectory.java:1415) at com.ibm.websphere.product.WASDirectory.getIMLogLocation(WASDirectory.java:435) at com.ibm.websphere.product.VersionInfo.printSource(VersionInfo.java:1534) at com.ibm.websphere.product.VersionInfo.printReport(VersionInfo.java:1322) at com.ibm.websphere.product.VersionInfo.runReport(VersionInfo.java:1064) at com.ibm.websphere.product.VersionInfo.runReport(VersionInfo.java:1025) at com.ibm.ws.rsadapter.spi.ServerFunction$7.run(ServerFunction.java:596) at com.ibm.ws.rsadapter.spi.ServerFunction$7.run(ServerFunction.java:590) at com.ibm.ws.security.util.AccessController.doPrivileged(AccessController.java:118) at com.ibm.ws.rsadapter.spi.ServerFunction.getServerVersion(ServerFunction.java:588) at com.ibm.ws.rsadapter.spi.WSManagedConnectionFactoryImpl.(WSManagedConnectionFactoryImpl.java:748) at java.lang.J9VMInternals.newInstanceImpl(Native Method) at java.lang.Class.newInstance(Class.java:1899) at com.ibm.ejs.j2c.J2CUtilityClass.createMCFEntry(J2CUtilityClass.java:468) at com.ibm.ejs.j2c.ConnectionFactoryBuilderServerImpl.createMCFandPM(ConnectionFactoryBuilderServerImpl.java:592) at com.ibm.ejs.j2c.ConnectionFactoryBuilderServerImpl.processObjectInstance(ConnectionFactoryBuilderServerImpl.java:1185) at com.ibm.ejs.j2c.ServerFunction.processObjectInstance(ServerFunction.java:2009) at com.ibm.ejs.j2c.ConnectionFactoryBuilderImpl.getObjectInstance(ConnectionFactoryBuilderImpl.java:662) at org.apache.aries.jndi.ObjectFactoryHelper.getObjectInstanceUsingObjectFactoryBuilders(ObjectFactoryHelper.java:349) at org.apache.aries.jndi.ObjectFactoryHelper.getObjectInstance(ObjectFactoryHelper.java:89) at org.apache.aries.jndi.OSGiObjectFactoryBuilder.getObjectInstance(OSGiObjectFactoryBuilder.java:62) at javax.naming.spi.NamingManager.getObjectInstance(NamingManager.java:311) at com.ibm.ws.naming.util.Helpers.processSerializedObjectForLookupExt(Helpers.java:1122) ... 50 more
I was facing the same issue and here was my resolution
I had wrongly spelled my jta data source in IBM Admin Console and was using a different name in my persistence xml so Websphere couldn't connect.
Please check the Resources Tab in the Admin Console and validate your jta data source name as declared in persistence xml

Redis Session Serializer mismatch between 3.2 and 4.2

I have a Spring Cloud-based application running on multiple spring-boot servers. All servers share the same Spring Session using #EnableRedisHttpSession.
I now want to integrate a third party widget into my application. Working with the third party, I was able to get initial configuration running, but I'm failing when the third party tries to access the Redis Session data. This is because I am using Spring 4 and the third party uses Spring 3.2. I cannot upgrade the third party's Spring version.
The exception is:
org.springframework.data.redis.serializer.SerializationException: Cannot deserialize; nested exception is
org.springframework.core.serializer.support.SerializationFailedException:
Failed to deserialize payload. Is the byte array a result of corresponding serialization for DefaultDeserializer?; nested exception is
java.io.InvalidClassException: org.springframework.security.core.context.SecurityContextImpl; local class incompatible: stream classdesc serialVersionUID = 400, local class serialVersionUID = 320
Caused by: java.io.InvalidClassException:
org.springframework.security.core.context.SecurityContextImpl; local class incompatible: stream classdesc serialVersionUID = 400, local class serialVersionUID = 320
at java.io.ObjectStreamClass.initNonProxy(ObjectStreamClass.java:616) ~[na:1.8.0_66]
at java.io.ObjectInputStream.readNonProxyDesc(ObjectInputStream.java:1623) ~[na:1.8.0_66]
at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1518) ~[na:1.8.0_66]
at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1774) ~[na:1.8.0_66]
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1351) ~[na:1.8.0_66]
at java.io.ObjectInputStream.readObject(ObjectInputStream.java:371) ~[na:1.8.0_66]
at org.springframework.core.serializer.DefaultDeserializer.deserialize(DefaultDeserializer.java:41) ~[spring-core-4.0.6.RELEASE.jar:4.0.6.RELEASE]
at org.springframework.core.serializer.support.DeserializingConverter.convert(DeserializingConverter.java:59) ~[spring-core-4.0.6.RELEASE.jar:4.0.6.RELEASE]
... 66 common frames omitted
Is there any way to easily translate between the two versions?
Some days ago i have also faced same issue when i was upgrading spring boot version from 2.2.1 to 2.2.6.
This issue was due to serialVersionUID which is present in SecurityContextImpl class. It has been changed between spring versions.
In your case it has been changed to 400 to 320 or vice-versa.
Resolution :
Stop storing session on redis-server via setting property spring.session.store-type=none
Use Jackson serialisation to avoid this type of issues in future version upgrades.
Override implementation of SecurityContextImpl class. No need to do anything only serialVersionUID changes are sufficient.
Adding a great reference for more details: https://github.com/spring-projects/spring-session/issues/1924

Resources