我有以下客户端使用在 tomcat(本地主机)上运行的 Web 服务
客户端
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.xml.ws.BindingProvider;
import javax.xml.ws.handler.MessageContext;
public class NewClass {
static {
//for localhost testing only
javax.net.ssl.HttpsURLConnection.setDefaultHostnameVerifier(
new javax.net.ssl.HostnameVerifier(){
public boolean verify(String hostname,
javax.net.ssl.SSLSession sslSession) {
if (hostname.equals("localhost")) {
return true;
}
return false;
}
});
}
public static void main(String[] args) {
System.out.println(receive(5));
}
private static java.util.List<java.lang.Object> receive(int resNumber) {
System.setProperty("javax.net.ssl.trustStore","c:\\mylocalhost.jks"); //path to jks
System.setProperty("javax.net.ssl.trustStorePassword","****"); //path to jks
System.setProperty("javax.net.ssl.keyStore","c:\\myclient.jks"); //path to jks
System.setProperty("javax.net.ssl.keyStorePassword","*****"); //path to jks
System.setProperty("javax.net.debug","all");
client.NewWebService_Service service = new client.NewWebService_Service();
client.NewWebService port = service.getNewWebServicePort();
java.util.Map<String,Object> rmap = ((BindingProvider)port).getRequestContext();
java.util.Map<String,List<String>> header= new HashMap();
header.put("Username", Collections.singletonList("1"));
header.put("Password", Collections.singletonList("1"));
rmap.put(MessageContext.HTTP_REQUEST_HEADERS , header);
rmap.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY,"https://localhost:8443/WSTest1/NewWebService");
return port.receiveData(resNumber);
}
}
现在在 tomcat 上我在 server.xml 中有以下内容
<Connector port="8443" protocol="org.apache.coyote.http11.Http11NioProtocol"
maxThreads="150" SSLEnabled="true"
keystoreFile="conf/mytomcatkeystore.jks" clientAuth="false" scheme="https" secure="true"
/>
我正在使用以下选项来启动 tomcat
set JAVA_OPTS="-Djavax.net.ssl.trustStore=file:///c:/mylocalhost.jks" "-Djavax.net.ssl.trustStorePassword=****" "-Djavax.net.debug=all"
现在,当 clientAuth="false"
时,通过 ssl 的 Web 服务调用工作正常,但是如果
我在 server.xml 中设置 clientAuth="true"
我收到以下错误。
com.sun.xml.ws.client.ClientTransportException: HTTP transport error: javax.net.ssl.SSLException: Unrecognized SSL message, plaintext connection?
试图在许多网站上搜索解决方案 - 但没有成功。 如果有人可以提供帮助 - 将不胜感激。
最佳答案
好的。经过许多令人沮丧的时间,我终于找到了解决方案,感谢 this所以发帖。
所以解决方案是注释掉 server.xml
中的以下行
<Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on" />
关于java web 服务 jax-ws 客户端身份验证 Tomcat 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40148049/