|
#1
|
|||
|
|||
|
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>
Code:
public static void main(String[] args)
{
new ClassPathXmlApplicationContext("spring-context.xml");
}
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> 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>
This is the code for HelloWorldApplication object: Code:
public class HelloWorldApplication extends WebApplication
{
public HelloWorldApplication()
{
getPages().setHomePage(HelloWorld.class);
}
}
Code:
public class HelloWorld extends WebPage
{
public HelloWorld()
{
add(new Label("message", "Hello World!"));
}
}
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));
}
}
What do you think? S. |
|
#2
|
|||
|
|||
|
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 |
![]() |
| Thread Tools | |
| Display Modes | |
|
|
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 |