0

im on WSO2 ESB 4.8.1. I need to block some request if their path match a regular expression. So i've implemented this proxy and these sequences:

In my proxy:

  <target>
  <inSequence>        
     <sequence key="MySequence"></sequence>
     <send>
         <endpoint key="epProva"></endpoint>
     </send>
  </inSequence>

Where MySequence is:

<sequence xmlns="http://ws.apache.org/ns/synapse" name="MySequence">        
     <conditionalRouter continueAfter="false">
        <conditionalRoute breakRoute="true" asynchronous="true">
           <condition>
              <match type="url" regex=".*/my/path/.*"></match>
           </condition>
           <target sequence="conf:/BannedListMessage"></target>
        </conditionalRoute>
     </conditionalRouter>     
</sequence>

where BannedListMessage is:

<sequence xmlns="http://ws.apache.org/ns/synapse">   
   <header name="To" action="remove"></header>
   <property name="HTTP_SC" value="401" scope="axis2"></property>
   <property name="RESPONSE" value="true"></property>
   <property name="NO_ENTITY_BODY" action="remove" scope="axis2"></property>
   <payloadFactory media-type="json">
      <format>
        {"code":"401", "unhautorized."}      
     </format>
  </payloadFactory>
  <property name="messageType" value="application/json" scope="axis2"></property>
   <send></send> 
</sequence>

MySquence has the job to check if the request url matches the regular expression and, in that case, it has to block the request's flow, before it can reach the server, and to call the BannedListMessage sequence which will send back an error response (401) to the client.

During my attempts i noticed that

  • if the attribute continueAfter=true in MySequence i get the 401 "unauthorized" error as response but the request reach the server.

  • If i set continueAfter="false" i receive a 202 Accepted response and the request doesn't reach the server.

My target is to send the BannedListMessage 401 error to the client and to block the request. What have i to do?

Community
  • 1
  • 1
Alex
  • 1,515
  • 2
  • 22
  • 44

1 Answers1

0

Please use the respond mediator instead of send mediator in BannedListMessage sequence. Here is the modified sequence.

<sequence xmlns="http://ws.apache.org/ns/synapse">
   <header name="To" action="remove"></header>
   <property name="HTTP_SC" value="401" scope="axis2"></property>
   <property name="RESPONSE" value="true"></property>
   <property name="NO_ENTITY_BODY" action="remove" scope="axis2"></property>
   <payloadFactory media-type="json">
      <format>
        {"code":"401", "unhautorized."} 
     </format>
  </payloadFactory>
  <property name="messageType" value="application/json" scope="axis2"></property>
   <respond></respond> 
</sequence>
Eranda
  • 1,439
  • 1
  • 17
  • 30
  • i replaced the send tag with the respond one as you suggested. The behaviour is the same. Setting continueAfter=true iìm getting the 401 response but the request reach the server. If i set continueAfter=false i get 202 ... I suppose that continue After should be set to TRUE but i have to prevent the request to reach the servive in case of matghing with the regular expression in the conditional router mediator. – Alex Jan 30 '15 at 00:13