refInput = conn.getInputStream();
}
post.setRequestEntity(new InputStreamRequestEntity(refInput, ppio
.getMimeType()));
} else {
throw new WPSException("A POST request should contain a non empty body");
}
} else if (body instanceof String) {
post.setRequestEntity(new StringRequestEntity((String) body, ppio
.getMimeType(), encoding));
} else {
throw new WPSException(
"The request body should be contained in a CDATA section, "
+ "otherwise it will get parsed as XML instead of being preserved as is");
}
method = post;
}
// add eventual extra headers
if (ref.getHeader() != null) {
for (Iterator it = ref.getHeader().iterator(); it.hasNext();) {
HeaderType header = (HeaderType) it.next();
method.setRequestHeader(header.getKey(), header.getValue());
}
}
int code = client.executeMethod(method);
if (code == 200) {
input = method.getResponseBodyAsStream();
} else {
throw new WPSException("Error getting remote resources from " + ref.getHref()
+ ", http error " + code + ": " + method.getStatusText());
}
} else {
// use the normal url connection methods then...
URLConnection conn = destination.openConnection();
conn.setConnectTimeout(executor.getConnectionTimeout());
conn.setReadTimeout(executor.getConnectionTimeout());
input = conn.getInputStream();
}
// actually parse teh data
if (input != null) {
return ppio.decode(input);
} else {
throw new WPSException("Could not find a mean to read input " + inputId);
}
} finally {
// make sure to close the connection and streams no matter what
if (input != null) {
input.close();