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

RE: [soaplite] SOAP::Lite server and Java client

Expand Messages
  • 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 1 of 2 , Mar 5, 2003
    • 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.