Just finished my Javapolis Presentation on Zero

1
1 year, 3 weeks ago by jason?
All done… I just finished my Zero presentation at Javapolis and it went really well. Great attendance and some good feedback. If you want to see the slides I presented, I posted them on Slideshare and I believe the recording of the presentation will be available on the Javapolis web site.

… reply

About to present at Javapolis

1
1 year, 3 weeks ago by jason?
I am here at Javapolis in Antwerp… very good conference. Seems to be about 3000 people here. In about 3 hours I am going to present an overview of Project Zero. There are lots of sessions here on complementary technology, including AJAX and Flex and the state of the Java world in general. I saw a great keynote on a site called Parleys.com that provides online video to educate developers on technology. It has some really interesting content. Currently the site is written as an AJAX application using JEE as the back end.

Wish me luck on my presentation!

… reply

Podcast on Project Zero

1 year, 1 month ago by jason?
I recently did a podcast on Project Zero for IBM developerWorks. In the podcast I talked about the current state of affairs with Zero, highlights of the latest M2 release and I shared my opinions on agility and simplicity. Check it out here.
… reply

Accessing Amazon's E-Commerce Service (ECS) from Zero

2
1 year, 3 months ago by jason?
I mentioned last month that I was working on a library for Zero that allows easy access to Amazon ECS (the e-commerce catalog and engine). Well, that library is now available in the Zero repository as zero.amazon.ecs. It is definately a 0.1 version. There is a lot more to do, but this version is a start. The current library allows easy search access to the Amazon catalog. I wrote up a bunch of documentation? in the developer's guide already so I thought I would blog a simple example. This application basically provides a simplistic search form that allows you to search the Amazon catalog and provide nicely formatted results. Nothing too exciting (amazon.com already does this smile ) but useful for explaining how to use this new library.

Adding the extension to your project

As described in the documentation, you need an Amazon Access ID Key to use this library. Assuming you have that, the first step is to add the new extension to your project. To do this you have to add the zero.amazon.ecs library to your ivy.xml file as shown below:

<?xml version="1.0" encoding="UTF-8"?>
<ivy-module version="1.3">
    <info module="TestAmazon" organisation="zero" packagingType="shared" packagingVersion="1.0.0" revision="1.0.0">
        <license name="type of license" url="http://license.page;/;
        <ivyauthor name="AuthorsName" url="http://authors.home.page"/>
        <description homepage="http://module.description.page"/>
    </info>
    <publications>
        <artifact name="TestAmazon" org="zero" type="zip"/>
    </publications>
    
<!-- uncomment this section to declare the dependencies of the project. 
     Note: the default for dependencies from maven is the maven2 notation. -->
    <dependencies>
        <dependency name="zero.amazon.ecs" org="zero" rev="1.0+"/>
        <dependency name="zero.core.webtools" org="zero" rev="1.0+"/>
        <dependency name="zero.core" org="zero" rev="1.0+"/>
    </dependencies>

</ivy-module>

Adding your key to zero.config

Once you have the dependency and you have resolved your project, the next step is to configure your Amazon Access ID Key, as shown:

# HTTP port (default is 8080)
[/app/http]
port=8080

[/app/amazon]
accessKeyId=xyxyxyxyxyxyxyxyxy

Of course, replace xyxyxyxyxyxyxy with your own key.

Creating the input form

The first part of my app is a simple input form that accepts the name of a search index (such as Books or Music) and submits the search to the Zero application. Here is my simple form (no jokes on the basic nature of the form):

<html>
<body>
    <h2>Search Amazon's Store</h2>
   <form action="handleForm.groovy" method="get">
      Index: <input name="index"/><br>
      Keywords: <input name="keywords"/><br>
      <input type="submit"/>
   </form>
</body>
</html>

This form is saved in a file called searchAmazon.html in the public folder.

The fun part… the service

The simple input form submits a request to a Groovy script that uses the Amazon ECS extension to access Amazon and get the search result. Here is the script:

def m = [SearchIndex:request.params.index[0].get(), 
         Keywords:request.params.keywords[0].get(),
           ResponseGroup:"Medium,ItemAttributes",
           responseType: "dom"
         ];
