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>


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM