}
public XScriptObject invoke()
throws ProcessingException
{
HttpConnection conn = null;
try {
if (action == null || action.equals(""))
action = "\"\"";
String host = url.getHost();
int port = url.getPort();
if (System.getProperty("http.proxyHost") != null) {
String proxyHost = System.getProperty("http.proxyHost");
int proxyPort = Integer.parseInt(System.getProperty("http.proxyPort"));
conn = new HttpConnection(proxyHost, proxyPort, host, port);
}
else {
conn = new HttpConnection(host, port);
}
PostMethod method = new PostMethod(url.getFile()) {
protected String generateRequestBody(HashMap params)
{
try {
StringBuffer bodyBuffer
= new StringBuffer(super.generateRequestBody(params));
// Write the SOAP request
InputSource saxInputStream = xscriptObject.getInputSource();
InputStream is = saxInputStream.getByteStream();
InputStreamReader isr = new InputStreamReader(is);
char[] buffer = new char[1024];
int len;
while ((len = isr.read(buffer)) > 0)
bodyBuffer.append(buffer, 0, len);
isr.close();
is.close();
return bodyBuffer.toString();
}
catch (Exception ex) {
return null;
}
}
};
method.setRequestHeader(
new Header("Content-type", "text/xml; charset=\"utf-8\""));
method.setRequestHeader(new Header("SOAPAction", action));
method.setUseDisk(false);
method.execute(new HttpState(), conn);
String ret = method.getResponseBodyAsString();
int startOfXML = ret.indexOf("<?xml");
if(startOfXML == -1) { // No xml?!
throw new ProcessingException("Invalid response - no xml");
}
return new XScriptObjectInlineXML(
xscriptManager,
ret.substring(startOfXML));
}
catch (Exception ex) {
throw new ProcessingException("Error invoking remote service: " + ex,
ex);
}
finally {
try {
if (conn != null)
conn.close();
}
catch (Exception ex) {
}
}
}