Dec
04
2008
0

GrailsUI - Very Nice Indeed

I recently took the time to install and work with the Grails plugin, GrailsUI. It provides a great tag library that is based on YUI and the Bubbling library, a YUI extension. I really like the components that are available and if you need that rich Ajax feel in your Grails application, this is a low impedance path to get things done. So, in order to get your Grails project up and running with GrailsUI, you need to install all 3 plugins in this order:

...
grails install-plugin yui
grails install-plugin bubbling
grails install-plugin grails-ui
...

At first, I just started adding some of the static components to the index.gsp page and then moved on to wiring the rich Ajax components to controllers. If you follow the code snippets on the GrailsUI plugin page or if you check out the guiDemo Grails project, you should have very little problem understanding the core components and their attributes. Grails with GrailsUI can get your next Web application up and running with a very popular UI technology and the learning curve is not too steep if you first check out the guiDemo on the GrailsUI plugin page.

Written by R.J. Salicco in: Development | Tags: , ,
Oct
21
2008
0

Apache CXF: Open Source Service Framework - The Client

Earlier this year I posted Apache CXF: Open Source Service Framework to demonstrate how easy it is to create a simple echo Web Service with Apache CXF. Now I would like to post an example client for that service using Apache CXF.

First, we need our dependencies: (download them here)

...
commons-logging-1.1.1.jar
cxf-2.1.2.jar
FastInfoset-1.2.2.jar
geronimo-activation_1.1_spec-1.0.2.jar
geronimo-annotation_1.0_spec-1.1.1.jar
geronimo-javamail_1.4_spec-1.3.jar
geronimo-jaxws_2.1_spec-1.0.jar
geronimo-servlet_2.5_spec-1.2.jar
geronimo-stax-api_1.0_spec-1.0.1.jar
geronimo-ws-metadata_2.0_spec-1.1.2.jar
jaxb-api-2.1.jar
jaxb-impl-2.1.7.jar
jaxen-1.1.jar
jdom-1.0.jar
jetty-6.1.9.jar
jetty-util-6.1.9.jar
neethi-2.0.4.jar
saaj-api-1.3.jar
saaj-impl-1.3.jar
spring-beans-2.0.8.jar
spring-context-2.0.8.jar
spring-core-2.0.8.jar
spring-web-2.0.8.jar
stax-utils-20060502.jar
wsdl4j-1.6.2.jar
wstx-asl-3.2.4.jar
xml-resolver-1.2.jar
XmlSchema-1.4.2.jar
...

Then we need the Echo Service interface (this should be provided for us from our service providers) :

...
package com.thejavajar.service;

import javax.jws.WebService;

@WebService
public interface EchoServiceIfc {

	public String echo(String text);
}
...

The last piece of the pie is our client that makes the call out to http://localhost:9000/echo, where our service lives, in order to invoke an operation on the service.

...
package com.thejavajar.client;

import org.apache.cxf.frontend.ClientProxyFactoryBean;

import com.thejavajar.service.EchoServiceIfc;

public class EchoClient {

	public static void main(String[] args) {

		String request = new String("test 1");

		ClientProxyFactoryBean factory = new ClientProxyFactoryBean();
		factory.setServiceClass(EchoServiceIfc.class);
		factory.setAddress("http://localhost:9000/echo");
		EchoServiceIfc client = (EchoServiceIfc) factory.create();

		System.out.println("Sending: " + request);
		String response = client.echo(request);
		System.out.println("Returned: " + response);

		System.exit(0);
	}
}
...

All we need to do is run our main method in our EchoClient class and we will get something like:

...
Sending: test 1
Returned: test 1
...

That’s all folks. Obviously, this example, along with our previously posted service, is not solving complex problems that we might face in our current Java development endeavors but it provides us with peak into Apache CXF and opens up more people to a technology that I enjoy working with.

Eclipse Project: apache-cxf-echo-client.zip

Written by R.J. Salicco in: Development | Tags: , ,
Oct
19
2008
1

Editable Flex Datagrid and Grails

I have been really digging into Flex lately and I have been complimenting Flex’s incredibly nice UI capabilities with services written on Grails. I am extremely impressed with Flex and Grails really helps me get things up and running very quickly (you already know this if you are using Grails). Let’s look at a quick example of where I am using one domain class and a few simple Grails actions in a controller in order to provide search and editing capabilities to a simple Flex application based on a datagrid.

The Grails domain class, Item.groovy:

...
class Item {

        String name
        String brand
        String line
}
...

The Grails controller class ItemController.groovy:

...
class ItemController {

    def search = {
	    if(!params.max) {
        	params.max = 100
        }
        if(!params.name) {
        	params.name = ""
        }

        def itemList = Item.findAllByNameLike("$params.name%",[max:params.max])

        render(contentType:"text/xml") {
        	items {
        		for(i in itemList) {
        			item {
        				id(i.id)
        				name(i.name)
        				brand(i.brand)
        				line(i.line)
        			}
        		}
        	}
        }
    }

	def save = {
		if(params.id) {
			def item = Item.get(params.id)

			if(item) {
				item.properties = params
				if(!item.hasErrors() && item.save()) {
					render ""
				}
				else {
					render ""
				}
			}
	  	}
	}
}
...

I also added this to the conf/BootStrap.groovy so I would have some data to work with once I started up the Grails applicaiton. The code below creates 1,000 items during start-up:

...
     def init = { servletContext ->

     	(1..1000).each {
     		new Item(name: "Item $it", brand: "My Brand", line: "My Line").save()
     	}
     }
...

I mostly worked with only 1,000 items, but I increased this up to 100,000 items to put it through some tests and it worked very nicely.

Now let’s dive right into the MXML. Here is the entire itemlist.mxml file:

...
<?xml version="1.0"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">

    <mx:Script>
        <![CDATA[

            import mx.controls.Alert;
            import mx.events.DataGridEvent;
            import mx.rpc.events.FaultEvent;
            import mx.rpc.events.ResultEvent;

            [Bindable]
            private var itemId:String;

            [Bindable]
            private var itemName:String;

            [Bindable]
            private var itemBrand:String;

            [Bindable]
            private var itemLine:String;

            private function sendItemData(event:DataGridEvent):void
			{
                var myEditor:TextInput = TextInput(event.currentTarget.itemEditorInstance);
				itemName = myEditor.text;

                itemId = event.currentTarget.editedItemRenderer.data["id"];
				itemBrand = event.currentTarget.editedItemRenderer.data["brand"];
				itemLine = event.currentTarget.editedItemRenderer.data["line"];

				itemSaveService.send();
            }

			protected function filterList():void
			{
				itemSearchService.send();
			}	

			private function fault_Handler(event:FaultEvent):void
			{
				Alert.show(event.fault.message, "Could not load items.");
			}
        ]]>
    </mx:Script>

    <mx:HTTPService
        id="itemSaveService"
        method="POST"
        url="http://localhost:8080/itemlist/item/save"
  		resultFormat="e4x"
  		fault="fault_Handler(event);"
  		showBusyCursor="true">
			<mx:request xmlns="">
				<id>{itemId}</id>
				<name>{itemName}</name>
				<brand>{itemBrand}</brand>
				<line>{itemLine}</line>
			</mx:request>
  	</mx:HTTPService>

    <mx:HTTPService
        id="itemSearchService"
        method="GET"
        url="http://localhost:8080/itemlist/item/search"
  		resultFormat="e4x"
  		fault="fault_Handler(event);"
  		showBusyCursor="true">
			<mx:request xmlns="">
				<name>{searchBox.text}</name>
			</mx:request>
  	</mx:HTTPService>

    <mx:Panel title="Item List" height="100%" width="100%" paddingTop="10" paddingLeft="10" paddingRight="10">

		<mx:Label text="Search:"/><mx:TextInput id="searchBox" enter="filterList();"/>

        <mx:DataGrid id="dg" width="100%" height="50%" rowCount="5"
        	dataProvider="{itemSearchService.lastResult.item}"
        	editable="true"
			itemEditEnd="sendItemData(event);">
            <mx:columns>
            	<mx:DataGridColumn dataField="id" headerText="Id" editable="false"/>
                <mx:DataGridColumn dataField="name" headerText="Name"/>
                <mx:DataGridColumn dataField="brand" headerText="Brand" editable="false"/>
                <mx:DataGridColumn dataField="line" headerText="Line" editable="false"/>
            </mx:columns>
        </mx:DataGrid>

    </mx:Panel>
</mx:Application>
...

Now that all of the code is out on the table, we can start to dissect what is happening with the Flex UI.

When the application starts up:

Once we type in “Item ” and press enter:

When we click on a value under the “Name” column in our datagrid:

We have 2 HTTPService’s setup to send requests back to our Grails controller at http://localhost:8080/itemlist/item/save and http://localhost:8080/itemlist/item/search. The first service call will send all the item data to the ItemController’s save action and the second one will send our search box’s text to the ItemController’s search action. We have ActionScript functions that handle the “Enter” key press event on the search box and we also have a function that will be called after the datagrid field has been edited.

