cainiaoxiaohei 2020-11-06 20:22 采纳率: 0%
浏览 424

rampart报Unsupported or unrecognized SSL异常?

rampart1.7.1自带的示例代码,sample-tomcat搭建之后,第一次能够正常运行客户端代码。

第二次再次执行的时候,抛org.apache.axis2.AxisFault: javax.net.ssl.SSLException: Unsupported or unrecognized SSL message异常。

org.apache.axis2.AxisFault: javax.net.ssl.SSLException: Unsupported or unrecognized SSL message
	at org.apache.axis2.AxisFault.makeFault(AxisFault.java:430)
	at org.apache.axis2.transport.http.SOAPMessageFormatter.writeTo(SOAPMessageFormatter.java:78)
	at org.apache.axis2.transport.http.AxisRequestEntity.writeRequest(AxisRequestEntity.java:85)
	at org.apache.commons.httpclient.methods.EntityEnclosingMethod.writeRequestBody(EntityEnclosingMethod.java:499)
	at org.apache.commons.httpclient.HttpMethodBase.writeRequest(HttpMethodBase.java:2114)
	at org.apache.commons.httpclient.HttpMethodBase.execute(HttpMethodBase.java:1096)
	at org.apache.commons.httpclient.HttpMethodDirector.executeWithRetry(HttpMethodDirector.java:398)
	at org.apache.commons.httpclient.HttpMethodDirector.executeMethod(HttpMethodDirector.java:171)
	at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:397)
	at org.apache.axis2.transport.http.impl.httpclient3.HTTPSenderImpl.executeMethod(HTTPSenderImpl.java:872)
	at org.apache.axis2.transport.http.impl.httpclient3.HTTPSenderImpl.sendViaPost(HTTPSenderImpl.java:212)
	at org.apache.axis2.transport.http.HTTPSender.send(HTTPSender.java:121)
	at org.apache.axis2.transport.http.CommonsHTTPTransportSender.writeMessageWithCommons(CommonsHTTPTransportSender.java:403)
	at org.apache.axis2.transport.http.CommonsHTTPTransportSender.invoke(CommonsHTTPTransportSender.java:234)
	at org.apache.axis2.engine.AxisEngine.send(AxisEngine.java:431)
	at org.apache.axis2.description.OutInAxisOperationClient.send(OutInAxisOperation.java:399)
	at org.apache.axis2.description.OutInAxisOperationClient.executeImpl(OutInAxisOperation.java:225)
	at org.apache.axis2.client.OperationClient.execute(OperationClient.java:150)
	at org.apache.axis2.client.ServiceClient.sendReceive(ServiceClient.java:533)
	at org.apache.axis2.client.ServiceClient.sendReceive(ServiceClient.java:509)
	at org.apache.rampart.tomcat.sample.Client.main(Client.java:79)
Caused by: javax.xml.stream.XMLStreamException: javax.net.ssl.SSLException: Unsupported or unrecognized SSL message
	at java.xml/com.sun.xml.internal.stream.writers.XMLStreamWriterImpl.flush(XMLStreamWriterImpl.java:398)
	at org.apache.axiom.util.stax.wrapper.XMLStreamWriterWrapper.flush(XMLStreamWriterWrapper.java:50)
	at org.apache.axiom.om.impl.MTOMXMLStreamWriter.flush(MTOMXMLStreamWriter.java:231)
	at org.apache.axiom.om.impl.MTOMXMLStreamWriter.close(MTOMXMLStreamWriter.java:223)
	at org.apache.axiom.om.impl.common.AxiomContainerSupport.ajc$interMethod$org_apache_axiom_om_impl_common_AxiomContainerSupport$org_apache_axiom_om_impl_intf_AxiomContainer$serializeAndConsume(AxiomContainerSupport.aj:324)
	at org.apache.axiom.om.impl.dom.NSAwareElement.serializeAndConsume(NSAwareElement.java:1)
	at org.apache.axis2.transport.http.SOAPMessageFormatter.writeTo(SOAPMessageFormatter.java:74)
	... 19 more
