Java调用webservice

1,JWS

import java.io.UnsupportedEncodingException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import javax.xml.namespace.QName;
import javax.xml.ws.Service;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import com.crc.util.ConfigPropertiesUtil;
import com.sun.org.apache.xml.internal.security.utils.Base64;

public class CASignUtil
{
	private static Log log = LogFactory.getLog(CASignUtil.class);
	private static final String namespace = "http://signservice.itrus.com/";

	public static List<String> getSignInfo(String inPlaintext) throws UnsupportedEncodingException, MalformedURLException
	{
		log.info("CA start");
		
		List<String> outList = new ArrayList<String>();

		String username = ConfigPropertiesUtil.getValueByKey("sign.username");
		String password = ConfigPropertiesUtil.getValueByKey("sign.password");
		
		URL webserviceURL = new URL(ConfigPropertiesUtil.getValueByKey("sign.webserviceURL"));
		QName serviceQName = new QName(namespace, "ICASignService");
		Service service = Service.create(webserviceURL, serviceQName);
		TmsICASignDelegate signDelegate = service.getPort(new QName(namespace, "ICASignPort"), TmsICASignDelegate.class);

		if(signDelegate.isKeyStoreExist())
		{
			signDelegate.checkPassWord(password);
			
			String signCertSN = signDelegate.getSignCertificateSerialnumber(username);
			outList.add(signCertSN);
			
			System.out.println("Certificate[".concat(username).concat("] SerialNumber:".concat(signCertSN)));
			
			byte[] signData = signDelegate.sign(inPlaintext.getBytes("UTF-8"), username);
			String signString = Base64.encode(signData);
			outList.add(signString);
			
			System.out.println("s---->" + signString);
		}
		else
		{
			log.info("CA: Service can not find the keystore for using.");
		}

		log.info("CA end");
		return outList;
	}
}
<service name="ICASignService">
<port binding="tns:ICASignPortBinding" name="ICASignPort">
<soap:address location="http://10.0.63.155:8088/signportal/ICASignPort"/>
</port>
</service>


2,AXIS2

Object[] args = new Object[3];
args[0] = inPlaintextBase64;
args[1] = signInfo.get(1);
args[2] = signInfo.get(0);
Object[] tmsResult = this.sendTMSWebService(configBean.getMcUrl(), "impbill", args);

public Object[] sendTMSWebService(String webServiceURl, String method, Object[] args) throws AxisFault
	{
		RPCServiceClient client = new RPCServiceClient();
		Options options = client.getOptions();
		EndpointReference epr = new EndpointReference(webServiceURl);
		options.setTo(epr);
		options.setTimeOutInMilliSeconds(10 * 60 * 1000);
		QName qname = new QName(tmsNameSpace, method);
		Object[] result = client.invokeBlocking(qname, args, new Class[]{String.class, String.class, String.class});
		return result;
	}
<wsdl:service name="ImplHrWSService">
<wsdl:port binding="intf:ImplHrWSSoapBinding" name="ImplHrWS">
<wsdlsoap:address location="http://10.0.63.29:9080/axis/services/ImplHrWS"/>
</wsdl:port>
</wsdl:service>



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值