Apache HISE. Nowy element otwartego stosu aplikacji SOA.

Apache HISE (Human Interactions Service Engine) to projekt, którego celem jest implementacja specyfikacji WS-HumanTask (Web Services Human Task). Specyfikacja ta opisuje zadania wykonywane przez ludzi jako usługi podlegające mechanizmom orkiestracji. HISE znajduje się obecnie w inkubatorze Apache. Obsługa procesów biznesowych jest zwykle realizowana za pomocą orkiestracji usług sieciowych. Mechanizmem tym steruje język BPEL (Business Process Execution Language). BPEL pozwala na definiowanie procesów w usługach sieciowych oraz koordynację wywoływania zewnętrznych usług. Język BPEL pozwala wyrazić konstrukcje zgodne z paradygmatem programowania strukturalnego, a jednocześnie umożliwia tworzenie równoległych ścieżek wykonania. Human Task w SOA BPEL jest dojrzałym produktem. Nie daje jednak możliwości opisu procesów wymagających zaangażowania ludzi. Tymczasem interakcje z ludźmi są istotnym elementem każdego, nawet najbardziej zautomatyzowanego, procesu biznesowego. Potrzeba znalezienia w SOA odpowiedniego miejsca dla usług realizowanych przez osobę ujawnia się zawsze podczas prac nad integracją usług w przedsiębiorstwach. Odpowiedzią na tę potrzebę jest wydana w 2007 roku, po kilku latach gromadzenia doświadczeń w dziedzinie integracji, specyfikacja Web Services Human Task. Implementacja WS-HumanTask stwarza możliwość szerszej adaptacji technologii BPEL. Celem specyfikacji WS-HumanTask jest umożliwienie włączenia zadań realizowanych przez ludzi do istniejących już mechanizmów orkiestracji. Aby było to możliwe, zadania te muszę być traktowane przez system jak zewnętrzne usługi. Dlatego zadania WS-HumanTask składają się z jednej strony z interfejsu wyrażonego przy pomocy WSDL i opisującego usługę, z drugiej – z zestawu funkcji pozwalających na zarządzanie zadaniami. W tej sytuacji fakt realizacji usługi przez osobę, a nie przez komponent systemu informatycznego, nie ma znaczenia. Specyfikacja WS-HumanTask opisuje sposób definiowania usług i cykl życia zadań w powiązaniu z rolami osób je obsługujących. Komponent implementujący specyfikację wczytuje definicje zadań (human task definition) zawierające: specyfikację WSDL usług realizowanej przez zadania, użytkowników mogących realizować zadania bądź nimi zarządzać, sposoby eskalacji i informacje o oczekiwanych czasach wykonania, informacje o sposobie prezentacji na liście zadań i sposobach realizacji w różnych środowiskach klienckich. HISE w opensourceowym stosie SOA Znajdujący się obecnie w inkubatorze projekt Apache HISE będzie w pełni implementował specyfikację WS-HumanTask. Rozwiązanie będzie dystrybuowane w postaci modułów pozwalających na uruchomienie w różnych środowiskach. W tej chwili utworzone dystrybucje pozwalają na uruchomienie aplikacji w kontenerze serwletów lub jako komponentu OSGi w ServiceMix4.

You May Also Like

OSGi Blueprint visualization

What is blueprint?Blueprint is a dependency injection framework for OSGi bundles. It could be written by hand or generated using Blueprint Maven Plugin. Blueprint file is only an XML describing beans, services and references. Each OSGi bundle could hav...

Simple trick to DRY your Grails controller

Grails controllers are not very DRY. It's easy to find duplicated code fragments in default generated controller. Take a look at code sample below. It is duplicated four times in show, edit, update and delete actions:

class BookController {
def show() {
def bookInstance = Book.get(params.id)
if (!bookInstance) {
flash.message = message(code: 'default.not.found.message', args: [message(code: 'book.label', default: 'Book'), params.id])
redirect(action: "list")
return
}
[bookInstance: bookInstance]
}
}

Why is it duplicated?

There is a reason for that duplication, though. If you move this snippet to a method, it can redirect to "list" action, but it can't prevent controller from further execution. After you call redirect, response status changes to 302, but after method exits, controller still runs subsequent code.

Solution