Caused by: javax.net.ssl.SSLException: Unsupported or unrecognized SSL message
	at java.base/sun.security.ssl.SSLSocketInputRecord.handleUnknownRecord(SSLSocketInputRecord.java:440)
	at java.base/sun.security.ssl.SSLSocketInputRecord.decode(SSLSocketInputRecord.java:175)
	at java.base/sun.security.ssl.SSLTransport.decode(SSLTransport.java:110)
	at java.base/sun.security.ssl.SSLSocketImpl.decode(SSLSocketImpl.java:1196)
	at java.base/sun.security.ssl.SSLSocketImpl.readHandshakeRecord(SSLSocketImpl.java:1105)
	at java.base/sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:399)
	at java.base/sun.security.ssl.SSLSocketImpl.ensureNegotiated(SSLSocketImpl.java:725)
	at java.base/sun.security.ssl.SSLSocketImpl$AppOutputStream.write(SSLSocketImpl.java:1010)
	at java.base/java.io.BufferedOutputStream.flushBuffer(BufferedOutputStream.java:81)
	at java.base/java.io.BufferedOutputStream.flush(BufferedOutputStream.java:142)
	at org.apache.commons.httpclient.ChunkedOutputStream.flush(ChunkedOutputStream.java:191)
	at java.xml/com.sun.xml.internal.stream.writers.UTF8OutputStreamWriter.flush(UTF8OutputStreamWriter.java:138)
	at java.xml/com.sun.xml.internal.stream.writers.XMLStreamWriterImpl.flush(XMLStreamWriterImpl.java:396)
	... 25 more

在浏览器中访问webservice,https://localhost:8443/rampart/services/SimpleService?wsdl,也是报ERR_SSL_PROTOCOL_ERROR的错误。

这个问题困扰两天了,哪位大神能帮帮忙,拜托了。

1.客户端代码

/*
 * Copyright 2004,2005 The Apache Software Foundation.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.apache.rampart.tomcat.sample;

import java.util.Iterator;
import java.util.List;

import org.apache.axiom.om.OMAbstractFactory;
import org.apache.axiom.om.OMElement;
import org.apache.axiom.om.OMFactory;
import org.apache.axiom.om.OMNamespace;
import org.apache.axiom.om.impl.builder.StAXOMBuilder;
import org.apache.axis2.addressing.EndpointReference;
import org.apache.axis2.client.Options;
import org.apache.axis2.client.ServiceClient;
import org.apache.axis2.context.ConfigurationContext;
import org.apache.axis2.context.ConfigurationContextFactory;
import org.apache.axis2.transport.http.HTTPConstants;
import org.apache.neethi.Assertion;
import org.apache.neethi.Policy;
import org.apache.neethi.PolicyEngine;
import org.apache.rampart.RampartMessageData;

import javax.xml.namespace.QName;

public class Client {

	public static void main(String[] args) throws Exception {
		ServiceClient client = null;

		/*
		 * if(args.length != 3) { System.out.
		 * println("Usage: $java Client endpoint_address client_repo_path policy_xml_path"
		 * ); }
		 */

		
		/*
		 * System.setProperty("javax.net.ssl.keyStore",
		 * "D:\\Goodjob\\eclipse\\workspace\\rampart\\build\\client.jks");
		 * System.setProperty("javax.net.ssl.keyStorePassword", "apache");
		 */
		 

		ConfigurationContext ctx = ConfigurationContextFactory.createConfigurationContextFromFileSystem("build", null);
		/*
		 * ctx.setProperty(HTTPConstants.REUSE_HTTP_CLIENT, Boolean.TRUE);
		 */

		client = new ServiceClient(ctx, null);
		Options options = new Options();

		options.setAction("urn:echo");
		options.setTo(new EndpointReference("https://localhost:8443/rampart/services/SimpleService"));
		options.setProperty(RampartMessageData.KEY_RAMPART_POLICY,
				loadPolicy("build/client_repository/conf/policy.xml"));
		
		options.setManageSession(true);
		options.setProperty(HTTPConstants.REUSE_HTTP_CLIENT,true);
		
		client.setOptions(options);

		client.engageModule("addressing");
		client.engageModule("rampart");
		OMElement response = client.sendReceive(getPayload("Hello world"));
		System.out.println(response);
		client.cleanupTransport();
//		client.disengageModule("addressing");
//		client.disengageModule("rampart");

	}

	private static Policy loadPolicy(String xmlPath) throws Exception {
		StAXOMBuilder builder = new StAXOMBuilder(xmlPath);
		OMElement elem = builder.getDocumentElement();
		return PolicyEngine.getPolicy(builder.getDocumentElement());
	}

	private static OMElement getPayload(String value) {
		OMFactory factory = OMAbstractFactory.getOMFactory();
		OMNamespace ns = factory.createOMNamespace("http://sample.tomcat.rampart.apache.org", "ns1");
		OMElement elem = factory.createOMElement("echo", ns);
		OMElement childElem = factory.createOMElement("arg", null);
		childElem.setText(value);
		elem.addChild(childElem);
		return elem;
	}

}

2.客户端配置文件policy.xml

