gpt4 book ai didi

java - 无法发送 48681 字节的消息来保护来自 java 的 wcf 服务

转载 作者:塔克拉玛干 更新时间:2023-11-03 05:33:34 27 4
gpt4 key购买 nike

我必须使用相互身份验证从 java 调用安全的 WCF 服务。一切正常,除了我无法发送大于 48680 字节的消息。因此,48680 字节的消息已成功发送,但 48681 字节的消息未成功发送,Java 应用程序因读取超时异常而失败,尽管 WCF 的配额设置允许更大的消息。

那么可能是什么问题呢?


编辑

源代码:

package foo.bar;

import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
import org.junit.Test;

import javax.net.ssl.*;
import java.io.*;
import java.net.URL;
import java.security.KeyStore;

public class ReadTimedOutTest {

@Test
public void testReadTimedOut() throws Exception {
URL url = new URL("https://services/endpoint/");

HttpsURLConnection connection = (HttpsURLConnection) url.openConnection();
setUpSSL(connection);
connection.setDoOutput(true);
connection.setDoInput(true);
connection.setRequestMethod("POST");
connection.setRequestProperty("SOAPAction", "http://namespace/2012/01/service/Operation");
connection.setRequestProperty("Accept", "*/*");
connection.setRequestProperty("Connection", "Keep-Alive");
connection.setRequestProperty("Content-Type", "text/xml; charset=utf-8");

connection.setConnectTimeout(10 * 1000);
connection.setReadTimeout(10 * 1000);
connection.setInstanceFollowRedirects(true);

ByteArrayOutputStream bos = new ByteArrayOutputStream();
InputStream is = ReadTimedOutTest.class.getResourceAsStream("payload.failure.xml");
try {
IOUtils.copy(is, bos);
} finally {
is.close();
}
byte[] bytes = bos.toByteArray();
connection.setRequestProperty("Content-Length", String.valueOf(bytes.length));

OutputStream os = connection.getOutputStream();
try {
IOUtils.copy(new ByteArrayInputStream(bytes), os);
os.flush();
} finally {
os.close();
}

int respCode = connection.getResponseCode();
if(respCode >= HttpsURLConnection.HTTP_INTERNAL_ERROR) {
is = connection.getErrorStream();
try {
IOUtils.copy(is, System.err);
} finally {
is.close();
}
} else {
is = connection.getInputStream();
try {
IOUtils.copy(is, System.out);
} finally {
is.close();
}
}
}

private void setUpSSL(HttpsURLConnection connection) throws Exception {
byte[] bytes = FileUtils.readFileToByteArray(new File("d:\\workspace\\temp\\keystore"));
KeyStore keyStore = KeyStore.getInstance("JKS");
keyStore.load(new ByteArrayInputStream(bytes), "changeit".toCharArray());
KeyManagerFactory keyManagerFactory = KeyManagerFactory.getInstance("X509");
keyManagerFactory.init(keyStore, "changeit".toCharArray());

bytes = FileUtils.readFileToByteArray(new File("d:\\workspace\\temp\\truststore"));
KeyStore trustStore = KeyStore.getInstance("JKS");
trustStore.load(new ByteArrayInputStream(bytes), "changeit".toCharArray());
TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance("X509");
trustManagerFactory.init(trustStore);

SSLContext context = SSLContext.getInstance("TLS");
context.init(keyManagerFactory.getKeyManagers(), trustManagerFactory.getTrustManagers(), null);
SSLSocketFactory socketFactory = context.getSocketFactory();

connection.setSSLSocketFactory(socketFactory);
}

}

更新

我已经用 .net WCF 客户端测试了该服务,它能够成功调用该服务,所以我想知道可能是什么问题?为什么 WCF 客户端能够调用服务和 Java 客户端,即使使用带有 UrlConnection 的普通 HTTP POST 请求,也不能?


更新

这是肥皂消息的示例

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<DoSomethingUseful xmlns="http://namespace/2012/01/service">
...
</DoSomethingUseful>
</soap:Body>
</soap:Envelope>

更新

有人告诉我在 .net 服务端有 "Client certificate is required. No certificate was found in the request"似乎在 ssl session 恢复时出现的消息。只有当 Content-Length 大于 48680 字节时才会发生。WCF 服务还配置了 basicHttpBinding 以使用传输级安全性。

最佳答案

您是否尝试查看正在发送的实际数据包 - 例如。使用 tcpdump/Wireshark ( http://www.wireshark.org/ ) ?

我曾经只在某些平台上遇到过问题,该平台访问的是非常挑剔的 SSL 卸载引擎背后的服务。

关于java - 无法发送 48681 字节的消息来保护来自 java 的 wcf 服务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9046593/

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