in jelly-tags/soap/src/main/java/org/apache/commons/jelly/tags/soap/InvokeRawTag.java [51:141]
public void doTag(XMLOutput output)
throws MissingAttributeException, JellyTagException
{
if (endpoint == null)
{
throw new MissingAttributeException("endpoint");
}
String request = getBodyText();
String answer = null;
try
{
// Prepare HTTP post
PostMethod post = new PostMethod(endpoint);
// Request content will be retrieved directly
// from the input stream
post.setRequestBody(new StringInputStream(request));
// Per default, the request content needs to be buffered
// in order to determine its length.
// Request body buffering can be avoided when
// = content length is explicitly specified
// = chunk-encoding is used
if (request.length() < Integer.MAX_VALUE)
{
post.setRequestContentLength((int) request.length());
}
else
{
post.setRequestContentLength(
EntityEnclosingMethod.CONTENT_LENGTH_CHUNKED);
}
// Specify content type and encoding
// If content encoding is not explicitly specified
// ISO-8859-1 is assumed
post.setRequestHeader(
"Content-type",
"text/xml; charset=ISO-8859-1");
// Set the SOAPAction header
if ( soapAction == null )
{
post.setRequestHeader( "SOAPAction", "");
}
else
{
post.setRequestHeader( "SOAPAction", soapAction);
}
// Get HTTP client
HttpClient httpclient = new HttpClient();
// Execute request
int result = httpclient.executeMethod(post);
answer = post.getResponseBodyAsString();
// Release current connection to the connection pool once you are done
post.releaseConnection();
}
catch (MalformedURLException e)
{
throw new JellyTagException(e);
}
catch (RemoteException e)
{
throw new JellyTagException(e);
}
catch (HttpException e)
{
throw new JellyTagException(e);
}
catch (IOException e)
{
throw new JellyTagException(e);
}
if (var != null)
{
context.setVariable(var, answer);
}
else
{
// should turn the answer into XML events...
throw new JellyTagException(
"Not implemented yet; should stream results as XML events. Results: "
+ answer);
}
}