Sunday, May 15, 2016

Accessing the API using api_key through python and retrieving the data

 

Following python script connects to public api using the api_key and we can retrieve the data from it. In order to get authenticated and read data we need to get the api_key.

# The python script is to test  connection to public api using the api_key and load the data based on the selection of object attributes

image 
Once we execute the script, sample output is as below.

C:\u01\Python-2711\python.exe C:/Users/xxxxxx/PycharmProjects/Learning/APIConnect.py
Please enter the city where you like to search : Nashua
Planet Fitness (603) 816-3555 03063
Cravings (603) 882-6626 03060
Thousand Crane II (603) 579-0888 03060
Preciou's Hair Salon (603) 882-0443 03060
Supercuts (603) 594-8545 03060
Tom's Barber Shop (603) 889-0223 03060
xxxxxxx

Tuesday, March 8, 2016

Importing certificate to oracle ohs wallet using orapki

Importing the client root/intermediate/public cert to oracle http server wallet

As middleware administrator tasks its regular to update the new certs to oracle wallets , we can import the new certs to wallet in different ways either  using the owm utility to import through GUI or by using orapki command utility . In my other post i have explained the creation of wallet using the orapki command in the topic i will provide the steps to import the user certificates/partner certificates using orapki utility.

First we need to set the java home

export JAVA_HOME=/u01/java/jdk

Import the root certificate first to wallet. Go to oracle_common/bin where we have orapki installed.

./orapki wallet add –wallet <wallet location> –trusted_cert –cert <certlocaton> –pwd <wallet password>

eg : ./orapki wallet add –wallet /u02/keystore/default –trusted_cert –cert /stage/clientcert/root.cer –pwd Welcome123

Import the intermediate certificate to wallet

./orapki wallet add –wallet <wallet location> –trusted_cert –cert <certlocaton> –pwd <wallet password>

eg : ./orapki wallet add –wallet /u02/keystore/default –trusted_cert –cert /stage/clientcert/intermediate.cer –pwd Welcome123

Import the public certificate to wallet

./orapki wallet add –wallet <wallet location> –trusted_cert –cert <certlocaton> –pwd <wallet password>

eg : ./orapki wallet add –wallet /u02/keystore/default –trusted_cert –cert /stage/clientcert/public.cer –pwd Welcome123

Verify the certificate import is added properly to wallet by using the display option

./orapki wallet display –wallet  /u02/keystore/default

Monday, March 7, 2016

Undeploy SOA Composite using wlst

SOA composite undeploy when em is not working:

Method :1:

cd $MIDDLEWARE_HOME\ORACLE_SOA_HOME\common\bin
wlst.cmd
connect('weblogic','password','t3://localhost:8001')
wls:/soa_prod_domain/serverConfig> sca_listDeployedComposites('localhost','8001','weblogic','password')
wls:/soa_prod_domain/serverConfig> sca_undeployComposite('http://localhost:8001",'composite_name','1.0','weblogic','password');

Method :2:

Check the SOA logs and determine which composite is causing the problem and then follow the below process to undeploy the composite by editing deployed-composites.xml:

1. Download and copy the ShareSoaInfraPartition.ear file to $MIDDLEWARE_HOME/oracle_common/common/bin

2. cd to $MIDDLEWARE_HOME/oracle_common/common/bin

and

run wlst.sh
3.  Connect to a SOA server:

connect()
> Provide the username, password and server URL
connect('weblogic','password','t3://localhost:8001')

4. run the below command to deploy ShareSoaInfraPartition.ear to the server:

deploy('ShareSoaInfraPartition','ShareSoaInfraPartition.ear',upload='true')
5. Now run the below command by changing the "toLocation" ('/fmw11g/fmw1115/Middleware' is some location path on SOA machine)

exportMetadata(application='ShareSoaInfraPartition',server='AdminServer',toLocation='/fmw11g/fmw1115/Middleware',docs='/deployed-composites/deployed-composites.xml')
6. A deployed-composites folder will be created at "toLocation" path with deployed-composites.xml in it

7. Delete the composite which is causing the problem and save the file

For example, the MediatorTest composite:

<composite-series name="default/MediatorTest" default="default/MediatorTest!1.0">
<composite-revision dn="default/MediatorTest!1.0" state="on" mode="active" location="dc/soa_58b98be8-9ec8-41af-bb83-590f6004d1aa">
<composite dn="default/MediatorTest!1.0*soa_58b98be8-9ec8-41af-bb83-590f6004d1aa" deployedTime="2011-11-17T09:01:54.750+05:30"/>
8. Now run the below command by changing the "fromLocation" (this should be the same location as previous)

importMetadata(application='ShareSoaInfraPartition',server='AdminServer',fromLocation='/fmw11g/fmw1115/Middleware',docs='/deployed-composites/deployed-composites.xml')
9. Now bounce your server and the composite will not be deployed by SOA when it comes up and hence that should bring your soa-infra up.

Note:  When you remove a composite that contains task definitions manually, the Task definition references to the composite are still in WFTASKMETADATA table. Even though the composite is not loaded during startup there will be an  exception when loading the task definition,
<Error> <oracle.soa.services.workflow.task>
<BEA-000000> <<.> Could not locate composite.

The references to WFTASKMETADATA for that specific composite/version can only be removed when a composite containing task definitions is cleanly undeployed using em/wlst.

Shell Script to monitor folder and send email with new files created on the folder

#!/bin/bash

# The following script is developed to monitor the folders and send an email with new files generated in the folders

a_dir=/u01/app/a_folder/
b_dir=/u01/app/b_folder/
c_dir=/u01/app/c_folder/

bfiles=$(find "$a_dir" -maxdepth 1 | sort)
mfiles=$(find "$b_dir" -maxdepth 1 | sort)
dfiles=$(find "$c_dir" -maxdepth 1| sort)

# Email Distribution lists for each Folder

A_DL="tri-1@email.com,tri-2@email.com,tri-3@email.com.com"
B_DL="tri-1@email.com,tri-2@email.com,tri-3@email.com.com"
C_DL="tri-1@email.com,tri-2@email.com,tri-3@email.com.com"


files=$(find "$a_dir" -maxdepth 1 | sort||find "$b_dir" -maxdepth 1 | sort||find "$c_dir" -maxdepth 1| sort)
IFS=$'\n'

while true
do
  sleep 5s

  anewfiles=$(find "$a_dir" -maxdepth 1 | sort)
  aadded=$(comm -13 <(echo "$afiles") <(echo "$anewfiles"))
  bnewfiles=$(find "$b_dir" -maxdepth 1 | sort)
  badded=$(comm -13 <(echo "$bfiles") <(echo "$bnewfiles"))
  cnewfiles=$(find "$c_dir" -maxdepth 1 | sort)
  cadded=$(comm -13 <(echo "$cfiles") <(echo "$cnewfiles"))
  [ "$aadded" != "" ] &&
    find $aadded -maxdepth 1 -printf '%Tc\t%s\t%p\n' | mail -s "File Generated in a_dir" -a $aadded "$A_DL"
   bfiles=$bnewfiles
  [ "$badded" != "" ] &&
    find $badded -maxdepth 1 -printf '%Tc\t%s\t%p\n' | mail -s "File Generated b_dir" -a $badded "$B_DL"
   bfiles=$bnewfiles
  [ "$cadded" != "" ] &&
    find $cadded -maxdepth 1 -printf '%Tc\t%s\t%p\n' | mail -s "File Generated c_dir" -a $cadded "$C_DL"
   cfiles=$cnewfiles

  files=$anewfiles
done