关于CXF大文件的传输问题

 2023-09-05 阅读 28 评论 0

摘要:为什么80%的码农都做不了架构师?>>> 1.客户端调用webservice工具类 package cn.net.sunge.oas_dep.utils;import java.io.File; import java.io.FileInputStream; import java.security.KeyStore; import java.util.Map;import javax.activation.DataHandle

为什么80%的码农都做不了架构师?>>>   hot3.png

1.客户端调用webservice工具类


package cn.net.sunge.oas_dep.utils;import java.io.File;
import java.io.FileInputStream;
import java.security.KeyStore;
import java.util.Map;import javax.activation.DataHandler;
import javax.activation.DataSource;
import javax.activation.FileDataSource;
import javax.net.ssl.KeyManager;
import javax.net.ssl.KeyManagerFactory;
import javax.net.ssl.TrustManager;
import javax.net.ssl.TrustManagerFactory;import org.apache.cxf.configuration.jsse.TLSClientParameters;
import org.apache.cxf.endpoint.Client;
import org.apache.cxf.frontend.ClientProxy;
import org.apache.cxf.jaxws.JaxWsProxyFactoryBean;
import org.apache.cxf.transport.http.HTTPConduit;import cn.net.sunge.oas_dep.modules.webservice.model.FileEntity;public class WsClientUtil {public static <T> T getInterface(Class<T> clazz, String address) {return getInterface(clazz, address, null);}@SuppressWarnings("unchecked")public static <T> T getInterface(Class<T> clazz, String address, Map<String, Object> properties) {JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();factory.setAddress(address);factory.setServiceClass(clazz);if (null != properties) {factory.setProperties(properties);}return (T) factory.create();}public static <T> T getHttpsInterface(Class<T> clazz, String address, String jksPath, String jksPwd) {return getHttpsInterface(clazz, address, jksPath, jksPwd, null);}@SuppressWarnings("unchecked")public static <T> T getHttpsInterface(Class<T> clazz, String address, String jksPath, String jksPwd, Map<String, Object> properties) {JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();factory.setAddress(address);factory.setServiceClass(clazz);if (null != properties) {factory.setProperties(properties);}T t = (T) factory.create();configureSSLOnTheClient(t, jksPath, jksPwd);return t;}private static void configureSSLOnTheClient(Object obj, String jksPath, String jksPwd) {File file = new File(jksPath);Client client = ClientProxy.getClient(obj);HTTPConduit httpConduit = (HTTPConduit) client.getConduit();try {TLSClientParameters tlsParams = new TLSClientParameters();tlsParams.setDisableCNCheck(true);KeyStore keyStore = KeyStore.getInstance("JKS");String password = jksPwd;String storePassword = jksPwd;keyStore.load(new FileInputStream(file), storePassword.toCharArray());TrustManagerFactory trustFactory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());trustFactory.init(keyStore);TrustManager[] trustManagers = trustFactory.getTrustManagers();tlsParams.setTrustManagers(trustManagers);keyStore.load(new FileInputStream(file), storePassword.toCharArray());KeyManagerFactory keyFactory = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());keyFactory.init(keyStore, password.toCharArray());KeyManager[] keyManagers = keyFactory.getKeyManagers();tlsParams.setKeyManagers(keyManagers);// FiltersType filtersTypes = new FiltersType();// filtersTypes.getInclude().add(".*_EXPORT_.*");// filtersTypes.getInclude().add(".*_EXPORT1024_.*");// filtersTypes.getInclude().add(".*_WITH_DES_.*");// filtersTypes.getInclude().add(".*_WITH_NULL_.*");// filtersTypes.getExclude().add(".*_DH_anon_.*");// tlsParams.setCipherSuitesFilter(filtersTypes);tlsParams.setDisableCNCheck(true);httpConduit.setTlsClientParameters(tlsParams);} catch (Exception e) {e.printStackTrace();}}/*** Construct FileEntity.* * @param the*            real file path.* @return FileEntity.*/public static FileEntity constructFileEntity(String filePath) {// construct FileEntityFileEntity fileEntity = new FileEntity();File file = new File(filePath);fileEntity.setFileName(file.getName().substring(0, (file.getName().lastIndexOf("."))));fileEntity.setFileType(filePath.substring(filePath.lastIndexOf(".") + 1));DataSource source = new FileDataSource(file);DataHandler handler = new DataHandler(source);fileEntity.setFile(handler);return fileEntity;}
}

2.调用Util

Map<String, Object> properties = Maps.newHashMap();
properties.put("mtom-enabled", true);
IntranetFileWebserviceI intranetFileWebservice = WsClientUtil.getIntranetInterface(IntranetFileWebserviceI.class, IntranetFileWebserviceI.address, properties);



 参考资料:

http://yanghui-java.iteye.com/blog/1747643

转载于:https://my.oschina.net/u/859228/blog/534232

版权声明:本站所有资料均为网友推荐收集整理而来,仅供学习和研究交流使用。

原文链接:https://hbdhgg.com/3/1317.html

发表评论:

本站为非赢利网站,部分文章来源或改编自互联网及其他公众平台,主要目的在于分享信息,版权归原作者所有,内容仅供读者参考,如有侵权请联系我们删除!

Copyright © 2022 匯編語言學習筆記 Inc. 保留所有权利。

底部版权信息