bbtforumserviceencsignclient.java

来自「spring企业级开发电子书籍.......」· Java 代码 · 共 52 行

JAVA
52
字号
package com.baobaotao.xfire.wss4j.client;

import java.lang.reflect.Proxy;
import java.net.MalformedURLException;
import java.util.Properties;

import org.apache.ws.security.handler.WSHandlerConstants;
import org.codehaus.xfire.client.Client;
import org.codehaus.xfire.client.XFireProxy;
import org.codehaus.xfire.client.XFireProxyFactory;
import org.codehaus.xfire.security.wss4j.WSS4JOutHandler;
import org.codehaus.xfire.service.Service;
import org.codehaus.xfire.service.binding.ObjectServiceFactory;
import org.codehaus.xfire.util.dom.DOMOutHandler;

import com.baobaotao.xfire.server.BbtForumService;

public class BbtForumServiceEncSignClient {
	private static XFireProxyFactory serviceFactory = new XFireProxyFactory();
	public static void main(String[] args) {
		Service serviceModel = new ObjectServiceFactory().create(BbtForumService.class);
		
		try {
			String serviceURL = "http://localhost:8088/baobaotao/service/BbtForumServiceEncSign";
			BbtForumService service =  (BbtForumService) serviceFactory.create(serviceModel, serviceURL);

			Client client = ((XFireProxy)Proxy.getInvocationHandler(service)).getClient();
			client.addOutHandler(new DOMOutHandler());
			
			Properties properties = new Properties();
			//加密
			properties.setProperty(WSHandlerConstants.ACTION, WSHandlerConstants.ENCRYPT + " "
	                + WSHandlerConstants.SIGNATURE);
		    properties.setProperty(WSHandlerConstants.ENCRYPTION_USER, "server");	
			properties.setProperty(WSHandlerConstants.ENC_PROP_FILE,
					"com/baobaotao/xfire/wss4j/client/outsecurity_enc.properties");
            //签名
			properties.setProperty(WSHandlerConstants.USER, "client");
			properties.setProperty(WSHandlerConstants.PW_CALLBACK_CLASS, PasswordHandler.class.getName());
			properties.setProperty(WSHandlerConstants.SIG_PROP_FILE, "com/baobaotao/xfire/wss4j/client/outsecurity_sign.properties");
			properties.setProperty(WSHandlerConstants.SIG_KEY_ID, "IssuerSerial");
			
			client.addOutHandler(new WSS4JOutHandler(properties));
			
			int count = service.getRefinedTopicCount(20);
		    System.out.println("count:"+count);
		} catch (MalformedURLException e) {
			e.printStackTrace();
		}
	}
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?