Errors using <http:body> in EXPath HTTP Client

70 views
Skip to first unread message

Stephan Lehmke

unread,
May 16, 2016, 7:44:32 AM5/16/16
to EXPath
I tried to make a simple http client to test posting from XSLT:

<?xml version="1.0" encoding="UTF-8"?>

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
               
xmlns:xs="http://www.w3.org/2001/XMLSchema"
               
xmlns:http="http://expath.org/ns/http-client"
               
xmlns:h="http://www.w3.org/1999/xhtml"
               
exclude-result-prefixes="#all"
               
version="2.0">

   
<xsl:import href="http://expath.org/ns/http-client.xsl"/>

   
<xsl:output indent="yes"/>

   
<xsl:template name="main" match="/">
     
<root>
         
<!-- the request element -->
         
<xsl:variable name="request" as="element(http:request)">
           
<http:request method="post" href="http://127.0.0.1:8888/test">
         
<http:body media-type="text/plain">foo</http:body>
       
</http:request>
         
</xsl:variable>
         
<!-- sending the request -->
         
<xsl:variable name="resp" select="http:send-request($request)"/>
         
<!-- add the http:response element to the output tree -->
         
<xsl:sequence select="$resp[1]"/>
     
</root>
   
</xsl:template>

</xsl:stylesheet>


I'm using expath-http-client-saxon-0.12.0.

When I run the script with

saxon -xsl:post-example.xsl -it:main

then I get the following error messages

INFO: Create a new repository with storage: File system storage in /usr/share/expath/repo
No license file found - running with licensable features disabled
2016/05/15 13:08:04:193 CEST [INFO] DefaultHttpClient - I/O exception (java.io.IOException) caught when processing request to {}->http://127.0.0.1:8888: Error serializing the body content
2016/05/15 13:08:04:195 CEST [INFO] DefaultHttpClient - Retrying request to {}->http://127.0.0.1:8888
2016/05/15 13:08:04:196 CEST [INFO] DefaultHttpClient - I/O exception (java.io.IOException) caught when processing request to {}->http://127.0.0.1:8888: Error serializing the body content
2016/05/15 13:08:04:196 CEST [INFO] DefaultHttpClient - Retrying request to {}->http://127.0.0.1:8888
2016/05/15 13:08:04:196 CEST [INFO] DefaultHttpClient - I/O exception (java.io.IOException) caught when processing request to {}->http://127.0.0.1:8888: Error serializing the body content
2016/05/15 13:08:04:196 CEST [INFO] DefaultHttpClient - Retrying request to {}->http://127.0.0.1:8888
Error on line 18 of post-example.xsl:
 
Error sending the HTTP request
Error sending the HTTP request


and an invalid request is sent.

I assume something is wrong in my setup... Where should I start looking?

regards
Stephan

Adam Retter

unread,
May 16, 2016, 9:03:45 AM5/16/16
to exp...@googlegroups.com
As a very simple test, the following works for me using with
expath-http-client-saxon-0.11.0 and Saxon EE 9.6.0.7:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:http="http://expath.org/ns/http-client"
exclude-result-prefixes="xs"
version="3.0">

<xsl:param name="base-uri" required="yes" as="xs:string"/>

<xsl:template match="/">
<xsl:variable as="element(http:request)" name="request">
<http:request href="{$base-uri}" method="get">
<http:header name="Accept"
value="application/xml;charset=utf-8"/>
</http:request>
</xsl:variable>
<xsl:variable name="response" select="http:send-request($request)"/>
<xsl:if test="$response[1]/xs:integer(@status) ne 200">
<xsl:sequence select="error((), 'Status is not 200.')"/>
</xsl:if>
<xsl:copy>
<xsl:copy-of select="$response[2]"/>
</xsl:copy>
</xsl:template>

</xsl:stylesheet>



On 15 May 2016 at 07:10, 'Stephan Lehmke' via EXPath
> --
> You received this message because you are subscribed to the Google Groups
> "EXPath" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to expath+un...@googlegroups.com.
> To post to this group, send email to exp...@googlegroups.com.
> Visit this group at https://groups.google.com/group/expath.
> For more options, visit https://groups.google.com/d/optout.



--
Adam Retter

skype: adam.retter
tweet: adamretter
http://www.adamretter.org.uk

Stephan Lehmke

unread,
May 16, 2016, 10:01:19 AM5/16/16
to EXPath


Am Montag, 16. Mai 2016 15:03:45 UTC+2 schrieb Adam Retter:
As a very simple test, the following works for me using with
expath-http-client-saxon-0.11.0 and Saxon EE 9.6.0.7:


Thanks. Actually the request itself worked for me as well, the issue was with serializing the body of my post request.

But with version 0.11.0 of the client that works for me as well!

So thanks a lot, after asking over on Stack Overflow (and looking at the low traffic in this group) I was starting to fear the user base of this tool was dwindling to nothing...

regards
Stephan

Chi Dung Nguyen

unread,
Jan 14, 2021, 12:09:00 PM1/14/21
to EXPath
Hi everyone,

I have the same issue with a more recent version of the HTTP Client,  unfortunately . For my project I tried using the HTTP Client v. 1.3.0 with SaxonHE9-9-1-7J for sending a post request to my web-app.
Simple GET or POST requests without a body work fine with it. But as soon as I added the http:body element, the "Error serializing the body content" raised.

For testing, I used the example1 files which I modified slightly:


<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    xmlns:http="http://expath.org/ns/http-client"
    exclude-result-prefixes="xs"
    version="2.0">
    
    <xsl:template match="/">
        <xsl:variable name="my-request" as="element(http:request)">
            <http:request href='https://reqres.in/api/login' method='POST' override-media-type='text/plain'>

                <http:body media-type='text/plain' method='text'>{"email": "eve....@reqres.in", "password": "cityslicka"}</http:body>
            </http:request>
        </xsl:variable>
        <xsl:copy-of select="http:send-request($my-request)"/>
    </xsl:template>
    
</xsl:stylesheet>


And running the following command :
 java -cp ".\http-client-saxon-1.3.0-uber.jar;.\saxon9he.jar" net.sf.saxon.Transform -s:.\input1.xml -xsl:.\example1.xslt -config:.\config.xml -o:output.xml

The example above would raise an error for me and no http message is sent. But if I remove the http:body line, a message is sent.

Any idea, why this happends?

Regards
Chi
Reply all
Reply to author
Forward
0 new messages