Perl -> Java implementation

"amracel" <[email protected]> Fri, 22 Feb 2008 17:52:14 -0000
Newsgroups gmane.text.xml.rpc.specification
Message-ID <[email protected]>
Trying to use some existing Perl code from within Java, I ran across
the following article:

http://www.javaworld.com/javaworld/jw-10-2004/jw-1011-xmlrpc.html

I've implemented the Perl side as suggested:

----
sub createXmlReport {
	my ($first, $pass_data) = @_;
	my $count = 0;
	
	my $retVal;
	#delegate to the legacy method
	use DataExtractor::WtiReportDataExtractor;
	$retVal =
DataExtractor::WtiReportDataExtractor->createXmlReport($pass_data);
	return $retVal;
}
----
$retVal returns an xml document.

I then created the very simple web interface they suggested:

----

use XMLRPC::Transport::HTTP;

my $facadeserver = XMLRPC::Transport::HTTP::CGI
                     ->dispatch_to('DataExtractor::PerlSystemFacade')
                     ->handle;

------

.... which works fine on my test case from Perl:

my %vars = (connection => 'dbi:Pg:dbname=fusion2;host=172.26.20.31',
            server     => 'fusion2',
            login      => 'postgres',
            password   => 'postgres',
            type       => 'News',
            client     => 'WTI',
            start      => '2008-02-12',
            end        => '2008-02-13',
            taxids     => '22,23,24');

print XMLRPC::Lite
	-> proxy('http://localhost/cgi-bin/server.pl')
	-> call('DataExtractor.PerlSystemFacade.createXmlReport, %vars')
	-> result;

-----

But now, when I try to call it from Java, I keep getting a
ClassCastException:

Exception in thread "main" java.lang.ClassCastException:
java.lang.String cannot be cast to java.lang.Integer

I've tried creating the Java client using the Redstone and the Apache
XML-RPC libraries and get the same result.  So I'm guessing the
problem is in the results?  In the call?  I'm not sure what.

Here's the code using the Apache packages:

	public Object get_xml() {
		Integer retVal = null;

		try {
			XmlRpcClient xmlrpc = new XmlRpcClient();
			XmlRpcClientConfigImpl config = new XmlRpcClientConfigImpl();
			config.setServerURL(new URL(SERVER_URL));
			config.setEnabledForExtensions(true);
			xmlrpc.setConfig(config);
			xmlrpc.setTransportFactory(new XmlRpcLiteHttpTransportFactory(
					xmlrpc));

			String methodName = "DataExtractor.PerlSystemFacade.createXmlReport";

			List<HashMap> params = new ArrayList<HashMap>();

			HashMap<String, String> map = new HashMap<String, String>();
			map.put("connection", "dbi:Pg:dbname=fusion2;host=xxx.xx.xx.xxx");
			map.put("server", "fusion2");
			map.put("login", "postgres");
			map.put("password", "postgres");
			map.put("client", "ABC");
			map.put("start", "2008-02-12");
			map.put("end", "2008-02-13");
			map.put("taxids", "22,23,24");

			params.add(map);

			// retVal = xmlrpc.execute(config,methodName,params);
			// retVal = xmlrpc.execute(methodName, params);
			retVal = (Integer) xmlrpc.execute(methodName, new Object[] { map });

		} catch (MalformedURLException me) {
			me.printStackTrace();
		} catch (XmlRpcException xre) {
			xre.printStackTrace();
		} catch (Exception ex) {
			ex.printStackTrace();
		}
		return retVal;
	}

------
Here's the code using the Redstone packages:

	public static void main(String[] args) {
		
		try
		{
			HashMap<String, String> map = new HashMap<String, String>();
			map.put("connection", "dbi:Pg:dbname=fusion2;host=xxx.xx.xx.xxx");
			map.put("server", "fusion2");
			map.put("login", "postgres");
			map.put("password", "postgres");
			map.put("client", "ABC");
			map.put("start", "2008-02-12");
			map.put("end", "2008-02-13");
			map.put("taxids", "22,23,24");
			
			XmlRpcClient client = new XmlRpcClient(SERVER_URL,true);
			Object result = client.invoke(methodName, new Object[] {map});
			System.out.println(result.toString());
		}
		catch(MalformedURLException mx)
		{
			mx.printStackTrace();
		}
		catch(XmlRpcException xr)
		{
			xr.printStackTrace();
		}
		catch(XmlRpcFault xf)
		{
			xf.printStackTrace();
		}

	}
-----

Any ideas?



 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/xml-rpc/

<*> Your email settings:
    Individual Email | Traditional

<*> To change settings online go to:
    http://groups.yahoo.com/group/xml-rpc/join
    (Yahoo! ID required)

<*> To change settings via email:
    mailto:[email protected] 
    mailto:[email protected]

<*> To unsubscribe from this group, send an email to:
    [email protected]

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/