Monday, September 7, 2020

Oracle Integration /ICS/OIC Connection Credential Replace automated

 

The requirement was to do a find and replace connection credential in OIC .


There can be a scenario where the credentials in the connection that are setup in OIC expires and the security teams reset it to a different password.

It is difficult to know which connection is using that credential which needs to be changed.



We are achieving this using the rest APIs exposed by OIC to fetch and update the connection details.


Step 1 : Use the shell script in URL





It accepts 4 Parameters : 

ICS_CONNECTION_URL= https://xxxx-dev-xxxx.integration.ocp.oraclecloud.com

OIC_USERNAME= abc@oracle.com

OIC_PASS= welcome

replaceuser= This is the user you want to find and replace. - 123@oracle.com


Change the connection details in CONN.json file :


Step 2 : Load the shell script in a unix box with CONN.json which you want to load.


./main.sh "https://xxxx-dev-xxxx.integration.ocp.oraclecloud.com" "abc@oracle.com" "welcome" "123@oracle.com"

This will run the script.




Once you run the script , this will generate a file connections.txt which will contain all the connections replaced.




Shell Script (You can also find the same in git attached above) :

ICS_CONNECTION_URL=$1
OIC_USERNAME=$2
OIC_PASS=$3
replaceuser=$4
if [ -f "user_accounts.txt" ]
        then
           rm user_accounts.txt
    fi
if [ -f "connections.txt" ]
        then
           rm connections.txt
    fi
 #curl -k -v -X GET -u $OIC_USERNAME:$OIC_PASS -H Accept:application/json  $ICS_CONNECTION_URL/ic/api/integration/v1/connections?q={status:%27CONFIGURED%27} -o curl_result 2>&1 | tee curl_output
     curl -G -X GET -u $OIC_USERNAME:$OIC_PASS -H "Accept:application/json" --data-urlencode "q={status:  'CONFIGURED'}"  $ICS_CONNECTION_URL/ic/api/integration/v1/connections -o curl_result 2>&1 | tee curl_output
    Integr_count=$(jq '.items | length' curl_result )
for ((i=0; i < $Integr_count; i++))
               do
                err_message=""
               #Obtain the Integration artifacts from file
               id=$( jq -r '.items['$i'] | .id' curl_result )            
  
curl -X GET -u $OIC_USERNAME:$OIC_PASS -H "Accept:application/json" $ICS_CONNECTION_URL/ic/api/integration/v1/connections/$id -o curl_result_conn 2>&1 | tee curl_output_conn
            name=$( jq -r '.securityProperties[0] | .propertyName' curl_result_conn )
     value=$( jq -r '.securityProperties[0] | .propertyValue' curl_result_conn )
            
echo "$id | $name | $value">>user_accounts.txt
  if [ "$value" == "$replaceuser" ]
then
curl   -X POST  -u $OIC_USERNAME:$OIC_PASS -H "X-HTTP-Method-Override:PATCH" -H "Content-Type:application/json" -d @CONN.json $ICS_CONNECTION_URL/ic/api/integration/v1/connections/$id -o "curl_result_conn_$id" | tee "curl_output_conn_$id"
              # filenm=curl_output_conn_$id
             int_status=$( cat "curl_result_conn_$id" | jq -r .status ) 
    echo "*********$id   $int_status*********"
          if [ "$int_status" == 'CONFIGURED' ] 
  then
   echo "Connection Activated successfully"
   echo "$id | SUCCESS" >>connections.txt
  else
   echo "Failed while Updating the connection"
               echo "$id | FAILURE" >>connections.txt
          fi
fi

done
echo "*******************DONE !!!****************"






Friday, April 10, 2020

Custom OAuth2.0 in OIC/ ICS Oracle Integration

User Case :

There are some API's which need OAuth 2.0 policy which is sometimes a custom created API or where we cannot use the direct OAuth 2.0 option in the OIC/ICS Rest Connection.

**Please note SOAP Connection dosent have this . You have to invoke the token API first and pass the access token as header in SOAP Header : Authorization




We have to use the Custom Token Request string here .

This is nothing but a curl statement that you would have executed in Bash to get a response .

