Topic
  • 6 replies
  • Latest Post - ‏2015-06-01T09:41:15Z by HermannSW
salman123
salman123
7 Posts

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

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

    ‏2011-07-25T13:59:34Z  
    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
    6019 Posts

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

    ‏2011-07-25T19:29:57Z  
    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

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

    ‏2011-07-25T21:30:58Z  
    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

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

    ‏2013-05-06T10:22:06Z  
    • salman123
    • ‏2011-07-25T21:30:58Z
    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.
    <pre class="java dw" data-editor-lang="java" data-pbcklang="java" dir="ltr">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 </pre>

    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...

    Could you pelase explain this more?

  • DivyaManaktala
    DivyaManaktala
    10 Posts

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

    ‏2015-05-29T03:42:51Z  
    • HermannSW
    • ‏2011-07-25T19:29:57Z
    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:
    <pre class="jive-pre"> [stammw@dp4-l3 html]$ cat >txt.txt1 abc [stammw@dp4-l3 html]$ </pre>

    Now accessing that file is successful and the file content is returned hexadecimally:
    <pre class="jive-pre"> $ 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>) $ </pre>

    Now we remove the file on the HTTP server:
    <pre class="jive-pre"> [stammw@dp4-l3 html]$ rm txt.txt1 [stammw@dp4-l3 html]$ </pre>

    Now the access to the file on the HTTP server fails after three retries:
    <pre class="jive-pre"> $ 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>) $ </pre>

     
    Hermann<myXsltBlog/>

    Hi,

    I want to retrieve files from local folder that have encrypted content (pgp). I want to dp:url-open that file(sample.txt) and compress it.

    I am using below code:

    <xsl:variable name="Target_URL" select="concat('local:///FileProcessing/Files/',$fileName)"/>
                
                <xsl:variable name="File">
                    <dp:url-open target="{$Target_URL}" response="binaryNode" data-type="ignore">                
                </dp:url-open>            
                </xsl:variable>

    Result of dp:url-open is File is :  ***BINARY NODE***-1true

    I did not understand what data it is.

     

    Please advise how to make it work.

     

  • HermannSW
    HermannSW
    6019 Posts

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

    ‏2015-06-01T09:41:15Z  

    Hi,

    I want to retrieve files from local folder that have encrypted content (pgp). I want to dp:url-open that file(sample.txt) and compress it.

    I am using below code:

    <xsl:variable name="Target_URL" select="concat('local:///FileProcessing/Files/',$fileName)"/>
                
                <xsl:variable name="File">
                    <dp:url-open target="{$Target_URL}" response="binaryNode" data-type="ignore">                
                </dp:url-open>            
                </xsl:variable>

    Result of dp:url-open is File is :  ***BINARY NODE***-1true

    I did not understand what data it is.

     

    Please advise how to make it work.

     

    <responsecode>-1</responsecode> (can be seen by <xsl:copy-of> instead of <xsl:value-of>) tells you that dp:url-open failed to work.


    Hermann.