I'm trying to serialize a Java Object from a Java client application toward a JIRA plugin (servlet) and in the reverse direction too.
Whereas the serialization works from the client to the server, it looks like corrupted when serialized from the plugin toward the client application:
invalid stream header: 3F3F0005
This is the code at the servlet:
OutputStream os = httpServletResponse.getOutputStream(); oos = new ObjectOutputStream(os); oos.writeObject("World!"); oos.flush(); httpServletResponse.flushBuffer();
And this is the code at the client:
// ... This works ... oos = new ObjectOutputStream(conn.getOutputStream()); oos.writeObject("Hello"); oos.flush(); // Connect ... conn.connect(); // This does NOT work ois = new ObjectInputStream(conn.getInputStream()); Object result = ois.readObject();
The "Hello" object sent from the client is properly read from the plugin, whereas the "World" object sent by the plugin is not read by the client app.
Note: conn is an HttpClient (3.x) connection object. The example code works fine when used in an standard web app on Tomcat rather on a JIRA plugin.
The error occurs just in the line below:
ois = new ObjectInputStream(conn.getInputStream());
which verifies some special headers at the beginning. As I saw some Atlassian's Java classes wrapping the servlet output, I wonder whether that code might impact on this.
More than likely it's the osgi container that's causing your headaches. Whenever you need to do stuff with class loading in p2 - you're asking for a lot of pain (personal experience here ). Don't know if this helps or not:
I would probably suggest stepping back and see if you can't get away from the serialization/deserialization and maybe using json or other language neutral transport mechanism. It will be more code to write, but I suspect you'll not be banging your head against a wall as much.
@Danie, thanks for the answer. Unfortunately, due the nature of the project, any alternative serialization is not an option :(. I would say the OSGi environment is not a problem (yet) because the serialized objects were Java's basic types (java.lang.String) which are available in any JVM and therefore no problem with packages visibility. I found this post: http://stackoverflow.com/questions/21635198/objectinputstream-invalid-stream-header-00000000 pointing to an outputstream related issue (just the same raised error: "invalid stream header"). While debugging, I saw some Atlassian's wrapper classes for the plugin servlet outputstream channel furthermore some sanitize tasks removing '/r' and '/n' characters. Perhaps (this is my guess) the Atlassian's Plugin Framework makes some http header manipulation, i.e: by adding some custom or "inoffensive" header in any servlet response. This would cause the "invalid stream header" error as the ObjectInputStream would read the Atlassian's injected header rather than the expected one.
Hello! My name is Genevieve Blanch, and I'm the Marketing Manager at RefinedWiki, creators of apps to give teams the tools to customize Atlassian platforms. Currently, 44% of the tech team at Re...
Connect with like-minded Atlassian users at free events near you!Find a group
Connect with like-minded Atlassian users at free events near you!
Unfortunately there are no AUG chapters near you at the moment.Start an AUG
You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs