Welcome to

Confessions of a build breaker

A blog on Java, JEE and Spring by Jelmer Kuperus

JSF Security video

June 12th, 2006 by site admin

Today while looking around on google video I found a recording of a presentation by Duncan Mills on JSF Security. Am I the only person who thinks it’s crazy that such a simple and more importantly, very common requirement is so hard to implement in jsf ?

Posted in java | 1 Comment »

Integrating spring and GWT

June 4th, 2006 by site admin

I just completed my first shot at integrating Spring with GWT. You can check it out here

Here’s what you do to expose a simple service.

1) Write the remote service, note that the service no longer extends RemoteServiceServlet however HelloService should still implement RemoteService


public class HelloServiceImpl implements HelloService {
public String sayHello(String name) {
return "hello " + name;
}
}

2) Define this service in your application context

<bean id=”helloService” class=”nl.jteam.hello.server.HelloServiceImpl”/>

3) expose the bean as a gwt service

<bean id=”defaultHandlerMapping” class=”org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping”/>

<bean name=”/helloService” class=”nl.jteam.gwt.exporter.GwtInvokerServiceExporter”>
<property name=”service” ref=”helloService”/>
<property name=”serviceInterface” value=”nl.jteam.hello.client.HelloService”/>
</bean>

4) Change the clientcode to point to your Spring service. be sure to use an absolute url while running in hosted mode or it will complain


helloService = (HelloServiceAsync) GWT.create(HelloService.class);
ServiceDefTarget endpoint = (ServiceDefTarget) helloService;
endpoint.setServiceEntryPoint("http://localhost:8080/helloservice");

Feedback is appreciated

Posted in java, spring | 14 Comments »

Google WebToolkit remoting

June 4th, 2006 by site admin

Last week I started playing around with the google webtoolkit an Ajax framework that allows software engineers to develop complex ajax web interfaces in java rather than javascript.

I found the google webtoolkit not without it’s limitations, most noteably it is very hard to style / layout pages compared to jsp templates etc. But I do think it has potential for certain types of applications. While I struggled with other component based frameworks such as jsf, tapestry and wicket GWT was really easy to get into even though the documentation is currently still lacking and without compare to that offered by the aformentioned frameworks.

GWT comes with its own rpc framework. I’ll give you an example of how this works

You start out by defining your service interface


public interface HelloService extends RemoteService {
String sayHello(String name);
}

Service interfaces should allways extend from the RemoteService marker interface. Then you create an asychronous companion interface


public interface HelloServiceAsync {
void sayHello(String name, AsyncCallback callback);
}

The relationship between a service interface and its asynchronous counterpart is straightforward:
If a service interface is called com.example.HelloService , then the async interface must be called com.example.HelloServiceAsync. The async interface must be in the same package and have the same name, but with the suffix Async.

I actually don’t like having to repeat myself like this but i suppose it can’t be helped, eventually the code will get translated to javascript and as I understand it all javascript code runs within the context of a single thread. You can’t have a method blocking for 5 seconds while waiting for a response from the server because it would effectively make your application nonresponsive. If you ever played around with DWR you should be familiar with this pattern.

Implementations of the remote interface extend from RemoteServiceServlet which is a thin layer on top of HttpServlet. and takes care of serializing / deserializing arguments and response objects.


public class HelloServiceImpl extends RemoteServiceServlet implements HelloService {
public String sayHello(String name) {
return "hello " + name;
}
}

Once you have this it is very simple to write a simple client.


public class Hello implements EntryPoint {
private HelloServiceAsync helloService;

public void onModuleLoad() {
helloService = (HelloServiceAsync) GWT.create(HelloService.class);
ServiceDefTarget endpoint = (ServiceDefTarget) helloService;
endpoint.setServiceEntryPoint(”/helloservice”);

HorizontalPanel buttonPanel = new HorizontalPanel();
buttonPanel.add(new Button(”Say hello to jelmer”, new ClickListener() {
public void onClick(Widget sender) {
helloService.sayHello(”jelmer”, new AsyncCallback() {
public void onSuccess(Object result) {
String message = (String) result;

Window.alert(message);
}
public void onFailure(Throwable caught) {
}
});
}
}));
RootPanel.get().add(buttonPanel);
}
}
This will add a button to your page. when pressed it will call sayHello on the remote interface and display the resulting message in a javascript alert box.

Overall i turned out to be pretty easy and painless to create some (relatively) sophisticated functionality. The resulting code is very clean, strongly typed and you can use you favorite java ide to write it, so you have autocompletion and all that goodness available to you

Posted in java | No Comments »

copyright © 2oo6 by Confessions of a build breaker | Powered by Wordpress

Ported by ThemePorter - template by Design4 | Sponsored by 47channel