gpt4 book ai didi

java - 如何为 MarkLogic 7 建立 SSL 连接?

转载 作者:行者123 更新时间:2023-12-01 12:59:40 25 4
gpt4 key购买 nike

我想按照此 http://docs.marklogic.com/guide/admin/SSL

建立 SSL 连接

但我遇到以下异常:

Exception in thread "main" com.marklogic.xcc.exceptions.ServerConnectionException: Unrecognized SSL message, plaintext connection? [Session: user=demo, cb=Arg [ContentSource: user=demo, cb=Arg [provider: SSLconn address=localhost/127.0.0.1:9470, pool=0/64]]] [Client: XCC/7.0-2] at com.marklogic.xcc.impl.handlers.AbstractRequestController.runRequest(AbstractRequestController.java:124) at com.marklogic.xcc.impl.SessionImpl.submitRequestInternal(SessionImpl.java:388) at com.marklogic.xcc.impl.SessionImpl.submitRequest(SessionImpl.java:371) at com.demoe2.MarklogicDemo.main(MarklogicDemo.java:41) Caused by: javax.net.ssl.SSLException: Unrecognized SSL message, plaintext connection? at sun.security.ssl.EngineInputRecord.bytesInCompletePacket(Unknown Source) at sun.security.ssl.SSLEngineImpl.readNetRecord(Unknown Source) at sun.security.ssl.SSLEngineImpl.unwrap(Unknown Source

我的源代码适用于 Java

public class MarklogicDemo {

public static void main(String[] args) throws Exception {
URI uri = new URI("xcc://demo:password@localhost:9470/Arg");
query = "for $x in cts:search(//PLAY,cts:element-word-query(xs:QName(\"LINE\"),\"King\")) return ($x//TITLE)";
ContentSource con =
ContentSourceFactory.newContentSource(
"localhost", 9470,
"demo", "password",
"Arg", newTrustOptions());
Session see = con.newSession();
Request req = see.newAdhocQuery(query);
ResultSequence rs = see.submitRequest (req);
System.out.println (rs.asString());
see.close();
}

protected static SecurityOptions newTrustOptions() throws Exception {
TrustManager[] trust =
new TrustManager[] {
new X509TrustManager() {
public void checkClientTrusted(
X509Certificate[] x509Certificates,
String s) throws CertificateException {
}

public void checkServerTrusted(
X509Certificate[] x509Certificates,
String s) throws CertificateException {
}
public X509Certificate[] getAcceptedIssuers() {
return null;
}
}
};
SSLContext sslContext = SSLContext.getInstance("SSLv3");
sslContext.init(null, trust, null);
return new SecurityOptions(sslContext);
}

}

最佳答案

在连接 URL 中,使用 xccs 而不是 xcc

您还可以查看https://github.com/marklogic/xqsync/blob/1cf82faa2fa2e7fb3fa06f41e0938bf5b002b7fa/src/java/com/marklogic/ps/Connection.java#L100查看同时处理 xccxccs 的示例。

关于java - 如何为 MarkLogic 7 建立 SSL 连接?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23607912/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com