}
public InputStream getInputStream(ArrayList<Object> params)
throws IOException {
NameValuePair pair = null;
Iterator<Object> iter = null;
InputStream stream = null;
URLConnection conn = null;
// send the form data
if (requestLog.isDebugEnabled(name))
requestLog.debug(name,Messages.getString("WebDataSource.14")+url); //$NON-NLS-1$
URL hp=new URL(url);
conn = hp.openConnection();
// we don't want the connection to stay alive
conn.setRequestProperty("Connection", "close"); //$NON-NLS-1$
conn.setDoOutput(true);
conn.setDoInput(true);
conn.setUseCaches(false);
// add headers
for (Enumeration<String> e = headers.keys() ; e.hasMoreElements() ;) {
String name = e.nextElement();
conn.setRequestProperty(name,headers.get(name));
}
HTTPmultipart mp = null;
if (params != null && params.size() > 0) {
mp = new HTTPmultipart();
String boundary = new String(mp.getBoundary());
conn.setRequestProperty("Boundary",boundary); //$NON-NLS-1$
conn.setRequestProperty("Content-Type","multipart/form-data; boundary=\""+boundary+"\""); //$NON-NLS-1$ //$NON-NLS-2$
}
ArrayList<Part> content = new ArrayList<Part>();
int length = 0;
// determine the content length and save the parts to the content list
if (params != null && params.size() > 0) {
try{
iter = params.iterator();
while (iter.hasNext()) {
Object o = iter.next();
if (o == null)
continue;
if (o instanceof NameValuePair) {
pair = (NameValuePair)o;
if (pair == null || pair.getName() == null || pair.getValue() == null) {
nullParameterWarning(pair);
continue;
}
StringPart part = new StringPart(pair.getName(),pair.getValue());
content.add(part);
length += mp.getContentLength(part);
} else if (o instanceof FileParameter) {
FileParameter fp = (FileParameter)o;
pair = fp.getNameValuePair();
if (pair == null || pair.getName() == null || pair.getValue() == null) {
nullParameterWarning(pair);
continue;
}
File f = new File(pair.getValue());
if (f == null) {
requestLog.warn(Messages.getString("WebDataSource.19")+pair.getValue()); //$NON-NLS-1$
continue;
}
FilePart part = new FilePart(pair.getName(),f);
content.add(part);
length += mp.getContentLength(part);
} else if (o instanceof FileDataItem) {
FileDataItem fp = (FileDataItem)o;
pair = fp.getNameValuePair();
if (pair == null || pair.getName() == null || pair.getValue() == null) {
nullParameterWarning(pair);
continue;
}
File f = new File(pair.getValue());
if (f == null){
requestLog.warn(Messages.getString("WebDataSource.20")+pair.getValue()); //$NON-NLS-1$
continue;
}
FilePart part = new FilePart(pair.getName(),f);
content.add(part);
length += mp.getContentLength(part);
} else if (o instanceof DataItem) {
DataItem fp = (DataItem)o;
pair = fp.getNameValuePair();
if (pair == null || pair.getName() == null || pair.getValue() == null) {
nullParameterWarning(pair);
continue;
}
StringPart part = new StringPart(pair.getName(),pair.getValue());
content.add(part);
length += mp.getContentLength(part);
} else if (o instanceof Parameter) {
Parameter param = (Parameter)o;
pair = param.getNameValuePair();
if (pair == null || pair.getName() == null || pair.getValue() == null) {
nullParameterWarning(pair);
continue;
}
StringPart part = new StringPart(pair.getName(),pair.getValue());
content.add(part);
length += mp.getContentLength(part);
}
if (requestLog.isDebugEnabled(name))
requestLog.debug(name,url+Messages.getString("WebDataSource.21")+pair.getName()+"="+pair.getValue()); //$NON-NLS-1$ //$NON-NLS-2$
}
}catch(Exception e){
throw new IOException(Messages.getString("WebDataSource.23")); //$NON-NLS-1$
}