Hello Raman,

 

yes, the following code works for me:

import java.io.ByteArrayInputStream;

import java.io.ByteArrayOutputStream;

import java.io.IOException;

import java.io.ObjectInputStream;

import java.io.ObjectOutputStream;

import java.io.PrintWriter;

import java.io.Serializable;

import java.io.StringWriter;

 

/**

 * Utility class to serialize and deserialize <code>java.lang.Throwable</code>, 
needed because JAXB cannot map Throwable

 * to XML on account of the non-serializable stack trace array.

 * @author sml

 * @version 3.0

 */

public class ThrowableWrapper implements Serializable

{

      private static final long serialVersionUID = 7112569161595756136L;

 

      private String stackTraceString;

      private byte[] throwableBytes;

 

      public ThrowableWrapper()

      {

      }

 

      public ThrowableWrapper( Throwable t ) throws IOException

      {

            // write Throwable to byte array

            ByteArrayOutputStream baos = new ByteArrayOutputStream();

            ObjectOutputStream oos = new ObjectOutputStream( baos );

            oos.writeObject( t );

            throwableBytes = baos.toByteArray();

 

            // as a convenience also save the stack trace as a string

            StringWriter s = new StringWriter();

            PrintWriter p = new PrintWriter( s );

            t.printStackTrace( p );

            stackTraceString = s.getBuffer().toString();

      }

 

      public Throwable getThrowable() throws IOException, ClassNotFoundException

      {

            ByteArrayInputStream bais = new ByteArrayInputStream( 
throwableBytes );

            ObjectInputStream ois = new ObjectInputStream( bais );

            Object t = ois.readObject();

            return (Throwable) t;

      }

 

// accessors for the properties so that JAXB can unmarshal the data into the

      // bean (wrapper).

 

      public String getStackTraceString()

      {

            return stackTraceString;

      }

 

 

      public void setStackTraceString( String stackTraceString )

      {

            this.stackTraceString = stackTraceString;

      }

 

      public void setThrowableBytes( byte[] throwableBytes )

      {

            this.throwableBytes = throwableBytes;

      }

 

      public byte[] getThrowableBytes()

      {

            return throwableBytes;

      }

 

}

 

 

From: Malisetti, Ramanjaneyulu [mailto:[email protected]] 
Sent: Monday, October 04, 2010 6:18 AM
To: [email protected]
Subject: RE: Throwable as method argument causes exception

 

Hi Sebastian,

                                  Is this solution finally working? I am 
curious to know what is the working solution. Because, I too have similar 
situation, but currently I am passing as a String and recreating exception on 
client side. I know this is hack.

 

Regards

Raman

 

From: Raymond Feng [mailto:[email protected]] 
Sent: Thursday, September 16, 2010 5:03 AM
To: [email protected]
Subject: Re: Throwable as method argument causes exception

 

You will have to add the setters for the properties so that JAXB can unmarshal 
the data into the bean (wrapper). 

________________________________________________________________ 

Raymond Feng

[email protected]
Apache Tuscany PMC member and committer: tuscany.apache.org
Co-author of Tuscany SCA In Action book: www.tuscanyinaction.com
Personal Web Site: www.enjoyjava.com

________________________________________________________________

 

[snip]

Reply via email to