Saturday, August 3, 2013

Validating the DOJO form programatically from Java Script

Validating the DOJO form programatically from Java Script

Sometimes we may need to validate the dojo form programatically from java script.

<form id="createForm" data-dojo-type="dijit.form.Form" data-dojo-attach-point="form"> .......</form>

The below line of code will help us to validate the form from java script

var formResult=dijit.byId('createForm').validate();

The validation result will be true if the validation of all the filed is success else the value will be false.


Getting the selected rows from DOJO Enhanced Grid

Getting the selected rows from DOJO Enhanced Grid :

The below line of code will help us to get the selected rows of the  Enhanced grid

dijit.byId(gridId).selection.getSelected();

Getting the model value of the selected rows.

var selectedRows=dijit.byId(gridId).selection.getSelected();

for(int i=0;i<selectedRows.length;i++)
{
   selectedRows[i].empName;
}



Stopping the Busy Button in DOJO

Stopping the Busy Button in DOJO

Getting the selected rows from DOJO Enhanced Grid :

DOJO busy button will help us to display the Busy Label to user while performing some actions, sometimes we need to stop the busy label and to display the normal button back.

<button data-dojo-type="dojox.form.BusyButton" id="loginButton" style ="margin-top: 10px; margin-right: -8px;" data-dojo-props="busyLabel:'Authenticating...'" onclick="loginForm()">SignIn</button>

If we are clicking on SignIn the button label will be changed to "Authenticating..." and the user will not be able to click the button again but in case of authentication failure the button should be displayed as normal

The below line of code will help as to cancel the busy button.

dijit.byId('loginButton').cancel();   


Getting the logged-in user details in Spring

Getting the logged-in user details in Spring

The below piece of code will help us to get the logged-in user details from spring security context.

User user = (User)SecurityContextHolder.getContext().getAuthentication().getPrincipal();
       
Sting userName=user.getUsername();
   


Tuesday, March 12, 2013

Creating Foreign JMS Server configurations through WLST script in Weblogic server

Creating Foreign JMS Server configurations through WLST script in Weblogic server


WebLogic JMS enables you to reference foreign (that is, external) JMS providers within a local WebLogic JNDI tree. Using the Foreign JMS Server node, you can quickly map a foreign JMS provider so that its connection factories and destinations appear in the WebLogic JNDI tree as a local JMS objects.

A Foreign JMS Server configuration can also be used to reference remote instances of WebLogic Server in another cluster or domain in the local WebLogic JNDI tree

Once the Foreign Provider is configured within Weblogic, for all practical purposes within the code — it can be called as if it was on local JNDI lookup. Weblogic will make the remote calls transparent to your code. This allows you to change your destination via configuration on the Weblogic console.

This tutorial explains the approach to configure Foreign JMS server through WLST script
WLST Script

The below WLST script help us to create a Foreign JMS server in a local server for a JMS resources running in a remote weblogic server(in different domain) but the same can be used to configure Foreign Server with external providers .

The JMS Server running on t3://localhost:7002 is configured as a Foreign JMS Server for t3://localhost:7002

The JMS clients can use the local JNDI configured in the local server to send the messages to the remote JMS server.

The same script can be modified to create a Foreign JNDI Server for other JMS providers, some of the important remote server properties to be modified is remoteDestinationJNDI, remoteConnectionFactoryJNDI, remoteConnectionURL, initialJNDIContextFactory, remoteUserName and remotePassword

ConfigureForeignJMSServer.properties

adminUserName=weblogic
adminUserPassword=weblogic1
adminServerHost=localhost
adminServerPort=7001foreignJMSModuleName=BAMForeginJMSResource
foreignJMSServerName=BAMForeignJMSServer
localConnectionFactoryJNDI=jms/BAMMonitoringConnectionfactory1
remoteConnectionFactoryJNDI=jms/BAMMonitoringConnectionfactory1
localDestinationJNDI=jms/BAMMonitoringQueue1
remoteDestinationJNDI=jms/BAMMonitoringQueue1remoteConnectionURL=t3://localhost:7002
initialJNDIContextFactory= weblogic.jndi.WLInitialContextFactory
remoteUserName=weblogic
remotePassword=welcome1

