The theoretically impossible has just happened: An IOException while reading to a ByteArrayInputStream.(it just happened)!

302 views
Skip to first unread message

Viggo Navarsete

unread,
Apr 19, 2014, 3:51:08 PM4/19/14
to axonfr...@googlegroups.com
When trying to isolate some issues related to a Saga I'm trying to implement I have remade a simple project to try to isolate why I get the theoretically impossible situation:) Allard, could you help me out on this one? I can share/attach the project to the issue if needed.

Exception in thread "main" org.axonframework.serializer.SerializationException: The theoretically impossible has just happened: An IOException while reading to a ByteArrayInputStream.
at org.axonframework.serializer.JavaSerializer.deserialize(JavaSerializer.java:98)
at org.axonframework.saga.repository.mongo.SagaEntry.getSaga(SagaEntry.java:94)
at org.axonframework.saga.repository.mongo.MongoSagaRepository.load(MongoSagaRepository.java:66)
at org.axonframework.saga.AbstractSagaManager.loadAndInvoke(AbstractSagaManager.java:240)
at org.axonframework.saga.AbstractSagaManager.invokeExistingSagas(AbstractSagaManager.java:135)
at org.axonframework.saga.AbstractSagaManager.handle(AbstractSagaManager.java:106)
at org.axonframework.eventhandling.SimpleCluster.doPublish(SimpleCluster.java:65)
at org.axonframework.eventhandling.AbstractCluster.publish(AbstractCluster.java:77)
at org.axonframework.eventhandling.ClusteringEventBus$SimpleEventBusTerminal.publish(ClusteringEventBus.java:132)
at org.axonframework.eventhandling.ClusteringEventBus.publish(ClusteringEventBus.java:94)
at com.navarsete.stand012.dummy.RunSupplierSaga.main(RunSupplierSaga.java:25)
Caused by: java.io.InvalidClassException: com.navarsete.stand012.dummy.SupplierSaga; local class incompatible: stream classdesc serialVersionUID = 1975893487230154183, local class serialVersionUID = -3893561804673049114
at java.io.ObjectStreamClass.initNonProxy(ObjectStreamClass.java:617)
at java.io.ObjectInputStream.readNonProxyDesc(ObjectInputStream.java:1622)
at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1517)
at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1771)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1350)
at java.io.ObjectInputStream.readObject(ObjectInputStream.java:370)
at org.axonframework.serializer.JavaSerializer.deserialize(JavaSerializer.java:94)
DummyAxon.tar.gz

Viggo Navarsete

unread,
Apr 19, 2014, 5:59:53 PM4/19/14
to axonfr...@googlegroups.com
Hi Allard!

I simply couldn't go to bed without looking more into this. When I removed the saga-repository="mongoSagaRepository" from the defintion of the saga-manager (meaning it will default to the in-memory manager), then I don't get the error mentioned below. Also, without the saga-repository set on the bean, then the CommandGateway IS injected into the saga, otherwise it's not! (meaning ending with NPE in the saga).

I really need a second pair of eyes on this one, since this is far outside my comfort zone :)

Regards,
Viggo

Srđan Šrepfler

unread,
Apr 20, 2014, 8:09:12 AM4/20/14
to axonfr...@googlegroups.com
Perhaps you have two different versions of the SupplierSaga class on your classpath which have a different value for the serialVersionUID field?

Srdan


--
You received this message because you are subscribed to the Google Groups "Axon Framework Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to axonframewor...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Viggo Navarsete

unread,
Apr 20, 2014, 8:40:33 AM4/20/14
to axonfr...@googlegroups.com
Hmm,how would I check it? Seems to only be a problem when I run with a mongo repository also,not with in-memory, but I don't know.

Srđan Šrepfler

unread,
Apr 20, 2014, 1:22:51 PM4/20/14
to axonfr...@googlegroups.com
Perhaps your project setup has two suppliersagaS on the classpath? If your project is within eclipse I'm sure there's a way you can see how many classes on the classpath have that name (Ctrl+Shit+T).

Srdan


On Sun, Apr 20, 2014 at 2:40 PM, Viggo Navarsete <viggo.n...@gmail.com> wrote:
Hmm,how would I check it? Seems to only be a problem when I run with a mongo repository also,not with in-memory, but I don't know.

Allard Buijze