-X POST -H "Content-Type: application/x-www-form-urlencoded"  -H  "Authorization: Bearer YOUR_BEARER_TOKEN_GOES_HERE"  -d   'grant_type=client_credentials'   https://xxxxxx-dev-zeka.oracleoutsourcing.com/ccadmin/v1/mfalogin

You can compare this to your postman request



This is the curl request which Postman sends.






$access_token automatically extracts the access token from the json response payload.



access_token_usage will be the actual header that will be passed which calling the endpoint defined in the connection, this automatically goes as part of the curl command in backend.


Pls ref https://blogs.oracle.com/adapters/integrate-ics-with-a-third-party-oauth-protected-rest-service-using-the-generic-rest-adapter-part-1

This explains the steps very clear and elaborately  .

Feel free to ask any question !

Happy Coding !

Download File as attachment in OIC


Use Case :


  • Create a download URL  in OIC , which upon clicking will download any attachment / file defined in the integration to local machine.
  • You want user to view a file as an attachment and don't want them to access the SFTP/FTP directly.
  • You may want the user to view maybe a callback file from Oracle Fusion Import Program (though it can be done through UCM, but still this is an option. )
  • You want to extract data from database and provide to user, but you don't want to expose the database (connection details) to user .


Logic Behind :

When we hit any URL in the browser, it actually requests for a GET operation to the server.

Our expectation here is anyone with the URL when hits in the Browser, it will auto download a file or an attachment .

Step 1 : Login and Create an app driven integration with a generic REST Adapter .




Step 2 : Make sure to configure Custom Header and operation = GET

** NOTE : You can define query parameters as well in case you want to put a filter on data in OIC.



Step 3 : Set the response Payload as Binary


Step 4 : Configure the Custom Header : Content-Disposition (We are using this to set the filename)

For more information on this header . Pls refer
https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Disposition



Step 5 : Verify the details as per the SS



Step 6 : Now since we are not dealing with any file in this integration, hence we are writing a custom file which we will download.

To write a dummy file , we are using stage write action.






This is sample file that i am using to configure the stage write activity .








Now i will map some dummy data and write the file .



Step 7 : Now we need to configure the response mapper, which is actually responsible to send the response.




  • Map the file reference that you want to be downloaded 



  • Set the Content-Disposition Header as  filename="abc.csv", here abc.csv is the file name and you can make it dynamic by passing a variable.
    I have hardcoded it for now.


Step 8 :  Save and Activate the Integration .


Step 9 : Click on the metadata URL generated , or you can get it clicking the i button beside the activation slider button.


Step 10 : Click on the URL . If you have configured the integration correctly , the file will auto download to your machine.



Open the file ! And bingo !! You are done !




** NOTE : In case you want to put a filter criteria . You can use query parameter in the URL. You need to configure same in the Rest adapter.

Example :

https://xxxxxxx.integration.ocp.oraclecloud.com:443/ic/api/integration/v1/flows/rest/TESTPOC/1.0/testfile?customerno=120&batch=2

Happy Coding !


Umm are you searching for the code now ? Even i would have done the same :P

https://github.com/sauvik8/sauvik-public/tree/master/OIC%20File%20Download%20Attachment

Wednesday, April 1, 2020

Finding distinct in Oracle OIC - Oracle Integration Cloud / ICS

There is no function available in Oracle Integration Cloud to find distinct of node values.

distinct function can be used in xsl , but that can be done from backend only which may invalid the mapper sometime.

We can use the following to get rid of repetitions / find distinct.

This needs to be applied in the xsl . Will post the examples shortly.

[not(nsmpr7:LOC=preceding::*)]


$StageRead/nsmpr2:ReadResponse/nsmpr4:RecordSet/nsmpr4:HeaderRecord[not(nsmpr4:SequenceNumber=preceding::*)]  --> This will pick HeaderRecord for distinct SequenceNumber

$ReadInChunk/nsmpr4:ReadResponse/nsmpr7:RecSet/nsmpr7:Rec[not(nsmpr7:LOC=preceding::*)] --> This will pick HeaderRecord for distinct LOC

Oracle OIC Email Notification Template

 Oracle HTML template for email notification <html> <body style="margin: 0px; background-color: rgb(226, 229, 232);"> ...