You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by Antony Grinyer <an...@csw.co.uk> on 2006/06/13 20:24:58 UTC

Passing XML to webservice?

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="myorder.xml"/>

            <map:transform src="format_order.xslt"/>

             SEND TO WEBSERVICE HERE!

</map:match>

 

Many thanks in advance,

Ant


Re: Passing XML to webservice?

Posted by Antonio Gallardo <ag...@agssa.net>.
Antony Grinyer escribió:
>
> 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="myorder.xml"/>
>
>             <map:transform src="format_order.xslt"/>
>
>              SEND TO WEBSERVICE HERE!
>
> </map:match>
>
>  
>
> Many thanks in advance,
>
> Ant
>
Hi Antony,

This patch might help you [1].


Best Regards,

Antonio Gallardo.

[1] http://issues.apache.org/jira/browse/COCOON-1618

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Re: Passing XML to webservice?

Posted by Dennis Dam <d....@hippo.nl>.
Anton,

You can also use soap actions in XSP, like this:

<?xml version="1.0" encoding="UTF-8"?>
<xsp:page language="java" xmlns:xsp="http://apache.org/xsp"
  xmlns:xsp-request="http://apache.org/xsp/request/2.0" 
xmlns:soap="http://apache.org/xsp/soap/3.0">
  <search-results>
    <soap:call url="${cocoon.parameters.url}"
      method="http://your.webservice.domain/somemethod"
      xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance"
      xmlns:xsd="http://www.w3.org/1999/XMLSchema">
     
      <your-message-content/>

    </soap:call>
  </search-results>
</xsp:page>

In your sitemap all you have to do is

<map:generate src="cocoon:/zoek.xsp" type="serverpages"/>

where serverpages is the transformer 
org.apache.cocoon.generation.ServerPagesGenerator. For more info, see 
the XSP block in cocoon 2.1.8 / 9 under samples/soap!

hope this helps, regards,

Dennis Dam

Antony Grinyer wrote:
>
> 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="myorder.xml"/>
>
>             <map:transform src="format_order.xslt"/>
>
>              SEND TO WEBSERVICE HERE!
>
> </map:match>
>
>  
>
> Many thanks in advance,
>
> Ant
>


-- 

Hippo
Oosteinde 11
1017WT Amsterdam
The Netherlands
Tel  +31 (0)20 5224466
-------------------------------------------------------------
d.dam@hippo.nl / http://www.hippo.nl
-------------------------------------------------------------- 


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


RE: Passing XML to webservice?

Posted by Warrell <wa...@iquo.co.uk>.
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="risk{1}.xml"/>

      <map:transform type="iproxy"
src="http://xxx.warrell.co.uk/WS/services/getQuote">

                        <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="quote.xsl">

                                                            <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:antony.grinyer@csw.co.uk] 
Sent: 13 June 2006 19:25
To: users@cocoon.apache.org
Subject: Passing XML to webservice?

 

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="myorder.xml"/>

            <map:transform src="format_order.xslt"/>

             SEND TO WEBSERVICE HERE!

</map:match>

 

Many thanks in advance,

Ant