Most of the code is pretty self explanatory but if you have any questions, feel free to contact me. Also, Marcel Overdijk has some great posts on Grails and Flex that can really help out when you get stuck.

Written by R.J. Salicco in: Development | Tags: , ,
Sep
02
2008
0

Apache CXF: Open Source Service Framework

Web Service development has come a long way. I had some experience with XFire a few years ago and thought Web Service development could not get any easier. Then XFire became the Apache CXF project. I wanted to take a peak at Apache CXF so the other night I put together a simple echo Web Service. Alright, if you would like to follow along, you can create a Web Service in about 10 minutes:

First, we need our dependencies: (download them here)

...
commons-logging-1.1.1.jar
cxf-2.1.2.jar
FastInfoset-1.2.2.jar
geronimo-activation_1.1_spec-1.0.2.jar
geronimo-annotation_1.0_spec-1.1.1.jar
geronimo-javamail_1.4_spec-1.3.jar
geronimo-jaxws_2.1_spec-1.0.jar
geronimo-servlet_2.5_spec-1.2.jar
geronimo-stax-api_1.0_spec-1.0.1.jar
geronimo-ws-metadata_2.0_spec-1.1.2.jar
jaxb-api-2.1.jar
jaxb-impl-2.1.7.jar
jaxen-1.1.jar
jdom-1.0.jar
jetty-6.1.9.jar
jetty-util-6.1.9.jar
neethi-2.0.4.jar
saaj-api-1.3.jar
saaj-impl-1.3.jar
spring-beans-2.0.8.jar
spring-context-2.0.8.jar
spring-core-2.0.8.jar
spring-web-2.0.8.jar
stax-utils-20060502.jar
wsdl4j-1.6.2.jar
wstx-asl-3.2.4.jar
xml-resolver-1.2.jar
XmlSchema-1.4.2.jar
...

Second, we need our service interface: (note the @WebService annotation)

...
package com.thejavajar.service;

import javax.jws.WebService;

@WebService
public interface EchoServiceIfc {
        public String echo(String text);
}
...

Next, we need an implementation of our service interface: (note the @WebService annotation)

...
package com.thejavajar.service;

import javax.jws.WebService;

@WebService
public class EchoServiceImpl implements EchoServiceIfc {
        public String echo(String text) {
                return text;
        }
}
...

Finally, we can create a simple Java class that will start a server and expose our service:

...
package com.thejavajar.server;

import org.apache.cxf.frontend.ServerFactoryBean;

import com.thejavajar.service.EchoServiceIfc;
import com.thejavajar.service.EchoServiceImpl;

public class Server {
	public static void main(String[] args) {
		EchoServiceImpl echoServiceImpl = new EchoServiceImpl();

		// Create our Server
		ServerFactoryBean svrFactory = new ServerFactoryBean();
		svrFactory.setServiceClass(EchoServiceIfc.class);
		svrFactory.setAddress("http://localhost:9000/echo");
		svrFactory.setServiceBean(echoServiceImpl);
		svrFactory.create();
	}
}
...

Above, we set a few properties of the ServerFactoryBean that we have instantiated. We basically set up our service interface, our address (URL) to our service endpoint and the implementation class. We can run this as a normal Java application and browse over to http://localhost:9000/echo?wsdl and see our WSDL generated for our echo service.

There is nothing too complicated about the echo service. It is basically a Java interface, an implementation class and a few annotations. This is a great start for any developer who wants to start developing Web Services without getting overwhelmed with the full capabilities and features of Apache CXF or the spec. For more information, head on over to http://cxf.apache.org.

Eclipse Project: apache-cxf-echo-service.zip

Written by R.J. Salicco in: Development | Tags: , ,
Jul
10
2008
0

Groovy, Grails and JetBrains IntelliJ IDEA

I might be late in the game with this post, but I have to comment on some niceness I have experienced when working with Groovy, Grails and IntelliJ IDEA 7.0. I received a license for IntelliJ IDEA when I attended the Groovy/Grails Experience in February 2008. That ended up being a very cool event; learning from the creators and contributors and getting software to make life easier all in one weekend.

I downloaded the JetGroovy plugin using IntelliJ’s plugin manager and I was on my way. First, I created a new Grails project and ran it to see that everything was setup properly with the plugin. Everything worked as I had expected and I was up and running with my new Grails project. Instead of working with this new project from scratch, I imported my Grails POC code and started working to make some minor changes to see how IntelliJ and Grails work together. I opened up one of my domain objects and noticed that the controller, views and tests were now just a click away on the toolbar while I was looking at my domain object.

