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
SUPPORTED_METHODS_FOR_LONG_CONVERSION collection. 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 <[email protected]>
Bug-Url: https://bugzilla.redhat.com/1145621
---
M 
backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/xmlrpc/XmlRpcUtils.java
1 file changed, 36 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/74/35274/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 efc6b90..62907f6 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,17 @@
 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.HashSet;
+import java.util.List;
+import java.util.Set;
 import java.util.concurrent.Callable;
 import java.util.concurrent.FutureTask;
 import java.util.concurrent.TimeUnit;
@@ -21,10 +27,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 +47,15 @@
 import org.ovirt.engine.core.utils.ssl.AuthSSLProtocolSocketFactory;
 import org.ovirt.engine.core.utils.threadpool.ThreadPoolUtil;
 import org.ovirt.engine.core.vdsbroker.vdsbroker.FutureCall;
+import org.xml.sax.SAXException;
+
 
 public class XmlRpcUtils {
 
     private static final String HTTP = "http://";;
     private static final String HTTPS = "https://";;
     private static final Log log = LogFactory.getLog(XmlRpcUtils.class);
+    private static final Set<String> SUPPORTED_METHODS_FOR_LONG_CONVERSION = 
new HashSet<String>(Arrays.asList(""));
     static {
         if (Config.<Boolean> getValue(ConfigValues.EncryptHostCommunication)) {
             URL keystoreUrl;
@@ -269,6 +280,31 @@
                 method.setRequestHeader(FLOW_ID_HEADER_NAME, correlationId);
             }
         }
+
+        @Override
+        protected ReqWriter newReqWriter(XmlRpcRequest pRequest)
+                throws XmlRpcException, IOException, SAXException {
+            if 
(SUPPORTED_METHODS_FOR_LONG_CONVERSION.contains(pRequest.getMethodName())) {
+                pRequest =
+                        new XmlRpcClientRequestImpl(pRequest.getConfig(),
+                                pRequest.getMethodName(),
+                                normalizeLongs(pRequest));
+            }
+            return super.newReqWriter(pRequest);
+        }
+
+        private Object[] normalizeLongs(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/35274
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I97ffc2da3703dbf7ce58607b7461a02aea35f2bb
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-engine
Gerrit-Branch: ovirt-engine-3.5
Gerrit-Owner: Piotr Kliczewski <[email protected]>
_______________________________________________
Engine-patches mailing list
[email protected]
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to