apache-cxf 调用远程服务接口
public static String getNoCompressStr(String methodName, String params) {
WebClient client = WebClient.create(NET_CLIENT + methodName);
HTTPConduit conduit = (HTTPConduit) WebClient.getConfig(client).getConduit();
HTTPClientPolicy httpClientPolicy = new HTTPClientPolicy();
httpClientPolicy.setConnectionTimeout(1000 * 60 * 3000);
httpClientPolicy.setAllowChunking(false);
httpClientPolicy.setMaxRetransmits(100000);
httpClientPolicy.setReceiveTimeout(1000 * 60 * 3000);
conduit.setClient(httpClientPolicy);
String retStr = null;
try {
retStr = client.accept("application/x-www-form-urlencoded").type("application/x-www-form-urlencoded")
.post(params, String.class);
} catch (ClientException e) {
} catch (IllegalStateException e) {
}
if(UtilValidator.isEmpty(retStr)){
return null;
}
SAXReader read = new SAXReader();
Document doc = null;
try {
doc = read.read(new ByteArrayInputStream(retStr.getBytes("UTF-8")));
} catch (UnsupportedEncodingException | DocumentException e) {
} catch (ClientException e) {
}
if(null == doc){
return null;
}
Element root = doc.getRootElement();
if(UtilValidator.isEmpty(root)){
return null;
}
return root.getText();
}
评论0
最新资源