Loading ...
Sorry, an error occurred while loading the content.

SOAP::Lite server and Java client

Expand Messages
  • Daryl Williams
    folks, i have a small SOAP::Lite server with one method (besides the constructor) that returns a reference to a list of hashes. this has worked fine with a
    Message 1 of 2 , Mar 5 10:17 AM
    • 0 Attachment
      folks,

      i have a small SOAP::Lite server with one method (besides the constructor)
      that returns a reference to a list of hashes. this has worked fine with
      a perl
      client. i now need to service a java client. this is my first experience
      doing this and i am getting dizzy with all the research i have been doing.

      anyway to do this i have created wsdl and xsd files using WSDL::Generator
      and WSDL::Generator::Schema. i realize i will probably need ot tweak these
      files. i have also looked for wsdl java client software library and have
      more
      or less settled on using apache's wsif infrastructure.

      my question to the group is, am i on the right track here and are there any
      examples of how to do this, i.e. get a java client to execute a SOAP::lite
      method that returns somthing like this:

      my $package = {
      'name' => $PACKAGE{'name'},
      'url' => $PACKAGE{'url'},
      'description' => $PACKAGE{'description'},
      };

      push(@pkglist, $package);

      return $pkglist;

      your help is appreciated. regards,

      daryl
    • Martin Hajduch
      ... SOAP::lite ... i was dealing with maybe similar problem some time a go i haven t found a direct way to pass perl hash to a java client so that it would be
      Message 2 of 2 , Mar 5 1:53 PM
      • 0 Attachment
        > examples of how to do this, i.e. get a java client to execute a
        SOAP::lite
        > method that returns somthing like this:
        >
        > my $package = {
        > 'name' => $PACKAGE{'name'},
        > 'url' => $PACKAGE{'url'},
        > 'description' => $PACKAGE{'description'},
        > };

        i was dealing with maybe similar problem some time a go
        i haven't found a direct way to pass perl hash to a java client so that it
        would be received as a java.util.Hashtable (i think there is no hash type
        for soap messages - is this right ?)

        so i was using my own objects
        you have to create package object on java side, if you want to use axis'
        bean serializer/deserializer (using java reflection mechanism), it should
        have methods following bean naming convention, i.e.:
        setName, getName, setUrl, getUrl, setDescription, getDescription in your
        case
        (this is the easy way - other solution is to use your own deserializer,
        but this is more work ...)

        then you need to tell axis to use those objects when recieving data (let's
        suppose that your class has name Package)
        first create call object, something like this:

        Call call = (Call)m_service.createCall();
        call.setTargetEndpointAddress(new java.net.URL(m_endpoint));
        call.setOperationName(new QName(m_namespace, m_method));

        then register your object with this Call:

        call.registerTypeMapping(Package.class, qn,
        new
        org.apache.axis.encoding.ser.BeanSerializerFactory(Package.class, qn),
        new
        org.apache.axis.encoding.ser.BeanDeserializerFactory(Package.class, qn));

        now issue a call - you have to supply correct parameters, let's suppose
        that there are none for now:

        java.lang.Object _resp = createCall(m_method).invoke(new
        java.lang.Object[] {});

        and finally translate the result to the correct type:

        if (_resp instanceof java.rmi.RemoteException) {
        System.out.println("ERROR during call: " + _resp.toString());
        return null;
        }
        else {
        try {
        return (Package[]) _resp;
        }
        catch (java.lang.Exception _exception) {
        return (Package[]) org.apache.axis.utils.JavaUtils.
        convert(_resp, Package[].class);
        }
        }
        }

        (note that this is valid if you are receiving *array* of objects Package)

        as for the perl side, you have to make sure that correct types &
        namespaces are used for the response (i was usually using one and the same
        namespace for everything, so that i haven't got any troubles with it - it
        is a good way to get *something* working)

        you can do this using 'type' property of SOAP::Data object; in general, if
        you are aiming at interoperability, you'd better always qualify all
        elements when returning data from the service
        see Microsoft .NET section in SOAP::Lite manpage for more details - most
        of it applies also for interoperability with axis

        hope that this helps,

        regards,
        martin
      Your message has been successfully submitted and would be delivered to recipients shortly.