[infinispan-dev] infinispan cache retrieval - byte[]

Alessandro Vaccarezza avaccarezza at c2b2.co.uk
Thu Aug 31 05:19:15 EDT 2017


Hi Gustavo and thank you, your solution is indeed sorting things out.

Regards,

Alessandro

From: infinispan-dev-bounces at lists.jboss.org [mailto:infinispan-dev-bounces at lists.jboss.org] On Behalf Of Gustavo Fernandes
Sent: August 30, 2017 23:35
To: infinispan -Dev List <infinispan-dev at lists.jboss.org>
Subject: Re: [infinispan-dev] infinispan cache retrieval - byte[]

Hi Alessandro, this kind of question is better suited for the forums [1], since this list if for development related discussions.

But since we're here, regarding your question:

What's probably happening is that since you are creating a cache inside the servlet from the cache manager that is also used by the Infinispan server,
this cache is internally being created with an encoding scheme suitable to used for remote clients, meaning storage will be POJO but reads/writes will
be done using byte[].

In Infinispan 9.1.0 you can choose the encoding to read and write from a particular cache: so in your case, from you servlet, you can specify that you don't want
any encoding by wrapping your cache with:

Cache c = cache.getAdvancedCache().withEncoding(IdentityEncoder.class)

[1] http://infinispan.org/community/

On Wed, Aug 30, 2017 at 6:16 PM, Alessandro Vaccarezza <avaccarezza at c2b2.co.uk<mailto:avaccarezza at c2b2.co.uk>> wrote:
Hi guys,

we ar facing an issue since quite a long time and can't come up with a solution.

Our simple application is deployed on a wildfly instance and make use of a local infinispan data store (infinispan-9.1.0.Final).

Wildfly resides on a CentOS 6.8 instance, Java version is 1.8.0_112.

We implemented a very basic servlet and registered as a listener. Within this servlet we use an org.infinispan.manager.EmbeddedCacheManager to retrieve an
existing cache and add values to it.

Compatibility mode is on.

The values added to the cache are instance of a simple Java POJO.

When we try to retrieve what we just added, within the same servlet, we get a byte array, no way to retrieve the original POJO.
When we force the cast we get the obvious:

java.lang.ClassCastException: [B cannot be cast to com.my.pojo.SamplePOJO

Servlet: https://gist.github.com/anonymous/e8752cc8457301c2c70b3255e5c3bbc5
POJO: https://gist.github.com/anonymous/f35900875500a4bd6b4bb3b0cf73a363
Infinispan config file: https://gist.github.com/anonymous/b8482595f6b86ecc5642cceb6a99ad5e

Retrieving the cache via Hot Rod client works fine; also, if compatibility mode is turned off everything works fine as well.

_______________________________________________
infinispan-dev mailing list
infinispan-dev at lists.jboss.org<mailto:infinispan-dev at lists.jboss.org>
https://lists.jboss.org/mailman/listinfo/infinispan-dev

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/infinispan-dev/attachments/20170831/2b8332f9/attachment.html 


More information about the infinispan-dev mailing list