package com.lzw.b2b.soap;
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.methods.InputStreamRequestEntity;
import org.apache.commons.httpclient.methods.PostMethod;
import org.apache.commons.httpclient.methods.RequestEntity;
import org.dom4j.Attribute;
import org.dom4j.Document;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class DynamicSoapclientCall {
private static Logger logger = LoggerFactory.getLogger(DynamicSoapclientCall.class);
private String namespace;
private String methodName;
private String wsdlLocation;
private String soapResponseData;
public DynamicSoapclientCall(String namespace, String methodName, String wsdlLocation) {
this.namespace = namespace;
this.methodName = methodName;
this.wsdlLocation = wsdlLocation;
}
public int invoke(Map<String, String> patameterMap) throws Exception {
PostMethod postMethod = new PostMethod(wsdlLocation);
String soapRequestData = buildRequestData(patameterMap);
byte[] bytes = soapRequestData.getBytes("utf-8");
InputStream inputStream = new ByteArrayInputStream(bytes, 0, bytes.length);
RequestEntity requestEntity = new InputStreamRequestEntity(inputStream,
bytes.length, "application/soap+xml; charset=utf-8");
postMethod.setRequestEntity(requestEntity);
HttpClient httpClient = new HttpClient();
int statusCode = httpClient.executeMethod(postMethod);
soapResponseData = postMethod.getResponseBodyAsString();
return statusCode;
}
private String buildRequestData(Map<String,