At TouK we've implemented a simple trick to resolve that situation:

  1. wrap everything with a simple withStoppingOnRender method,
  2. whenever you want to render or redirect AND stop controller execution - throw EndRenderingException.

We call it Big Return - return from a method and return from a controller at once. Here is how it works:

class BookController {
def show(Long id) {
withStoppingOnRender {
Book bookInstance = Book.get(id)
validateInstanceExists(bookInstance)
[bookInstance: bookInstance]
}
}

protected Object withStoppingOnRender(Closure closure) {
try {
return closure.call()
} catch (EndRenderingException e) {}
}

private void validateInstanceExists(Book instance) {
if (!instance) {
flash.message = message(code: 'default.not.found.message', args: [message(code: 'book.label', default: 'Book'), params.id])
redirect(action: "list")
throw new EndRenderingException()
}
}
}

class EndRenderingException extends RuntimeException {}

Example usage

For simple CRUD controllers, you can use this solution and create some BaseController class for your controllers. We use withStoppingOnRender in every controller so code doesn't look like a spaghetti, we follow DRY principle and code is self-documented. Win-win-win! Here is a more complex example:

class DealerController {
@Transactional
def update() {
withStoppingOnRender {
Dealer dealerInstance = Dealer.get(params.id)
validateInstanceExists(dealerInstance)
validateAccountInExternalService(dealerInstance)
checkIfInstanceWasConcurrentlyModified(dealerInstance, params.version)
dealerInstance.properties = params
saveUpdatedInstance(dealerInstance)
redirectToAfterUpdate(dealerInstance)
}
}
}

Inconsistent Dependency Injection to domains with Grails

I've encountered strange behavior with a domain class in my project: services that should be injected were null. I've became suspicious as why is that? Services are injected properly in other domain classes so why this one is different?

Constructors experiment

I've created an experiment. I've created empty LibraryService that should be injected and Book domain class like this:

class Book {
def libraryService

String author
String title
int pageCount

Book() {
println("Finished constructor Book()")
}

Book(String author) {
this()
this.@author = author
println("Finished constructor Book(String author)")
}

Book(String author, String title) {
super()
this.@author = author
this.@title = title
println("Finished constructor Book(String author, String title)")
}

Book(String author, String title, int pageCount) {
this.@author = author
this.@title = title
this.@pageCount = pageCount
println("Finished constructor Book(String author, String title, int pageCount)")
}

void logInjectedService() {
println(" Service libraryService is injected? -> $libraryService")
}
}
class LibraryService {
def serviceMethod() {
}
}

Book has 4 explicit constructors. I want to check which constructor is injecting dependecies. This is my method that constructs Book objects and I called it in controller:

class BookController {
def index() {
constructAndExamineBooks()
}

static constructAndExamineBooks() {
println("Started constructAndExamineBooks")
Book book1 = new Book().logInjectedService()
Book book2 = new Book("foo").logInjectedService()
Book book3 = new Book("foo", 'bar').logInjectedService()
Book book4 = new Book("foo", 'bar', 100).logInjectedService()
Book book5 = new Book(author: "foo", title: 'bar')
println("Finished constructor Book(Map params)")
book5.logInjectedService()
}
}

Analysis

Output looks like this:

Started constructAndExamineBooks
Finished constructor Book()
Service libraryService is injected? -> eu.spoonman.refaktor.LibraryService@2affcce2
Finished constructor Book()
Finished constructor Book(String author)
Service libraryService is injected? -> eu.spoonman.refaktor.LibraryService@2affcce2
Finished constructor Book(String author, String title)
Service libraryService is injected? -> null
Finished constructor Book(String author, String title, int pageCount)
Service libraryService is injected? -> null
Finished constructor Book()
Finished constructor Book(Map params)
Service libraryService is injected? -> eu.spoonman.refaktor.LibraryService@2affcce2

What do we see?

  1. Empty constructor injects dependencies.
  2. Constructor that invokes empty constructor explicitly injects dependencies.
  3. Constructor that invokes parent's constructor explicitly does not inject dependencies.
  4. Constructor without any explicit call declared does not call empty constructor thus it does not inject dependencies.
  5. Constructor provied by Grails with a map as a parameter invokes empty constructor and injects dependencies.

Conclusion

Always explicitily invoke empty constructor in your Grail domain classes to ensure Dependency Injection! I didn't know until today either!