Groovy URL example to check if web application is alive

Here is a handy KeepAlive.groovy script that will simply connect to a web application to make sure it’s alive.  The database connection for the web application would often timeout because of lack of activity, especially during non-work hours. By periodically making a request to the web application the database connection will remain active.

KeepAlive.groovy

System.out.println(“Start KeepAlive.groovy”);

def urlList = [‘http://server1Name/appName/controller/action?id=xyz’,
‘http://server2Name/appName/controller/action?id=xyz’]

Date currentDate = new Date();
File f = new File(“%LOGDIR%/KeepAlive.out”);
f.append(“\n”);
f.append(currentDate);
f.append(“\n”);

// Send data
URL url;
URLConnection conn;
BufferedReader rd;
String line;

try {

for (urlString in urlList) {
System.out.println(“Try using URL..: ” + urlString);
url = new URL(urlString);
conn = url.openConnection();
conn.setDoOutput(true);

// Get the response
rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
while ((line = rd.readLine()) != null) {
// Process line…
f.append(line);
}
rd.close();
f.append(“\n”);
}
f.close();
} catch (Exception e) {
System.out.println(“Exception: ” + e.getMessage());
}

System.out.println(“Finished KeepAlive.groovy”);

Posted in Groovy Grails | Comments Off on Groovy URL example to check if web application is alive

mysqldump: Error 1194

I’ve used MySql for a number of years and never incurred an error with mysqldump until today.  Fortunately there is an easy solution to the problem.

mysqldump: Error 1194: Table ‘comments’ is marked as crashed and should be repaired when dumping table `comments` at row: 12o

MySql provides a “repair table `table_name`” command to fix it.  In my case I logged into the mysql database and executed the following commands.

mysql>  use mydb;

mysql> repair table `comment`

Posted in Uncategorized | Comments Off on mysqldump: Error 1194

Define and increment a counter in Apache Jmeter

Create a User Defined Variable and initialize the value.  In this case the value is zero.

Here’s an example of incrementing the “my_counter” value in an HTTP request.  The request URL will include the name value pair:  counter=1

           ${__intSum(${my_counter},1,my_counter)}

Posted in Apache Jmeter | Comments Off on Define and increment a counter in Apache Jmeter

Grails Transient properties in a domain class

Transient properties are useful to carry additional meta data in a domain class without a direct database mapping required.  Transient properties can be useful to handle read only information queried from multiple databases.

  • static transients = [‘manuf’, ‘make’, ‘model’]
  • String manuf
  • String make
  • String model
Posted in Groovy Grails | Comments Off on Grails Transient properties in a domain class