Monday, 8 January 2018

Passing HTTP Basic Authentication to secure Webservices With SOA Suite 11g BPEL

In this post we will see  how to use SOA 11g BPEL to pass a username & password pair to a webservice that was protected by HTTP basic authentication.
Below are steps for achieving this using 11g JDeveloper;
  1. Open your SOA composite and in your BPEL process add the partner link call to the remote secured webservice wsdl location.
  2. Once you’ve browsed for the wsdl, edit your projects composite.xml file via the Application Navigator on the left.
  3. Now right click on the external referenced service that you added and select ‘Configure WS policies’
  4. Within the Security tab, click the Add button and select oracle/wss_username_token_client_policy.
  5. Via the Property Inspector window click the ADD button under the Binding Properties tab.
  6. Now Open the property Inspector window and click the add button under Binding properties tab.
  7. Manually add oracle.webservices.auth.username and oracle.webservices.auth.password and their properties. ie: add two new properties, oracle.webservices.auth.username and a value, then another property – oracle.webservices.auth.password and a value.
  8. Compile and deploy the project to observe how those properties are now passed to the remote webservice.

Creating Data source and DB adapter outbound connection pool using WLST

In this post we will see how to create a data source , DB adapter outbound connection pool and redeployment using wlst scripts.
Lets look at the script which creates both DS and DB adapter connection pool and redeployment.
import time
# admin server url
url = ‘t3://localhost:7001’
# username to connect to the admin server
username = ‘weblogic’
# password to connect to the admin server
password = ‘welcome1’
# the name for the EIS
eisName = ‘eis/db/myDS’
# the admin or managed server to target where the DbAdapter is deployed
serverName = ‘AdminServer’
#nmServerName = ‘soa_server1’
# the name for the data source
dsName = ‘myDS’
# the JNDI name for the data source
jndiName = ‘jbdc/myDS’
# the database url for the data source
dbUrl = ‘jdbc:oracle:thin:@localhost:1522:SOAORA’
# the database user
dbUser = ‘soa12c_soainfra’
# the database password
dbPassword = ‘welcome_1’
# the database driver to use
dbDriver = ‘oracle.jdbc.xa.client.OracleXADataSource’
# the host where node manager is running
#nmHost = ‘localhost’
# the port to connect to node manager (5556 is default for plain mode)
#nmPort = ‘5556’
# the user to connect to node manager
#nmUser = ‘weblogic’
# the password to connection to node manager
#nmPassword = ‘welcome1’
# the name of the weblogic domain
domain = ‘soa12c_domain’
# don’t change the below ones
uniqueString = ”
appName = ‘DbAdapter’
moduleOverrideName = appName+’.rar’
moduleDescriptorName = ‘META-INF/weblogic-ra.xml’
#
# method definitions
#
def makeDeploymentPlanVariable(wlstPlan, name, value, xpath, origin=’planbased’):
try:
variableAssignment = wlstPlan.createVariableAssignment(name, moduleOverrideName, moduleDescriptorName)
variableAssignment.setXpath(xpath)
variableAssignment.setOrigin(origin)
wlstPlan.createVariable(name, value)
except:
print(‘–> was not able to create deployment plan variables successfully’)
def main():
uniqueString = str(int(time.time()))
#
# Create a JDBC Data Source.
#
try:
print(‘–> about to connect to weblogic’)
connect(username, password, url)
print(‘–> about to create a data source ‘ + dsName)
edit()
startEdit()
cmo.createJDBCSystemResource(dsName)
cd(‘/JDBCSystemResources/’ + dsName + ‘/JDBCResource/’ + dsName)
cmo.setName(dsName)
cd(‘/JDBCSystemResources/’ + dsName + ‘/JDBCResource/’ + dsName + ‘/JDBCDataSourceParams/’ + dsName)
set(‘JNDINames’,jarray.array([String(jndiName)], String))
cd(‘/JDBCSystemResources/’ + dsName + ‘/JDBCResource/’ + dsName + ‘/JDBCDriverParams/’ + dsName)
cmo.setUrl(dbUrl)
cmo.setDriverName(dbDriver)
cmo.setPassword(dbPassword)
cd(‘/JDBCSystemResources/’ + dsName + ‘/JDBCResource/’ + dsName + ‘/JDBCConnectionPoolParams/’ + dsName)
cmo.setTestTableName(‘DUAL’)
cd(‘/JDBCSystemResources/’ + dsName + ‘/JDBCResource/’ + dsName + ‘/JDBCDriverParams/’ + dsName + ‘/Properties/’ + dsName)
cmo.createProperty(‘user’)
cd(‘/JDBCSystemResources/’ + dsName + ‘/JDBCResource/’ + dsName + ‘/JDBCDriverParams/’ + dsName + ‘/Properties/’ + dsName + ‘/Properties/user’)
cmo.setValue(dbUser)
cd(‘/JDBCSystemResources/’ + dsName + ‘/JDBCResource/’ + dsName + ‘/JDBCDataSourceParams/’ + dsName)
cmo.setGlobalTransactionsProtocol(‘TwoPhaseCommit’)
cd(‘/JDBCSystemResources/’ + dsName)
set(‘Targets’,jarray.array([ObjectName(‘com.bea:Name=’ + serverName + ‘,Type=Server’)], ObjectName))
save()
print(‘–> activating changes’)
activate()
print(‘–> done’)
#
# update the deployment plan
#
print(‘–> about to update the deployment plan for the DbAdapter’)
startEdit()
planPath = get(‘/AppDeployments/DbAdapter/PlanPath’)
appPath = get(‘/AppDeployments/DbAdapter/SourcePath’)
print(‘–> Using plan ‘ + planPath)
plan = loadApplication(appPath, planPath)
print(‘–> adding variables to plan’)
makeDeploymentPlanVariable(plan, ‘ConnectionInstance_eis/DB/’ + dsName + ‘_JNDIName_’ + uniqueString, eisName, ‘/weblogic-connector/outbound-resource-adapter/connection-definition-group/[connection-factory-interface=”javax.resource.cci.ConnectionFactory”]/connection-instance/[jndi-name=”‘ + eisName + ‘”]/jndi-name’)
makeDeploymentPlanVariable(plan, ‘ConfigProperty_xADataSourceName_Value_’ + uniqueString, eisName, ‘/weblogic-connector/outbound-resource-adapter/connection-definition-group/[connection-factory-interface=”javax.resource.cci.ConnectionFactory”]/connection-instance/[jndi-name=”‘ + eisName + ‘”]/connection-properties/properties/property/[name=”xADataSourceName”]/value’)
print(‘–> saving plan’)
plan.save();
save();
print(‘–> activating changes’)
activate(block=’true’);
cd(‘/AppDeployments/DbAdapter/Targets’);
print(‘–> redeploying the DbAdapter’)
redeploy(appName, planPath, targets=cmo.getTargets());
print(‘–> done’)
except:
print(‘–> something went wrong, bailing out’)
stopEdit(‘y’)
raise SystemExit
#
# disconnect from the admin server
#
print(‘–> disconnecting from admin server now’)
disconnect()
#
# this is the main entry point
#
main()
To use this script, we need to edit the parameters at the top of the program.
save it somewhere in the server location(cd /your/fmwhome/wlserver/server/bin/) with name like “createMyDS.py”
Set the domain environment by running the below command.
cd /your/fmwhome/wlserver/server/bin/> setDomainEnv.cmd
Now run the python script with below command.
/your/fmwhome/wlserver/server/bin/>  java weblogic.WLST createMyDS.py
Now if you open your weblogic console you will find both DS and DB adapter configured with above values.
wlstdswlstdb1

