|
Hi Ant, Funny you should ask that. I have just
written a custom transformer to do that! I first adapted the WSProxyGenerator to
set the SoapAction header but being a generator was a bit too restrictive. I
was hoping to add the new transformer into the development stream but have been
too busy using it. Mostly complete source code below – mostly taken from
the WSProxyGenerator.java but for a DOMTransformer. It uses dom4j which feels
like cheating but times are tough….. public class WSProxy extends
AbstractDOMTransformer { private String configuredSoapAction =
null; private HttpClient httpClient = null; private static final String HTTP_CLIENT =
"HTTP_CLIENT"; private static final String SOAP_ACTION =
"SOAPAction"; public void setup(SourceResolver resolver,
Map objectModel, String src, Parameters par) throws ProcessingException,
SAXException, IOException { super.setup(resolver,objectModel,src,par); try { Source
inputSource = resolver.resolveURI(super.source); this.source
= inputSource.getURI(); } catch(SourceException
se) { throw
SourceUtil.handle("Unable to resolve " + super.source, se); } this.configuredSoapAction
= par.getParameter("soap-action", new String()); this.httpClient
= this.getHttpClient(); } protected org.w3c.dom.Document
transform(org.w3c.dom.Document document) { InputStream
soapResponse; org.w3c.dom.Document
doc; PostMethod
post = new PostMethod(this.source); try { post.setRequestHeader(new
Header(SOAP_ACTION, this.configuredSoapAction)); org.dom4j.Document
domj = new DOMReader().read(document);
post.setRequestBody(domj.asXML()); //
Get HTTP client HttpClient
httpclient = new HttpClient(); //
Execute request int
result = httpclient.executeMethod(post); soapResponse
= post.getResponseBodyAsStream(); doc
= parse(soapResponse); } catch(Exception
e) { this.getLogger().error("SOAP_ACTION:
" + this.configuredSoapAction + " Failed"); return
WSProxyUtility.reportErrorAsDOM(e); } finally { //
Release current connection to the connection pool once you are done post.releaseConnection(); } return
doc; } /** * Create one per client session */ protected HttpClient getHttpClient()
throws ProcessingException { URI
uri = null; String
host = null; Request
request = ObjectModelHelper.getRequest(objectModel); Session
session = request.getSession(true); HttpClient
httpClient = null; if
(session != null) { httpClient
= (HttpClient)session.getAttribute(HTTP_CLIENT); } if
(httpClient == null) { httpClient
= new HttpClient(); HostConfiguration
config = httpClient.getHostConfiguration(); if
(config == null) { config
= new HostConfiguration(); } /*
TODO: fixme! *
When the specified source sent to the wsproxy is not "http" *
(e.g. "cocoon:/"), the HttpClient throws an exception. Does the
source *
here need to be resolved before being set in the HostConfiguration? */ try { uri
= new URI(this.source); host
= uri.getHost(); config.setHost(uri); } catch
(URIException ex) { throw
new ProcessingException("URI format error: " + ex, ex); } httpClient.setHostConfiguration(config); session.setAttribute(HTTP_CLIENT,
httpClient); } return
httpClient; } private org.w3c.dom.Document
parse(InputStream in) { try {
SAXReader
reader = new SAXReader(); org.dom4j.Document
document = reader.read(in); return
new DOMWriter().write(document); } catch(DocumentException
dex) { return
WSProxyUtility.reportErrorAsDOM(dex); } } } Sitemap entry is :- <map:match
pattern="test*.html"> <map:generate src=""> <map:transform type="iproxy" src=""> <map:parameter
name="soap-action" value="getQuote"/>
</map:transform>
<map:select type="request"> <map:parameter
name="parameter-name" value="xml"/> <map:when
test="true"> <map:serialize
type="xml"/> </map:when> <map:otherwise> <map:transform src=""> <map:parameter
name="risk" value="{1}"/> </map:transform> <map:serialize/> </map:otherwise>
</map:select> </map:match> Let me know if further help needed, Regards Warrell From:
Antony Grinyer [mailto:[EMAIL PROTECTED] Hi, In the sitemap, how do you pass the XML produced from a
transformer onto an external web service: <map:match pattern="create_order"> <map:generate src=""> <map:transform src="">
SEND TO WEBSERVICE HERE! </map:match> Many thanks in advance, Ant |
- RE: Passing XML to webservice? Warrell
- Re: Passing XML to webservice? Dennis Dam
- Re: Passing XML to webservice? Antonio Gallardo