unread,
Apr 20, 2014, 4:21:27 PM4/20/14
to Axon Framework Users
Hi VIggo,

the problem is that you have a serialized version of a class that has been modified since you stored it. This happens when you don't specify a Serializer to use. For backwards compatibility reasons, the default serializer is the JavaSerializer. It uses Java's own serialization mechanism. You probably haven't specified a serialVersionUid in your Saga. If you do (and set it to 1975893487230154183, it's likely to work again. Unless you made a breaking change.
My advice would be to use the XStream serializer. It's more tolerant of class changes.

If you don't specify a repository, and store everything in-memory, it works because it doesn't need to do any serialization.

Cheers,

Allard

Viggo Navarsete

unread,
Apr 25, 2014, 4:51:15 PM4/25/14
to axonfr...@googlegroups.com
Hi Allard!

Tonight I had time to try your suggestion, I added the serialVersionUid and also tried to add the use of XStream serializer, but the code is still not very happy with me:(

Output:
Exception in thread "main" com.thoughtworks.xstream.io.StreamException:  : only whitespace content allowed before start tag and not \ufffd (position: START_DOCUMENT seen \ufffd... @1:1) 
at com.thoughtworks.xstream.io.xml.XppReader.pullNextEvent(XppReader.java:124)
at com.thoughtworks.xstream.io.xml.AbstractPullReader.readRealEvent(AbstractPullReader.java:148)
at com.thoughtworks.xstream.io.xml.AbstractPullReader.readEvent(AbstractPullReader.java:141)
at com.thoughtworks.xstream.io.xml.AbstractPullReader.move(AbstractPullReader.java:118)
at com.thoughtworks.xstream.io.xml.AbstractPullReader.moveDown(AbstractPullReader.java:103)
at com.thoughtworks.xstream.io.xml.XppReader.<init>(XppReader.java:63)
at com.thoughtworks.xstream.io.xml.AbstractXppDriver.createReader(AbstractXppDriver.java:54)
at org.axonframework.serializer.xml.CompactDriver.createReader(CompactDriver.java:48)
at com.thoughtworks.xstream.XStream.fromXML(XStream.java:1012)
at org.axonframework.serializer.xml.XStreamSerializer.doDeserialize(XStreamSerializer.java:142)
at org.axonframework.serializer.AbstractXStreamSerializer.deserialize(AbstractXStreamSerializer.java:225)
at org.axonframework.saga.repository.mongo.SagaEntry.getSaga(SagaEntry.java:94)
at org.axonframework.saga.repository.mongo.MongoSagaRepository.load(MongoSagaRepository.java:66)
at org.axonframework.saga.AbstractSagaManager.loadAndInvoke(AbstractSagaManager.java:240)
at org.axonframework.saga.AbstractSagaManager.invokeExistingSagas(AbstractSagaManager.java:135)
at org.axonframework.saga.AbstractSagaManager.handle(AbstractSagaManager.java:106)
at org.axonframework.eventhandling.SimpleCluster.doPublish(SimpleCluster.java:65)
at org.axonframework.eventhandling.AbstractCluster.publish(AbstractCluster.java:77)
at org.axonframework.eventhandling.ClusteringEventBus$SimpleEventBusTerminal.publish(ClusteringEventBus.java:132)
at org.axonframework.eventhandling.ClusteringEventBus.publish(ClusteringEventBus.java:94)
at com.navarsete.stand012.supplier.RunSupplierSaga.main(RunSupplierSaga.java:30)
Caused by: org.xmlpull.v1.XmlPullParserException: only whitespace content allowed before start tag and not \ufffd (position: START_DOCUMENT seen \ufffd... @1:1) 
at org.xmlpull.mxp1.MXParser.parseProlog(MXParser.java:1519)
at org.xmlpull.mxp1.MXParser.nextImpl(MXParser.java:1395)
at org.xmlpull.mxp1.MXParser.next(MXParser.java:1093)
at com.thoughtworks.xstream.io.xml.XppReader.pullNextEvent(XppReader.java:109)

Here is my spring-context.xml:
       xmlns:cloud="http://schema.cloudfoundry.org/spring"
       xsi:schemaLocation="
 
    <axon:annotation-config />
    
    <context:annotation-config />
 
    <!-- Wholesaler START -->
    <axon:event-sourcing-repository id="purchaseOrderRepository" 
                                    aggregate-type="com.navarsete.stand012.wholesaler.PurchaseOrder"
                                    event-bus="eventBus"
                                    event-store="eventStore"
                                    >
        <!--axon:snapshotter-trigger event-count-threshold="3" snapshotter-ref="snapshotter"/-->
    </axon:event-sourcing-repository>
 
    <axon:aggregate-command-handler id="purchaseOrderCommandHandler"
                                    aggregate-type="com.navarsete.stand012.wholesaler.PurchaseOrder"
                                    repository="purchaseOrderRepository"
                                    command-bus="commandBus"
    />

    <bean class="com.navarsete.stand012.wholesaler.PurchaseOrderEventHandler"/>        
    <!-- Wholesaler END -->
    
    <!-- Transporter START -->
    <axon:event-sourcing-repository id="transportOrderRepository" 
                                    aggregate-type="com.navarsete.stand012.transporter.TransportOrder"
                                    event-bus="eventBus"
                                    event-store="eventStore"
                                    >
        <!--axon:snapshotter-trigger event-count-threshold="3" snapshotter-ref="snapshotter"/-->
    </axon:event-sourcing-repository>
 
    <axon:aggregate-command-handler id="transportOrderCommandHandler"
                                    aggregate-type="com.navarsete.stand012.transporter.TransportOrder"
                                    repository="transportOrderRepository"
                                    command-bus="commandBus"
    />

    <bean class="com.navarsete.stand012.transporter.TransportOrderEventHandler"/> 
    <!-- Transporter END -->
    
    <!-- Supplier START -->
    <axon:event-sourcing-repository id="supplierOrderRepository" 
                                    aggregate-type="com.navarsete.stand012.supplier.SupplierOrder"
                                    event-bus="eventBus"
                                    event-store="eventStore"
                                    >
        <!--axon:snapshotter-trigger event-count-threshold="3" snapshotter-ref="snapshotter"/-->
    </axon:event-sourcing-repository>
    
    <axon:aggregate-command-handler id="supplierOrderCommandHandler"
                                    aggregate-type="com.navarsete.stand012.supplier.SupplierOrder"
                                    repository="supplierOrderRepository"
                                    command-bus="commandBus"
    />
        
    <bean class="com.navarsete.stand012.supplier.SupplierOrderEventHandler"/>    
    
    
    
    <axon:saga-manager id="supplierSagaManager" saga-repository="mongoSagaRepository" event-bus="eventBus" >
        <!--axon:async processor-count="10" executor="myThreadPool"/-->
        <axon:types>                
            com.navarsete.stand012.supplier.SupplierSaga
        </axon:types>
    </axon:saga-manager>    
    <!-- Supplier END -->   
    
    <!-- COMMON START -->    
    <axon:event-bus id="eventBus"/>
    <axon:command-bus id="commandBus"/> <!--SimpleCommandBus, default -->

    <!--axon:disruptor-command-bus id="commandBus" event-bus="eventBus" event-store="eventStore">
        <axon:repositories>
            <axon:repository id="purchaseOrderRepository" aggregate-type="com.navarsete.stand012.wholesaler.PurchaseOrder"/>
            <axon:repository id="transportOrderRepository" aggregate-type="com.navarsete.stand012.transporter.TransportOrder"/>
            <axon:repository id="supplierOrderRepository" aggregate-type="com.navarsete.stand012.supplier.SupplierOrder"/>
        </axon:repositories>
    </axon:disruptor-command-bus-->

    <!--axon:filesystem-event-store id="eventStore" base-dir="events"/-->

    <bean id="eventStore" class="org.axonframework.eventstore.mongo.MongoEventStore">
        <constructor-arg ref="mongoTemplate"/>
    </bean>
 
    <bean id="mongoTemplate" class="com.navarsete.stand012.infra.CFMongoTemplate">
        <constructor-arg ref="mongoDbFactory"/>
    </bean>
 
     
    <bean id="commandGateway" class="org.axonframework.commandhandling.gateway.CommandGatewayFactoryBean">
        <property name="commandBus" ref="commandBus"/>
    </bean>
 
    <bean id="snapshotter" class="org.axonframework.eventsourcing.SpringAggregateSnapshotter">
        <property name="eventStore" ref="eventStore"/>
        <property name="executor" ref="taskExecutor"/>
    </bean>

    <bean id="taskExecutor" class="org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor">
        <property name="corePoolSize" value="2"/>
        <property name="maxPoolSize" value="5"/>
        <property name="waitForTasksToCompleteOnShutdown" value="true"/>
    </bean>    
    
    <!--task:executor id="myThreadPool" pool-size="30" /-->
    
    <bean id="xstreamSagaSerializer" class="org.axonframework.serializer.xml.XStreamSerializer" /> 
    
    <bean id="springResourceInjector" class="org.axonframework.saga.spring.SpringResourceInjector"/>
    
    <bean id="mongoSagaRepository" class="org.axonframework.saga.repository.mongo.MongoSagaRepository">
        <constructor-arg ref="sagaMongoTemplate"/>
        <property name="serializer" ref="xstreamSagaSerializer" /> 
        <property name="resourceInjector" ref="springResourceInjector" /> 
    </bean>
 
    <bean id="sagaMongoTemplate" class="org.axonframework.saga.repository.mongo.DefaultMongoTemplate">
        <constructor-arg ref="mongoDb"/>
    </bean>
    
    <bean id="mongoDb" class="com.mongodb.Mongo" factory-bean="mongoFactoryBean" factory-method="createMongo"
          lazy-init="true"/>
    <bean id="mongoFactoryBean" class="org.axonframework.eventstore.mongo.MongoFactory" lazy-init="true">
        <property name="mongoOptions">
            <bean class="com.mongodb.MongoOptions" factory-bean="mongoOptionsFactory"
                  factory-method="createMongoOptions"/>
        </property>
    </bean>    
    <bean id="mongoOptionsFactory" class="org.axonframework.eventstore.mongo.MongoOptionsFactory">
        <property name="connectionsPerHost" value="100"/>
    </bean>    
    
    <beans profile="default">
        <mongo:db-factory id="mongoDbFactory" dbname="stand012" host="127.0.0.1" port="27017"/>
    </beans>

    <beans profile="cloud">
        <!--cloud:mongo-db-factory id="mongoDbFactory"/-->
    </beans> 
    <!-- COMMON END -->    
</beans>


I might send/add more if you need to look into this!

Regards,
Viggo

Viggo Navarsete

unread,
Apr 25, 2014, 5:30:52 PM4/25/14
to axonfr...@googlegroups.com
I see that the issue I have with the "only whitespace content allowed.." is also discussed (but not concluded) in this thread: https://groups.google.com/forum/#!msg/axonframework/A8l0HSs0yV0/cGAYYVcqfi0J

Viggo Navarsete

unread,
Apr 26, 2014, 4:05:08 PM4/26/14
to axonfr...@googlegroups.com
I've tried to use the MongoSagaRepository with the ToDoSaga in Axon Quickstart, and it works. I then tried to copy the ToDoSaga (and dependent classes) into my project and run it there to see if it was any of my dependencies (i.e more current Spring version..) that made my own Saga fail, but the ToDoSaga still worked. SO, I think this must be related to some issues in my own classes, so I'll try strip down my own project to make it even simpler to see what can cause my issues. I'll let you know if I need any assistance, but since the Axon Quickstart ToDoSaga works, it should be a good example to follow to fix my own:)

Cheers :)


On Friday, April 25, 2014 11:30:52 PM UTC+2, Viggo Navarsete wrote:
I see that the issue I have with the "only whitespace content allowed.." is also discussed (but not concluded) in this thread: https://groups.google.com/forum/#!msg/axonframework/A8l0HSs0yV0/cGAYYVcqfi0J


 to 

Allard Buijze

unread,
Apr 27, 2014, 1:54:15 PM4/27/14
to Axon Framework Users
Hi Viggo,

have you cleaned your DB in between serializer changes? If you're trying to load Java-serialized data back in using UTF-8, you can get \ufffd characters, which are replacement characters. It's used when reading a character not representable in unicode.
This could also have been the issue while you were using the Java serializer. Perhaps there was serialized data of another version of the class in there.

Hope this helps.
Cheers,

Allard

Viggo Navarsete

unread,
May 1, 2014, 2:12:03 PM5/1/14
to axonfr...@googlegroups.com
Hi Allard:)

Seems like all problems vanished as soon as I dropped the database! Thanks a lot :)
Reply all
Reply to author
Forward
0 new messages