1

I have a custom Spring XD source module that uses Spring Social for Twitter and outputs Tweet objects. This is working just fine. I can log the output of the source and see the Tweet objects listed. I can change the output type of the source for that stream to application/json to see the output at JSON. This works as expected.

I then created a processor module that will create a new object from that Tweet and output it. The transform message expects a GenericMessage containing a Tweet object as its payload (I've also tried having the method argument be just the Tweet, but that also didnt work).

@Transformer
public OtherThing<Tweet> transform(GenericMessage<Tweet> message) {
    // ... snip ...
}

However, when i link the two modules together

stream create --name test --definition 'my-tweet-source-module | my-tweet-processor | log' --deploy

and a Tweet is output from the source module, i get a class cast exception:

java.lang.ClassCastException: org.springframework.social.twitter.api.Tweet cannot be cast to org.springframework.social.twitter.api.Tweet

I've verified that both modules are using the same version of Spring Social Twitter so there should be no problem there. Currently, the modules are communicating over local transport, so this shouldn't be any class loading problem either (they will eventually need to communicate over non-local transport).

I've tried workarounds as well such as defining in the stream that the output type for the source module should be application/json and then try to read the JSON from the input string payload but due to the nature of the Spring Social Tweet object, Jackson doesnt comply.

I'm wondering why this is happening and how i should resolve this? I feel that i'm undoubtedly doing something wrong. If i'm not allowed to do this, i'd like to know why that is and what the appropriate thing to do is.

Any help would be appreciated.

Thank you

EDIT: I'm using Spring XD 1.2.1.RELEASE

loesak
  • 1,413
  • 2
  • 19
  • 33

1 Answers1

4

See ClassCastException when casting to the same class . This is almost certainly a class loader issue. Try removing spring-social from the modules' class path and add it to xd/lib so it's loaded by the same class loader.

Community
  • 1
  • 1
dturanski
  • 1,723
  • 1
  • 13
  • 8
  • I was actually trying this the other day but was getting an error about the jar being compressed. I extracted the contents and recreated the jar as uncompressed based on what the internet said to do and was still giving me the compression error. Will try again and see. – loesak Sep 13 '15 at 19:13
  • so ultimately i think you are correct. I was able to get rid of the error by unjaring, rejaring w/ zero compression, and placing into libs directory. however, i received other errors because that jar's dependencies were not in the xd/lib directory. For me to track down each needed jar, unjar, then rejar uncompressed, just to get java serialization to work, is just not practical. I'm going to go forward with serialization with jackson/boon or kryo. Thank you for your answer as i was really stuck. – loesak Sep 15 '15 at 23:34