ovirt-engine-sdk-java的使⽤过程中的错误整理本篇记录ovirt java sdk的使⽤前准备与使⽤中的⼀些坑。
0、参考⽂档:
java下载过程1、下载ovirt java sdk的jar包
2、下载ine.sdk所需要的依赖包
在ing.sdk下载页⾯下⽅,有着⼀个“Compile Dependencies”表格,是sdk的依赖包。
根据表格中的信息下载相应的版本的jar包。
3、测试使⽤ine.sdk
import ine.sdk.Api;aspenv9
import ptions.ServerException;
import ptions.UnsecuredConnectionAttemptError;
import java.io.IOException;
import java.security.KeyManagementException;
import java.util.List;
public class SdkTest {
private static final String URL = "host/api/";
private static final String USERNAME = "123@hao"; // 普通⽤户账号
private static final String PASSWORD = "123456";
@SuppressWarnings("deprecation")
public static void main(String[] args) throws ClientProtocolException, ServerException,
手机怎么下载网页视频UnsecuredConnectionAttemptError, IOException {
Api api = new Api(URL, USERNAME, PASSWORD);
List<VM> vm = VMs().list();
int len = vm.size();
for (int i = 0; i < len; i ++) {
System.out.printf("%s\n", vm.get(i).getName());
}
try {
api.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
* 注意:“ClientProtocolException”异常是Api类必须的,⽽且是在org.apache.http.client.ClientProtocolException(httpclient 4.2)中。
4、不停的ClassNotFoundException
(1)照理来说,只要将这些jar包放⼊buildpath中,就可以正常使⽤sdk了,但是实际的运⾏结果:
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/http/params/HttpParams
at ine.sdk.Api.<init>(Api.java:596)
at ine.sdk.Api.<init>(Api.java:109)
at SdkTest.main(SdkTest.java:22)
Caused by: java.lang.ClassNotFoundException: org.apache.http.params.HttpParams
at java.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 3 more
显⽰缺少了org.apache.http.params.HttpParams,但是我并没有⽤到这个东西!?
org.apache.http.params.HttpParams ----->>> httpcore-4.2.jar
(2)加⼊了httpcore之后,还没完:
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory
at org.apache.PoolingClientConnectionManager.<init>(PoolingClientConnectionManager.java:73)
at org.apache.PoolingClientConnectionManager.<init>(PoolingClientConnectionManager.java:99)
at org.apache.PoolingClientConnectionManager.<init>(PoolingClientConnectionManager.java:85)
at ine.sdk.atePoolingClientConnectionManager(ConnectionsPoolBuilder.java:314) at ine.sdk.ateDefaultHttpClient(ConnectionsPoolBuilder.java:257)
at ine.sdk.web.ConnectionsPoolBuilder.build(ConnectionsPoolBuilder.java:437)
at ine.sdk.Api.<init>(Api.java:607)
at ine.sdk.Api.<init>(Api.java:109)
at SdkTest.main(SdkTest.java:22)
Caused by: java.lang.ClassNotFoundException: org.apachemons.logging.LogFactory
at java.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 9 more
这次缺的是org.apachemons.logging.LogFactory。有种没完没了的感觉。
org.apachemons.logging.LogFactory ----->>> commons-logging-1.2.jar
(3)⼜加了jar包,再次运⾏程序:
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/codec/binary/Base64
at org.apache.http.impl.auth.BasicScheme.authenticate(BasicScheme.java:186)
at org.apache.http.impl.auth.BasicScheme.authenticate(BasicScheme.java:158)
at org.apache.http.client.protocol.RequestAuthenticationBase.authenticate(RequestAuthenticationBase.java:125) at org.apache.http.client.protocol.RequestAuthenticationBase.process(RequestAuthenticationBase.java:83) at org.apache.http.client.protocol.RequestTargetAuthentication.process(RequestTargetAuthentication.java:80) at org.apache.http.protocol.ImmutableHttpProcessor.process(ImmutableHttpProcessor.java:109)
at org.apache.http.protocol.HttpRequestExecutor.preProcess(HttpRequestExecutor.java:176)
at org.apache.http.impl.ute(DefaultRequestDirector.java:516)
at org.apache.http.impl.ute(AbstractHttpClient.java:906)
at org.apache.http.impl.ute(AbstractHttpClient.java:805)
at ine.sdk.ute(ConnectionsPool.java:97)
at ine.sdk.ute(HttpProxy.java:114)
at ine.sdk.(HttpProxyBroker.java:415)
at ine.sdk.(HttpProxyBroker.java:394)
at ine.EntryPoint(Api.java:653)
at ine.sdk.Api.initResources(Api.java:665)
at ine.sdk.Api.<init>(Api.java:615)
at ine.sdk.Api.<init>(Api.java:109)
java 定义数组at SdkTest.main(SdkTest.java:22)
Caused by: java.lang.ClassNotFoundException: dec.binary.Base64
at java.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
.
.. 19 more
是真的没完没了!?⼜缺了包!这次是dec.binary.Base64。到底是哪⾥⽤到了这东西dec.binary.Base64 ----->>> commons-codec-1.10.jar
5、创建Api代理过程中的错误
(1)执⾏上⾯的代码,没有ClassNotFoundException。但是出现了500服务器错误。
Exception in thread "main"
code : 500
reason: Internal Server Error
detail: <html><head><title>Error</title></head><body>Internal Server Error</body></html>
html引入外部js文件的方法at ine.sdk.ute(HttpProxy.java:120)
at ine.sdk.(HttpProxyBroker.java:415)
at ine.sdk.(HttpProxyBroker.java:394)
at ine.EntryPoint(Api.java:653)
at ine.sdk.Api.initResources(Api.java:665)
at ine.sdk.Api.<init>(Api.java:615)
at ine.sdk.Api.<init>(Api.java:109)
at SdkTest.main(SdkTest.java:25)
不知道具体原因。代码中使⽤的是普通账号,但是该账号和密码在ovirt engine上能成功登录。
后来使⽤管理员账号登录绕过了这个问题。
(2)管理员账号登录失败,因为证书验证失败
Exception in thread "main" javax.ssl.SSLPeerUnverifiedException: peer not authenticated
at sun.security.PeerCertificates(Unknown Source)
at org.ssl.AbstractVerifier.verify(AbstractVerifier.java:128)
at org.tSocket(SSLSocketFactory.java:572)
at org.apache.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:180) at org.apache.ManagedClientConnectionImpl.open(ManagedClientConnectionImpl.java:294)
at org.apache.http.impl.Connect(DefaultRequestDirector.java:641)
at org.apache.http.impl.ute(DefaultRequestDirector.java:480)
at org.apache.http.impl.ute(AbstractHttpClient.java:906)
at org.apache.http.impl.ute(AbstractHttpClient.java:805)
at ine.sdk.ute(ConnectionsPool.java:97)
at ine.sdk.ute(HttpProxy.java:114)
at ine.sdk.(HttpProxyBroker.java:415)
武汉java培训机构在这⾥采⽤的解决⽅法是将ovirt engine的证书添加到jre的证书库中。
⾸先将下载好的crt证书复制到jre的安装⽬录下的bin⽬录中。
然后,在bin⽬录下打开cmd,执⾏命令:
D:\Software\Java\jre1.8\bin>keytool -import -v -trustcacerts -alias svcloud - -storepass changeit -keystore D:/Software/Java/jre1.8/lib/sec
urity/cacerts
所有者: CN=svcloud.casvip.46215, O=casvip, C=US
发布者: CN=svcloud.casvip.46215, O=casvip, C=US
序列号: 1000
有效期为 Wed Sep 12 10:43:25 CST 2018 ⾄ Sun Sep 10 10:43:25 CST 2028
证书指纹:
MD5: 35:B2:6F:79:15:29:7C:C3:39:D3:89:BC:1B:CA:08:38
SHA1: 05:62:9C:41:42:92:2D:ED:07:86:FF:01:AD:4F:49:1E:1C:83:F3:B2
SHA256: 99:37:BF:A9:CC:0B:FA:3C:C1:76:34:DA:71:22:02:2B:32:93:D4:D9:8B:
46:30:C6:B7:CC:CB:D9:08:B9:60:BD
签名算法名称: SHA256withRSA
主体公共密钥算法: 2048 位 RSA 密钥
版本: 3
。。。
是否信任此证书? [否]: y
证书已添加到密钥库中
[正在存储D:/Software/Java/jre1.8/lib/security/cacerts]
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论