You are viewing a plain text version of this content. The canonical link for it is here.
Posted to xmlrpc-dev@ws.apache.org by BlackMage <ds...@uncw.edu> on 2010/01/17 21:16:37 UTC

XML-RPC Return Hash Map

I am having problem with a Java program that calls a Perl/CGI Script, creates
a hash and returns. A simple example looks like this:

Perl Script:

[code]

sub createHash{

%hashTable = ();

$hashTable{"first"} = 1; # inserts a new hash table entry with key="first"
and value=1
$hashTable{"second"} = 2; # new entry with key="second" and value=2

return %hashTable;

}#end createHash

[/code]

Java Program

{code}

public void getHash(){
		
		HashMap hashmap=new HashMap();
		Vector params = new Vector();
		
		//Create Variables
    	try {
			XmlRpcClient xmlrpc = new XmlRpcClient(SERVER_URL);
			
			//Set Strings
        	        String methodName = "MyProgram.createHash";
           
            
           
        	System.out.println(xmlrpc.execute( methodName, params));
                //The line below is commented out because it throws an error
                //hashmap=(HashMap) xmlrpc.execute( methodName, params);
		
    	
    	
    	} catch (MalformedURLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (XmlRpcException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
    	
    	
    	

	}//end class

{code}


The problems are this, when, I System.out.print the return hash created in
Perl, is only prints out the last value. When I cast the return value to a
Java Hash, it throws a string execption.

So how do I return a hash table or multiple values from a perl program?
-- 
View this message in context: http://old.nabble.com/XML-RPC-Return-Hash-Map-tp27202339p27202339.html
Sent from the Apache Xml-RPC - Dev mailing list archive at Nabble.com.


Re: XML-RPC Return Hash Map

Posted by BlackMage <ds...@uncw.edu>.
Thanks! That solved the problem perfectly!



Jochen Wiedmann wrote:
> 
> It is more than likely that you ought to use a hash *reference*, not a
> hash. In other words:
> 
>   $hashTable = {};
>   $hashTable->{"first"} = 1;
>   $hashTable->{"second"} = 2;
>   return $hashTable;
> 
> 
> 
> 
> On Sun, Jan 17, 2010 at 9:16 PM, BlackMage <ds...@uncw.edu> wrote:
>>
>> I am having problem with a Java program that calls a Perl/CGI Script,
>> creates
>> a hash and returns. A simple example looks like this:
>>
>> Perl Script:
>>
>> [code]
>>
>> sub createHash{
>>
>> %hashTable = ();
>>
>> $hashTable{"first"} = 1; # inserts a new hash table entry with
>> key="first"
>> and value=1
>> $hashTable{"second"} = 2; # new entry with key="second" and value=2
>>
>> return %hashTable;
>>
>> }#end createHash
>>
>> [/code]
>>
>> Java Program
>>
>> {code}
>>
>> public void getHash(){
>>
>>                HashMap hashmap=new HashMap();
>>                Vector params = new Vector();
>>
>>                //Create Variables
>>        try {
>>                        XmlRpcClient xmlrpc = new
>> XmlRpcClient(SERVER_URL);
>>
>>                        //Set Strings
>>                        String methodName = "MyProgram.createHash";
>>
>>
>>
>>                System.out.println(xmlrpc.execute( methodName, params));
>>                //The line below is commented out because it throws an
>> error
>>                //hashmap=(HashMap) xmlrpc.execute( methodName, params);
>>
>>
>>
>>        } catch (MalformedURLException e) {
>>                        // TODO Auto-generated catch block
>>                        e.printStackTrace();
>>                } catch (XmlRpcException e) {
>>                        // TODO Auto-generated catch block
>>                        e.printStackTrace();
>>                } catch (IOException e) {
>>                        // TODO Auto-generated catch block
>>                        e.printStackTrace();
>>                }
>>
>>
>>
>>
>>        }//end class
>>
>> {code}
>>
>>
>> The problems are this, when, I System.out.print the return hash created
>> in
>> Perl, is only prints out the last value. When I cast the return value to
>> a
>> Java Hash, it throws a string execption.
>>
>> So how do I return a hash table or multiple values from a perl program?
>> --
>> View this message in context:
>> http://old.nabble.com/XML-RPC-Return-Hash-Map-tp27202339p27202339.html
>> Sent from the Apache Xml-RPC - Dev mailing list archive at Nabble.com.
>>
>>
> 
> 
> 
> -- 
> Germanys national anthem is the most boring in the world - how telling!
> 
> 

-- 
View this message in context: http://old.nabble.com/XML-RPC-Return-Hash-Map-tp27202339p27211863.html
Sent from the Apache Xml-RPC - Dev mailing list archive at Nabble.com.


Re: XML-RPC Return Hash Map

Posted by Jochen Wiedmann <jo...@gmail.com>.
It is more than likely that you ought to use a hash *reference*, not a
hash. In other words:

  $hashTable = {};
  $hashTable->{"first"} = 1;
  $hashTable->{"second"} = 2;
  return $hashTable;




On Sun, Jan 17, 2010 at 9:16 PM, BlackMage <ds...@uncw.edu> wrote:
>
> I am having problem with a Java program that calls a Perl/CGI Script, creates
> a hash and returns. A simple example looks like this:
>
> Perl Script:
>
> [code]
>
> sub createHash{
>
> %hashTable = ();
>
> $hashTable{"first"} = 1; # inserts a new hash table entry with key="first"
> and value=1
> $hashTable{"second"} = 2; # new entry with key="second" and value=2
>
> return %hashTable;
>
> }#end createHash
>
> [/code]
>
> Java Program
>
> {code}
>
> public void getHash(){
>
>                HashMap hashmap=new HashMap();
>                Vector params = new Vector();
>
>                //Create Variables
>        try {
>                        XmlRpcClient xmlrpc = new XmlRpcClient(SERVER_URL);
>
>                        //Set Strings
>                        String methodName = "MyProgram.createHash";
>
>
>
>                System.out.println(xmlrpc.execute( methodName, params));
>                //The line below is commented out because it throws an error
>                //hashmap=(HashMap) xmlrpc.execute( methodName, params);
>
>
>
>        } catch (MalformedURLException e) {
>                        // TODO Auto-generated catch block
>                        e.printStackTrace();
>                } catch (XmlRpcException e) {
>                        // TODO Auto-generated catch block
>                        e.printStackTrace();
>                } catch (IOException e) {
>                        // TODO Auto-generated catch block
>                        e.printStackTrace();
>                }
>
>
>
>
>        }//end class
>
> {code}
>
>
> The problems are this, when, I System.out.print the return hash created in
> Perl, is only prints out the last value. When I cast the return value to a
> Java Hash, it throws a string execption.
>
> So how do I return a hash table or multiple values from a perl program?
> --
> View this message in context: http://old.nabble.com/XML-RPC-Return-Hash-Map-tp27202339p27202339.html
> Sent from the Apache Xml-RPC - Dev mailing list archive at Nabble.com.
>
>



-- 
Germanys national anthem is the most boring in the world - how telling!