def ms = request.amazon.mySearch.toGPath();
ms.puts(m);

amazonecs.itemSearch(ms.toPath());

request.headers.out.'Content-Type'="text/html";
request.view="XML";
request.xml.output = ms.result.get();
request.xml.stylesheet = "amazon-item-search.xsl";

render();

This script is saved in a file called handleForm.groovy in the public folder. You can see the search takes the input fields from the form, makes a search against Amazon, and then formats the result using the included amazon-item-search.xsl stylesheet.

Running the application

Start the application and go to http://localhost:8080/searchAmazon.html and start searching. The form should look something like this:

SearchAmazon Input Form

If I searched for books about Harry Potter I might see the following:

SearchAmazon Results

Summary

This new library is just the beginning. One of the values of Zero over time will be the collection of libraries like this that aim to make your life easier as a developer when building applications. You could have built this application without the zero.amazon.ecs library, but it would have been more work and the coding would have to be done at a much lower level. Let me know what you think and what else you want to see in this library and on Zero.

… reply

GlobalContext shortcuts

1
1 year, 4 months ago by jason?
No more repetitive GC keys….
I have been working recently on a new Zero module for accessing Amazon's E-Commerce REST services. Something to make it really easy. I do not know if you have ever played with Amazon ECS. Really powerful and simple to use. Mostly I have been wrapping ItemSearch so far and boy does it have a lot of options. As I have been designing the module for Zero, I realized that the GlobalContext made this option complexity really easy to deal with. It provided a nice way to specify a mix of optional and required attributes to use when making the item search call. Basically the model I choose (which I think will become a common pattern in Zero) is one where you setup attributes under a key in the GC and then make a call, passing the root key where you stashed all of the attributes. The results can go back into the GC as well. So, it would be something like this:

request.amazon.mySearch.SearchIndex="Books"
request.amazon.mySearch.Keywords="Harry Potter"
request.amazon.mySearch.ResponseGroup="ItemAttributes"

amazonecs.itemSearch(request.amazon.mySearch.toPath());

request.headers.out.'Content-Type'="text/html";
request.view="XML";
request.xml.output = request.amazon.mySearch.result.get();
request.xml.stylesheet = "item-search.xsl";

zero.core.views.ViewEngine.render();

Not bad. Easy to understand and it handles all of the optional/required attributes business easily. It is also very nice for things like paging, since you can just add the page number attribute and call item search again.

The thing I did not like about this was all of the repetitive request.amazon.mySearch business. Having to keep repeating the root of my key all of the time was tedious. So, we added a couple of features to Zero to make the syntax more concise. First, we provided a way to alias a GC key. I can do something like this:

def ms = request.amazon.mySearch.toGPath();

Now I can just use ms as the GC key in the rest of the script. Much shorter! The other feature we added was a way to do a bunch of puts to the GC in one operation from a Map, a feature we call puts() on the GlobalContext. So, instead of doing this:

ms.SearchIndex="Books"
ms.Keywords="Harry Potter"
ms.ResponseGroup="ItemAttributes"

I can do this:

def m = [
SearchIndex:"Books", 
Keywords:"Harry Potter",
ResponseGroup:"ItemAttributes",
];
ms.puts(m);

I build up the Map using simple Groovy map syntax and then the puts loads all of the keys into the GC for me. With these two changes I get a nice, concise script, like this:

def ms = request.amazon.mySearch.toGPath();
def m = [
SearchIndex:"Books", 
Keywords:"Harry Potter",
ResponseGroup:"ItemAttributes",
];
ms.puts(m);

amazonecs.itemSearch(ms.toPath());

request.headers.out.'Content-Type'="text/html";
request.view="XML";
request.xml.output = ms.result.get();
request.xml.stylesheet = "item-search.xsl";

zero.core.views.ViewEngine.render();

These syntax shortcuts are small items but they make developing the scripts easier and they help the scripts to be more maintainable and readable. So for me they are big.

PS – Look for the amazon library to be released soon smile I will blog about that when it is available.

… reply

r1 – 13 Jun 2007 – 18:01:42 – TWikiGuest