/**
*
* @param sendXml
* 需要发送的报文字符串
* @param requestUrl
* 请求url地址
* @return 响应报文字符串
*/
public static String sendSOAP(String sendXml, String requestUrl) {
String responseBodySOAP = null;
byte[] requestBytes;
try {
// 请求发送前给系统添加参数,JKS证书
System.setProperty("javax.net.ssl.trustStore", csj.jks");
System.setProperty("javax.net.ssl.trustStorePassword", "123456");
System.setProperty("javax.net.ssl.keyStoreType", "JKS");
System.setProperty("javax.net.ssl.keyStore",csj.jks");
System.setProperty("javax.net.ssl.keyStorePassword", "123456");
requestBytes = sendXml.getBytes();
HttpClient httpClient = new HttpClient();
PostMethod postMethod = new PostMethod(requestUrl);
InputStream inputStream = new ByteArrayInputStream(requestBytes, 0, requestBytes.length);
RequestEntity requestEntity = new InputStreamRequestEntity(inputStream, requestBytes.length,
"application/soap+xml; charset=utf-8");
postMethod.setRequestEntity(requestEntity);
System.out.println("请求报文:" + sendXml);
httpClient.executeMethod(postMethod);
// responseBodySOAP = postMethod.getResponseBodyAsString();
BufferedReader br = new BufferedReader(
new InputStreamReader(postMethod.getResponseBodyAsStream(), "utf-8"));
String responseLine = "";
StringBuffer sb = new StringBuffer();
for (responseLine = br.readLine(); responseLine != null; responseLine = br.readLine()) {
sb.append(responseLine);
}
br.close();
responseBodySOAP = sb.toString();
} catch (Exception e) {
e.printStackTrace();
}
System.out.println("响应报文:" + responseBodySOAP);
return responseBodySOAP;
}
*
* @param sendXml
* 需要发送的报文字符串
* @param requestUrl
* 请求url地址
* @return 响应报文字符串
*/
public static String sendSOAP(String sendXml, String requestUrl) {
String responseBodySOAP = null;
byte[] requestBytes;
try {
// 请求发送前给系统添加参数,JKS证书
System.setProperty("javax.net.ssl.trustStore", csj.jks");
System.setProperty("javax.net.ssl.trustStorePassword", "123456");
System.setProperty("javax.net.ssl.keyStoreType", "JKS");
System.setProperty("javax.net.ssl.keyStore",csj.jks");
System.setProperty("javax.net.ssl.keyStorePassword", "123456");
requestBytes = sendXml.getBytes();
HttpClient httpClient = new HttpClient();
PostMethod postMethod = new PostMethod(requestUrl);
InputStream inputStream = new ByteArrayInputStream(requestBytes, 0, requestBytes.length);
RequestEntity requestEntity = new InputStreamRequestEntity(inputStream, requestBytes.length,
"application/soap+xml; charset=utf-8");
postMethod.setRequestEntity(requestEntity);
System.out.println("请求报文:" + sendXml);
httpClient.executeMethod(postMethod);
// responseBodySOAP = postMethod.getResponseBodyAsString();
BufferedReader br = new BufferedReader(
new InputStreamReader(postMethod.getResponseBodyAsStream(), "utf-8"));
String responseLine = "";
StringBuffer sb = new StringBuffer();
for (responseLine = br.readLine(); responseLine != null; responseLine = br.readLine()) {
sb.append(responseLine);
}
br.close();
responseBodySOAP = sb.toString();
} catch (Exception e) {
e.printStackTrace();
}
System.out.println("响应报文:" + responseBodySOAP);
return responseBodySOAP;
}