Showing posts with label middleware. Show all posts
Showing posts with label middleware. Show all posts

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

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, March 6, 2019

Using WAIT/Delay/Sleep in OSB Code


Using WAIT/Delay/Sleep in OSB Code


In Oracle Service Bus 12C, wait activity is not supported by and hence we will be using a piece of java code , which will be basically make the thread to sleep for certain milliseconds passed to the method.


Step 1 :- Download the JAR




Piece of Java Callout : 
********************
Will attach the link to the JAR file that you need to import in your Jdev / Please comment in case you need it.
********************

package threadsleep;

public class Threadsleep {
    
    public static String  sleepthreadmilis(int timer){
        try{
            Thread.sleep(timer);
        }
        catch(InterruptedException ex)
        {
            Thread.currentThread().interrupt();
        }
    return "Success";
    }

public static void main(String args[]) {
    String a="Call the method for testing";
    
       a=sleepthreadmilis(2000);
   System.out.println(a)  ;
    
}
}

Step 2 : Import the JAR

Now i will be using it in my OSB project using java callout.

Copy and paste the JAR file in any of your project folder.



Step 3 : Refresh the Artifacts in Jdeveloper :





Step 4 : Add Java callout activity in the pipeline.






**Have upload new jar (earlier it was threadsleepjar now it is archive1 )




Step 5 : Choose the Jar File 






Step 6 - Choose the Method 





Step 7 - Set the Parameters : 

Arguments int : set the delay time in milliseconds - here we are using 2 mins -> 120000 ms








Oracle OIC Email Notification Template

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