Serializing/Deserializing Objects..Urgent !!!

Hello Everyone,
Out of the blue I got an exception like
java.io.StreamCorruptedException: invalid stream header
     at java.io.ObjectInputStream.readStreamHeader(Unknown Source)
     at java.io.ObjectInputStream.<init>(Unknown Source)
I am implementing "Applet to Servlet communication".
Actually i am trying to deserialize the object which was passed to the servlet.But when i read it back i am geting the above exception.
Can anyone throw some light on it?
Her is my code
APPLET CODE:
private void interactWithServlet() {
WBObject result = null;
try {
// Create an object we can use to communicate with the servlet
URL servletURL = new URL(sURL);
URLConnection servletConnection = servletURL.openConnection();
servletConnection.setDoOutput(true);
servletConnection.setUseCaches(false);
servletConnection.setRequestProperty("Content-Type", "application/octet-stream;charset=utf-8");
ObjectOutputStream request = new ObjectOutputStream(
new BufferedOutputStream(servletConnection.getOutputStream()));
WBObject wbObj=m_whiteBoardComponent.getDesignPanel().getWBObject();
int size=wbObj.getChildren().size();
for(int i=0;i<size;i++){
PickObject pick=(PickObject)wbObj.getChildren().get(i);
System.out.println("the pick object name is"+pick.getName());
int count=pick.getChildren().size();
for(int j=0;j<count;j++){
ItemObject item=(ItemObject)pick.getChildren().get(j);
System.out.println("the item object name is"+item.getName());
request.writeObject(wbObj);
request.flush();
request.close();
ObjectInputStream response = new ObjectInputStream(
new BufferedInputStream(servletConnection.getInputStream()));
result = (WBObject)response.readObject();
System.out.println("The object is"+(result instanceof WBObject));
response.close();
} catch (Exception e) {
e.printStackTrace();
SERVLET CODE:
public void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException,
IOException {
WBObject o = null;
ObjectInputStream inputStream = new ObjectInputStream(
new BufferedInputStream(req.getInputStream()));
try {
o = (WBObject)inputStream.readObject();
inputStream.close();
} catch( ClassNotFoundException ex ) {
ex.printStackTrace();
// send response
resp.setStatus(HttpServletResponse.SC_OK);
resp.setContentType("application/octet-stream;charset=utf-8");
ObjectOutputStream oos = new ObjectOutputStream(
new BufferedOutputStream(resp.getOutputStream()));
oos.writeObject(o);
oos.close();
Best Regards
Ashish

client
URLConnection servletConnection = servletURL.openConnection();try
HttpURLConnection servletConnection = (HttpURLConnection)servletURL.openConnection();server
// send response
resp.setStatus(HttpServletResponse.SC_OK);
resp.setContentType("application/octet-stream;charset=utf-8");
ObjectOutputStream oos = new ObjectOutputStream(
new BufferedOutputStream(resp.getOutputStream()));
oos.writeObject(o);
oos.close();try
// send response
//resp.setStatus(HttpServletResponse.SC_OK);
//resp.setContentType("application/octet-stream;charset=utf-8");
ObjectOutputStream oos = new ObjectOutputStream(
new BufferedOutputStream(resp.getOutputStream()));
oos.writeObject(o);
oos.flush();
oos.close();

Similar Messages

  • Serializing & Deserializing objects through ObjectMessage

    Hi,
    I'm having trouble sending objects/instances of a class (Data) through the message queue. I also made Data to be serializable.
    public class Data implements Serializable {
    }The following are snippets of code from the Message producer side:
    objectMessage = mySess.createObjectMessage();
    MessageProducer myMsgProducer = mySess.createProducer(myQueue);
    Data e = new Data();
    objectMessage.setObject(e);
    myMsgProducer.send(objectMessage);And the following are snippets of code from the message consumer:
    public void onMessage(Message message) {
                 if(message instanceof ObjectMessage ){
             try{
                  ObjectMessage objMsg = (ObjectMessage) message;
                  Data myData = (Data)objMsg.getObject();
             catch(JMSException e){
                  System.out.println("Exception occured: " + e.toString());
    }The result of attempting to cast the objMsg to a Data is an exception thrown.
    i did noticed however, that when I was debugging the message consumer, that the byteArrayInputStream values for both message and objMsg are null meaning that the data is not being sent or received. Any help would be greatly appreciated, thanks!
    Edited by: 883631 on Sep 13, 2011 4:09 PM
    Edited by: EJP on 14/09/2011 09:22: added {noformat}{noformat} tags. Please use them.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

    Sorry, the exception thrown is:
    Exception occured: com.sun.messaging.jms.MessageFormatException: [C4015]: Deserialize message failed. - cause: java.lang.ClassNotFoundException: MsgSender.Data
    Sep 14, 2011 8:53:50 AM com.sun.messaging.jmq.jmsclient.ExceptionHandler logCaughtException
    WARNING: [I500]: Caught JVM Exception: java.lang.ClassNotFoundException: MsgSender.Data
    where MsgSender is the name of the project that produces the messages to the queue.
    Data is the class that is both on the sender and receiver side, and the exception is thrown as a result of casting the object message back into a type Data.
    Data myData = (Data)objMsg.getObject();
    I hope this isn't too confusing. What I'm wondering is if there are extra steps to serializing your object or if the ObjectMessage's setObject method automatically does that for you so as long as you declare your class to implement Serializable. And if that's the case, how do you deserialize it back to the original object?
    Thank you

  • [java.nio] StreamCorruptedException when deserializing objects

    Hello everybody!
    I made a messaging (chat) program using java.io where all the client-server communication is done by serializing small objects. Now I would like to covert the server side to the NIO concept and I'm already struck. I successfully pass objects to the client and the client deserializes them, but only the first one! When it try to read the second it fails with a StreamCorruptedException.
    Here�s a sample (testing) code. In the server run() method I first serialize a string, then get its byte array from ByteArrayOutputStream and in the loop periodically send this byte array through the channel. On the client side I just read the deserialized object.
    Server run():
    public void run() {
            try {
                ByteArrayOutputStream baos = new ByteArrayOutputStream();
                ObjectOutputStream oos = new ObjectOutputStream(baos);
                oos.writeObject("abcdefgh");
                byte[] objectArr = baos.toByteArray();
                baos.close();
                oos.close();
                ByteBuffer buff = ByteBuffer.allocate(objectArr.length);
                buff.put(objectArr);
                buff.flip();
                while(true) {
                    selector.select();
                    Set keys = selector.selectedKeys();
                    for (Object o : keys) {
                        SelectionKey key = (SelectionKey)o;
                        if (key.isAcceptable()) {
                            ServerSocketChannel server = (ServerSocketChannel) key.channel();
                            clientChannel = server.accept();
                            if (clientChannel == null)
                                continue;
                            clientChannel.configureBlocking(false);
                            SelectionKey clientKey = clientChannel.register(selector, SelectionKey.OP_WRITE);
                        } else if (key.isWritable()) {
                            SocketChannel client = (SocketChannel) key.channel();
                            if (buff.hasRemaining()) {
                                client.write(buff);
                            } else {
                                buff.clear();
                                buff.put(objectArr);
                                buff.flip();
                    try {
                        Thread.currentThread().sleep(2000);
                    } catch (InterruptedException e) {
                        return;
            } catch (IOException e) {
                e.printStackTrace();
        }Client run():
    public void run() {
            try {
                soc = new Socket("localhost", 4000);
                ObjectInputStream ois = new ObjectInputStream(soc.getInputStream());
                while(true) {
                    Object d = ois.readObject();
                    System.out.println("data = " + d.toString());
            } catch (Exception ex) {
                ex.printStackTrace();
        }At the second read I get a StreamCorruptedException.
    Apart from this I would like some hints in how to implement the application with NIO. For example how can I tell the objects apart on the client side � should I send every time a byte array before the object, which tells the length of the next coming object? This is probably not a 100% bulletproof solution and presents additional data transfer?
    Than you in advance!

    OK, I found a solution but I don't like it, because I don't understand it.
    The ObjectOutputStream adds a header (4 bytes) to the stream - if I send the array with those four bytes I get an StreamCorruptedException. If I send the array without the header I also get a StreamCorruptedException: "invalid stream header".
    If I reconstruct the object, by calling ObjectOutputStream.writeObject() and get it's byte array from ByteArrayOutputStream.toByteArray(), every time I have to fill the ByteBuffer, then it works.
    Here's the modified sending block, for the above example:
    } else if (key.isWritable()) {
                            SocketChannel client = (SocketChannel) key.channel();
                            if (buff.hasRemaining()) {
                                client.write(buff);
                            } else {
                                //* ---- added code ---------
                                baos.reset();
                                oos.writeObject("abcdefgh");
                                objectArr = baos.toByteArray();
                                buff.clear();
                                buff.put(objectArr);
                                buff.flip();
                        }   I really don't understand why I have to write the object in the object stream every time. I used ObjectOS and ByteArrayOS, to get the object byte array and then I thought I could forget about those streams and use this array to fill the ByteBuffer. What changes if I send the object through this process with every iteration (and how this harms speed - it's like sending everything twice)? If someone would explain this to me I would appreciate it much.

  • Problems deserializing objects with Microsoft VM

    I am getting a 30 second delay when deserializing objects: using Java 1.1.8 ObjectOutputStream.defaultReadObject() causes a 30 second delay. This only happens on Internet Explorer using the Microsoft Virtual Machine.Any ideas what's causing this delay?

    HERE'S THE CODE ..
    URLConnection con = servlet.openConnection();
    con.setDoInput(true);
    con.setDoOutput(true);
    con.setUseCaches(false);
    con.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
    ObjectOutputStream out = new ObjectOutputStream(SecurityToolkit.openOutputStream(con));
    int numObjects = objs.length;
    for (int x = 0; x < numObjects; x++) {
    out.writeObject(objs[x]);
    out.flush();
    out.close();
    InputStream inStream = SecurityToolkit.openInputStream(con);
    ObjectInputStream in = new ObjectInputStream(inStream);
    return in;
    So .. this is the ObjectInputStream returned and objects are read off this stream. But reading hangs for 30 seconds and then starts reading again.

  • JMS getObject() Error deserializing object for client

    I am using WL6.1 and having a problem deserializing an object for a
              client that doesn't have access to the corresponding implementation
              object in its CLASSPATH (it only deals with the interface). From
              previous posts, I read that upgrading to SP3 would fix this issue, but
              I am still having this problem on both Solaris and Windows using SP3.
              If I modify the client CLASSPATH to include the Server-side JAR file
              that contains the implementation class, I don't have the problem and I
              can successfully perform getObject() and deserialize the object. The
              following is the code for the client:
              public void onMessage(Message msg)
              String msgText;
              if(msg instanceof ObjectMessage)
              try
              ObjectMessage objMsg = (ObjectMessage) msg;
              ActivityCreationEvent msgEvent =
              (ActivityCreationEvent) objMsg.getObject();
              System.out.println("Got a creation event");
              catch(Exception ex)
              System.out.println("Error getting JMS message:" + ex);
              ex.printStackTrace();
              the following is the code for the server:
              objMsg = tSess.createObjectMessage(null);
              ActivityCreationEvent createEvent=new ActivityCreationEventImpl();
              objMsg.setObject(createEvent);
              tPublisher.publish(objMsg);
              and the following is the client stack trace:
              Error getting JMS message:weblogic.jms.common.JMSException: Error
              deserializing object
              weblogic.jms.common.JMSException: Error deserializing object
              at weblogic.jms.common.ObjectMessageImpl.getObject(ObjectMessageImpl.java:141)
              at com.test.producer.tck.CreateProducerByValue.onMessage(CreateProducerByValue.java:566)
              at weblogic.jms.client.JMSSession.onMessage(JMSSession.java:1865)
              at weblogic.jms.client.JMSSession.execute(JMSSession.java:1819)
              at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:139)
              at weblogic.kernel.Kernel.execute(Kernel.java:257)
              at weblogic.kernel.Kernel.execute(Kernel.java:269)
              ----------- Linked Exception -----------
              at weblogic.jms.client.JMSSession.pushMessage(JMSSession.java:1733)
              at weblogic.jms.client.JMSSession.invoke(JMSSession.java:2075)
              at weblogic.jms.dispatcher.Request.wrappedFiniteStateMachine(Request.java:510)
              at weblogic.jms.dispatcher.DispatcherImpl.dispatchAsync(DispatcherImpl.java:149)
              at weblogic.jms.dispatcher.DispatcherImpl.dispatchOneWay(DispatcherImpl.java:429)
              at weblogic.jms.dispatcher.DispatcherImpl_WLSkel.invoke(Unknown
              Source)
              at weblogic.rmi.internal.BasicServerRef.invoke(BasicServerRef.java:305)
              at weblogic.rmi.internal.BasicServerRef.handleRequest(BasicServerRef.java:274)
              at weblogic.rmi.internal.BasicExecuteRequest.execute(BasicExecuteRequest.java:22)
              at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:139)
              at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:120)
              java.lang.ClassNotFoundException:
              com.test.activity.ri.ActivityCreationEventImpl
              at java.net.URLClassLoader$1.run(URLClassLoader.java:195)
              at java.security.AccessController.doPrivileged(Native Method)
              at java.net.URLClassLoader.findClass(URLClassLoader.java:183)
              at java.lang.ClassLoader.loadClass(ClassLoader.java:294)
              at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:281)
              at java.lang.ClassLoader.loadClass(ClassLoader.java:250)
              at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:310)
              at java.lang.Class.forName0(Native Method)
              at java.lang.Class.forName(Class.java:190)
              at weblogic.jms.common.ObjectMessageImpl$ObjectInputStream2.resolveClass(ObjectMessageImpl.java:277)
              at java.io.ObjectInputStream.inputClassDescriptor(ObjectInputStream.java:913)
              at java.io.ObjectInputStream.readObject(ObjectInputStream.java:361)
              at java.io.ObjectInputStream.readObject(ObjectInputStream.java:231)
              at java.io.ObjectInputStream.inputObject(ObjectInputStream.java:1181)
              at java.io.ObjectInputStream.readObject(ObjectInputStream.java:381)
              at java.io.ObjectInputStream.readObject(ObjectInputStream.java:231)
              at weblogic.jms.common.ObjectMessageImpl.getObject(ObjectMessageImpl.java:127)
              at com.test.producer.tck.CreateProducerByValue.onMessage(CreateProducerByValue.java:566)
              at weblogic.jms.client.JMSSession.onMessage(JMSSession.java:1865)
              at weblogic.jms.client.JMSSession.execute(JMSSession.java:1819)
              at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:139)
              at weblogic.kernel.Kernel.execute(Kernel.java:257)
              at weblogic.kernel.Kernel.execute(Kernel.java:269)
              at weblogic.jms.client.JMSSession.pushMessage(JMSSession.java:1733)
              at weblogic.jms.client.JMSSession.invoke(JMSSession.java:2075)
              at weblogic.jms.dispatcher.Request.wrappedFiniteStateMachine(Request.java:510)
              at weblogic.jms.dispatcher.DispatcherImpl.dispatchAsync(DispatcherImpl.java:149)
              at weblogic.jms.dispatcher.DispatcherImpl.dispatchOneWay(DispatcherImpl.java:429)
              at weblogic.jms.dispatcher.DispatcherImpl_WLSkel.invoke(Unknown
              Source)
              at weblogic.rmi.internal.BasicServerRef.invoke(BasicServerRef.java:305)
              at weblogic.rmi.internal.BasicServerRef.handleRequest(BasicServerRef.java:274)
              at weblogic.rmi.internal.BasicExecuteRequest.execute(BasicExecuteRequest.java:22)
              at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:139)
              at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:120)
              The client doesn't need to have access to the implementation class for
              any other aspect of the code, and I would like to keep it that way.
              Does anyone have information as to the cause of the problem and a
              solution?
              Thanks in advance
              

    Hi James,
              Just having the interface is not sufficient, as the JVM must be able to
              find the implementation class of an object in order to unserialize it - this is not a WebLogic
              thing, it is a java thing. Either package the required class in the .ear that contains
              the MDB or put it in your classpath.
              Tom
              James J wrote:
              > I am using WL6.1 and having a problem deserializing an object for a
              > client that doesn't have access to the corresponding implementation
              > object in its CLASSPATH (it only deals with the interface). From
              > previous posts, I read that upgrading to SP3 would fix this issue, but
              > I am still having this problem on both Solaris and Windows using SP3.
              > If I modify the client CLASSPATH to include the Server-side JAR file
              > that contains the implementation class, I don't have the problem and I
              > can successfully perform getObject() and deserialize the object. The
              > following is the code for the client:
              >
              > public void onMessage(Message msg)
              > {
              > String msgText;
              >
              > if(msg instanceof ObjectMessage)
              > {
              > try
              > {
              > ObjectMessage objMsg = (ObjectMessage) msg;
              > ActivityCreationEvent msgEvent =
              > (ActivityCreationEvent) objMsg.getObject();
              > System.out.println("Got a creation event");
              > }
              > catch(Exception ex)
              > {
              > System.out.println("Error getting JMS message:" + ex);
              > ex.printStackTrace();
              > }
              > }
              > }
              >
              > the following is the code for the server:
              >
              > objMsg = tSess.createObjectMessage(null);
              > ActivityCreationEvent createEvent=new ActivityCreationEventImpl();
              > objMsg.setObject(createEvent);
              > tPublisher.publish(objMsg);
              >
              > and the following is the client stack trace:
              >
              > Error getting JMS message:weblogic.jms.common.JMSException: Error
              > deserializing object
              > weblogic.jms.common.JMSException: Error deserializing object
              > at weblogic.jms.common.ObjectMessageImpl.getObject(ObjectMessageImpl.java:141)
              > at com.test.producer.tck.CreateProducerByValue.onMessage(CreateProducerByValue.java:566)
              > at weblogic.jms.client.JMSSession.onMessage(JMSSession.java:1865)
              > at weblogic.jms.client.JMSSession.execute(JMSSession.java:1819)
              > at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:139)
              > at weblogic.kernel.Kernel.execute(Kernel.java:257)
              > at weblogic.kernel.Kernel.execute(Kernel.java:269)
              > ----------- Linked Exception -----------
              > at weblogic.jms.client.JMSSession.pushMessage(JMSSession.java:1733)
              > at weblogic.jms.client.JMSSession.invoke(JMSSession.java:2075)
              > at weblogic.jms.dispatcher.Request.wrappedFiniteStateMachine(Request.java:510)
              > at weblogic.jms.dispatcher.DispatcherImpl.dispatchAsync(DispatcherImpl.java:149)
              > at weblogic.jms.dispatcher.DispatcherImpl.dispatchOneWay(DispatcherImpl.java:429)
              > at weblogic.jms.dispatcher.DispatcherImpl_WLSkel.invoke(Unknown
              > Source)
              > at weblogic.rmi.internal.BasicServerRef.invoke(BasicServerRef.java:305)
              > at weblogic.rmi.internal.BasicServerRef.handleRequest(BasicServerRef.java:274)
              > at weblogic.rmi.internal.BasicExecuteRequest.execute(BasicExecuteRequest.java:22)
              > at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:139)
              > at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:120)
              > java.lang.ClassNotFoundException:
              > com.test.activity.ri.ActivityCreationEventImpl
              > at java.net.URLClassLoader$1.run(URLClassLoader.java:195)
              > at java.security.AccessController.doPrivileged(Native Method)
              > at java.net.URLClassLoader.findClass(URLClassLoader.java:183)
              > at java.lang.ClassLoader.loadClass(ClassLoader.java:294)
              > at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:281)
              > at java.lang.ClassLoader.loadClass(ClassLoader.java:250)
              > at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:310)
              > at java.lang.Class.forName0(Native Method)
              > at java.lang.Class.forName(Class.java:190)
              > at weblogic.jms.common.ObjectMessageImpl$ObjectInputStream2.resolveClass(ObjectMessageImpl.java:277)
              > at java.io.ObjectInputStream.inputClassDescriptor(ObjectInputStream.java:913)
              > at java.io.ObjectInputStream.readObject(ObjectInputStream.java:361)
              > at java.io.ObjectInputStream.readObject(ObjectInputStream.java:231)
              > at java.io.ObjectInputStream.inputObject(ObjectInputStream.java:1181)
              > at java.io.ObjectInputStream.readObject(ObjectInputStream.java:381)
              > at java.io.ObjectInputStream.readObject(ObjectInputStream.java:231)
              > at weblogic.jms.common.ObjectMessageImpl.getObject(ObjectMessageImpl.java:127)
              > at com.test.producer.tck.CreateProducerByValue.onMessage(CreateProducerByValue.java:566)
              > at weblogic.jms.client.JMSSession.onMessage(JMSSession.java:1865)
              > at weblogic.jms.client.JMSSession.execute(JMSSession.java:1819)
              > at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:139)
              > at weblogic.kernel.Kernel.execute(Kernel.java:257)
              > at weblogic.kernel.Kernel.execute(Kernel.java:269)
              > at weblogic.jms.client.JMSSession.pushMessage(JMSSession.java:1733)
              > at weblogic.jms.client.JMSSession.invoke(JMSSession.java:2075)
              > at weblogic.jms.dispatcher.Request.wrappedFiniteStateMachine(Request.java:510)
              > at weblogic.jms.dispatcher.DispatcherImpl.dispatchAsync(DispatcherImpl.java:149)
              > at weblogic.jms.dispatcher.DispatcherImpl.dispatchOneWay(DispatcherImpl.java:429)
              > at weblogic.jms.dispatcher.DispatcherImpl_WLSkel.invoke(Unknown
              > Source)
              > at weblogic.rmi.internal.BasicServerRef.invoke(BasicServerRef.java:305)
              > at weblogic.rmi.internal.BasicServerRef.handleRequest(BasicServerRef.java:274)
              > at weblogic.rmi.internal.BasicExecuteRequest.execute(BasicExecuteRequest.java:22)
              > at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:139)
              > at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:120)
              >
              > The client doesn't need to have access to the implementation class for
              > any other aspect of the code, and I would like to keep it that way.
              > Does anyone have information as to the cause of the problem and a
              > solution?
              >
              > Thanks in advance
              

  • The Proper way to go - Passing Serialized Java Objects vs. Web Services?

    The team which I am apart of in our little "community" is trying to convince some "others" (management) that we should not use web services to communicate (move large data) within the same application (allbeit a huge application spanning across many servers).
    Furthermore these "others" are trying to tell us that in this same application when two small apps. inside of this large app. are both java we should not communicate via serialized java objects but instead we should use Web Services and XML. We are trying to convince them that the simplest way is best.
    They have asked us to provide them with proof that passing serialized java objects back and forth between two smaller java applications inside of a larger one is an Industry Standard. Can anyone help either straighten my fellow workers and I out or help us convince the "others" of the proper way to go?

    When I was a consultant we always gave the client what they wanted. Even if it was the wrong choice. Suck it up.
    I'm glad I wasn't one of those customers. Although I agree that a customer is the one who decides what to do, when I pay someone for consultancy, I expect them to consult me. If they know I'm trying to do something that I shouldn't be doing, I expect a good consultant to be able to show me that there's a better way (not just tell me I'm not doing it right, mind you).
    We pass a lot of data using XML and we don't have any transmission or processing speed issues.
    Then you either have a much better network than our customer did, or we're not talking about the same amounts of data here.
    I used the JAX-RPC RI ...
    That's cool... our customer was, unfortunately, infected with Borland products, so we had to use BES. The web services on BES were run by Axis.
    How large were these messages?
    Huge... each element had about 15 attributes, so 1,200 elements would require 19,200 XML nodes (envelope not included). By comparison, the serialized messages weren't even a quarter that size. It's not just about what you send across the network; it's also the effort of parsing XML compared to desrializing Java objects. Our web service wasn't exactly the only process running at the server.
    Anyone who understand the fundamental difference between ASCII (XML) and binary (serialized) formats realizes that no web service can possibly achieve the performance of binary Java services. Why do you think that work is being put into binary web services? I'm not saying XML is never a good thing; just that it's not The Holy Grail that a lot of people are making it look like.
    http://issues.apache.org/jira/browse/AXIS-688
    Ouch.

  • Error deserializing object

    Hi all,
    I am posting a serializable object as message to MDB Queue and trying to deserialize it in onMessage() method. But, getting below error
    "Exception in onMessage weblogic.jms.common.JMSException: Error deserializing object"
    Here is my onMessage method. Please help me !!!
    public void onMessage(Message msg) {
         ProcessQuery prQuery = null;          
         try {
              ObjectMessage message = (ObjectMessage) msg;
              ProcessQuery pQ = (ProcessQuery) message.getObject();
              prQuery = pQ.execute();
         catch(JMSException ex) {
              System.out.println("Exception in onMessage " + ex);
              ex.printStackTrace();
    ProcessQuery is a serializable object.
    Thanks in advance,
    Anitha

    Hi all,
    I am posting a serializable object as message to MDB Queue and trying to deserialize it in onMessage() method. But, getting below error
    "Exception in onMessage weblogic.jms.common.JMSException: Error deserializing object"
    Here is my onMessage method. Please help me !!!
    public void onMessage(Message msg) {
         ProcessQuery prQuery = null;          
         try {
              ObjectMessage message = (ObjectMessage) msg;
              ProcessQuery pQ = (ProcessQuery) message.getObject();
              prQuery = pQ.execute();
         catch(JMSException ex) {
              System.out.println("Exception in onMessage " + ex);
              ex.printStackTrace();
    ProcessQuery is a serializable object.
    Thanks in advance,
    Anitha

  • Un-serializing java objects.

    Hi,
    I have a serialized java object.How can I convert it to a normal object or string object?
    Thanks
    Vivek

    Hi,
    I am not writing object into a file.I am
    just creating a objectoutputstream object.I have to
    convert it to string which i guess can be done using
    objectInputstream object .So is there any way out?
    Thanks
    vivekI'm confused by what you are trying to accomplish. An ObjectOutputStream is intended to write objects to a file. You can't convert an ObjectOutputStream to a String, they aren't related. Are you trying to write the objects to a String? I don't see the point of that.

  • XML serializing/deserializing versus parsing

    Hi all,
    This is not a strictly java question but after reading many discussions and creative solutions offered by different members of this forum, i feel that the right audience for my question are the folks in this very forum. Moderator, if you feel this question makes sense in a different forum, where it might get better responses feel free to move it.
    We are starting off on a new b2b web services project. Everyone in the group agreed that in order to appropriately serve the consumers in our space the best format to use is XML. We are java based and our first consumer is also java based, but we see in the future that our services will be consumed by other types of consumers as well. There seems to be a deep divide in how the xml structure should look like. There are two schools of thoughts. The first one (which is the popular one) is to have loosely typed tag names. Something like this
    <header>
    <map>
    <entry>
    <string>CUSTOMERNAME</string>
    <string>Mahesh</string>
    </entry>
    </map>
    </header>
    The idea being, we could dump regular marshalling/unmarshalling/parsing techniques in favor of a serializing/deserializing tool (Like XStream). The argument here is that we don't worry about a schema/parsing etc and always deal with some sort of generic collection. The other argument is that parsing is more heavier (in terms of performance) than serializing/deserializing.
    I believe that (i belong to the other less popular school of thought) any xml structure should have a real structure (strongly typed tag names). The problems i have with the proposed structure are
    1. They are not self describing, i.e. no wsdl
    2. They cant be parsed with a SAX parser (since there are no tag names, i dont think they can be parsed with a SAX parser, but if anyone here disagrees please correct me)
    3. Since regular parsing is out of the question, you cant predict how your consumers are using it.
    4. I think that the only place to use a serializing/deserializing technique is when you control both end points (producer and consumer).
    What i wanted to find out from the audience here is what they think of the pros/cons of the XML structure described above. Specifically in terms of
    1. Usablity
    2. Scalability
    3. Performance
    The generic structure is also being pitched as the 'next gen' way of defining and using XML. Is that true? Maybe i am just getting old and need to catch up.
    Any thoughts/comments are appreciated.

    user13698018 wrote:
    >
    What? Of course you can parse that "unstructured XML" with a SAX parser, why shouldn't you be able to do that? It's still XML after all.
    >
    You are right, it can be parsed. What i meant to say was i wont be able to extract information from it easily. For e.g. if i have to read the customer name what tag event will i look for? If i look for the event that fires off when i encounter tag name 'string' that will only give me the tag name and not the value. I have to come up with some sort of counter mechanism to disregard the first tag event and look at the second event. Is my assumption correct?Well, parsing the "freeform" XML with SAX requires a few tricks but can result in code that does pretty much the same thing.
    Since the information is exactly the same in both (except that one is a bit more verbose), I don't see any major differences in how it can be parsed.
    The only (seeming) difference is that for "strictly defined" XML you'll need to pre-define which tags/properties exist. But even that can be avoided by clever use of xs:any and allowing other namespaces (i.e. allow a mydata:favoriteColor tag inside your myStrictSchema:person tag).
    Once you do those, the two formats become even more equivalent: some of the advantages of having strictly-formed XML are lost (because you have to handle "unknown" tags again), while some of the disadvantages are lost as well (yeah! extensibility without modifying the core standard).
    In my (partially humble) opinion, the "free form XML" approach is often used when people are too lazy to investigate the wide variety of tools available via official XML techniques.
    >
    3. Since regular parsing is out of the question, you cant predict how your consumers are using it.
    >
    What i meant here was, if my consumers find regular parsing techniques difficult to parse they will resort to short cuts to extract the information (like regex to pull information) and that will make it difficult to predict how consumers are using the xml and hence make it difficult to plan for changes in the future. Am i over thinking here?That's always a possible problem and won't be avoided by any choice in data format. They will try it with "strict XML" and they will try it with "freeform XML". If you have some kind of consulting function, then you can try to communicate the dangers of this approach, but in the end you can hardly force people to "do it the right way".
    Which one would you use?I'd prefer the strictly specified one usually. But I don't know enough about the problem domain to give a qualified answer.

  • Urgent: Problem serializing server objects

    hi there
    i have deployed an application in jboss. it uses instances of javax.media.rtp.RTPManager which is not serializable. now jboss requires each in-memory object to be Serializable. and i have to accomplish the transmission task on server side. so whats the solution? because trying these objects to serialize server throws NotSerializableException
    thanx in advance
    ra4a

    Maybe you can define:
    Class MyRTPManager extends javax.media.rtp.RTPManager implements Serializable {
    You can have this empty definition and then replace all RTPManager with myRTPManager.
    PC

  • Serializing an object and deserializing

    Hi,
    I have an object which i need to serialize so that i can store that in session.
    And then when i m reading from session i need to deserialize it.
    What is the best practice to do it.
    Appreciate ur help

    Simply implement Serializable and ensure that all fields in your class that are not static or transient are also of Serialzable types. You could implement Externalizable, but that is more work and probably of of limited value unless serialization performance is hyper-critical - it usually isn't.

  • EOFException when deserializing object in if statement

    Hi,
    I'm a java newbie and I've got a program in which I've got an method to open a serialized file.
    I am running into problems when determining the class of the object to be deserialized.
    When the code is as such everything works fine:
        ObjectInputStream ois;
        protected void open() {
            int returnVal = fc.showOpenDialog(this);
         if (returnVal == JFileChooser.APPROVE_OPTION) {
                File file = fc.getSelectedFile();
                try {
                 ois = new ObjectInputStream(new FileInputStream(file));     
              frameSeqA72 = (SeqA72) ois.readObject();
              getContentPane().add(frameSeqA72);
              frameSeqA72.setVisible(true);
              ois.close();                                                                                                           
             catch (IOException ioe) {ioe.printStackTrace();}
             catch (ClassNotFoundException cnfe) {}     
        }For some reason I don't understand everything changes when I use an if statement in the code as follows:
        ObjectInputStream ois;
        protected void open() {
            int returnVal = fc.showOpenDialog(this);
         if (returnVal == JFileChooser.APPROVE_OPTION) {
                File file = fc.getSelectedFile();
                try {
                 ois = new ObjectInputStream(new FileInputStream(file));     
              if (ois.readObject() instanceof SeqA72) {
                  frameSeqA72 = (SeqA72) ois.readObject();
                  getContentPane().add(frameSeqA72);
                  frameSeqA72.setVisible(true);
                  ois.close();                                                    
             catch (IOException ioe) {ioe.printStackTrace();}
             catch (ClassNotFoundException cnfe) {}     
        }An EOFException is thrown when this method is called -
    "EOFException at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1267)..."
    My serialized objects are of different classes so I want to determine the class before casting...so Im using "if (ois.readObject() instanceof SeqA72)".
    Why would the first version work and the second throw an exception?
    Am I going about this in a bad way?
    Casey

    You're calling readObject twice, so it's trying to read two objects.
    Read it once and save a reference in a variable. Use that variable, instead of calling readObject again.

  • Exception while Deserializing objects..

    There's a class which is serialized, and stored in the DB. Now, this class is changed (there's an attribute added) and there's new instances which are not stored in the DB. But the problem now comes when I have to deserialize both these instances. At this time I am getting exception. How do I handle deserializing of both these types of objects.
    The biggest issue in this is that there's no serialversionUID defined in this class (its a legacy code) so the standard remedies would not work. How do I handle this?
    by the way the exception I get is sometimes EOFException and sometimes StreamCorruptedException.

    javanewbie80 wrote:
    There's a class which is serialized, and stored in the DB. Now, this class is changed (there's an attribute added) and there's new instances which are not stored in the DB. But the problem now comes when I have to deserialize both these instances. At this time I am getting exception. How do I handle deserializing of both these types of objects.
    The biggest issue in this is that there's no serialversionUID defined in this class (its a legacy code) so the standard remedies would not work. How do I handle this?
    by the way the exception I get is sometimes EOFException and sometimes StreamCorruptedException.Figure out what the old serialVersionUID was and add it to your class. Serialization should be able to handle new fields.
    [http://www.j2ee.me/developer/technicalArticles/Programming/serialization/]
    See the section under version control:
    "The version control works great as long as the changes are compatible. Compatible changes include adding or removing a method or a field. Incompatible changes include changing an object's hierarchy or removing the implementation of the Serializable interface. A complete list of compatible and incompatible changes is given in the Java Serialization Specification."

  • Web Services with Complex Objects (Urgent !!)

    Hi,
    My last post was on a problem using IBM-RAD (Service) and AXIS2 (Client) in "New to Java" Forum. That is one of the trial scenarios I'm working on nowadays. Hope, I'll get some useful reply soon.
    Now, I need a suggestion about the application I'm working upon. It is as follows:
    (i) The application (i.e. Service Class) takes some primitive,String and/or some bean object as input
    (ii) It returns a bean object [or an array (can use collection class also if possible) of bean objects].
    (iii) The bean properties are primitive,String , other bean objects, and/or some collection object(Vector / ArrayList etc.) i.e. it should handle complex objects.
    (iv) The Service should run on Websphere and Client on Tomcat.
    A pictorial representation is given below:
    [primitive/String/bean object (Input arg)]
    [(Contains  primitive/String/other bean objects/collection class)] Bean <---------> Service <----------------------- Client
    [Calls bean] |===============> Client
    [Returns bean (or array of beans / collection object)]
    I'm now trying (by building test applications) a combination of IBM-RAD (Service) and AXIS2 (Client), but facing problems in handling array of beans and/or collection classes either on Service or on the Client side.
    So, I need some suggestions on whether I'm going the right way, or need to change my approach (or technology). Any suggestion would be appreciated.
    Please reply ASAP, it is urgent.
    Thanks in advance,
    Suman

    no problem for me, so it's not urgent.
    Request for help denied.

  • Casting an (deserialized) Object as a (custom) subclass.

    Haigh,
    I'm having trouble casting objects as their subclass.
    I'll explain, i have a class that fetches a stored serialized object from a Database.
    i can store the objects no problem.
    ex. oodb.store(new Machine());
    // machine being my custom class that stores information on the running machine (OS,JVM,ip and MAC address etc.)
    then when i want to retrive the object
    it should work with the method getObjectByID(int idOfObject) which returns an Object
    ex. oodb.getObjecyByID(7)
    then i create a new instance of machine
    Machine computer = (Machine) oodb.getObjectByID(7);
    but i get an error saying i cant cast Object (java.lang.Object) as a Machine (ie.iconicaelixia.objects.Machine to be exact)
    It worked before!
    well a variation of it worked, then i changed the testing class to suit another test.
    i've tried the if(Object intanceOf Machine) method aswell, but it never returned true. Eventhough the binary read of the stored object clearly states it is.
    Also, on the topic of serialized objects in a database, would it be more effective if my store/fetch methods stored/fetched Class(es) instead of Object(s)?
    If so, how would i return a Class?
    For Reference here is my Store/Fetch Methods:
    public void storeObject(String ClassType,Object ObjectToStore,String indexableInfo)
              try
                   indexableInfo = indexableInfo + "$ObjCreated="+new Date().toString();
                   if(ClassType==null)
                        ClassType = ObjectToStore.getClass().getName();
                   int oID = getAvailableID();
                   PreparedStatement ps = nasc.nasc().prepareStatement("Insert into iserv.objects Set OID = ?,Class = ?, Object = ?,Indexable = ? ");
                   ps.setInt(1,oID);
                   ps.setString(2,ClassType);
                   ps.setObject(3,ObjectToStore);
                   ps.setString(4,indexableInfo);
                   ps.execute();
                   ps = null;
              catch (SQLException sqle)
                   sqle.printStackTrace();
         public Object getObjectByID(int ObjectID)
              Object rO = null;
              try
                   PreparedStatement ps = nasc.nasc().prepareStatement("SELECT OID, OBJECT from iServ.Objects WHERE OID = "+ObjectID);
                   ResultSet rs = ps.executeQuery();
                   rs.next();
                   rO = rs.getObject("OBJECT");
                   LastRetrvID = rs.getInt("OID");
                   rs.close();
                   ps = null;
              catch (SQLException sqle)
                   sqle.printStackTrace();
              return rO;
         }Gurbh Míle síle as aon cabhair!

    Okay, I'll ask the obvious question:
    Why are you trying to store serialized objects? Why not use the usual approach to a relational database, break down the information into attributes and store them in appropriate fields?

Maybe you are looking for

  • Open my html file and cannot edit it

    When I open my html file from Flash, in view design all I get is a grey box with the Flash symbol in the middle and no html tools. I want to link some of my buttons but if I go into view live I get html tools but I still can't access them to make lin

  • OCR B Font Issue in prinitng

    Hi Friends, We are trying to print cheques using OCR B Font. When I try to print any of the cheque from SAP the font is not displayed in OCR B fromat. Please let me know if any one has worked on OCR B Font. Thanks, Naresh

  • Wireless only working with guest network?

    I've just about gotten a new TC working, but strangely it the wireless only seems to work on the guest network. Have checked the password, and its correct, but still no joy. I didn't think it was that big a deal, but now I'm wondering if its stopping

  • Simple example of grid

    can any one tell me script or simple example to configure grid. thankyou.

  • Multiple tasklist at one order

    Hi every one i have a query that can we assign more than one task list to an order (equipment and general task lists). so that we can add operation of both task list simultaneously. Regards Abhishek Edited by: abhishek sinha on Sep 16, 2009 2:28 PM