}
public InputStream getInputStream(ArrayList<Object> params)
throws IOException
{
NameValuePair pair = null;
Iterator<Object> iter = null;
InputStream stream = null;
OutputStream out;
if (url.startsWith("telnet:")) //$NON-NLS-1$
url = url.replaceFirst("telnet:","http:"); //$NON-NLS-1$ //$NON-NLS-2$
try {
URI u = new URI(url);
host = u.getHost();
port = u.getPort();
} catch (URISyntaxException ex) {
LOG.warn(Messages.getString("SocketDataSource.6")+url); //$NON-NLS-1$
return null;
}
Socket sock = new Socket(host,port);
stream = sock.getInputStream();
out = sock.getOutputStream();
// send the form data
if (LOG.isDebugEnabled())
LOG.debug(Messages.getString("SocketDataSource.7")+url); //$NON-NLS-1$
int paramcount = 0;
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 p = new StringPart(pair.getName(),pair.getValue());
out.write(p.toString().getBytes());
} 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) {
LOG.warn(Messages.getString("SocketDataSource.8")+pair.getValue()); //$NON-NLS-1$
continue;
}
byte[] b = new byte[1024];
//send the file
FileInputStream fin = new FileInputStream(f);
while(fin.available() > 0) {
fin.read(b);
out.write(b);
}
} 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){
LOG.warn(Messages.getString("SocketDataSource.9")+pair.getValue()); //$NON-NLS-1$
continue;
}
//send the file
byte[] b = new byte[1024];
//send the file
FileInputStream fin = new FileInputStream(f);
while(fin.available() > 0) {
fin.read(b);
out.write(b);
}
} 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 p = new StringPart(pair.getName(),pair.getValue());
out.write(p.toString().getBytes());
} 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 p = new StringPart(pair.getName(),pair.getValue());
out.write(p.toString().getBytes());
}
paramcount++;
if (LOG.isDebugEnabled())
LOG.debug(url+Messages.getString("SocketDataSource.10")+pair.getName()+"="+pair.getValue()); //$NON-NLS-1$ //$NON-NLS-2$
}
return stream;
}