Question

I have an http method fault that executes when an incorrect http method is sent in the request.

when I set the status code as 405 ,the request returns a 502 bad gateway .

my fault is :

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<RaiseFault async="false" continueOnError="false" enabled="true" name="invalid-htttp-method-fault">
    <DisplayName>invalid htttp method fault</DisplayName>
    <FaultRules/>
    <Properties/>
    <FaultResponse>
        <Set>
            <Headers/>
            <Payload contentType="application/xml">
                <Fault>
                    <Code>405</Code>
                    <Description>Method Not Allowed</Description>
</Fault>
      </Payload>
            <StatusCode>405</StatusCode>
            <ReasonPhrase>Method Not Allowed</ReasonPhrase>
        </Set>
    </FaultResponse>
    <IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables>
</RaiseFault>

If I change

 <StatusCode>405</StatusCode>
                <ReasonPhrase>Method Not Allowed</ReasonPhrase> 

to

 <StatusCode>403</StatusCode>
                <ReasonPhrase>Method Not Allowed</ReasonPhrase>

I can see the response payload is returned perfectly . when I use 405 the response returned is :

{"fault":{"faultstring":"Received 405 Response without Allow Header","detail":{"errorcode":"protocol.http.Response405WithoutAllowHeader"}}}
Was it helpful?

Solution

I was able to reproduce the exact issue that you are facing and by doing some more research I found that HTTP 405 response must include an Allow-Header

Try changing your fault policy by adding a header -

      <Headers>
        <Header name="Allow">YOUR ALLOWED METHODS LIST</Header>
      </Headers>

By doing this you should no more be getting the 502 bad gateway and will get what you are expecting as a response.

I hope this helps.

Thanks!

OTHER TIPS

Ah.... Interesting. Response 405 requires an Allow header per the HTTP spec (see http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html). So, the Apigee error is telling you that you need to add an Allow header to your FaultResponse like this:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<RaiseFault async="false" continueOnError="false" enabled="true" name="Fault-405">
    <DisplayName>Fault 405</DisplayName>
    <FaultRules/>
    <Properties/>
    <FaultResponse>
        <Set>
          <Headers>
            <Header name="Allow">GET, PUT, POST, DELETE</Header>
          </Headers>
            <Payload contentType="text/plain">This wasn't supposed to happen</Payload>
            <StatusCode>405</StatusCode>
            <ReasonPhrase>405 Rules</ReasonPhrase>
        </Set>
    </FaultResponse>
    <IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables>
</RaiseFault>

So add the Allow verbs in the <Set> block and you should be cool.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top