ConfigureForeignJMSServer.py

from java.io import FileInputStreampropInputStream = FileInputStream("ConfigureForeignJMSServer.properties")
configProps = Properties()
configProps.load(propInputStream)connect(configProps.get("adminUserName"),configProps.get("adminUserPassword"), 't3://'+configProps.get("adminServerHost")+':'+configProps.get("adminServerPort"))foreignJMSModuleName=configProps.get("foreignJMSModuleName")
foreignJMSServerName=configProps.get("foreignJMSServerName")
localConnectionFactoryJNDI=configProps.get("localConnectionFactoryJNDI")
localDestinationJNDI=configProps.get("localDestinationJNDI")remoteDestinationJNDI=configProps.get("remoteDestinationJNDI")
remoteConnectionFactoryJNDI=configProps.get("remoteConnectionFactoryJNDI")remoteConnectionURL=configProps.get("remoteConnectionURL")
initialJNDIContextFactory=configProps.get("initialJNDIContextFactory")
remoteUserName=configProps.get("remoteUserName")
remotePassword=configProps.get("remotePassword")edit()
startEdit()cd('/')
cmo.createJMSSystemResource(foreignJMSModuleName)cd('/SystemResources/'+foreignJMSModuleName)
set('Targets',jarray.array([ObjectName('com.bea:Name=AdminServer,Type=Server')], ObjectName))cd('/JMSSystemResources/'+foreignJMSModuleName+'/JMSResource/'+foreignJMSModuleName)
cmo.createForeignServer(foreignJMSServerName)cd('/JMSSystemResources/'+foreignJMSModuleName+'/JMSResource/'+foreignJMSModuleName+'/ForeignServers/'+foreignJMSServerName)
cmo.setDefaultTargetingEnabled(true)cmo.setJNDIPropertiesCredential(remotePassword)cmo.setInitialContextFactory(initialJNDIContextFactory)
cmo.setConnectionURL(remoteConnectionURL)
cmo.createJNDIProperty('java.naming.security.principal')cd('/JMSSystemResources/'+foreignJMSModuleName+'/JMSResource/'+foreignJMSModuleName+'/ForeignServers/'+foreignJMSServerName+'/JNDIProperties/java.naming.security.principal')
cmo.setValue(remoteUserName)cd('/JMSSystemResources/'+foreignJMSModuleName+'/JMSResource/'+foreignJMSModuleName+'/ForeignServers/'+foreignJMSServerName)cmo.createForeignConnectionFactory('ForeignJMSConnectionFactory')cd('/JMSSystemResources/'+foreignJMSModuleName+'/JMSResource/'+foreignJMSModuleName+'/ForeignServers/'+foreignJMSServerName+'/ForeignConnectionFactories/ForeignJMSConnectionFactory')
cmo.setLocalJNDIName(localConnectionFactoryJNDI)
cmo.setRemoteJNDIName(remoteConnectionFactoryJNDI)cd('/JMSSystemResources/'+foreignJMSModuleName+'/JMSResource/'+foreignJMSModuleName+'/ForeignServers/'+foreignJMSServerName)
cmo.createForeignDestination('ForeignJMSDestination')cd('/JMSSystemResources/'+foreignJMSModuleName+'/JMSResource/'+foreignJMSModuleName+'/ForeignServers/'+foreignJMSServerName+'/ForeignDestinations/ForeignJMSDestination')
cmo.setLocalJNDIName(localDestinationJNDI)
cmo.setRemoteJNDIName(remoteDestinationJNDI)activate()

Script

https://github.com/techforum-repo/youttubedata/tree/master/scripts/wlst/ConfigureForeignJMSServer

Before executing the script, change the configurations as required.

Execute the script — <<Oracle_Home>>\oracle_common\common\bin\wlst.cmd ConfigureForeignJMSServer.py







Now the foreign JMS server is configured and ready for use — the messages can be send/receive through local JNDI’s , Weblogic server internally communicate to the remote server. The foreign JMS server configuration helps as to abstract the remote server details from clients, the remote server implementations can be changed any time without impacting the clients