icon-arrow icon-check icon-mail icon-phone icon-facebook icon-linkedin icon-youtube icon-twitter icon-cheveron icon-download icon-instagram play close close icon-arrow-uturn icon-calendar icon-clock icon-search icon-chevron-process icon-skills icon-knowledge icon-kite icon-education icon-languages icon-tools icon-experience icon-coffee-cup
Werken bij Integration & Application Talents
Blog 29/06/2016

Creating FTP connection factories using WLST

Creating a connection

Whitehorses
Mike Heeren /
Integratie expert

Creating FTP connection factories using the Weblogic console can take a lot of time, mainly because it are multiple screens you have to click through every time. But creating these FTP connection factories can be done a lot easier and faster when using a WLST script.

The following script can be used as a base for your script to generate your FTP connection factories. I have used this script on a Weblogic 12c environment.

# 
# Script settings
#
appName = 'FtpAdapter'

moduleOverrideName = appName + '.rar'
moduleDescriptorName = 'META-INF/weblogic-ra.xml'

soaHome = '/u01/Oracle/Products/Middleware/soa'
appPath = soaHome + '/soa/connectors/' + moduleOverrideName
planPath = soaHome + '/soa/FTPAdapterPlan.xml'

#
# Connect to Weblogic server
#
print('Connecting to local weblogic domain... ')
username = raw_input('Enter username: ')
password = raw_input('Enter password: ')
connect(username,password,'t3://localhost:7001')

#
# Method to insert variable to deployment plan
#
def makeDeploymentPlanVariable(wlstPlan, name, value, xpath, origin='planbased'):
    try:
        while wlstPlan.getVariableAssignment(name, moduleOverrideName, moduleDescriptorName):
            wlstPlan.destroyVariableAssignment(name, moduleOverrideName, moduleDescriptorName)
        variableAssignment = wlstPlan.createVariableAssignment(name, moduleOverrideName, moduleDescriptorName)
        variableAssignment.setXpath(xpath)
        variableAssignment.setOrigin(origin)
        wlstPlan.createVariable(name, value)
    except:
        print 'Error during makeDeploymentPlanVariable: ', sys.exc_info()[0]

#
# Update property for FTP adapter
#
def updatePropertyForFtpAdapter(deploymentPlan, jndiName, propertyName, propertyValue):
    try:
        shortJndiName = jndiName.split('/')[2]
        makeDeploymentPlanVariable(deploymentPlan, 'ConfigProperty_' + propertyName + '_Value_' + shortJndiName, propertyValue, '/weblogic-connector/outbound-resource-adapter/connection-definition-group/[connection-factory-interface="javax.resource.cci.ConnectionFactory"]/connection-instance/[jndi-name="' + jndiName + '"]/connection-properties/properties/property/[name="' + propertyName + '"]/value', moduleOverrideName)
    except:
        print 'Error during updatePropertyForFtpAdapter: ', sys_exc_info()[0]

