Topic
4 replies Latest Post - ‏2013-05-06T10:22:06Z by sreejithkumar
salman123
salman123
7 Posts
ACCEPTED ANSWER

Pinned topic How to capture the HTTP Return Code while using url-open with binaryNode

‏2011-07-23T05:31:53Z |
Hi,

I am facing an issue.

I am using following url-open statement with responseType as binaryNode

<xsl:variable name="URLopenresult">
<dp:url-open
target="{$targetLocation}"
response="binaryNode"
timeout="120"
data-type="ignore"
/>
</xsl:variable>
In scenario, where HTTP successful and response code is 200 -
I can get the binary content and process it ..
<xsl:variable name="encodedResult" select="dp:binary-encode($result/result/binary)"/>
<xsl:variable name="rawResult" select="dp:decode($encodedResult, 'base-64')"/>

And also, I am able to retrieve the HTTP Response code -
<xsl:value-of select="substring($URLopenresult//responsecode,1)"/>
But, when the error code is for example - 403, I am unable to get the HTTP responsecode ..

Can you please let me know - how to get http response code in any given scenario?
Note: - I need to use binaryNode always, as I need to get binary response data in case of success.
Updated on 2011-07-25T21:30:58Z at 2011-07-25T21:30:58Z by salman123
  • JBrennan
    JBrennan
    77 Posts
    ACCEPTED ANSWER

    Re: How to capture the HTTP Return Code while using url-open with binaryNode

    ‏2011-07-25T13:59:34Z  in response to salman123
    I have done this quite some time ago but I recall that there is a DP variable set containing the response code. The problem as I recall is that you cannot access this until action has already completed. Look at the variables in the probe and there will be a variable name extension_* (or something like that). THe name of the action that performed the url-open() is part of the variable name. You would need to implement your logic based on the RC in another action if this is the case. I know the response headers from the url-open are there and I would think the RC is there as well.
  • HermannSW
    HermannSW
    4124 Posts
    ACCEPTED ANSWER

    Re: How to capture the HTTP Return Code while using url-open with binaryNode

    ‏2011-07-25T19:29:57Z  in response to salman123
    Hi,

    > But, when the error code is for example - 403, I am unable to get the HTTP responsecode ..
    >
    you experience a known limitation of dp:url-open() with reponse-type="binaryNode".
    When dp:url-open() fails the empty nodeset is returned and responsecode is unavailable.

    This behaviour is in the firmware since day 1 and an Enhancement Request (ER) by you is needed for changing this.
    Please contact your sales representative for the ER.

    > Can you please let me know - how to get http response code in any given scenario?
    > Note: - I need to use binaryNode always, as I need to get binary response data in case of success.

    After an unsuccessful dp:url-open() with response-type="binaryNode" you could do a second dp:url-open() with response-type="responsecode".
    Of course the second call can return a HTTP 200 -- in that case retry the binaryNode call.

    Find attached a recursive retry-stylesheet which may fit your needs.

    First file "txt.txt1" is created on the webserver:
    
    [stammw@dp4-l3 html]$ cat >txt.txt1 abc [stammw@dp4-l3 html]$
    


    Now accessing that file is successful and the file content is returned hexadecimally:
    
    $ echo 
    "<x/>" | coproc2 retry.xsl - http:
    //dp3-l3:2223; echo 6162630A<br/>   (<result><binary>***BINARY NODE***</binary><responsecode>200</responsecode><headers><header name=
    "Date">Mon, 25 Jul 2011 19:39:41 GMT</header><header name=
    "Server">Apache/2.2.3 (Red Hat)</header><header name=
    "Last-Modified">Mon, 25 Jul 2011 19:39:36 GMT</header><header name=
    "ETag">
    "17182cc-4-f9a48e00"</header><header name=
    "Content-Type">text/plain; charset=UTF-8</header></headers></result>) $
    


    Now we remove the file on the HTTP server:
    
    [stammw@dp4-l3 html]$ rm txt.txt1 [stammw@dp4-l3 html]$
    


    Now the access to the file on the HTTP server fails after three retries:
    
    $ echo 
    "<x/>" | coproc2 retry.xsl - http:
    //dp3-l3:2223; echo <br/>   (<url-open><statuscode>15</statuscode><responsecode>404</responsecode><errorstring>Remote error on URL</errorstring><headers><header name=
    "Date">Mon, 25 Jul 2011 19:39:57 GMT</header><header name=
    "Server">Apache/2.2.3 (Red Hat)</header><header name=
    "Content-Length">300</header><header name=
    "Keep-Alive">timeout=15</header><header name=
    "Connection">Keep-Alive</header><header name=
    "Content-Type">text/html; charset=iso-8859-1</header></headers></url-open>) $
    


     
    Hermann<myXsltBlog/>
  • salman123
    salman123
    7 Posts
    ACCEPTED ANSWER

    Re: How to capture the HTTP Return Code while using url-open with binaryNode

    ‏2011-07-25T21:30:58Z  in response to salman123
    Thanks @JBrenna, @HermannSW for the resolutions.. I have done the following to get it to work-

    I have made the processing rule as below -

    Match --> Transform1 --> Transform2 --> Result

    In Transform1, the input context is NULL and output context is (say ..) dpvar_1

    Thus, the result of the url-open() call with binaryMode of this action is stored in context variables.
    var://context/dpvar_1/_extension/response-header/Content-Type string 'text/plain'
    var://context/dpvar_1/_extension/response-header/Pragma string 'no-cache'
    --------------
    --------------
    var://context/dpvar_1/_extension/response-headers node-set (show nodeset)
    var://context/dpvar_1/_extension/responsecode number 403
    


    In Transform2, the input/output context is NULL.
    Here, I read the context variable and process/throw error as needed depending on the responsecode

    Thanks...
    Updated on 2014-03-25T03:13:52Z at 2014-03-25T03:13:52Z by iron-man
    • sreejithkumar
      sreejithkumar
      9 Posts
      ACCEPTED ANSWER

      Re: How to capture the HTTP Return Code while using url-open with binaryNode

      ‏2013-05-06T10:22:06Z  in response to salman123

      Could you pelase explain this more?