Monday, September 17, 2007

Using CHRONOS Timescale Converter Service Calls

The timescale converter web application accessible through the CHRONOS portal (Ref: http://portal.chronos.org/gridsphere/gridsphere?cid=tools_tsconvert) uses publicly available web service calls to the timescale service described by the WSDL document located at http://services.chronos.org:9090/axis/timescales.jws?wsdl. These services are available for use on any platform.

Simple clients to these end points can be created in any modern programming language. Examples using Python and Groovy, two popular dynamic languages, are given below. Examples using Ruby or C# would be quite similar.

Example using Python

#!/usr/bin/python
#

import re, string
from SOAPpy import SOAPProxy

server = SOAPProxy("http://services.chronos.org:9090/axis/timescales.jws")
time = 20.0

while time < 40.0:

result = server.convertTime("GTS 2004", "Berggren 95",time)

print time , result

time = time + 0.1



Example using Groovy

import groovy.net.soap.SoapClient

def proxy = new SoapClient("http://services.chronos.org:9090/axis/timescales.jws?wsdl")


def serviceClosure = {

time -> return proxy.convertTime("GTS 2004", "Berggren 95", time)
}

for (float f = 20;f< 40.0; f=f+0.1) {
println serviceClosure(f)
}

A slightly more advanced example of a real-world application of these services is the implementation of the service in a Java-based web application server. In this case, a user would use e.g. the Xfire (http://xfire.codehaus.org/Client+and+Server+Stub+Generation+from+WSDL) or Apache Axis (http://ws.apache.org/axis/java/client-side-axis.html) packages to generate a library from the WSDL file. The resulting library could then be easily called from various locations in the application with only a few lines of code.

The first step would involve the creation of the stub classes in a WSDL-to-Java process. We will use the Apache Axis package in this example but the process is similar for Xfire or C# style environments. The initial stub classes are generated through a call like:

java -cp axis.jar:commons-logging-1.0.4.jar:commons-discovery-0.2.jar:axis-ant.jar:log4j-1.2.8.jar:wsdl4j-1.5.1.jar:jaxrpc.jar:saaj.jar org.apache.axis.wsdl.WSDL2Java -o . -d Session -p org.chronos.ws http://services.chronos.org:9090/axis/timescales.jws?wsdl

The result of this call is a set of Java source files that would then be compiled:

javac -classpath axis.jar:commons-logging-1.0.4.jar:commons-discovery-0.2.jar:axis-ant.jar:log4j-1.2.8.jar:wsdl4j-1.5.1.jar:jaxrpc.jar:saaj.jar org/chronos/ws/*.java

and the resulting class files collected into a jar file:

jar -cvf timescale.jar org/chronos/ws/*.class

The resulting jar file can then be used to greatly simplify the creation of clients in Java or any other Java byte code compatible language like Jruby, Jpython or Groovy.

An example of Java client that gets the color scheme for the Geological Time Scale is:

public class wsClient {
public static void main(String [] args) throws Exception {

// Make a service
org.chronos.ws.TimescalesService service = new org.chronos.ws.TimescalesServiceLocator();

// Now use the service to get a stub to the service org.chronos.ws.Timescales_PortType ts = service.gettimescales();

// Make the actual call

System.out.println("call " + ts.getColorScales());

}

}


A Groovy client that uses the jar file (here using the batch convert method for time conversion) is:
import java.text.DecimalFormat

// Make a service

def org.chronos.ws.TimescalesService service = new org.chronos.ws.TimescalesServiceLocator();

// Now use the service to get a stub to the service

def org.chronos.ws.Timescales_PortType ts = service.gettimescales();

// Make the actual call

def batchResults = (ts.convertTimeBatch("GTS 2004", "Berggren 95", 0.toDouble(), 60.toDouble(), 1.toDouble()));


DecimalFormat df2 = new DecimalFormat( "#,###,###,##0.000" );

// Closure for 2 place formating

def decf2 = {

value -> return new Double(df2.format(value)).doubleValue();

}

for (item in batchResults) {
println decf2(item)
}


These examples illustrate the process involved in the creation of clients using only the WSDL URL. Once created, jar libraries like those at the end of the process can be dropped into application server class paths and used in frameworks like Grails (http://www.grails.org), Seam ( http://www.jboss.com/products/seam) or JSR-168 portal environments like Gridsphere (http://www.gridsphere.org). Any application or tool with network access can invoke these services in a similar manner.

All CHRONOS services a similar pattern and can be utilized in web-based or stand-alone clients that have access to the network.

Tuesday, September 04, 2007

Grails SQL date formating lib

Been working with Grails more and created a little tag lib I thought I would post up for others. The date that comes out of the domains is a rather ugly SQL date style so I create a tag lib with the following code:

 def formatSqlDate = { attrs -> 
def String startdatetime = "${attrs['targetDate']}"
def DateFormat odf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss.S");
def DateFormat df = new SimpleDateFormat( "MMM d, ''yy" );
out << df.format(odf.parse(startdatetime))
}
Then I can simple reference it with:

<g:formatsqldate targetdate="${domain.dateObject}">

A person can mode the date format string all they want and also could put in various cases or a flag to select a format style if they wished.

Friday, July 27, 2007

Terminal shell in eclipse


The state of working with Grails in Eclipse is not the best for me. Using the external tool call has been a pain and I have been using an external terminal shell. Today I went looking for a terminal shell solution built into Eclipse and found the Target Management Project.

You can install the components for this via the Eclipse update manager with the information from: http://europa-mirror1.eclipse.org/dsdp/tm/updates/.

Once this is done use the menu sequence Window -> Show_View -> Other and select the Remote Systems folder. From there I added "Remote System Details" (not really needed) and "Remote Shell". Using the triangle menu for this latter element I selected the default local connection.

After all this though.. failure.. it exec's each command out to the shell and as such there is no way to re-attach and kill a process easily. If you run grails run-app it's disconnected to one has to ps its PID and kill it. (not optimal).

After some looking I found sshView (http://www.eclipse-plugins.info/eclipse/plugin_details.jsp?id=1187). This installed but gave some very strange behavior and never was able to get it to successfully work. You can access it in the same sequence as above and look for sshview.

In the end there is easyShell. However, all this does is launch the shell I was using when I started this journey. Yes, you can configure it to open up in the directory the file is in and you can get to rather easily through the contextual menu. In the end not really worth the time and effort and still no good built into the IDE view shell solutions that I can find at least.

Thursday, July 19, 2007

Using Grails GSP to provide alternating colors in a table

Using Grails GSP to provide alternating colors in a table

I saw something related to this a while ago on the net but was not able to find it again. So I just came up with my own approach.

I wanted a table that had alternating rows highlighted. There are many ways to approach this. This solution is what I am going to use since it all falls on the view side of things and as such is rather easy to code. It is based on the code examples from http://grails.org/GSP+Tag+-+set

<table width="50%" align="right" border="0" cellpaddinng="0" cellspacing="0">
<g:def var="counter" value="${1}" />

<g:each in="${lastElement}">

<tr>

<td style="background:
${counter % 2 == 0 ? 'white' : 'grey'">
<g:showElementResults id='${it.id}'/>

</td>

</tr>

<g:set var="counter" value="${counter + 1}" />

</g:each>

</table>


It is the "${counter % 2 == 0 ? 'white' : 'grey'}" that does all the work. The only other interesting elements are in bold. Simply change the two colors to get the banding effect you want. A more advanced version of this could set a style name or some other CSS element to improve the approach. I am sure there are several ways to do this. This seems to work for me. The "<g:showElementResults id='${it.id}'/>" code is not relevant here. It's just a taglib I use to create the formatted text of the cell based on an id and the rest is the just the <g:each> tag boilerplate.

Thursday, July 12, 2007

Keyboard shortcut for grails external tool in Eclipse


Somehow I think this should have been much easier to do. Since it didn't seem to be I am placing it here.

Using Grails in Eclipse (IDE integration information here), I wanted to make a shortcut for the external tools command which is used so much in this set up.

To do this you need to go to preferences (under the window menu), and select Keys -> Modify (Tab) -> Run/Debug (Category pull down) -> Run Last Launched External Tool (Name pull down) then assign the key in the key sequence and be sure to click the "Add" button.

Once all that is done you have a keyboard shortcut for the external tool.

(Please.. I'd like to see netbeans and grails integration)

Tuesday, June 26, 2007

Perm gen size and Grails

I've been continuing to work with the Grails framework and found an interesting issue. When working with the Tomcat application server I run into several issues related to out of memory errors with Grails applications.

Attempts to resolve this with -Xmx512m or some other setting for the memory heap size failed to work. This seems to be due to the large number of elements (controllers, domains, etc) in my grails app that load classes. I believe this is related to issues of lots of use of reflection (not sure). It does appear that this memory is alive during the entire life of the application (not garbage collected). After installing several plug-ins and increasing the size of the application quite a bit this occurred. It also seems to be partly related to the creation of an additional "Context Path" for an application in Tomcat.

I found some reference to Tomcat 6 having better "perm size" management on the net vs Tomcat 5 series. Though nothing of a definitive nature. I saw it seems related since it removing the extra "Context Path" for this grails application seemed to resolve things. Perhaps it is an issue with grails applications in multiple Context Path's but the perm gen size increase did resolve it cleanly.

My current options line for catalina.sh:
JAVA_OPTS='-Xmx512m -XX:MaxPermSize=256m -server -Djava.awt.headless=true'

Friday, May 18, 2007

CBS bought me (well, last.fm)

So I didn't want this blog to become abandoned, and in fact I have several items throughout the last weeks that I have felt worthy of blogging about and have not. I think I just need to discipline myself to post my thoughts when I have them and not "I'll do that later".

But yesterday when I heard CBS bought last.fm (and being a last.fm user) it got me to thinking and motivated to post this thought. I have just been bought... along with my data. Will CBS keep it, take it, toss it out? Indeed if you look around I have relationships with Google, Amazon, Last.fm, Digg and other sites. All this data is valuable to me and what might happen to it in a merger, take-over, bankruptcy?

Do we need a Federal DATA Insurance Corp.
I had this thought a few weeks ago when talking to Josh, regarding my use of Amazon S3 to backup my data. I was looking at various on-line data backup sites. There are many and for my small amount several I could get free (add supported). However, I liked the Amazon S3 due to it's use of services and quite frankly the size and apparent strength of Amazon.

We began talking about the amount of data a person has on the net. I have data I would call valuable with Google (mail, RSS, this blog and a bit more), Amazon (data via S3) and Yahoo (they own del.icio.us now).

However, if any of these were to go away what would happen to my data? Gone? It got me to thinking about the Federal Deposit Insurance Corp. Established to provide some assurance that money (or at least some) would be safe.

Though the analogy is obviously not one to one it does make me wonder if there isn't some general consumer SLA that needs to be established with on-line data "deposit" sites. A Federal DATA Insurance Corp. to provide the public with some level of trust, confidence that data stored on-line in places like Flicker, MySpace, S3, Google, etc are retrievable when/if a company goes south.