Community   SpringSource   Projects    Downloads    Documentation    Forums    Training   Exchange   Blogs

Go Back   Spring Community Forums > Core Spring Projects > Web

Reply
 
Thread Tools Display Modes
  #1  
Old Oct 22nd, 2005, 12:26 PM
Stefan Arentz Stefan Arentz is offline
Senior Member
 
Join Date: Aug 2004
Location: Toronto, ON, Canada
Posts: 101
Default My take on Spring/Wicket integration

I've been reading the Spring/Wicket integration threads on the mailing lists and looked at the code that is available but I was not entirily happy with the things I saw. So, stubborn as I am, I decided to forget everything and do some things 'my own way' instead >:-)

First, I embedded Jetty in Spring. This is actually something I did for a previous project where I needed an embedded web server that could run a servlet and serve XML-RPC. I really like this way of doing web applications/services as I don't have to deal with any arcane servlet archive and deployment cr*p that only adds complexity instead of making things easier.

This is a really simple example of a web server that simply serves static content on both 8080 and 8443 (SSL).

Code:
  <bean name="myJettyServer" class="com.sateh.spring.jetty.JettyServer">

    <property name="listeners">
      <list>
        <bean class="org.mortbay.http.SocketListener">
          <property name="port" value="8088"/>
        </bean>
         <bean class="org.mortbay.http.SunJsseListener">
          <property name="port" value="8443"/>
          <property name="keystore" value="./keystore"/>
          <property name="password" value="test"/>
          <property name="keyPassword" value="test"/>
        </bean>
    </list>
    </property>

    <property name="contexts">
      <list>
        <bean name="myContext" class="com.sateh.spring.jetty.JettyContext">
          <property name="contextPath" value="/test/*"/>
          <property name="resourceBase" value="./webroot"/>
          <property name="handlers">
            <list>
              <bean class="com.sateh.spring.jetty.JettyResourceHandler"/>
              <bean class="org.mortbay.http.handler.NotFoundHandler"/>
            </list>
          </property>
        </bean>
      </list>
    </property>

  </bean>
I deploy this with:

Code:
  public static void main(String[] args)
  {
     new ClassPathXmlApplicationContext("spring-context.xml");
  }
You have to admin that this is pretty simple!

Ok so now for Wicket integration. I simply created a WicketHandler that can be added to the Jetty server. This handler takes a bean reference to the web application.

So first here is the web application:

Code:
  <bean name="wicketWebApplication" class="com.sateh.test.webapp.HelloWorldApplication">
  </bean>
And here is the Jetty server:

Code:
  <bean name="myJettyServer" class="com.sateh.spring.jetty.JettyServer">

    <property name="listeners">
      <list>
        <bean class="org.mortbay.http.SocketListener">
          <property name="port" value="8088"/>
        </bean>
      </list>
    </property>

    <property name="contexts">
      <list>
        <bean name="myContext1" class="com.sateh.spring.jetty.JettyContext">
          <property name="contextPath" value="/"/>
          <property name="resourceBase" value="./webroot"/>
          <property name="handlers">
            <list>
              <bean class="com.sateh.spring.jetty.WicketHandler">
                <property name="path" value="/"/>
                <property name="webApplication" ref="wicketWebApplication"/>
              </bean>
            </list>
          </property>
        </bean>
      </list>
    </property>

  </bean>
As you can see this is all pretty much The Spring Way. The HelloWorldApplication that is referenced in the WicketHandler is basically the standard Wicket example. It doesn't have to inherit from a special SpringWebApplication because of IoC.

This is the code for HelloWorldApplication object:

Code:
public class HelloWorldApplication extends WebApplication
{
    public HelloWorldApplication()
    {
        getPages().setHomePage(HelloWorld.class);
    }
}
And this is the code for the HelloWorld page object:

Code:
public class HelloWorld extends WebPage
{
    public HelloWorld()
    {
        add(new Label("message", "Hello World!"));
    }
}
Injecting your application with other beans from the Spring context works as usual. For example, here is a little Hello World service.

Code:
public interface HelloWorldService
{
    String getMessage();
}

public class HelloWorldServiceImpl implements HelloWorldService
{
    public String getMessage()
    {
        return "Hallo, wereld!";
    }
}
Code:
  <bean name="dutchHelloWorldService" class="com.sateh.test.webapp.HelloWorldServiceImpl"/>

  <bean name="wicketWebApplication" class="com.sateh.test.webapp.HelloWorldApplication">
    <property name="helloWorldService" ref="dutchHelloWorldService"/>
  </bean>
Code:
public class HelloWorld extends WebPage
{
    public HelloWorld()
    {
        String message = ((HelloWorldApplication) getApplication()).getHelloWorldService().getMessage();
        add(new Label("message", message));
    }
}
That cast is a bit yukkie but can easily be solved by making an abstract HelloWorldPage that has getters for the injected services.

What do you think?

S.
Reply With Quote
  #2  
Old Nov 18th, 2005, 10:46 AM
aloleary aloleary is offline
Junior Member
 
Join Date: Sep 2004
Posts: 23
Default

Hello,
I am wondering if you have posted any more sample code about this. I am trying simply to embed jetty in spring and get full control over it..

I would love to see some sample code as to how this is done. When I do google searches your posts keep coming up but I think im missing some key sample code ... i think just seeing the skeleton of com.sateh.spring.jetty.JettyServer would be great !

Maybe you have blogged this or something ?

Thanks
-Alan
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem while spring-struts Integration avinashb Web 1 Sep 26th, 2005 12:49 PM
JIDE integration jwray Spring Rich Client Project 6 Jul 19th, 2005 12:11 PM
AspectWerkz integration Rod Johnson AOP (Aspect Oriented Programming) 5 Jul 14th, 2005 09:15 AM
Separation of integration and unit test source eliot Architecture Discussion 4 Jan 30th, 2005 02:27 PM
3rd party integration for Glazed Lists swankjesse Spring Rich Client Project 12 Nov 25th, 2004 02:44 PM


All times are GMT -5. The time now is 08:54 AM.


Contegix provides first-class managed hosting and partial sponsorship of these forums.

Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.