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

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

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

Alessandro Vaccarezza

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
[hidden email]
https://lists.jboss.org/mailman/listinfo/infinispan-dev
Reply | Threaded
Open this post in threaded view
|

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

Gustavo Fernandes-2
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)

On Wed, Aug 30, 2017 at 6:16 PM, Alessandro Vaccarezza <[hidden email]> 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
[hidden email]
https://lists.jboss.org/mailman/listinfo/infinispan-dev


_______________________________________________
infinispan-dev mailing list
[hidden email]
https://lists.jboss.org/mailman/listinfo/infinispan-dev
Reply | Threaded
Open this post in threaded view
|

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

Alessandro Vaccarezza

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

 

Regards,

 

Alessandro

 

From: [hidden email] [mailto:[hidden email]] On Behalf Of Gustavo Fernandes
Sent: August 30, 2017 23:35
To: infinispan -Dev List <[hidden email]>
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)

 

On Wed, Aug 30, 2017 at 6:16 PM, Alessandro Vaccarezza <[hidden email]> 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
[hidden email]
https://lists.jboss.org/mailman/listinfo/infinispan-dev

 


_______________________________________________
infinispan-dev mailing list
[hidden email]
https://lists.jboss.org/mailman/listinfo/infinispan-dev