#
# Method to create new FTP connection factory
#
def createFTPConnectionFactory(jndiName, type, host, port, securePort, username, password, walletLocation='', walletPassword=''):
    try:
        newPlan = loadApplication(appPath, planPath)
        makeDeploymentPlanVariable(newPlan, 'ConnectionInstance_' + jndiName + '_JNDIName', jndiName, '/weblogic-connector/outbound-resource-adapter/connection-definition-group/[connection-factory-interface="javax.resource.cci.ConnectionFactory"]/connection-instance/[jndi-name="' + jndiName + '"]/jndi-name', moduleOverrideName)
        
        if(type == 'sftp'):
            updatePropertyForFtpAdapter(newPlan, jndiName, 'UseFtps', 'false')
            updatePropertyForFtpAdapter(newPlan, jndiName, 'UseSftp', 'true')
        elif(type == 'ftps'):
            updatePropertyForFtpAdapter(newPlan, jndiName, 'UseFtps', 'true')
            updatePropertyForFtpAdapter(newPlan, jndiName, 'UseSftp', 'false')
        else:
            updatePropertyForFtpAdapter(newPlan, jndiName, 'UseFtps', 'false')
            updatePropertyForFtpAdapter(newPlan, jndiName, 'UseSftp', 'false')
        
        updatePropertyForFtpAdapter(newPlan, jndiName, 'Host', host)
        updatePropertyForFtpAdapter(newPlan, jndiName, 'Username', username)
        updatePropertyForFtpAdapter(newPlan, jndiName, 'Password', password)
        updatePropertyForFtpAdapter(newPlan, jndiName, 'Port', port)
        updatePropertyForFtpAdapter(newPlan, jndiName, 'SecurePort', securePort)
        updatePropertyForFtpAdapter(newPlan, jndiName, 'WalletLocation', walletLocation)
        updatePropertyForFtpAdapter(newPlan, jndiName, 'WalletPassword', walletPassword)
        
        newPlan.save();
        save();
    except:
        print 'Error during createFTPConnectionFactory: ', sys.exc_info()[0]

#
# Create FTP connection factories
#
try:
    edit()
    startEdit()
    
    createFTPConnectionFactory('eis/Ftp/ftp_server1', 'ftp', '127.0.0.1', '21', '21', 'username', 'password')
    createFTPConnectionFactory('eis/Ftp/sftp_server1', 'sftp', 'localhost', '22', '22', 'username', 'password')
    createFTPConnectionFactory('eis/Ftp/ftps_server1', 'ftps', 'localhost', '990', '990', 'username', 'password', '/location/to/pkcs/wallet/ftps_wallet.p12', 'wallet_password')
    
    print 'Updating and restarting application...'
    cd('/AppDeployments/FtpAdapter/Targets');
    updateApplication(appName, planPath);
    startApplication(appName)
    
    print 'Done with changes. Calling activate...'
    activate()
except:
    print 'Unexpected error: ', sys.exc_info()[0]
    dumpStack()
    raise

Save the script as create_ftp_connection_factories.py on the Weblogic server and execute the following statement:

$ORACLE_HOME/oracle_common/common/bin/wlst.sh create_ftp_connection_factories.py

At the moment I have only implemented the createFTPConnectionFactory method to be able to configure the Host, Username, Password, Port, SecurePort, WalletLocation and WalletPassword properties. However, if you want to be able to edit other properties via this script, it is very easy as well.

To view all properties of an existing FTP connection factory, open the Weblogic console and navigate to Deployments > FtpAdapter > Configuration > Outbound Connection Pools. Extend javax.resource.cci.ConnectionFactory and select the desired connection factory. You will immediately see 8 pages full of properties. With some minor modifications to the WLST script, it is very easy to edit any of these properties. We just have to add a call to updatePropertyForFtpAdapter within the createFTPConnectionFactory method, and provide the application plan, the JNDI name of the connection factory we want to edit, the property name (as shown in the Weblogic console) and the desired property value.

For example, if we want to use implicit SSL, we can see the property UseImplicitSSL via the Weblogic console, which is false by default. To make this property value true by default, we just have to add the following line before the newPlan.save() statement.

updatePropertyForFtpAdapter(newPlan, jndiName, 'UseImplicitSSL', 'true')

I hope this will save you a lot of time when configuring your FTP connection factories. If you have any problem with this script, please let me know.

Geen reacties

Geef jouw mening

Reactie plaatsen

Reactie toevoegen

Jouw e-mailadres wordt niet openbaar gemaakt.

Geen HTML

  • Geen HTML toegestaan.
  • Regels en alinea's worden automatisch gesplitst.
  • Web- en e-mailadressen worden automatisch naar links omgezet.
Whitehorses
Mike Heeren /
Integratie expert

Wil je deel uitmaken van een groep gedreven en ambitieuze experts? Stuur ons jouw cv!