[SoapRMI] Q: UndeclaredThrowableException

Aleksander Slominski aslom_at_cs.indiana.edu
Sun, 24 Nov 2002 15:40:17 -0500


Mark Swanson wrote:

> Hello,
>
> I created some code to talk to a remote SOAP service and am having trouble
> with this Exception (below). Any idea what might be causing this?

hi,

XSOAP dynamic stubs excepts that all checked exception will
be extending RemoteException (is SOAPException doing this?).
you can overcome this using ThrowableRewrapper to dynamically
unwrap UndeclaredThrowableException (see soaprmi.util.dynamic_proxy.ThrowableRewrapper).

you will need to wrap remote reference with ThrowableRewrapper
for example

UserIfc  wrappedRef = (UserIfc) ThrowableRewrapper.wrap(
            serviceRef, SOAPException.class, "SOAP exception when interacting service");

this is not perfect solution as it adds some overhead for each call
to pass through one extra dynamic proxy.

> java.lang.reflect.UndeclaredThrowableException
>         at $Proxy0.findEmails(Unknown Source)
>         at com.wss.xsoap.HelloClient.main(HelloClient.java:41)
> Caused by: soaprmi.RemoteException: IO Exception; nested exception is:
>         java.net.ConnectException: Connection refused
>         at
> soaprmi.soaprpc.HttpSocketSoapInvocationHandler.invokeTransport(Unknown
> Source)
>         at soaprmi.soaprpc.SoapDynamicStub.invoke(Unknown Source)
>         ... 2 more
>
> The remote service interface is defined with this method:
>
> byte[] findEmails(String emailRegex) throws SOAPException;
>
> So, I do not see why SOAPException should have to be declared? (If that 's the
> cause of the exception...)

this is cause of problems as all of XSOAP expects all thrown remote exceptions
to extend soaprmi.RemoteException (i want to remove this limitation in next major version)

> Also, I think the Connection refused is bogus because the service is up and
> running and accessible from other SOAP clients.

> Any suggestions would be most welcome.

run TCPReflector or other HTTP tracer and verify what is going on the wire.


> The client code I'm using is this:
>
> public class HelloClient {
>
>     public static void main (String args[]) throws Exception {
>
>         XmlJavaMapping mapping =
>             soaprmi.soap.Soap.getDefault().getMapping();
>         // disable XSOAP auto mapping
>         mapping.setDefaultStructNsPrefix(null);
>
>         fixNames(mapping);
>
>         UserIfc serviceRef = null;
>         String location = "http://localhost/sw/ServletServer/user";
>
>         // create reference ot service
>         serviceRef = (UserIfc)
>             soaprmi.soaprpc.SoapServices.getDefault().createStartpoint(
>             location,  // service location
>             new Class[]{UserIfc.class}, // remote service interface
>             "user", // endpoint name
>             soaprmi.soap.SoapStyle.SOAP11,
>             "" // SOAPAction
>         );
>
>         byte[] result;
>         try {
>             result = serviceRef.findEmails("t0_at_a.com");
>         } catch(Throwable t) {
>             t.printStackTrace();
>             return;
>         }
>         System.out.println("Server said '" + result +"'");
>     }
>
>     public static void fixNames(XmlJavaMapping mapping) throws Exception {
>
>         XmlJavaPortTypeMap portMap = mapping.queryPortType(UserIfc.class);
>
>         // extract mapping for operation
>         XmlJavaOperationMap oMap =portMap.queryMethodRequest("findEmails");
>
>         // get in message and change part names
>         XmlJavaMessageMap requestMsg = oMap.getRequest();
>         XmlJavaPartMap[] reqParts = requestMsg.getParts();
>         reqParts[0].setPartName("email");
>
>         /*
>         mapping.mapStruct(
>             "user" //NAMESPACE URI
>             "UserIfc" // NAMESPACE LOCAL
>             UserNotFoundSOAPException.class // Java Bean class
>         );
>         */
>
>     }
> }

this code looks OK and should be working,

let me know if you still have problems.

thanks,

alek
--
The ancestor of every action is a thought. - Ralph Waldo Emerson