If you are already familiar with the Grails world, above is a selector with the application’s domain objects, a quick link to the controller, views and tests that correspond to the domain object selected. Very nice.

Code completion, highlighting and refactoring are other nice features supported in IntelliJ via the JetGroovy plugin that we usually take for granted in the Java IDE space. The JetGroovy plugin does a great job of exposing a new Groovy developer to an environment that most seasoned Java developers are already accustomed to. So, if you are a Java developer who is interested in learning Groovy/Grails and would like to exploit the comforts of IDE support, IntelliJ 7.0 and the JetGroovy plugin will get you started on the right path.

Written by R.J. Salicco in: Development | Tags: , ,
Jul
01
2008
0

GridGain at the Tampa JUG

Dmitriy Setrakyan, Founder and Director of Development at GridGain , presented at the Tampa JUG on June 24th, 2008 and showed us just how easy grid computing can be with Java and GridGain. Dmitriy showed the group how to take a simple "Hello World" example and grid enable it within about 10 minutes. Here is my explanation of the demo:

In our Java Class, we create a simple public static void main(String[] args) method that calls a static method named sayHello().

...
public static void sayHello() {
    System.out.println("Hello World");
}

public static void main(String[] args) {
    sayHello();
}
...

Now we can run our class and see "Hello World" printed out. Next we need to "grid-ify" our little application by adding the GridGain dependencies to our project Classpath and by adding a few key lines to our code:

...
@Gridify
public static void sayHello() {
    System.out.println("Hello World");
}

public static void main(String[] args) {
    GridFactory.start();
    try {
        sayHello();
    } finally {
        GridFactory.stop();
    }
}
...

So, we added the @Gridify annotation to our sayHello() method, the GridFactory.start() and GridFactory.stop() lines and a try/finally block to our code. Now, all we have to do is start up a few GridGain nodes (this is done manually by going to GRIDGAIN_HOME/bin/gridgain.bat) and then running our little application. Our application starts it’s own node, GridFactory.start(), and then the sayHello() method will run on one of our running nodes! Pretty simple? Yeah, obviously there is bit more we can dive into other than grid enabling a "Hello World" application, but when Dmitriy did this simple demo at the Tampa JUG, it got me to start playing with GridGain .

Written by R.J. Salicco in: Development |
Mar
15
2008
2

Create Bugs with Bugzilla’s XMLRPC Web Service and Groovy

The other day I was looking into moving development bugs from one bug system over to Bugzilla. Someone in my group pointed out that Bugzilla had an XMLRPC Web service exposed at:

http://bugzilla-address/xmlrpc.cgi.

The current bug system had a feature that would export the bugs into XML data. I exported the bug data, moved the XML file to my local machine, and opened the Groovy Console. Let’s check out how simple things can be.

Here is sort of what the XML looks like:

...
<issues>
    <issue>
        <product>Product Name</product>
        <component>Component Name</component>
        <summary>Summary</summary>
        <version>1.0</version>
        <description>Description</description>
        <opsys>Operating System</opsys>
        <platform>Platform</platform>
        <priority>High</priority>
        <severity>Low</severity>
        <status>Open</status>
    </issue>
</issues>
...

Here is what we need to import into our Groovy script:

...
import groovy.util.XmlSlurper

import java.util.Map
import java.util.HashMap
import java.net.ServerSocket

import org.apache.commons.httpclient.*
import org.apache.xmlrpc.client.*
...

Here is our class, main method, dependencies, and setup of the XMLRPCClient (I needed the HTTPClient and XMLRpcCommonsTransportFactory because Bugzilla likes to deal with Cookies after logged in):

...
public class BugzillaCreateFromXML {

    // get the xml data of our issues in the .xml file
    def xmlData = new XmlSlurper().parse(new File("C:/issues.xml"))

    def httpClient = new HttpClient()
    def rpcClient = new XmlRpcClient()
    def factory = new XmlRpcCommonsTransportFactory(rpcClient)
    def config = new XmlRpcClientConfigImpl()factory.setHttpClient(httpClient)

    rpcClient.setTransportFactory(factory)
    config.setServerURL(new URL("http://bugzilla-addres/xmlrpc.cgi"))
    rpcClient.setConfig(config)

