This is not production quality code and hasn't been tested, but gives the
basis of how to achieve your intended results... any problems, get back to
me James


package com.rbsfm.commonx.xmlrpc.apache;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.OutputStream;
import java.io.Serializable;
import java.util.Vector;

import org.apache.xmlrpc.Base64;
import org.apache.xmlrpc.XmlRpcClient;

/**
 * @author [EMAIL PROTECTED]
 */
public class Solution {
    
    public static void main(String[]argv) throws Exception{
        Serializable toPass = null; //it must be serializable
        XmlRpcClient client = new XmlRpcClient("blah");
        Vector parameters = new Vector();
        parameters.add(Base64.encode(serializeObject(toPass)));
        Object retVal = client.execute("myMethod", parameters);
        //..
        
        //for deserialisation once you have the byte array
        //byte[] myParameter = null;
        //Object myDeserializedObject =
readObject(Base64.decode(myParameter));
    }
    public static Object readObject(byte[] bytes) throws IOException,
ClassNotFoundException{
        Object retVal = null;
        ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
        ObjectInputStream ois = null;
        try{
            ois = new ObjectInputStream(bais);
            retVal = ois.readObject();   
        }finally{
            close(bais);
            close(ois);
        }
        return retVal;
    }
    public static byte[] serializeObject(Serializable o) throws IOException{
        byte[] retVal = null;
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        ObjectOutputStream oos = null;
        try{
            oos = new ObjectOutputStream(baos);
            oos.writeObject(o);
            oos.flush();
            retVal = baos.toByteArray();
        }finally{
            close(oos);
            close(baos);    
        }
        return retVal;
    }
    private static void close(OutputStream os){
        if(os != null){
            try{
                os.close();
            }catch(IOException ioex){
                ioex.printStackTrace();   
            }   
        }  
    }
    private static void close(InputStream os){
        if(os != null){
            try{
                os.close();
            }catch(IOException ioex){
                ioex.printStackTrace();   
            }   
        }  
    }
    
}

-----Original Message-----
From: stephane parenton [mailto:[EMAIL PROTECTED]
Sent: 30 July 2003 16:21
To: [EMAIL PROTECTED]
Subject: Re: how one would do to.... the return


John Wilson a �crit:

>It's reasonably easy to do. You can pass Java classes as <base64> elements
>in an XML-RPC message.
>  
>
hi again.... i'm not reasonable ;-) i can't make it work.... my problem 
is the xmlrpc message....

i have a server called wserver, in which i have (the name of sendAgent 
is poorly chosen because it's more likely the receiveAgent...) :
...
server.addHandler( "agent", new sendAgent() );
...
this server runs on the computer i want classes to be updated.


I run a small program within which i have a case calling :

System.out.println(client.getDatas("agent","ecriture",new Vector()));

and i have a class sendAgent in which i have a procedure called 
"ecriture" that should get things and write them to the appropriate 
location....

My problem is probably my understanding of the xml-rpc thing, but here 
what i'm trying to do : I want to send base64 datas as parameters (am i 
right ?). but i don't figure out how and where to send this... is it 
instead of the "new Vector" thing ? I tried to let "ecriture" to have 
parameters, but then i had to change the calling in the 
client.getDatas.... there, i'm lost, mostly because i don't understand 
one thing that may be obvious for you.... can somebody please give me a 
push ?.... ;-)

Thanks in advance
St�phane


***********************************************************************************
This e-mail is intended only for the addressee named above.
As this e-mail may contain confidential or privileged information,
if you are not the named addressee, you are not authorised to
retain, read, copy or disseminate this message or any part of it.
The Royal Bank of Scotland plc is registered in Scotland No 90312
Registered Office: 36 St Andrew Square, Edinburgh EH2 2YB
             Regulated by the Financial Services Authority

            Visit our website at http://www.rbs.co.uk/CBFM/
***********************************************************************************

Reply via email to