xml-soap-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Kailash Aynor" <kail_l...@hotmail.com>
Subject Re: Array of objects serialization...
Date Thu, 10 Aug 2000 03:34:46 GMT
here is the modified code.I tweaked the Addressbook Sample to test this. The 
following changes have been made to the Addressbook class. Function
public String[] reverse(String[] strArray) has been added to the class. Here 
is function body.
Essentially it takes an array of string, reverse every 2 Strings and sends 
it back.

public static String[] reverse(String[] strArray)
  {
    int len = strArray.length;
    for(int i =0; i < len; i++)
    {
        if (i+1 < len)
        {
            String tmp = strArray[i];
            strArray[i] = new String(strArray[i+1]);
            strArray[i+1] = new String(tmp);
            i++;
        }
    }
    return strArray;
  }

You need to add this "reverse" function in the deployment-descriptor.xml

and the client code to test this out is as follows. I have hardcoded  the 
router address. Change it accordingly.


import java.io.*;
import java.util.*;
import java.net.*;
import org.w3c.dom.*;
import org.apache.soap.util.xml.*;
import org.apache.soap.*;
import org.apache.soap.encoding.*;
import org.apache.soap.encoding.soapenc.*;
import org.apache.soap.rpc.*;


public class test
{
  public static void main(String[] args) throws Exception
  {
    String encodingStyleURI = Constants.NS_URI_SOAP_ENC;
    URL url = new URL("http://localhost:8080/soap/rpcrouter/rpcrouter.jsp");
    SOAPMappingRegistry smr = new SOAPMappingRegistry();

    ArraySerializer aSer = new ArraySerializer();
     String[] data = new String[2];
     data[0] = new String("kailash");
     data[1] = new String("aynor");

    smr.mapTypes(Constants.NS_URI_SOAP_ENC,
    new QName(Constants.NS_URI_SOAP_ENC,
    "Array"),
    String[].class, aSer, aSer);

    Vector params = new Vector();
    params.addElement(new Parameter("rootElement",
    String[].class, (String[]) data, Constants.NS_URI_SOAP_ENC));

    // Build the call.
    Call call = new Call();

    call.setSOAPMappingRegistry(smr);
    call.setTargetObjectURI("urn:AddressFetcher");
    call.setMethodName("reverse");
    call.setEncodingStyleURI(Constants.NS_URI_SOAP_ENC);

    call.setParams(params);

    // Invoke the call.
    Response resp;
    try
    {
      resp = call.invoke(url, "");
    }
    catch (SOAPException e)
    {
      System.err.println("Caught SOAPException (" +
                         e.getFaultCode() + "): " +
                         e.getMessage());
      return;
    }

    // Check the response.
    if (!resp.generatedFault())
    {
      Parameter ret = resp.getReturnValue();
      String[] value = (String[])ret.getValue();

      System.out.println(value[0] + "   " + value[1]);
    }
    else
    {
      Fault fault = resp.getFault();

      System.err.println("Generated fault: ");
      System.out.println ("  Fault Code   = " + fault.getFaultCode());
      System.out.println ("  Fault String = " + fault.getFaultString());
    }

  }
}

It worked quite well while testing. Probably this can be added to the 
samples.

Kailash.



>From: Deepak Patil <deepak_patil@CENTEGY.COM>
>Reply-To: SOAP <SOAP@DISCUSS.DEVELOP.COM>
>To: SOAP@DISCUSS.DEVELOP.COM
>Subject: Array of objects serialization...
>Date: Wed, 9 Aug 2000 13:38:26 -0700
>
>Hi,
>
>I am still stuck up with that arrayserializer...do anybody has a running
>example using ArraySerializer....
>I am getting an exception :
>
>Caught SOAPException (SOAP-ENV:Client): Unable to retrieve 'myName' 
>property
>value: object is not
>an instance of declaring class.
>
>It will be highly appreciated, if anyone did it please send me the lines of
>code at the client side mapping and the DD,
>
>Thanks & Regards
>Deepak

________________________________________________________________________
Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com


Mime
View raw message