API Connect

API Connect

Join this online group to communicate across IBM product users and experts by sharing advice and best practices with peers and staying up to date regarding product enhancements.

 View Only
  • 1.  how response code will work in dp:url-open

    Posted Tue May 27, 2025 02:49 AM

    Dears,

    I am using dp:url-open in my XSLT to call MQ and ACE. However, one thing is not clear to me regarding setting a response.

    response="xml | binaryNode | ignore | responsecode | responsecode-binary | responsecode-ignore"

    If set response ="responsecode" as below, and if I receive 500 or any other from the target URL, will the flow be stopped or continue?

    <dp:url-open target="URL" response="responsecode"

    </dp:url-open>



    ------------------------------
    Kumar
    ------------------------------


  • 2.  RE: how response code will work in dp:url-open

    Posted Wed May 28, 2025 01:05 AM

    The exception in this case will be reported on system log but processing will continue.



    ------------------------------
    Ajitabh Sharma
    ------------------------------



  • 3.  RE: how response code will work in dp:url-open

    Posted Wed May 28, 2025 07:57 AM

    Kumar,
    You must check the response code from the returned nodeset and issue the apigw:reject to stop processing if that is your requirement.

    Steve



    ------------------------------
    Steve Linn
    Senior Consulting I/T Specialist
    IBM Retired
    ------------------------------



  • 4.  RE: how response code will work in dp:url-open

    Posted Sat May 31, 2025 06:30 AM

    HI Kumar, 

    if the response code returned as 500, it will not stop the process.
    However you can log the report and stop the process by following the code:
     
    <dp:variable name="responsecode" />
    <dp:url-open target="http://example.com/api" response="responsecode">
        <!-- Request setup if needed -->
    </dp:url-open>
     
    <!-- Check the response code -->
    <xsl:if test="$responsecode = 500">
        <!-- Log the error -->
        <dp:log level="error" category="apigw" xmlns:dp="http://www.datapower.com/extensions">
            HTTP 500 error received from http://example.com/api
        </dp:log>
     
        <!-- Raise a fault to stop processing -->
        <dp:raise-fault
            name="HTTP500Error"
            xmlns:dp="http://www.datapower.com/extensions"
            description="Remote server returned HTTP 500 - Internal Server Error"/>
    </xsl:if>
     
    <!-- Continue with processing only if not error -->
     
     
    If you want to play with the response code then you can use xsl:choose like below
    <dp:variable name="responsecode" />
    <dp:url-open target="http://example.com/api" response="responsecode">
        <!-- Request setup if needed -->
    </dp:url-open>
     
    <!-- Check if response is 500 -->
    <xsl:choose>
        <xsl:when test="$responsecode = 500">
            <!-- Log error -->
            <!-- Raise fault and exit -->
            <dp:raise-fault
                name="HTTP500Error"
                xmlns:dp="http://www.datapower.com/extensions"
                description="Remote server returned HTTP 500 - Internal Server Error"/>
        </xsl:when>
     
        <xsl:otherwise>
            <!-- Response is NOT 500: continue processing -->
            <!-- Continue with your processing -->
            <!-- e.g., transform, route, or respond -->
        </xsl:otherwise>
    </xsl:choose>



    ------------------------------
    Nrusingha Sahoo
    ------------------------------