<?xml version="1.0" encoding="UTF-8"?>
<wsp:Policy wsu:Id="UTOverTransport" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy">
	<wsp:ExactlyOne>
	  <wsp:All>
		<sp:TransportBinding xmlns:sp="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy">
		  <wsp:Policy>
			<sp:TransportToken>
			  <wsp:Policy>
				<sp:HttpsToken RequireClientCertificate="false"/>
			  </wsp:Policy>
			</sp:TransportToken>
			<sp:AlgorithmSuite>
			  <wsp:Policy>
				<sp:Basic128/>
			  </wsp:Policy>
			</sp:AlgorithmSuite>
			<sp:Layout>
			  <wsp:Policy>
				<sp:Lax/>
			  </wsp:Policy>
			</sp:Layout>
			<sp:IncludeTimestamp/>
		  </wsp:Policy>
		</sp:TransportBinding>
		<sp:SignedSupportingTokens xmlns:sp="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy">
			<wsp:Policy>
				<sp:UsernameToken sp:IncludeToken="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy/IncludeToken/AlwaysToRecipient" />
		  </wsp:Policy>
		</sp:SignedSupportingTokens>
		
		<ramp:RampartConfig xmlns:ramp="http://ws.apache.org/rampart/policy"> 
			<ramp:user>alice</ramp:user>
			<ramp:passwordCallbackClass>org.apache.rampart.tomcat.sample.PWCBHandler</ramp:passwordCallbackClass>
<!-- 			<ramp:sslConfig> 
 				<ramp:property name="javax.net.ssl.trustStore">build\client.jks</ramp:property>
        			<ramp:property name="javax.net.ssl.trustStorePassword">apache</ramp:property>
			</ramp:sslConfig> -->
		</ramp:RampartConfig>
		
	  </wsp:All>
	</wsp:ExactlyOne>
</wsp:Policy>

3.webservice配置文件services.xml

<?xml version="1.0" encoding="UTF-8"?>
<!--
 !
 ! Copyright 2006 The Apache Software Foundation.
 !
 ! Licensed under the Apache License, Version 2.0 (the "License");
 ! you may not use this file except in compliance with the License.
 ! You may obtain a copy of the License at
 !
 !      http://www.apache.org/licenses/LICENSE-2.0
 !
 ! Unless required by applicable law or agreed to in writing, software
 ! distributed under the License is distributed on an "AS IS" BASIS,
 ! WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 ! See the License for the specific language governing permissions and
 ! limitations under the License.
 !-->
<!-- services.xml of sample-1 : UsernameToken-->
<service>
	<operation name="echo">
		<messageReceiver class="org.apache.axis2.rpc.receivers.RPCMessageReceiver"/>
	</operation>    
	<parameter name="ServiceClass" locked="false">org.apache.rampart.tomcat.sample.SimpleService</parameter>
	
	<module ref="rampart" />
	<module ref="addressing" />

	<wsp:Policy wsu:Id="UTOverTransport" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy">
		<wsp:ExactlyOne>
		  <wsp:All>
			<sp:TransportBinding xmlns:sp="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy">
			  <wsp:Policy>
				<sp:TransportToken>
				  <wsp:Policy>
					<sp:HttpsToken RequireClientCertificate="false"/>
				  </wsp:Policy>
				</sp:TransportToken>
				<sp:AlgorithmSuite>
				  <wsp:Policy>
					<sp:Basic128/>
				  </wsp:Policy>
				</sp:AlgorithmSuite>
				<sp:Layout>
				  <wsp:Policy>
					<sp:Lax/>
				  </wsp:Policy>
				</sp:Layout>
				<sp:IncludeTimestamp/>
			  </wsp:Policy>
			</sp:TransportBinding>
			<sp:SignedSupportingTokens xmlns:sp="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy">
				<wsp:Policy>
					<sp:UsernameToken sp:IncludeToken="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy/IncludeToken/AlwaysToRecipient" />
			  </wsp:Policy>
			</sp:SignedSupportingTokens>
			
			<ramp:RampartConfig xmlns:ramp="http://ws.apache.org/rampart/policy"> 
				<ramp:passwordCallbackClass>org.apache.rampart.tomcat.sample.PWCBHandler</ramp:passwordCallbackClass>
			</ramp:RampartConfig>
			
		  </wsp:All>
		</wsp:ExactlyOne>
	</wsp:Policy>

</service>

 

  • 写回答

2条回答 默认 最新

  • cainiaoxiaohei 2020-11-08 17:49
    关注

    Help!

    评论

报告相同问题?

悬赏问题

  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 LiBeAs的带隙等于0.997eV,计算阴离子的N和P
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 来真人,不要ai!matlab有关常微分方程的问题求解决,
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算