Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I pass an object using xmlrpc in java

Tags:

java

xml-rpc

I want to pass an object using xmlrpc as this is the only possible way it seems that I can pass an Integer and a String to a method on the server. Is it possible to do this using an object? If not is there some other way of doing it?

I have attempted to do it but am getting this error:

JavaClient: XML-RPC Consumer Fault #java.io.IOException: unsupported Java type: class Client.Article

This is the code on the client side:

public void addHash()
{
    try {
            addAuthorName = txtAddAuthorName.getText();
            int addArticleNumber = Integer.parseInt(txtAddArticleNumber.getText()); 
            newArticle = new Article(addAuthorName, addArticleNumber);

        Vector<Object> addArticleArglist = new Vector<Object>();
        addArticleArglist.addElement(newArticle);
        System.out.println(newArticle);

        // make the call
        String callit = ("GetSize.addHash");
        articleID = (Integer) client.execute(callit, addArticleArglist);
    } // Use XmlRpcException errors
    catch (XmlRpcException exception) {
        System.err.println("JavaClient: XML-RPC Consumer Fault #"
                + Integer.toString(exception.code) + ": "
                + exception.getCause() + "" + exception.toString());
    } catch (Exception exception) {
        System.err.println("JavaClient: XML-RPC Consumer Fault #" + exception.toString());
    }

}

This is the code on the server side however by using System.out.println I have discovered that for whatever reason none of the code within this method is being executed:

public void addHash(Article newArticle)
   {
       theHashtable.addHash(newArticle.getArticleName(), newArticle.getAuthorID());
   }
like image 472
Chris Bennett Avatar asked Mar 07 '26 18:03

Chris Bennett


1 Answers

Assuming you are using ws-xmlrpc the documentation states the following:

DOM nodes, or JAXB objects, can be transmitted. So are objects implementing the java.io.Serializable interface.

So by declaring your object serializable you would be able to transmit it. Depending what you want to do it might be a good idea to take a good look at jaxb.

See http://ws.apache.org/xmlrpc/ for more info.

like image 146
jontro Avatar answered Mar 09 '26 08:03

jontro



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!