You are viewing a plain text version of this content. The canonical link for it is here.
Posted to soap-user@ws.apache.org by "Johnston, Keith" <jo...@vignette.com> on 2000/10/12 15:23:42 UTC

Auto-Generation of C++/Java SOAP client stubs?

Is anyone aware of code that can generate the client stubs for SOAP-enabled
objects automatically from header files / Java classes / or some IDL format?

Thanks,
Keith Johnston

Re: Auto-Generation of C++/Java SOAP client stubs?

Posted by Aleksander Slominski <as...@cs.indiana.edu>.
"Johnston, Keith" wrote:

> Is anyone aware of code that can generate the client stubs for SOAP-enabled
> objects automatically from header files / Java classes / or some IDL format?

hi,

with JDK1.3 it is possible to use dynamic stubs using java.reflect.InvocationHandler.

the only problem is to get remote reference that will contain endpoint information (such as URL) and interface description (such as method name), for example:

public class SoapInvocationHandler implements InvocationHandler {

     private Class[] interfaces; //allow in fututre for component to have multiple ifaces
     private Endpoint epoint;

     public SoapInvocationHandler(Class[] interfaces, Endpoint epoint) {
         this.interfaces = (Class[]) interfaces.clone();
         this.epoint = epoint; // TODO: (Endpoint) epoint.clone();
     }


     public Object invoke(Object proxy, Method m, Object[] args) throws Throwable {
         Class declaringClass = m.getDeclaringClass();

             for (int i = 0; i < interfaces.length; i++) {
                 if (declaringClass.isAssignableFrom(interfaces[i])) {
                         return invoke(interfaces[i], m, args);
                 }
             }
         }
     }

  public Object invoke(Class iface, Method m, Object[] args) throws RemoteException {
   try {
    URL url = new URL(epoint.getHref());

    // Build the call.
    Call call = new Call ();
    call.setEncodingStyleURI(Constants.NS_URI_SOAP_ENC);
    call.setTargetObjectURI (epoint.getName());
    call.setMethodName (m.getName());
    //call.setEncodingStyleURI(encodingStyleURI);
    Vector params = new Vector ();
    idl.Method emethod = null;
    String methodName = m.getName();
    for(int i = 0; i < epoint.getMethodCount(); ++i) {
        String name = epoint.getMethod(i).getName();
        if(methodName.equals(name)) {
          emethod = epoint.getMethod(i);
          break;
        }
    }
    if(emethod == null) {
      throw new RemoteException("can't find method "+m.getName()+" in endpoint");
    }
    idl.Request erequest = emethod.getRequest();
    for(int i = 0; i < erequest.getParamCount(); ++i) {
      String name = erequest.getParam(i).getName();
      if(name == null) {
          name = erequest.getParam(i).getContent();
      }
      //System.err.println("param name="+name); //ALEK
      Object o = args[i];
      params.addElement (new Parameter(name, o.getClass(), o, null));
    }
    call.setParams (params);

    Response resp = call.invoke (url , /* actionURI */ "" );

    // Check the response.
    if (resp.generatedFault ()) {
      Fault fault = resp.getFault ();
      throw new RemoteException(fault.getFaultString ()+" (code="+fault.getFaultCode()+")");
    }

    Parameter result = resp.getReturnValue ();
    //System.out.println ("soap invocation result="+result.getValue ());
    return result.getValue();
   } catch(Exception ex) {
     throw new RemoteException("soap invocation fault", ex);
   }
  }
}

i have only implemented a prototype for Apache SOAP (the code above is a heart of it) so i do not have a fully working version :-).

regards

alek
--
Aleksander Slominski, LH 316, IU, http://www.extreme.indiana.edu/~aslom
As I look afar I see neither cherry Nor tinted leaves Just a modest hut
on the coast In the dusk of Autumn nightfall - Fujiwara no Teika (1162-1241)



Re: Auto-Generation of C++/Java SOAP client stubs?

Posted by Girish Bharadwaj <gi...@mailandnews.com>.
WSDL toolkit from IBM will generate the stubs for you..
Download it from alphaworks.ibm.com.


Girish Bharadwaj
----- Original Message -----
From: "Johnston, Keith" <jo...@vignette.com>
To: <so...@xml.apache.org>
Sent: Thursday, October 12, 2000 9:23 AM
Subject: Auto-Generation of C++/Java SOAP client stubs?


