mule的配置如下:
<mule xmlns:core="http://www.mulesoft.org/schema/mule/core" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:spring="http://www.springframework.org/schema/beans" xmlns:cxf="http://www.mulesoft.org/schema/mule/cxf" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation" xmlns:http="http://www.mulesoft.org/schema/mule/http" xsi:schemaLocation=" http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd http://www.mulesoft.org/schema/mule/cxf http://www.mulesoft.org/schema/mule/cxf/current/mule-cxf.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd " version="EE-3.3.0"> <flow name="UsernameTokenSignedServiceFlow" doc:name="UsernameTokenSignedServiceFlow"> <http:inbound-endpoint address="http://localhost:63083/services/signed" exchange-pattern="request-response" doc:name="HTTP Inbound Endpoint"/> <cxf:jaxws-service serviceClass="com.mulesoft.mule.soap.security.Greeter" doc:name="Secure UsernameToken Signed service"> <cxf:ws-security> <cxf:ws-config> <cxf:property key="action" value="UsernameToken Signature Timestamp"/> <cxf:property key="signaturePropFile" value="wssecurity.properties"/> <cxf:property key="passwordCallbackClass" value="com.mulesoft.mule.soap.security.PasswordCallback"/> </cxf:ws-config> </cxf:ws-security> </cxf:jaxws-service> <component class="com.mulesoft.mule.soap.security.GreeterService" doc:name="Greeter Service"/> </flow> <flow name="UsernameTokenEncryptedServiceFlow" doc:name="UsernameTokenEncryptedServiceFlow"> <http:inbound-endpoint address="http://localhost:63083/services/encrypted" exchange-pattern="request-response" doc:name="HTTP Inbound Endpoint"/> <cxf:jaxws-service serviceClass="com.mulesoft.mule.soap.security.Greeter" doc:name="Secure UsernameToken Encrypted service"> <cxf:ws-security> <cxf:ws-config> <cxf:property key="action" value="UsernameToken Timestamp Encrypt"/> <cxf:property key="decryptionPropFile" value="wssecurity.properties"/> <cxf:property key="passwordCallbackClass" value="com.mulesoft.mule.soap.security.PasswordCallback"/> </cxf:ws-config> </cxf:ws-security> </cxf:jaxws-service> <component class="com.mulesoft.mule.soap.security.GreeterService" doc:name="Greeter Service"/> </flow> </mule>
服务端测试:
import org.mule.api.MuleContext; import org.mule.api.MuleException; import org.mule.api.context.MuleContextFactory; import org.mule.config.spring.SpringXmlConfigurationBuilder; import org.mule.context.DefaultMuleContextFactory; public class MuleServerApp { public static void main(String[] args) throws MuleException { String configFile = "mule-config.xml"; System.setProperty("mule.verbose.exceptions","true"); String[] configFileArr = new String[] {configFile }; MuleContextFactory muleContextFactory = new DefaultMuleContextFactory(); MuleContext muleContext = muleContextFactory .createMuleContext(new SpringXmlConfigurationBuilder(configFileArr)); muleContext.start(); } }
客户端测试:
package com.mulesoft.mule.soap.test; import java.net.MalformedURLException; import java.net.URL; import java.util.HashMap; import java.util.Map; import javax.xml.namespace.QName; import javax.xml.ws.Service; import javax.xml.ws.soap.SOAPFaultException; import org.apache.cxf.endpoint.Client; import org.apache.cxf.frontend.ClientProxy; import org.apache.cxf.ws.security.wss4j.WSS4JOutInterceptor; import com.mulesoft.mule.soap.security.Greeter; import com.mulesoft.mule.soap.security.PasswordCallback; /** * * <p>功能描述,该部分必须以中文句号结尾。<p> * * 创建日期 2013-8-27<br> * @author $Author$<br> * @version $Revision$ $Date$ * @since 3.0.0 */ public class MuleSecureClient { public static void main(String[] args) throws Exception { try { Greeter service = createService("http://localhost:63083/services/signed?wsdl", getUsernameTokenProps("UsernameToken Signature Timestamp", "wssecurity.properties")); System.out.println(service.greet("Mule")); service = createService("http://localhost:63083/services/encrypted?wsdl", getUsernameTokenProps("UsernameToken Timestamp Encrypt", "wssecurity.properties")); System.out.println(service.greet("Mule")); } catch (SOAPFaultException e) { System.out.println(e.getMessage()); } } protected static Map<String, Object> getUsernameTokenProps(String action, String propertiesFile) { Map<String, Object> wss4jProps = new HashMap<String, Object>(); wss4jProps.put("action", action); wss4jProps.put("signaturePropFile", propertiesFile); wss4jProps.put("encryptionPropFile", propertiesFile); wss4jProps.put("user", "joe"); wss4jProps.put("encryptionUser", "joe"); wss4jProps.put("passwordCallbackClass", PasswordCallback.class.getName()); return wss4jProps; } public static Greeter createService(String url, Map<String, Object> wss4jProps) { URL wsdlDocumentLocation; try { wsdlDocumentLocation = new URL(url); } catch (MalformedURLException e) { throw new RuntimeException("Invalid test definition", e); } QName serviceName = new QName("http://security.soap.mule.mulesoft.com/", "GreeterService"); Service dynService = Service.create(wsdlDocumentLocation, serviceName); Greeter service = dynService.getPort(Greeter.class); Client client = ClientProxy.getClient(service); if (wss4jProps != null) { client.getOutInterceptors().add(new WSS4JOutInterceptor(wss4jProps)); } return service; } }
相关推荐
Mule ESB 是一个轻量级的基于java的企业服务总线和集成平台, 使得开发人员可以快速,简单的连接多个应用, 使得它们可以交换数据。 Mule ESB 容易集成现有异构系统,包括:JMS, Web Services, JDBC, HTTP, 等. ESB...
Mule ESB 项目在Linux中的部署与开发与应用案例
文档主要介绍了Mule ESB的使用方法,并结合具体实例加深对ESB的理解,对新手很有帮助哦!
MuleESB是一个基于Java的轻量级企业服务总线和集成平台,允许开发人员快速便利地连接多个应用,并支持应用间的数据交换。MuleESB支持集成现有系统而无论其底层采用何种技术,如JMS、WebServices、JDBC、HTTP以及其他...
Mule ESB应用部署 Mule ESB应用的目录结构,配置文件说明
ESB原理及Mule ESB实践
mule,mule esb,Mule,ESB
MuleESB3.0 属于轻量级的消息框架和整合平台,mule云
mule esb开发手册
mule esb 项目 例子 入门
MuleESB集成webservice+restful(sprintboot+mybatis+mysql)+activeMQ+javamail,五天的研究成果,集成了我所关注的点,希望有更多的朋友一起学习进步。
mule esb mule esb 开发工具
MuleEsb开源框架简介.pdf
mule esb mule esb打包手册文档
NULL 博文链接:https://topmanopensource.iteye.com/blog/1931175
企业服务总线(Mule ESB)的研究与实现
mule esb 的 简单介绍, 以及一些主要特性的介绍
MuleESB_3.0_中文教程