Creating JMS server, JMS module, JMS Connection Factory and JMS Queue through WLST

In this post we will see how to Creating JMS server, JMS module, JMS Connection Factory and JMS Queue using wlst scripts.
Create a directory in your system and create a properties file with below information and name it as “JMSconfig.properties“.
# 1 – ENTER Server Connection details
server.url = t3://localhost:7001
username = weblogic
password = welcome1
# 2 – ENTER JMSServer details
jms.server.name = TEST_JMSServer
store.name = TEST_JDBCStore
tragated.jms.server.name = AdminServer
# 3 – ENTER  SystemModule Details
system.module.name = TEST_JMSModule
tragated.system.module.name = AdminServer
# 4 – ENTER  ConnectionFactory Details
connection.factory.name = TEST_ConnectionFactory
connection.factory.jndi.name = jms/TEST_CF
# 5 – ENTER  Unit Of Order Details
unit.of.order.value = 1
# 6 – ENTER  SubDeployment & Queue Details
queue.sub.deployment.name = Sub_TEST_Queue
queue.name = TEST_Queue
queue.jndi.name = jms/TEST_Q
Now in the same directory create a new file for JMS script with below script and name it as “JMSConfig.py”
from java.io import FileInputStream
import java.lang
import os
import string
propInputStream = FileInputStream(“domain.properties”)
configProps = Properties()
configProps.load(propInputStream)
# 1 – Connecting details
serverUrl = configProps.get(“server.url”)
Username = configProps.get(“username”)
Password = configProps.get(“password”)
# 2 – JMSServer details
jmsServerName = configProps.get(“jms.server.name”)
storeName = configProps.get(“store.name”)
tragatedJMSServerName = configProps.get(“tragated.jms.server.name”)
# 3 – SystemModule Details
systemModuleName = configProps.get(“system.module.name”)
tragatedSystemModuleName = configProps.get(“tragated.system.module.name”)
# 4 – ConnectionFactory Details
connectionFactoryName = configProps.get(“connection.factory.name”)
ConnectionFactoryJNDIName = configProps.get(“connection.factory.jndi.name”)
# 5 – Unit Of Order Details
unitOfOrderValue = configProps.get(“unit.of.order.value”)
# 6 – SubDeployment & Queue Details
queueSubDeploymentName = configProps.get(“queue.sub.deployment.name”)
queueName = configProps.get(“queue.name”)
queueJNDIName = configProps.get(“queue.jndi.name”)
redirect(‘wlst.log’,’false’)
# 1 – Connecting to the Destination 
connect(Username,Password,serverUrl)
edit()
# 2 – JMSServer details
print “================== JMSSever ===================”
startEdit()
cmo.createJMSServer(jmsServerName)
print “Created a JMSServer !!”
cd(‘/Deployments/’+jmsServerName)
cmo.setPersistentStore(getMBean(‘/JDBCStores/’+storeName))
print “PersistentStore has been set for the JMSServer !!”
set(‘Targets’,jarray.array([ObjectName(‘com.bea:Name=’+tragatedJMSServerName+’,Type=Server’)], ObjectName))
print “Targeted the JMSServer !!”
activate()
print “”
# 3 – SystemModule Details
print “================== SystemModule ===================”
startEdit()
cd(‘/’)
cmo.createJMSSystemResource(systemModuleName)
print “Created a SystemModule !!”
cd(‘/SystemResources/’+systemModuleName)
set(‘Targets’,jarray.array([ObjectName(‘com.bea:Name=’+tragatedSystemModuleName+’,Type=Server’)], ObjectName))
print “Targeted the SystemModule !!”
activate()
print “”
# 4 – ConnectionFactory Details
print “================== ConnectionFactory ===================”
startEdit()
cd(‘/JMSSystemResources/’+systemModuleName+’/JMSResource/’+systemModuleName)
cmo.createConnectionFactory(connectionFactoryName)
cd(‘/JMSSystemResources/’+systemModuleName+’/JMSResource/’+systemModuleName+’/ConnectionFactories/’+connectionFactoryName)
cmo.setJNDIName(ConnectionFactoryJNDIName)
print “Created a ConnectionFactory !!”
cd(‘/JMSSystemResources/’+systemModuleName+’/JMSResource/’+systemModuleName+’/ConnectionFactories/’+connectionFactoryName+’/SecurityParams/’+connectionFactoryName)
cmo.setAttachJMSXUserId(false)
cd(‘/JMSSystemResources/’+systemModuleName+’/JMSResource/’+systemModuleName+’/ConnectionFactories/’+connectionFactoryName)
cmo.setDefaultTargetingEnabled(true)
print “Targeted the ConnectionFactory !!”
activate()
print “”
# 5 – Unit Of Order Details
print “================== Unit Of Order ===================”
startEdit()
cd(‘/JMSSystemResources/’+systemModuleName+’/JMSResource/’+systemModuleName+’/ConnectionFactories/’+connectionFactoryName+’/DefaultDeliveryParams/’+connectionFactoryName)
cmo.setDefaultUnitOfOrder(unitOfOrderValue)
print “Changed Unit Of Order !!”
activate()
print “”
# 6 – SubDeployment & Queue Details
print “================== SubDeployment & Queue ===================”
startEdit()
cd(‘/SystemResources/’+systemModuleName)
cmo.createSubDeployment(queueSubDeploymentName)
print “Created a SubDeployment for Queue !!”
cd(‘/JMSSystemResources/’+systemModuleName+’/JMSResource/’+systemModuleName)
cmo.createQueue(queueName)
print “Created a Queue !!”
cd(‘/JMSSystemResources/’+systemModuleName+’/JMSResource/’+systemModuleName+’/Queues/’+queueName)
cmo.setJNDIName(queueJNDIName)
cmo.setSubDeploymentName(queueSubDeploymentName)
cd(‘/SystemResources/’+systemModuleName+’/SubDeployments/’+queueSubDeploymentName)
set(‘Targets’,jarray.array([ObjectName(‘com.bea:Name=’+jmsServerName+’,Type=JMSServer’)], ObjectName))
print “Targeted the Queue to the created subdeployment !!”
activate()
print “”
cmd = “rm -f wlst.log”
os.system(cmd)
To use this script, we need to edit the properties file at the top of the program.
Now place both the properties and python file  in the server location(cd /your/fmwhome/wlserver/server/bin/)
Set the domain environment by running the below command.
cd /your/fmwhome/wlserver/server/bin/> setDomainEnv.cmd
Now run the python script with below command.
/your/fmwhome/wlserver/server/bin/>  java weblogic.WLST JMSConfig.py

