How to raise a fault on missing or empty request param,How to raise a fault if a query parameter is missing or empty

Hi,

I have an endpoint which needs an 'email' parameter and if the email parameter is missing or empty it need to raise a fault.

I have this code but, it doesn't work.

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ProxyEndpoint name="default">
    <PreFlow name="PreFlow">
        <Request>
            <Step>
                <Name>Verify-API-Key-1</Name>
            </Step>
            <Step>
                <Name>remove-query-param-apikey</Name>
            </Step>
            <Step>
                <Name>Raise-Fault-1</Name>
                <Condition>
                    request.queryparam.email is null 
                </Condition>
            </Step>
            <Step>
                <Name>Set-Target-Endpoint-Query-Parameters</Name>
            </Step>
        </Request>
        <Response/>
    </PreFlow>
    <Flows/>
    <PostFlow name="PostFlow">
        <Request/>
        <Response/>
    </PostFlow>
    <HTTPProxyConnection>
        <BasePath>/customers</BasePath>
        <VirtualHost>secure</VirtualHost>
    </HTTPProxyConnection>
    <RouteRule name="default">
        <TargetEndpoint>default</TargetEndpoint>
    </RouteRule>
</ProxyEndpoint>

,

How to raise a fault if a query parameter is missing or empty?

I have a URL which needs to take email as a query parameter and if the parameter is missing or empty it needs to raise a fault.

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ProxyEndpoint name="default">
    <PreFlow name="PreFlow">
        <Request>
            <Step>
                <Name>Verify-API-Key-1</Name>
            </Step>
            <Step>
                <Name>remove-query-param-apikey</Name>
            </Step>
            <Step>
                <Name>Raise-Fault-1</Name>
                <Condition>
                    request.queryparam.email is null 
                </Condition>
            </Step>
            <Step>
                <Name>Set-Target-Endpoint-Query-Parameters</Name>
            </Step>
        </Request>
        <Response/>
    </PreFlow>
    <Flows/>
    <PostFlow name="PostFlow">
        <Request/>
        <Response/>
    </PostFlow>
    <HTTPProxyConnection>
        <BasePath>/customers</BasePath>
        <VirtualHost>secure</VirtualHost>
    </HTTPProxyConnection>
    <RouteRule name="default">
        <TargetEndpoint>default</TargetEndpoint>
    </RouteRule>
</ProxyEndpoint>

It does't seem to work; please help.

Solved Solved
0 3 1,488
1 ACCEPTED SOLUTION

To be safe, it also helps to check for null or empty parameters. Your condition should look like this:

<Condition>(request.queryparam.email = null) or (request.queryparam.email = "")</Condition>

If you are still having trouble, do a trace. The step should show the expression, the result of evaluating it, and the variables used for evaluating the expression.

View solution in original post

3 REPLIES 3

Hi

At glance nothing looks wrong with your code. May be you can put a javascript step before Raise Falut step. Put following line of the javascript file code and inspect the value for incoming query parameter on trace output window.

print( "Email query param value " + context.getVariable('request.queryparam.email') ); 

if you are not passing email query parameter you expect it to see that value as null.

To be safe, it also helps to check for null or empty parameters. Your condition should look like this:

<Condition>(request.queryparam.email = null) or (request.queryparam.email = "")</Condition>

If you are still having trouble, do a trace. The step should show the expression, the result of evaluating it, and the variables used for evaluating the expression.

Not applicable

correcting your original code

<Condition>(request.queryparam.email Is null) or (request.queryparam.email Is "")</Condition>