Mule ESB 学习笔记(15)CXF SOAP基于JKS的验证的配置

阅读更多

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;
/**
 * 
 * 

功能描述,该部分必须以中文句号结尾。

* * 创建日期 2013-8-27
* @author $Author$
* @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 getUsernameTokenProps(String action, String propertiesFile) { Map wss4jProps = new HashMap(); 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 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,SOA,EIP,Cxf,JKS)