Wednesday, 3 January 2018

How to invoke Oracle BPEL process from Java?

Import the following classes.

// To connect to BPEL Process Manager
import com.oracle.bpel.client.Locator;

// To invoke BPEL process
import com.oracle.bpel.client.dispatch.IDeliveryService;

// To process XML messages
import com.oracle.bpel.client.NormalizedMessage;

Add following code to your invokation logic.
1: Connect to BPEL process manager

Locator locator = new Locator("Domain Name", "Pass Word" , "IP Address");

Ex: Locator locator = new Locator("default", "bpel", null);
// null IP address means local server

2: Get the handle of IDeliveryService instance which is used to invoke BPEL process.

IDeliveryService deliveryService =
(IDeliveryService)locator.lookupService(IDeliveryService.SERVICE_NAME );

3: Prepare the XMl message for input.

String xmlData = "XML data";
NormalizedMessage message = new NormalizedMessage( );
message.addPart("payload", xmlData );

4: Invoking BPEL process with two way operations
(which has both input and output messages)

NormalizedMessage res =
deliveryService.request("BPEL Process ID", "Operation Name", "message");
Map payload = res.getPayload();

5: Invoking BPEL process with one way operations
(which takes input message but returns not output)

deliveryService.post("BPEL Process ID", "Operation Name", "message");

