wso2esb - Passing Username and Password to a REST API in WSO2 ESB -


i using , rest api in wso2 esb call service basic authentication.

this api code:

<resource methods="post" uri-template="/deletezonefromenrolment/">   <insequence>      <property xmlns:ns="http://org.apache.synapse/xsd" name="authorization" expression="fn:concat('basic ', base64encode('user:password'))" scope="transport"></property>      <property name="disable_chunking" value="true" scope="axis2"></property>      <payloadfactory media-type="xml">         <format>            <enr:deletezonefromenrolment xmlns:enr="http://someurl/enrolment.xsd">               <enrolment>$1</enrolment>               <zone>$2</zone>            </enr:deletezonefromenrolment>         </format>         <args>            <arg evaluator="json" expression="$.enrolment"></arg>            <arg evaluator="json" expression="$.zone"></arg>         </args>      </payloadfactory>      <send>         <endpoint key="dev_enrolmentendpoint"></endpoint>      </send>      <log level="full"></log>   </insequence>   <outsequence>      <property name="messagetype" value="application/json" scope="axis2" type="string"></property>      <send></send>   </outsequence>   <faultsequence>      <sequence key="esb_error_handling_response"></sequence>   </faultsequence> 

i call rest api using json post this:

{  'enrolment':'whatever',  'zone':'1' } 

if hardcode user , password, work nicely. i`m going 1 step forward. need pass basic authorization post json use call rest api in esb or setting api pass authentication through get/post call.

does know how it? trying no success:

in app before call api (post http://esburl:8280/api/deletezonefromenrolment), code in base64 string 'user:password', result, this: 'chjhymf0adpwcmfiyxro'. change api code this:

<resource methods="post" uri-template="/deletezonefromenrolment/">   <insequence>      <property xmlns:ns="http://org.apache.synapse/xsd" name="authorization" expression="fn:concat('basic ', json-eval($.user))" scope="transport"></property>      <property name="disable_chunking" value="true" scope="axis2"></property>      <payloadfactory media-type="xml">         <format>            <enr:deletezonefromenrolment xmlns:enr="http://someurl/enrolment.xsd">               <enrolment>$1</enrolment>               <zone>$2</zone>            </enr:deletezonefromenrolment>         </format>         <args>            <arg evaluator="json" expression="$.enrolment"></arg>            <arg evaluator="json" expression="$.zone"></arg>            <arg evaluator="json" expression="$.user"></arg>         </args>      </payloadfactory>      <send>         <endpoint key="dev_enrolmentendpoint"></endpoint>      </send>      <log level="full"></log>   </insequence>   <outsequence>      <property name="messagetype" value="application/json" scope="axis2" type="string"></property>      <send></send>   </outsequence>   <faultsequence>      <sequence key="esb_error_handling_response"></sequence>   </faultsequence> 

and post json:

{  'enrolment':'whatever',  'zone':'1',  'user':'chjhymf0adpwcmfiyxro' } 

i resolved. easier thought, adding basic auth header inside app (when i'm calling esb api) username , password , credentials passing through api external service.


Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -