XCP-ng
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Register
    • Login

    Java SDK, XmlRpcClientException: Failed to parse server's response: Duplicate name: restrict_vtpm

    Scheduled Pinned Locked Moved REST API
    6 Posts 3 Posters 378 Views 2 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • S Offline
      Serwetka
      last edited by Danp

      Hi!

      The issue concerns working with the XenServer SDK in Java, problem arose upon starting work with the latest version XCP 8.3, and error occurred:

      Caused by: org.apache.xmlrpc.client.XmlRpcClientException: Failed to parse server's response: Duplicate name: restrict_vtpm
      	at org.apache.xmlrpc.client.XmlRpcStreamTransport.readResponse(XmlRpcStreamTransport.java:188) ~[engine.jar:?]
      	at org.apache.xmlrpc.client.XmlRpcStreamTransport.sendRequest(XmlRpcStreamTransport.java:156) ~[engine.jar:?]
      	at org.apache.xmlrpc.client.XmlRpcHttpTransport.sendRequest(XmlRpcHttpTransport.java:143) ~[engine.jar:?]
      	at org.apache.xmlrpc.client.XmlRpcSunHttpTransport.sendRequest(XmlRpcSunHttpTransport.java:69) ~[engine.jar:?]
      	at org.apache.xmlrpc.client.XmlRpcClientWorker.execute(XmlRpcClientWorker.java:56) ~[engine.jar:?]
      	at org.apache.xmlrpc.client.XmlRpcClient.execute(XmlRpcClient.java:167) ~[engine.jar:?]
      	at org.apache.xmlrpc.client.XmlRpcClient.execute(XmlRpcClient.java:137) ~[engine.jar:?]
      	at org.apache.xmlrpc.client.XmlRpcClient.execute(XmlRpcClient.java:126) ~[engine.jar:?]
      	at com.xensource.xenapi.Connection.dispatch(Connection.java:216) ~[engine.jar:?]
      	at com.xensource.xenapi.Host.getAllRecords(Host.java:3831) ~[engine.jar:?]
      

      The API sends this value twice in the method:

      Host.getAllRecords(connector)
      (package com.xensource.xenapi;)

      Everything else happens under the hood of the library, and I don't have access there, but when debugging, I did indeed discover that the second restrict_vtpm field is being returned.

      restrict.png

      I found the MapParser (package org.apache.xmlrpc.parser;) addResult method doesn't allow working with two identical fields:

      protected void addResult(Object pResult) throws SAXException {
      	    if (inName) {
      	        nameObject = pResult;
              } else {
                  if (nameObject == null) {
          			throw new SAXParseException("Invalid state: Expected name",
          										getDocumentLocator());
          		} else {
          			if (map.containsKey(nameObject)) {
          				throw new SAXParseException("Duplicate name: " + nameObject,
          											getDocumentLocator());
          			} else {
          				map.put(nameObject, pResult);
          			}
          		}
              }
      	}
      

      So, the Java libraries don't allow this behavior.

      I started looking for this setting in XCP UI and CLI but couldn't find any specific restriction related to vTPM. My searches also didn't yield any results.

      Thus, I have no access to the internals of the library, nor do I have control over this setting. Could you suggest please what could be done in this case? Could this issue be related to my use of an old version of your SDK (xenserver-7.6.0)?

      If so, is there any way I can fix it without updating the library? (I have too many dependencies tied to it already.)

      Thanks in advance and have a nice day!

      DanpD 1 Reply Last reply Reply Quote 0
      • DanpD Offline
        Danp Pro Support Team @Serwetka
        last edited by

        Hi @Serwetka

        I'm not sure that I understand your situation, so you may want to clarify your operating environment and what you are wanting to accomplish. Are you using the Xenserver SDK to communicate with XCP-ng?

        Regards,

        Dan

        S 1 Reply Last reply Reply Quote 0
        • S Offline
          Serwetka @Danp
          last edited by olivierlambert

          @Danp
          I'm using XCP-ng 8.3 Latest on VmWare, I'm trying to get all host on my environment. Yes, I'm using the Xenserver SDK to get all hosts, and for such purposes this method used to work great:

          public static Map<Host, Record> getAllRecords(Connection var0) throws Types.BadServerResponse, Types.XenAPIException, XmlRpcException {
                  String var1 = "host.get_all_records";
                  String var2 = var0.getSessionReference();
                  Object[] var3 = new Object[]{Marshalling.toXMLRPC(var2)};
                  Map var4 = var0.dispatch(var1, var3);
                  Object var5 = var4.get("Value");
                  return Types.toMapOfHostHostRecord(var5);
              }
          

          From Host class from Xenserver SDK, but with 8.3 it doesn't work.

          DanpD 1 Reply Last reply Reply Quote 0
          • DanpD Offline
            Danp Pro Support Team @Serwetka
            last edited by

            @Serwetka It isn't realistic IMO to expect the SDK from XS 7.6 to work in this scenario. Do you know if this works with XS 8.3 or newer?Have you tried using an updated version of the Xenserver SDK to see if the issue is still present?

            FWIW, we have REST APIs that you can use -- https://xen-orchestra.com/docs/restapi.html

            1 Reply Last reply Reply Quote 1
            • P Offline
              pxn
              last edited by

              Hi,

              i have same issue when adding XCP-ng 8.3 host to CloudStack 4.19.1.3 (pool with single host):

              cloudstack log:

              2024-11-28 15:24:31,812 INFO  [c.c.r.ResourceManagerImpl] (qtp660017404-16:ctx-2963461b ctx-f5077d60) (logid:c31fbed3) Trying to add a new host at http://10.1.253.118 in data
               center 1
              2024-11-28 15:24:31,865 WARN  [c.c.h.x.d.XcpServerDiscoverer] (qtp660017404-16:ctx-2963461b ctx-f5077d60) (logid:c31fbed3) Xml Rpc Exception
              org.apache.xmlrpc.client.XmlRpcClientException: Failed to parse server's response: Duplicate name: restrict_vtpm
                      at org.apache.xmlrpc.client.XmlRpcStreamTransport.readResponse(XmlRpcStreamTransport.java:188)
                      at org.apache.xmlrpc.client.XmlRpcStreamTransport.sendRequest(XmlRpcStreamTransport.java:156)
                      at org.apache.xmlrpc.client.XmlRpcHttpTransport.sendRequest(XmlRpcHttpTransport.java:143)
                      at org.apache.xmlrpc.client.XmlRpcSunHttpTransport.sendRequest(XmlRpcSunHttpTransport.java:69)
                      at org.apache.xmlrpc.client.XmlRpcClientWorker.execute(XmlRpcClientWorker.java:56)
                      at org.apache.xmlrpc.client.XmlRpcClient.execute(XmlRpcClient.java:167)
                      at org.apache.xmlrpc.client.XmlRpcClient.execute(XmlRpcClient.java:137)
                      at org.apache.xmlrpc.client.XmlRpcClient.execute(XmlRpcClient.java:126)
                      at com.xensource.xenapi.Connection.dispatch(Connection.java:330)
                      at com.xensource.xenapi.Host.getAllRecords(Host.java:3251)
                      at com.cloud.hypervisor.xenserver.discoverer.XcpServerDiscoverer.find(XcpServerDiscoverer.java:237)
              

              i've API call packet capture an i found that 'pool.get_record' section 'restrictions' has only one ocurence of 'restrict_vtpm'
              but 'host.get_all_records' section 'license_params' has 'restrict_vtpm' twice, same as 'xe host-license-view' output.

              Petr

              S 1 Reply Last reply Reply Quote 0
              • S Offline
                Serwetka @pxn
                last edited by Serwetka

                @pxn said in Java SDK, XmlRpcClientException: Failed to parse server's response: Duplicate name: restrict_vtpm:

                If you still encounter this issue - I found the way to bypass it.
                You can create your own mapper by extending on RecursiveTypeParserImpl and just copy-paste logic from MapParser (package org.apache.xmlrpc.parser;), except that logic of checking duplication, then you can inject custom parser to your custom factory (Extend TypeFactoryImpl and override getParser method). And inject this Factory to your client

                new XmlRpcClient().setTypeFactory(new CustomFactory(client));
                

                This works fine for me, I hope this could help you.

                Alex

                1 Reply Last reply Reply Quote 0
                • First post
                  Last post