java.rmi.RemoteException: VI SDK invoke exception:org.dom4j.DocumentException: Error on line 1 of document : Content is not allowed in prolog. Nested exception: Content is not allowed in prolog.

背景

项目使用VMware vSphere 在软件升级前进行snapshot。

问题

java.rmi.RemoteException: VI SDK invoke exception:org.dom4j.DocumentException: Error on line 1 of document : Content is not allowed in prolog. Nested exception: Content is not allowed in prolog.

Research

凭个人直觉,认定是对方升级了VM Server。(不要问为啥不通知)
那就找找现在的版本是哪个,如何查看版本

Starting with vSphere 4.0, information about the supported API versions is contained in an XML file, vimServiceVersions.xml, located on the server (see Service-Versions File (vimServiceVersions.xml)). You can access this file with the URL https://server_hostname/sdk/vimServiceVersions.xml.
ref: https://vdc-repo.vmware.com/vmwb-repository/dcr-public/5c1c7b8c-0d1b-4037-af84-5f43787eb378/fab98b61-56a7-4608-992f-818d3b40e4ae/GUID-75B9897E-551B-4C08-B382-A616A007A07D.html

Service-Versions File (vimServiceVersions.xml)
<?xml version="1.0" encoding="UTF-8" ?>
- <!--    Copyright 2008-2010 VMware, Inc.  All rights reserved. -->
- <namespaces version="1.0">
     - <namespace>
            <name>urn:vim25</name>
            <version>5.0</version>
     - <priorVersions>
          <version>2.5u2</version>
          <version>2.5</version>
       </priorVersions>
     </namespace>
     - <namespace>
          <name>urn:vim2</name>
          <version>2.0</version>
       </namespace>
  </namespaces>

查了一下,7.0.2.0

那会不会客户端使用的vijava版本也有更新?
Maven仓库一找,好家伙,仅此一版本,就是当前在使用的版本。

https://mvnrepository.com/artifact/com.vmware/vijava

那会不会这个7.x版本是新升级的,导致vijava.jar不支持了?
关键词确定为:vijava vsphere 7

果然有问题,见

https://segmentfault.com/a/1190000039928502

文中提到了官方的通知

vSphere 7.0 中的 HTTP 反向代理强制实施比以前版本更严格的标准合规性。这可能导致在应用程序用于对 vSphere 执行 SOAP 调用的某些第三方库中出现预先存在的问题。
如果您开发使用此类库的 vSphere 应用程序,或者在 vSphere 堆栈中包含依赖于此类库的应用程序,那么当这些库向 VMOMI 发送 HTTP 请求时,可能会遇到连接问题。例如,从 vijava 库发出的 HTTP 请求可能采用以下形式:
POST /sdk HTTP/1.1
SOAPAction
Content-Type: text/xml; charset=utf-8
User-Agent: Java/1.8.0_221
此示例中的语法违反了在 SOAPAction 后必须使用冒号的 HTTP 协议标头字段要求。因此,请求在执行时被拒绝。
解决办法:在应用程序中利用不合规库的开发人员可以考虑改为使用遵循 HTTP 标准的库。例如,使用 vijava 库的开发人员可以考虑改为使用最新版本的 yavijava 库。
ref:https://docs.vmware.com/cn/VMware-vSphere/7.0/rn/vsphere-esxi-vcenter-server-70-release-notes.html

解决

使用yavijava.jar替换vijava.jar.

https://github.com/yavijava/yavijava

  1. 下载jar
    https://mvnrepository.com/artifact/com.toastcoders/yavijava

  2. 安装jar
    mvn install:install-file -Dfile=PATH/yavijava-6.0.05.jar -DgroupId=com.toastcoders -DartifactId=yavijava -Dversion=6.0.05 -Dpackaging=jar

  3. 引用jar

<dependency>
    <groupId>com.toastcoders</groupId>
    <artifactId>yavijava</artifactId>
    <version>6.0.05</version>
</dependency>
posted @ 2021-10-21 21:58  talentzemin  阅读(1596)  评论(0编辑  收藏  举报