Piotr Kliczewski has uploaded a new change for review.

Change subject: xmlrpc: marshalling of Long type
......................................................................

xmlrpc: marshalling of Long type

The change let people use 64bit numerical type (long) with xmlrpc.
Jsonrpc already supports long type.

There is xmlrpc extension i8 which let people use long type but we do
not want to enable it due to backward compatibility reasons.

In order to use this code developer needs to add method name to
METHOD_LIST. This reduces overhead of type fixing only to known methods.
Long type is normalized to string to let older vdsms understand the
value.

Change-Id: I97ffc2da3703dbf7ce58607b7461a02aea35f2bb
Signed-off-by: pkliczewski <piotr.kliczew...@gmail.com>
---
M 
backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/xmlrpc/XmlRpcUtils.java
1 file changed, 33 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/54/34854/1

diff --git 
a/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/xmlrpc/XmlRpcUtils.java
 
b/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/xmlrpc/XmlRpcUtils.java
index 4ee0723..e0009a9 100644
--- 
a/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/xmlrpc/XmlRpcUtils.java
+++ 
b/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/xmlrpc/XmlRpcUtils.java
@@ -1,11 +1,15 @@
 package org.ovirt.engine.core.vdsbroker.xmlrpc;
 
+import java.io.IOException;
 import java.lang.reflect.InvocationHandler;
 import java.lang.reflect.Method;
 import java.lang.reflect.Proxy;
 import java.lang.reflect.UndeclaredThrowableException;
 import java.net.MalformedURLException;
 import java.net.URL;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
 import java.util.concurrent.Callable;
 import java.util.concurrent.FutureTask;
 import java.util.concurrent.TimeUnit;
@@ -21,10 +25,12 @@
 import org.apache.commons.httpclient.protocol.Protocol;
 import org.apache.commons.httpclient.protocol.ProtocolSocketFactory;
 import org.apache.commons.lang.StringUtils;
+import org.apache.xmlrpc.XmlRpcException;
 import org.apache.xmlrpc.XmlRpcRequest;
 import org.apache.xmlrpc.client.XmlRpcClient;
 import org.apache.xmlrpc.client.XmlRpcClientConfigImpl;
 import org.apache.xmlrpc.client.XmlRpcClientException;
+import org.apache.xmlrpc.client.XmlRpcClientRequestImpl;
 import org.apache.xmlrpc.client.XmlRpcCommonsTransport;
 import org.apache.xmlrpc.client.XmlRpcCommonsTransportFactory;
 import org.apache.xmlrpc.client.XmlRpcTransport;
@@ -39,12 +45,14 @@
 import org.ovirt.engine.core.vdsbroker.vdsbroker.FutureCall;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
+import org.xml.sax.SAXException;
 
 public class XmlRpcUtils {
 
     private static final String HTTP = "http://";;
     private static final String HTTPS = "https://";;
     private static final Logger log = 
LoggerFactory.getLogger(XmlRpcUtils.class);
+    private static final List<String> METHOD_LIST = Arrays.asList("");
     static {
         if (Config.<Boolean> getValue(ConfigValues.EncryptHostCommunication)) {
             URL keystoreUrl;
@@ -269,6 +277,31 @@
                 method.setRequestHeader(FLOW_ID_HEADER_NAME, correlationId);
             }
         }
+
+        @Override
+        protected ReqWriter newReqWriter(XmlRpcRequest pRequest)
+                throws XmlRpcException, IOException, SAXException {
+            if (METHOD_LIST.contains(pRequest.getMethodName())) {
+                pRequest =
+                        new XmlRpcClientRequestImpl(pRequest.getConfig(),
+                                pRequest.getMethodName(),
+                                normalizeDoubles(pRequest));
+            }
+            return super.newReqWriter(pRequest);
+        }
+
+        private Object[] normalizeDoubles(XmlRpcRequest request) {
+            List<Object> result = new ArrayList<>();
+            for (int i = 0; i < request.getParameterCount(); i++) {
+                Object object = request.getParameter(i);
+                if (Long.class.isInstance(object)) {
+                    result.add(object.toString());
+                    continue;
+                }
+                result.add(object);
+            }
+            return result.toArray();
+        }
     };
 
     /**


-- 
To view, visit http://gerrit.ovirt.org/34854
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I97ffc2da3703dbf7ce58607b7461a02aea35f2bb
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-engine
Gerrit-Branch: master
Gerrit-Owner: Piotr Kliczewski <piotr.kliczew...@gmail.com>
_______________________________________________
Engine-patches mailing list
Engine-patches@ovirt.org
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to