HTTPS是HTTP和安全协议的联合,用于访问敏感的信息。HTTPS在正常的协议之上创建一个安全传输层,
Client与Server之间的交互需要通过Certificate Authorities (CA)进行。下面展示一个例子:
完整代码参考http://springsfeng.iteye.com/blog/1634753附件。
1. 创建接口和实现类
import javax.jws.WebService;
@WebService
public interface OrderProcess {
String processOrder(Order order);
}
import javax.jws.WebService;
@WebService(portName = "OrderProcessSSLPort")
public class OrderProcessImpl implements OrderProcess {
public String processOrder(Order order) {
System.out.println("Processing order...");
String orderID = validate(order);
return orderID;
}
/**
* Validates the order and returns the order ID
**/
private String validate(Order order) {
String custID = order.getCustomerID();
String itemID = order.getItemID();
int qty = order.getQty();
double price = order.getPrice();
if (custID != null && itemID != null && qty > 0 && price > 0.0) {
return "ORD1234";
}
return null;
}
}
2. 创建一个密钥
keytool -genkey -alias Tomcat -keyalg RSA -storepass changeit -keypass changeit -keystore \
orderprocess.jks -dname "cn=localhost"
3. 创建服务器端和客户端配置文件
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:jaxws="http://cxf.apache.org/jaxws"
xmlns:http-conf="http://cxf.apache.org/transports/http/configuration"
xsi:schemaLocation="
http://cxf.apache.org/transports/http/configuration
http://cxf.apache.org/schemas/configuration/http-conf.xsd
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://cxf.apache.org/jaxws
http://cxf.apache.org/schemas/jaxws.xsd">
<import resource="classpath:META-INF/cxf/cxf.xml" />
<import resource="classpath:META-INF/cxf/cxf-extension-soap.xml" />
<import resource="classpath:META-INF/cxf/cxf-servlet.xml" />
<jaxws:endpoint id="orderProcess"
implementor="org.pbdp.sample.https.OrderProcessImpl"
address="/OrderProcess" />
</beans>
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:sec="http://cxf.apache.org/configuration/security"
xmlns:jaxws="http://cxf.apache.org/jaxws"
xmlns:http-conf="http://cxf.apache.org/transports/http/configuration"
xsi:schemaLocation="
http://cxf.apache.org/configuration/security
http://cxf.apache.org/schemas/configuration/security.xsd
http://cxf.apache.org/transports/http/configuration
http://cxf.apache.org/schemas/configuration/http-conf.xsd
http://cxf.apache.org/jaxws
http://cxf.apache.org/schemas/jaxws.xsd
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd">
<jaxws:client id="orderClient" serviceClass="org.pbdp.sample.https.OrderProcess"
address="https://localhost:8443/ws/OrderProcess" />
<http-conf:conduit name="*.http-conduit">
<http-conf:tlsClientParameters secureSocketProtocol="SSL">
<sec:trustManagers>
<sec:keyStore type="JKS" password="changeit"
file="/home/fdc/orderprocess.jks" />
</sec:trustManagers>
</http-conf:tlsClientParameters>
</http-conf:conduit>
</beans>
4. 配置服务器以支持SSL
配置文件:TOMCAT_HOME/conf/server.xml:
<Connector port="8443" maxHttpHeaderSize="8192"
maxThreads="150" minSpareThreads="25"
maxSpareThreads="75"
enableLookups="false" disableUploadTimeout="true"
acceptCount="100" scheme="https" secure="true"
clientAuth="false" sslProtocol="TLS"
keystoreFile="/home/fdc/orderprocess.jks"
keystorePass="changeit"/>
5. 开发客户端组件
import org.pbdp.sample.https.Order;
import org.pbdp.sample.https.OrderProcess;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public final class Client {
public Client() {
}
public static void main(String args[]) throws Exception {
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
new String[] { "org/pbdp/sample/https/client/client-bean.xml" });
OrderProcess client = (OrderProcess) context.getBean("orderClient");
Order order = new Order();
order.setCustomerID("C001");
order.setItemID("I001");
order.setQty(100);
order.setPrice(200.00);
String orderID = client.processOrder(order);
String message = (orderID == null) ? "Order not approved": "Order approved; order ID is " + orderID;
System.out.println(message);
System.exit(0);
}
}
分享到:
相关推荐
赠送jar包:cxf-rt-rs-client-3.0.1.jar; 赠送原API文档:cxf-rt-rs-client-3.0.1-javadoc.jar; 赠送源代码:cxf-rt-rs-client-3.0.1-sources.jar; 赠送Maven依赖信息文件:cxf-rt-rs-client-3.0.1.pom; 包含...
赠送jar包:cxf-rt-frontend-jaxrs-3.0.1.jar; 赠送原API文档:cxf-rt-frontend-jaxrs-3.0.1-javadoc.jar; 赠送源代码:cxf-rt-frontend-jaxrs-3.0.1-sources.jar; 赠送Maven依赖信息文件:cxf-rt-frontend-jaxrs...
赠送jar包:cxf-rt-transports-http-3.0.1.jar; 赠送原API文档:cxf-rt-transports-http-3.0.1-javadoc.jar; 赠送源代码:cxf-rt-transports-http-3.0.1-sources.jar; 赠送Maven依赖信息文件:cxf-rt-transports-...
赠送jar包:cxf-rt-frontend-simple-3.0.1.jar; 赠送原API文档:cxf-rt-frontend-simple-3.0.1-javadoc.jar; 赠送源代码:cxf-rt-frontend-simple-3.0.1-sources.jar; 赠送Maven依赖信息文件:cxf-rt-frontend-...
赠送jar包:cxf-rt-frontend-jaxws-3.0.1.jar; 赠送原API文档:cxf-rt-frontend-jaxws-3.0.1-javadoc.jar; 赠送源代码:cxf-rt-frontend-jaxws-3.0.1-sources.jar; 赠送Maven依赖信息文件:cxf-rt-frontend-jaxws...
赠送jar包:cxf-rt-bindings-soap-3.0.1.jar; 赠送原API文档:cxf-rt-bindings-soap-3.0.1-javadoc.jar; 赠送源代码:cxf-rt-bindings-soap-3.0.1-sources.jar; 赠送Maven依赖信息文件:cxf-rt-bindings-soap-...
赠送jar包:cxf-core-3.0.1.jar; 赠送原API文档:cxf-core-3.0.1-javadoc.jar; 赠送源代码:cxf-core-3.0.1-sources.jar; 赠送Maven依赖信息文件:cxf-core-3.0.1.pom; 包含翻译后的API文档:cxf-core-3.0.1-...
cxf-rt-frontend-jaxws-3.0.16.jar jar包下载3.0.16版本下载
赠送jar包:cxf-rt-rs-extension-providers-3.0.1.jar; 赠送原API文档:cxf-rt-rs-extension-providers-3.0.1-javadoc.jar; 赠送源代码:cxf-rt-rs-extension-providers-3.0.1-sources.jar; 赠送Maven依赖信息...
赠送jar包:cxf-rt-bindings-xml-3.0.1.jar; 赠送原API文档:cxf-rt-bindings-xml-3.0.1-javadoc.jar; 赠送源代码:cxf-rt-bindings-xml-3.0.1-sources.jar; 赠送Maven依赖信息文件:cxf-rt-bindings-xml-3.0.1....
赠送jar包:cxf-rt-ws-addr-3.0.1.jar; 赠送原API文档:cxf-rt-ws-addr-3.0.1-javadoc.jar; 赠送源代码:cxf-rt-ws-addr-3.0.1-sources.jar; 赠送Maven依赖信息文件:cxf-rt-ws-addr-3.0.1.pom; 包含翻译后的API...
cxf-core-3.0.0.jar,cxf-rt-bindings-soap-3.0.0.jar,cxf-rt-databinding-jaxb-3.0.0.jar,cxf-rt-frontend-jaxws-3.0.0.jar,cxf-rt-frontend-simple-3.0.0.jar,cxf-rt-transports-http-3.0.0.jar,cxf-rt-...
此外,还有其他如`cxf-rt-bindings-soap.jar`、`cxf-rt-databinding-jaxb.jar`、`cxf-rt-rs-extension-providers.jar`等,它们分别对应于不同的功能,如SOAP绑定、JAXB数据绑定和RESTful服务的提供者扩展。...
在本案例中,我们讨论的是"apache-cxf-3.4.3.tar.gz",这是Apache CXF 3.4.3版本的压缩包,通常包含了CXF框架的所有组件和必要的库文件。 **1. CXF框架介绍** Apache CXF是一个全面的服务开发框架,它的全称是...
综上所述,"cxf-rt-transports-http-jetty-3.0.2.zip"和"jcabi-aspects.zip"分别是Apache CXF框架的一个组件和一个Java注解库,它们都为Java开发者提供了强大的工具,以更高效和灵活的方式构建和管理Web服务及应用...
<import resource="classpath:META-INF/cxf/cxf.xml"/> <import resource="classpath:META-INF/cxf/cxf-extension-soap.xml"/> <import resource="classpath:META-INF/cxf/cxf-servlet.xml"/>
cxf-dosgi-ri-singlebundle-distribution-1.4.0.jar
"apache-cxf-3.5.0.zip" 文件包含了CXF框架的3.5.0版本,该版本可能包含了一些新特性、改进和错误修复。 1. **Apache CXF 框架概述** Apache CXF 是基于Java的,它允许开发者以Java编程语言来创建并暴露Web服务。...
cxf-core-3.0.15.jar cxf-rt-bindings-soap-3.0.15.jar cxf-rt-bindings-xml-3.0.15.jar cxf-rt-databinding-jaxb-3.0.15.jar cxf-rt-frontend-jaxws-3.0.15.jar cxf-rt-frontend-simple-3.0.15.jar cxf-rt-...
赠送jar包:cxf-rt-ws-policy-3.0.1.jar; 赠送原API文档:cxf-rt-ws-policy-3.0.1-javadoc.jar; 赠送源代码:cxf-rt-ws-policy-3.0.1-sources.jar; 赠送Maven依赖信息文件:cxf-rt-ws-policy-3.0.1.pom; 包含...