Forum Discussion
Usha_Kodali
16 years agoFrequent Contributor
Sharing the class for updating the endpoints dynamically
class DynamicEndpoint{
def log
def context
def envdym
def project
DynamicEndpoint(log,context,project){
this.log = log
this.context = context
this.project = project
}
def ChangeEndPoint(envdym)
{
def filename
def file
def props
def endpoint
def urldef
def currentendpoint
def spliturl
def jointlist
log.info("Environment is"+" "+envdym)
//reading the properties file
filename = context.expand( '${projectDir}\\endpoint.properties' )
log.info("Endpoint Properties filepath is:"+" "+filename)
//creating file handle for reading the contents
file = new java.io.File( filename )
// if the file exists,read the file and set the endpoint according to the environment entered and finally close the file
if( file.exists() )
{
FileReader r = null;
r = new java.io.FileReader( file )
props = new java.util.Properties()
props.load(r)
endpoint = props.get(envdym)
log.info("Endpoint tobe changed to is : $endpoint")
//Change the mainEndpoint property value in the Project
if( endpoint != null && endpoint.trim().length() > 0 )
{
project.setPropertyValue( "mainEndpoint", endpoint ) //setting the new endpoint
log.info( "Successfully Changed mainEndpoint to [" + endpoint + "]" )
}
else
{
log.info("Endpoint is not set")
}
log.info("**********************************************")
// To update the WSDL's
for(iface in project.getInterfaceList())
{
//Get the current URL Definition
urldef = iface.definition;
log.info("Current URL is:"+urldef)
//split the urldef to update the endpoint
spliturl = urldef.split("/active-bpel/")
log.info("Split URL is"+" "+spliturl.toString())
//join the endpoint,urldef,biniding
jointlist = [endpoint,'/active-bpel/',spliturl[1]]
log.info("Joint List is:"+" "+jointlist);
//create full url definition
urldef = ""
jointlist.each {
urldef += it + ""
}
// log.info("Final endpoint is:"+fullString)
//update definition with new endpoint
// urldef = fullString
log.info("New URL is:"+urldef)
//set the binding definition with new endpoint
iface.definition = urldef
log.info("Finished updating endpoint of Service:"+" "+iface.getName())
log.info("************************************************************")
}
r.close() //closing the file handle
}
else log.info( "Missing [" + filename + "]" )
}
}
call following way in the Load Script section of the Project
def m = new DynamicEndpoint(log,context,project)
m. ChangeEndPoint('qa')
class DynamicEndpoint{
def log
def context
def envdym
def project
DynamicEndpoint(log,context,project){
this.log = log
this.context = context
this.project = project
}
def ChangeEndPoint(envdym)
{
def filename
def file
def props
def endpoint
def urldef
def currentendpoint
def spliturl
def jointlist
log.info("Environment is"+" "+envdym)
//reading the properties file
filename = context.expand( '${projectDir}\\endpoint.properties' )
log.info("Endpoint Properties filepath is:"+" "+filename)
//creating file handle for reading the contents
file = new java.io.File( filename )
// if the file exists,read the file and set the endpoint according to the environment entered and finally close the file
if( file.exists() )
{
FileReader r = null;
r = new java.io.FileReader( file )
props = new java.util.Properties()
props.load(r)
endpoint = props.get(envdym)
log.info("Endpoint tobe changed to is : $endpoint")
//Change the mainEndpoint property value in the Project
if( endpoint != null && endpoint.trim().length() > 0 )
{
project.setPropertyValue( "mainEndpoint", endpoint ) //setting the new endpoint
log.info( "Successfully Changed mainEndpoint to [" + endpoint + "]" )
}
else
{
log.info("Endpoint is not set")
}
log.info("**********************************************")
// To update the WSDL's
for(iface in project.getInterfaceList())
{
//Get the current URL Definition
urldef = iface.definition;
log.info("Current URL is:"+urldef)
//split the urldef to update the endpoint
spliturl = urldef.split("/active-bpel/")
log.info("Split URL is"+" "+spliturl.toString())
//join the endpoint,urldef,biniding
jointlist = [endpoint,'/active-bpel/',spliturl[1]]
log.info("Joint List is:"+" "+jointlist);
//create full url definition
urldef = ""
jointlist.each {
urldef += it + ""
}
// log.info("Final endpoint is:"+fullString)
//update definition with new endpoint
// urldef = fullString
log.info("New URL is:"+urldef)
//set the binding definition with new endpoint
iface.definition = urldef
log.info("Finished updating endpoint of Service:"+" "+iface.getName())
log.info("************************************************************")
}
r.close() //closing the file handle
}
else log.info( "Missing [" + filename + "]" )
}
}
call following way in the Load Script section of the Project
def m = new DynamicEndpoint(log,context,project)
m. ChangeEndPoint('qa')