Petals BC REST

Improve customization of HTTP REST response

Details

  • Type: Improvement Request Improvement Request
  • Status: Resolved Resolved
  • Priority: Major Major
  • Resolution: Fixed
  • Affects Version/s: 1.1.1-BC
  • Fix Version/s: 1.2.0-BC
  • Component/s: Consumer mode
  • Security Level: Public
  • Description:
    Hide

    No parameter is available to control HTTP response on consumer side. According to the JBI response (OUT message, fault or error), the HTTP responses could be specific with different HTTP code, with or without HTTP body, eventually with HTTP header.

    Please add a customisation of HTTP response. For example:

    <jbi:jbi version="1.0" ..>
       <jbi:services binding-component="true">
          <jbi:consumes interface-name="inscription-cantine:inscriptionCantine">
             <cdk:timeout>${municipalite.timeout.clt-services.qf}</cdk:timeout>
             <cdk:mep xsi:nil="true" />
    
             <rest:service-base-path>/api/demarches-administratives</rest:service-base-path>
             <rest:mapping>
                <rest:operation name="inscription-cantine:new">
                   <!-- REST request part -->
                   <rest:http-method>POST</rest:http-method>
                   <rest:path-template>/demande-cantine</rest:path-template>
                   <rest:http-body-from-json-virtual-root>new</rest:http-body-from-json-virtual-root>
                   ...
                   
                   <!-- REST response part -->
                   <rest:on-jbi-response>
                      <rest:on-default-out>
                         <rest:http-response http-code="201">
                            <rest:header name="Access-Control-Allow-Origin">
                               <rest:constant>*</rest:constant>
                            </rest:header>
                            <rest:header name="Access-Control-Allow-Headers">
                               <rest:constant>Origin, X-Requested-With, Content-Type, Accept</rest:constant>
                            </rest:header>
                            <rest:http-body-to-json-virtual-root>newResponse</rest:http-body-to-json-virtual-root>
                         </rest:http-response>
                      </rest:on-default-out>
                      <rest:on-default-error>
                         <rest:http-response http-code="500" />
                      </rest:on-default-error>
                   </rest:on-jbi-response>
                </rest:operation>
                <rest:operation name="inscription-cantine:validate">
                   <!-- REST request part -->
                   <rest:http-method>PUT</rest:http-method>
                   <rest:path-template>/demande-cantine/{numero-demande}</rest:path-template>
                   <rest:http-body-from-json-virtual-root>validate</rest:http-body-from-json-virtual-root>
                   ...
                   
                   <!-- REST response part -->
                   <rest:on-jbi-response>
                      <rest:on-default-out>
                         <rest:http-response http-code="202">
                            <rest:http-body-to-json-virtual-root>validateResponse</rest:http-body-to-json-virtual-root>
                         </rest:http-response>
                      </rest:on-default-out>
                      <rest:on-fault order-id="0">
                         <rest:condition>
                            <rest:xpath>boolean(//*[local-name()='inscriptionInconnue'])</rest:xpath>
                         </rest:condition>
                         <rest:http-response http-code="404" />
                      </rest:on-fault>
                      <rest:on-fault order-id="1">
                         <rest:condition>
                            <rest:xpath>boolean(//*[local-name()='inscriptionDejaValidee'])</rest:xpath>
                         </rest:condition>
                         <rest:http-response http-code="409" />
                      </rest:on-fault>
                      <rest:on-default-error>
                         <rest:http-response http-code="500" />
                      </rest:on-default-error>
                   </rest:on-jbi-response>
                </rest:operation>
             </rest:mapping>
          </jbi:consumes>
    
          <jbi:consumes interface-name="flowable-integration:Task">
    
             <cdk:timeout>${municipalite.timeout.clt-services.qf}</cdk:timeout>
             <cdk:mep xsi:nil="true" />
    
             <rest:service-base-path>/api/tasks</rest:service-base-path>
             <rest:mapping>
                <rest:operation name="flowable-integration:getTasks">
                   <!-- REST request part -->
                   <rest:http-method>GET</rest:http-method>
                   <rest:path-template>/tasks</rest:path-template>
                   ...
                   
                   <!-- REST response part -->
                   <rest:on-jbi-response>
                      <rest:on-default-out>
                         <rest:transformation>
                            <rest:xsl>demandes-a-valider.xsl</rest:xsl>
                         </rest:transformation>
                         <rest:http-response http-code="200">
                            <rest:http-body-to-json-virtual-root>demandes</rest:http-body-to-json-virtual-root>
                            <rest:http-body-to-json-auto-array>true</rest:http-body-to-json-auto-array>
                         </rest:http-response>
                      </rest:on-default-out>
                      <rest:on-default-error>
                         <rest:http-response http-code="500" />
                      </rest:on-default-error>
                   </rest:on-jbi-response>
                </rest:operation>
             </rest:mapping>
          </jbi:consumes>
       </jbi:services>
    </jbi:jbi>
    Show
    No parameter is available to control HTTP response on consumer side. According to the JBI response (OUT message, fault or error), the HTTP responses could be specific with different HTTP code, with or without HTTP body, eventually with HTTP header. Please add a customisation of HTTP response. For example:
    <jbi:jbi version="1.0" ..>
       <jbi:services binding-component="true">
          <jbi:consumes interface-name="inscription-cantine:inscriptionCantine">
             <cdk:timeout>${municipalite.timeout.clt-services.qf}</cdk:timeout>
             <cdk:mep xsi:nil="true" />
    
             <rest:service-base-path>/api/demarches-administratives</rest:service-base-path>
             <rest:mapping>
                <rest:operation name="inscription-cantine:new">
                   <!-- REST request part -->
                   <rest:http-method>POST</rest:http-method>
                   <rest:path-template>/demande-cantine</rest:path-template>
                   <rest:http-body-from-json-virtual-root>new</rest:http-body-from-json-virtual-root>
                   ...
                   
                   <!-- REST response part -->
                   <rest:on-jbi-response>
                      <rest:on-default-out>
                         <rest:http-response http-code="201">
                            <rest:header name="Access-Control-Allow-Origin">
                               <rest:constant>*</rest:constant>
                            </rest:header>
                            <rest:header name="Access-Control-Allow-Headers">
                               <rest:constant>Origin, X-Requested-With, Content-Type, Accept</rest:constant>
                            </rest:header>
                            <rest:http-body-to-json-virtual-root>newResponse</rest:http-body-to-json-virtual-root>
                         </rest:http-response>
                      </rest:on-default-out>
                      <rest:on-default-error>
                         <rest:http-response http-code="500" />
                      </rest:on-default-error>
                   </rest:on-jbi-response>
                </rest:operation>
                <rest:operation name="inscription-cantine:validate">
                   <!-- REST request part -->
                   <rest:http-method>PUT</rest:http-method>
                   <rest:path-template>/demande-cantine/{numero-demande}</rest:path-template>
                   <rest:http-body-from-json-virtual-root>validate</rest:http-body-from-json-virtual-root>
                   ...
                   
                   <!-- REST response part -->
                   <rest:on-jbi-response>
                      <rest:on-default-out>
                         <rest:http-response http-code="202">
                            <rest:http-body-to-json-virtual-root>validateResponse</rest:http-body-to-json-virtual-root>
                         </rest:http-response>
                      </rest:on-default-out>
                      <rest:on-fault order-id="0">
                         <rest:condition>
                            <rest:xpath>boolean(//*[local-name()='inscriptionInconnue'])</rest:xpath>
                         </rest:condition>
                         <rest:http-response http-code="404" />
                      </rest:on-fault>
                      <rest:on-fault order-id="1">
                         <rest:condition>
                            <rest:xpath>boolean(//*[local-name()='inscriptionDejaValidee'])</rest:xpath>
                         </rest:condition>
                         <rest:http-response http-code="409" />
                      </rest:on-fault>
                      <rest:on-default-error>
                         <rest:http-response http-code="500" />
                      </rest:on-default-error>
                   </rest:on-jbi-response>
                </rest:operation>
             </rest:mapping>
          </jbi:consumes>
    
          <jbi:consumes interface-name="flowable-integration:Task">
    
             <cdk:timeout>${municipalite.timeout.clt-services.qf}</cdk:timeout>
             <cdk:mep xsi:nil="true" />
    
             <rest:service-base-path>/api/tasks</rest:service-base-path>
             <rest:mapping>
                <rest:operation name="flowable-integration:getTasks">
                   <!-- REST request part -->
                   <rest:http-method>GET</rest:http-method>
                   <rest:path-template>/tasks</rest:path-template>
                   ...
                   
                   <!-- REST response part -->
                   <rest:on-jbi-response>
                      <rest:on-default-out>
                         <rest:transformation>
                            <rest:xsl>demandes-a-valider.xsl</rest:xsl>
                         </rest:transformation>
                         <rest:http-response http-code="200">
                            <rest:http-body-to-json-virtual-root>demandes</rest:http-body-to-json-virtual-root>
                            <rest:http-body-to-json-auto-array>true</rest:http-body-to-json-auto-array>
                         </rest:http-response>
                      </rest:on-default-out>
                      <rest:on-default-error>
                         <rest:http-response http-code="500" />
                      </rest:on-default-error>
                   </rest:on-jbi-response>
                </rest:operation>
             </rest:mapping>
          </jbi:consumes>
       </jbi:services>
    </jbi:jbi>
  • Environment:
    -

Activity

People

Dates

  • Created:
    Mon, 9 Apr 2018 - 15:11:01 +0200
    Updated:
    Fri, 18 May 2018 - 09:21:38 +0200
    Resolved:
    Fri, 18 May 2018 - 09:21:37 +0200