2015-06-24 70 views
0

我有一個虛擬測試流程,其中我正在實例化一個POJO Person,它沒有實現Serializable。在執行時,我面臨着多重錯誤,而且我的緩存策略似乎不起作用。當我更改Person以實施Serializable時,它的工作原理沒有發生錯誤。在我的應用程序中有一些我不能改變的類。請建議一種解決方法。騾子版本3.5.2緩存塊不工作 - java.io.serializable錯誤

<?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 
+0

即將推出的版本3.7.0支持的ObjectStore的可插拔'serializer':https://github.com/mulesoft/mule/blob /mule-3.7.0-RC2/core/src/main/java/org/mule/util/store/PersistentObjectStorePartition.java#L54這將允許使用不需要實現'Serializable'的序列化程序,就像Kryo一樣。 –

回答

0

作爲一種變通方法,直到3.7版已經出來了,你可以嘗試以下解決方法:

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

這個想法是序列化t o在緩存它之前,將整個Mule消息(包含的屬性)XML化,並在從緩存中獲取它時從XML反序列化它。

參考文獻:

+0

每次我仍然在緩存內部着陸並獲取相同的錯誤消息。 – user3483129

+0

然後在這種情況下,請轉到MuleSoft專業支持:'ee:cache'是企業版功能,我無法訪問源代碼,因此無法解決問題。抱歉。 –