6 Replies Latest reply on Oct 12, 2006 10:02 AM by kapil.singhal

    How to create Cutom SoapException

    kapil.singhal

      Hello,

      I am creating a Web Service using JBossWS.

      I want to customize the contents of SOAP Exception, which I want to throw from my Web Service.

      For this, I am using SOAPFaultException to create my own exception classes. But I am not able to fill the detail in the Detail attribute of the SOAPFaultException.

      I am filling the specifics of JBossWS using the "org.jboss.ws.soap.SOAPFactoryImpl". But on the client side when I run my RMI Client, I found that one of the element is not Serializable. (Please find the stack below.)

      Can you suggest me how to fill these so that I can throw a customized SoapFault exception at the client end ?

      Any help will be appreciated.

      Kapil

      19:05:14,091 ERROR [ServerThread] failed
      java.io.NotSerializableException: org.jboss.ws.soap.DetailImpl
      at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1081)
      at java.io.ObjectOutputStream.access$100(ObjectOutputStream.java:139)
      at java.io.ObjectOutputStream$PutFieldImpl.writeFields(ObjectOutputStream.java:1518)
      at java.io.ObjectOutputStream.writeFields(ObjectOutputStream.java:429)
      at javax.xml.rpc.soap.SOAPFaultException.writeObject(SOAPFaultException.java:145)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      at java.lang.reflect.Method.invoke(Method.java:585)
      at java.io.ObjectStreamClass.invokeWriteObject(ObjectStreamClass.java:917)
      at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1339)
      at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1290)
      at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1079)
      at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1375)
      at java.io.ObjectOutputStream.defaultWriteObject(ObjectOutputStream.java:391)
      at java.lang.Throwable.writeObject(Throwable.java:649)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      at java.lang.reflect.Method.invoke(Method.java:585)
      at java.io.ObjectStreamClass.invokeWriteObject(ObjectStreamClass.java:917)
      at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1339)
      at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1290)
      at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1079)
      at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1375)
      at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1347)
      at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1290)
      at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1079)
      at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:302)
      at org.jboss.remoting.serialization.impl.java.JavaSerializationManager.sendObject(JavaSerializationManager.java:81)
      at org.jboss.remoting.marshal.serializable.SerializableMarshaller.write(SerializableMarshaller.java:84)
      at org.jboss.remoting.transport.socket.ServerThread.processInvocation(ServerThread.java:381)
      at org.jboss.remoting.transport.socket.ServerThread.dorun(ServerThread.java:412)
      at org.jboss.remoting.transport.socket.ServerThread.run(ServerThread.java:239)

        • 1. Re: How to create Cutom SoapException
          maeste

          I'm not sure to understand your problem.
          If you are using jsr181 you can simply throws a CustomException extending Exception to get a custom soapFault. Of course you can fill "message" attribute of your CustomException as you like.
          If you are using jsr109 it's not too harder. Take a look to chapter 8 of official docs.

          • 2. Re: How to create Cutom SoapException
            kapil.singhal

            Hello,

            I know I can use Custom Exception and customize it as per my need.

            But I want to customize the SoapFaultException and fill it attributes so that I can throw them from the Web Service.

            SOAPFaultException has the following attributes : QName, String, String, Detail

            I not able to fill the Detail attribute of the SOAPFaultException.

            I hope I am able to clear my problem.

            Please suggest.
            Kapil

            • 3. Re: How to create Cutom SoapException
              kapil.singhal

              I want to fill in SOAPFault with meaningful details.
              The SOAPFault contains the following:
              - FaultCode
              - FaultActor
              - FaultString
              - Detail

              I can fill-in most of the elements except the Detail object. This Detail object has the ability to contain a XML node, where I want to pass some of the details specific to the exception.

              Please refer to class "org.jboss.ws.jaxrpc.SOAPFaultExceptionHelper", which constructs a "javax.xml.rpc.soap.SOAPFaultException" from our exception that we are throwing from the service.

              If you look at the implementation of SOAPFaultExceptionHelper, you find that the Actor and Detail object are passed as null. As a result of this my client cannot get additional details, which I want to convey.

              Please suggest me a way that I can fill meaningful values in the SOAPFault which I want to throw from the server side. As in this case the same exception will be conveyed as it is.

              Regards,
              Kapil

              • 4. Re: How to create Cutom SoapException
                kapil.singhal

                I think it is difficult to proceed this way as I am exposing a EJB as a Web Service. So whatever exception I throw from my Web Service is converted to javax.ejb.EJBException and hence restricting me to customize the contents of SOAPFault.

                I would be glad if somebody can suggest me some solution, but I think JBoss implementation needs to improve on this.

                • 5. Re: How to create Cutom SoapException

                  Hi!

                  I had a similar issue.. look at http://www.jboss.com/index.html?module=bb&op=viewtopic&t=92041

                  regards!

                  /Ole
                  eviware.com

                  • 6. Re: How to create Cutom SoapException
                    kapil.singhal

                    Actor: null
                    Code: {http://schemas.xmlsoap.org/soap/envelope/}Client
                    String: com.barco.cms.openapi.RemoteException [Source=createProblem, Type=Internal Error, Message=Testing Checked Exception, Description=Some internal problem has occurred, contact Barco CSE, Timestamp=null]
                    Detail: null

                    Can you make something from this, where only FaultString belongs to me.

                    ?