    public static void main(String[] args) {
        // here is where the work getting done
        // map of the login data
        Map loginMap = new HashMap()
        loginMap.put("login", "admin")
        loginMap.put("password", "admin")
        loginMap.put("rememberlogin", "Bugzilla_remember")

        // login to bugzilla
        def loginResult = rpcClient.execute("User.login", loginMap)
        println loginResult

        // map of the bug data
        Map bugMap = new HashMap()

        // iterate through each issue
        xmlData.issue.each {
            bugMap.put("product", it.product.text())
            bugMap.put("component", it.component.text())
            bugMap.put("summary", it.summary.text())
            bugMap.put("version", it.version.text())
            bugMap.put("description", it.description.text())
            bugMap.put("op_sys", it.opsys.text())
            bugMap.put("platform", it.platform.text())
            bugMap.put("priority", it.priority.text())
            bugMap.put("severity", it.severity.text())
            bugMap.put("status", it.status.text())

            // create bug
            def createResult = rpcClient.execute("Bug.create", bugMap)
            println createResult

            // clear bugMap so we can re-populate it with the next issue
            bugMap.clear()
        }
    }
}
...

That is it. It took me about 30 minutes to parse the XML file and loop through each node with Groovy. I spent about an hour finding out that HTTPClient was also needed, I originally started working with Groovy’s XMLRPC library. You need to have the appropriate Apache XMLRPC Client libraries in place in your Groovy lib directory. I ran this from the Groovy Console and it did exactly what I needed it to do. The Groovy file is available for download .

Written by R.J. Salicco in: Development |
Mar
03
2008
0

Open Source Technologies

I have been doing some proof of concept work and some small demos using the following technologies: Java, Groovy, Grails (Hibernate and Spring under the covers), GWT, Flex, and MySQL. Some of the technologies listed are technologies I have been using for quite some time and some of them are brand new to me. I can honestly say that I am continually impressed and motivated while working with these technologies. My level of satisfaction with these technologies is not based on the cool factor or the cutting edge factor, but my satisfaction is based on the pure fact that I am getting quality work done. It is as simple as that. I know that in the future I will be digging into technologies like Ruby, Rails, Scala, and Python in more detail, but for now I can be certain that I will be less interested in the wow factor and more interested in producing quality results faster.

Written by R.J. Salicco in: Commentary, Development |
Jan
30
2008
0

Rich Internet Applications (RIA) with Adobe Flex

At the January 2008 Tampa JUG meeting, presenter James Ward demonstrated the power and flexibility of Adobe Flex. As a Java developer, it is difficult to detach from JSP and JSF and to head down a heterogeneous approach to Web development. Why would I want to walk away from Java on the front-end and integrate a new markup language and configuration set to my Internet application? One simple answer; because Flex is doing what most current front-end Web technologies only dream about.

Flex is doing for developers what Flash did for designers some time ago; it is inspiring people to take the Internet to a new level. It is taking what is expected on the desktop and putting that experience into a browser while being somewhat simple to implement as compared to traditional desktop programming. James knew his stuff and that was key to bringing across what Flex can do for Java developers. We only had about an hour or so to discuss what Flex could do and for James to do some on the spot coding, but I could have sat there for hours absorbing what Flex is all about. If you get a chance, try to catch him presenting at an event in the future. I believe he will be in Orlando at JBoss World in February 2008. Some of the Internet applications he showed us were more on the consumer side of the Web, but it is just a matter of time before Flex and similar technologies are bringing their features to internal Web applications.

With all that being said, after the presentation, I wanted to start a project that night when I got home at 12:30am. Now, I cannot say whether or not Flex is the answer for everyone or if it is a good choice for large enterprise Web applications, but I know that I need to work on something using Flex as soon as I can. All I need to do now is find some time.

Written by R.J. Salicco in: Development |
Oct
24
2007
0

Technology and Web Development

I have been a web developer for about 5 years now and I think I have been fighting the same problem over and over again. The problem isn’t with a technology or it isn’t a server or code issue that has been keeping me up at night. The problem that I have been running into is poor planning and management. I have worked with a few people, you know who you are, who truly know what is going on and how to get things done.

People expect that the terms “build a web site” or “build a web application” translates into a plan to complete a multi-tiered web application that integrates with their legacy environment. Some clients have asked for a simple web site with a newsletter maintenance application, content management system, and e-commerce piece that are branded and tailored to their unique business model that can be completed in about two weeks and cost under $2000 US.

I love what I do. Really I do. I just wish I could hurdle this problem every time I start a new project.

Written by R.J. Salicco in: Development |

Axiomatic IT Incorporated | Aeros Theme | TheBuckmaker.com WordPress Themes