>
> Is anyone aware of code that can generate the client stubs for
SOAP-enabled
> objects automatically from header files / Java classes / or some IDL
format?
>
> Thanks,
> Keith Johnston


Re: Auto-Generation of C++/Java SOAP client stubs?

Posted by Aleksander Slominski <as...@cs.indiana.edu>.
"Johnston, Keith" wrote:

> Is anyone aware of code that can generate the client stubs for SOAP-enabled
> objects automatically from header files / Java classes / or some IDL format?

hi,

with JDK1.3 it is possible to use dynamic stubs using java.reflect.InvocationHandler.

the only problem is to get remote reference that will contain endpoint information (such as URL) and interface description (such as method name), for example:

public class SoapInvocationHandler implements InvocationHandler {

     private Class[] interfaces; //allow in fututre for component to have multiple ifaces
     private Endpoint epoint;

     public SoapInvocationHandler(Class[] interfaces, Endpoint epoint) {
         this.interfaces = (Class[]) interfaces.clone();
         this.epoint = epoint; // TODO: (Endpoint) epoint.clone();
     }


     public Object invoke(Object proxy, Method m, Object[] args) throws Throwable {
         Class declaringClass = m.getDeclaringClass();

             for (int i = 0; i < interfaces.length; i++) {
                 if (declaringClass.isAssignableFrom(interfaces[i])) {
                         return invoke(interfaces[i], m, args);
                 }
             }
         }
     }

  public Object invoke(Class iface, Method m, Object[] args) throws RemoteException {
   try {
    URL url = new URL(epoint.getHref());

    // Build the call.
    Call call = new Call ();
    call.setEncodingStyleURI(Constants.NS_URI_SOAP_ENC);
    call.setTargetObjectURI (epoint.getName());
    call.setMethodName (m.getName());
    //call.setEncodingStyleURI(encodingStyleURI);
    Vector params = new Vector ();
    idl.Method emethod = null;
    String methodName = m.getName();
    for(int i = 0; i < epoint.getMethodCount(); ++i) {
        String name = epoint.getMethod(i).getName();
        if(methodName.equals(name)) {
          emethod = epoint.getMethod(i);
          break;
        }
    }
    if(emethod == null) {
      throw new RemoteException("can't find method "+m.getName()+" in endpoint");
    }
    idl.Request erequest = emethod.getRequest();
    for(int i = 0; i < erequest.getParamCount(); ++i) {
      String name = erequest.getParam(i).getName();
      if(name == null) {
          name = erequest.getParam(i).getContent();
      }
      //System.err.println("param name="+name); //ALEK
      Object o = args[i];
      params.addElement (new Parameter(name, o.getClass(), o, null));
    }
    call.setParams (params);

    Response resp = call.invoke (url , /* actionURI */ "" );

    // Check the response.
    if (resp.generatedFault ()) {
      Fault fault = resp.getFault ();
      throw new RemoteException(fault.getFaultString ()+" (code="+fault.getFaultCode()+")");
    }

    Parameter result = resp.getReturnValue ();
    //System.out.println ("soap invocation result="+result.getValue ());
    return result.getValue();
   } catch(Exception ex) {
     throw new RemoteException("soap invocation fault", ex);
   }
  }
}

i have only implemented a prototype for Apache SOAP (the code above is a heart of it) so i do not have a fully working version :-).

regards

alek
--
Aleksander Slominski, LH 316, IU, http://www.extreme.indiana.edu/~aslom
As I look afar I see neither cherry Nor tinted leaves Just a modest hut
on the coast In the dusk of Autumn nightfall - Fujiwara no Teika (1162-1241)



Re: Auto-Generation of C++/Java SOAP client stubs?

Posted by Girish Bharadwaj <gi...@mailandnews.com>.
WSDL toolkit from IBM will generate the stubs for you..
Download it from alphaworks.ibm.com.


Girish Bharadwaj
----- Original Message -----
From: "Johnston, Keith" <jo...@vignette.com>
To: <so...@xml.apache.org>
Sent: Thursday, October 12, 2000 9:23 AM
Subject: Auto-Generation of C++/Java SOAP client stubs?


>
> Is anyone aware of code that can generate the client stubs for
SOAP-enabled
> objects automatically from header files / Java classes / or some IDL
format?
>
> Thanks,
> Keith Johnston