Calls to SOA Services Show Timeout Errors and no more BPEL Instances are Created

Symptoms
When using SOA Suite Services like Applications Adapters and Database Adapters, after some running time all services stop and the application that make calls to these SOA services start to show timeout error.When checking the BPEL console, you can observed that no instance is generated.

Using AS Control you can observe that in the metrics of connection pool "Threads waiting connections" values are increasing and no more new connection is possible.

Checking the data-sources.xml file we can see that the connection pools define for several of these connections have the following attributes defined:

1
2
3
4
5
<connection-pool name="test" abandoned-connection-timeout="180" inactivity-timeout="50" max-connections="50">
....
</connection-pool>

Restarting the SOA Suite solves the issue.

Cause
The issue is caused by JDBC Bug 5842387 - THREADS LEAK WHEN CONNECTION CACHE ABANDON TIMEOUT IS ENABLED

The issue happens when the abandon time thread is locked while trying to close a connection (which is in use).
All subsequent threads which are requesting a connection will be locked. And, the oc4j container will have an increase of number of threads waiting to get a connection.

Solution
Option I
Implement the workaround which suggest NOT using attribute abandoned-connection-timeout for the data source.
Option II
Apply the patch 3438755.

How to set a timeout for a Partner Link / WebService in a BPEL

Modify partnerLinkBinding section in bpel.xml as follows
?
1
2
3
4
5
6
7
<partnerlinkbinding name="WebService">
  <property name="timeout">5</property>
  <property name="optSoapShortcut">false</property>
  <!-- other PartnerLink properties -->
</partnerlinkbinding>