缓存块不起作用 - java.io.serializable错误

时间:2015-06-24 00:17:42

标签: caching mule mule-studio mule-component

我有一个虚拟测试流程,我正在实例化一个没有实现Person的POJO Serializable。在执行时,我面临着多个错误,而且我的缓存策略似乎不起作用。当我更改Person以实现Serializable时,它可以正常工作而不会抛出错误。在我的应用程序中,有一些我无法改变的类。请建议一个解决方法。骡子版本3.5.2

<?xml version="1.0" encoding="UTF-8"?>
<mule version="EE-3.5.2" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation" xmlns:ee="http://www.mulesoft.org/schema/mule/ee/core" xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns:https="http://www.mulesoft.org/schema/mule/https" xmlns:spring="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.mulesoft.org/schema/mule/https           http://www.mulesoft.org/schema/mule/https/current/mule-https.xsd         http://www.springframework.org/schema/beans           http://www.springframework.org/schema/beans/spring-beans-current.xsd         http://www.mulesoft.org/schema/mule/core           http://www.mulesoft.org/schema/mule/core/current/mule.xsd         http://www.mulesoft.org/schema/mule/ee/core          http://www.mulesoft.org/schema/mule/ee/core/current/mule-ee.xsd         http://www.mulesoft.org/schema/mule/http             http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd">
    <https:connector clientSoTimeout="${http.connector.client.socket.timeout}" connectionTimeout="${http.connector.connection.timeout}" cookieSpec="rfc2109" doc:name="HttpsClientConnector" name="HttpsClientConnector" receiveBacklog="0" receiveBufferSize="${http.connector.receiveBufferSize}" sendBufferSize="${http.connector.sendBufferSize}" serverSoTimeout="10000" socketSoLinger="0" validateConnections="true">
        <dispatcher-threading-profile maxBufferSize="1" maxThreadsActive="200" maxThreadsIdle="150"/>
        <https:tls-server path="/Users/sakhandwala/Desktop/mule/cacerts" storePassword="changeit"/>
    </https:connector>
    <!--  get eventId caching strategy  -->
    <ee:object-store-caching-strategy doc:name="Autobulk EventID Caching Strategy" keyGenerationExpression="#[flowVars['kkr']]" name="EventIDCaching100Strategy">
        <managed-store entryTTL="${xyz.eventid.cache.entry.timetolive}" expirationInterval="${xyz.eventid.cache.expiration.interval}" maxEntries="${xyz.eventid.cache.max.entries}" persistent="true" storeName="${xyz.eventid.cache.store.name}"/>
    </ee:object-store-caching-strategy>
    <flow doc:name="tutorial6.2Flow1" name="tutorial6.2Flow1">
        <http:inbound-endpoint address="http://localhost:8081/earth" doc:name="HTTP" name="clientEndpoint"/>
        <set-variable doc:name="Variable" value="Tuesday" variableName="kkr"/>
        <set-variable doc:name="Variable" value="#[null]" variableName="test"/>
        <expression-component doc:name="Expression">flowVars['test']= new kk.Person();</expression-component>
        <ee:cache cachingStrategy-ref="EventIDCaching100Strategy" doc:name="Cache">
            <https:outbound-endpoint address="https://api-dev.slcd010.com/search/catalog/events/ship/v3/?locale=en_US&amp;venueName=SAP Center&amp;eventDateLocal=2015-11-11T19:30" connector-ref="HttpsClientConnector" contentType="application/json" doc:name="Invoke Search Events API" exchange-pattern="request-response" method="GET">
                <message-properties-transformer scope="outbound">
                    <add-message-property key="Authorization" value="Bearer dd393c7e990432b3249eaa8c5db6c"/>
                    <add-message-property key="Content-Type" value="application/json"/>
                    <add-message-property key="TARGET_HOST" value="slcq015"/>
                </message-properties-transformer>
            </https:outbound-endpoint>
            <echo-component doc:name="Echo"/>
        </ee:cache>
        <logger doc:name="Logger" level="INFO" message="over here"/>
    </flow>
</mule>

Java类 -

package kk;
public class Person{

    String name;
    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }
}

错误 -

        org.mule.api.store.ObjectStoreException: java.io.NotSerializableException: kk.Person (org.apache.commons.lang.SerializationException)
        at org.mule.util.store.PersistentObjectStorePartition.serialize(PersistentObjectStorePartition.java:356)
        at org.mule.util.store.PersistentObjectStorePartition.store(PersistentObjectStorePartition.java:127)
        at org.mule.util.store.PartitionedPersistentObjectStore.store(PartitionedPersistentObjectStore.java:111)
        at org.mule.util.store.ObjectStorePartition.store(ObjectStorePartition.java:37)
        at org.mule.util.store.ManagedObjectStore.store(ManagedObjectStore.java:89)
        Caused by: org.apache.commons.lang.SerializationException: java.io.NotSerializableException: kk.Person
        at org.apache.commons.lang.SerializationUtils.serialize(SerializationUtils.java:111)
        at org.mule.util.store.PersistentObjectStorePartition.serialize(PersistentObjectStorePartition.java:352)
        ... 103 more
    Caused by: java.io.NotSerializableException: kk.Person
        at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1165)
        at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:329)
        at org.apache.commons.collections.map.AbstractHashedMap.doWriteObject(AbstractHashedMap.java:1182)
        at org.mule.util.CaseInsensitiveHashMap.writeObject(CaseInsensitiveHashMap.java:142)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at java.io.ObjectStreamClass.invokeWriteObject(ObjectStreamClass.java:950)
        at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1482)
        at java.io.ObjectOutputStre

1 个答案:

答案 0 :(得分:0)

作为3.7版本之前的解决方法,您可以尝试以下解决方法:

...
<xml:object-to-xml-transformer acceptMuleMessage="true"/>
<ee:cache doc:name="Cache" cachingStrategy-ref="EventIDCaching100Strategy">
    <xml:xml-to-object-transformer />
    ...

我们的想法是在缓存之前将整个Mule消息(包括属性)序列化为XML,并在从缓存中获取时将其从XML反序列化。

参考文献: