Skip to content

Commit c7e2148

Browse files
committed
Resolve #46
1 parent 4494c86 commit c7e2148

File tree

1 file changed

+68
-11
lines changed

1 file changed

+68
-11
lines changed

_posts/2015-03-17-server.md

Lines changed: 68 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -70,19 +70,76 @@ If you need to create support for another embedded web server that is not implem
7070
than all you need to do is to implement [WebServer]({{ site.coreurl }}/src/main/java/ro/pippo/core/WebServer.java) or to extends [AbstractWebServer]({{ site.coreurl }}/src/main/java/ro/pippo/core/AbstractWebServer.java).
7171

7272
```java
73-
public interface WebServer {
74-
75-
public WebServerSettings getSettings();
76-
public void setSettings(WebServerSettings settings);
77-
public PippoFilter getPippoFilter();
78-
public void setPippoFilter(PippoFilter pippoFilter);
79-
public void start();
80-
public void stop();
73+
public interface WebServer<T extends WebServerSettings> {
74+
75+
T getSettings();
76+
77+
PippoFilter getPippoFilter();
78+
79+
WebServer setPippoFilter(PippoFilter pippoFilter);
80+
81+
String getPippoFilterPath();
82+
83+
WebServer setPippoFilterPath(String pippoFilterPath);
84+
85+
WebServer init(PippoSettings pippoSettings);
86+
87+
void start();
88+
89+
void stop();
90+
91+
}
92+
```
93+
94+
If you want to make your embedded server plugable for Pippo than you must add `@MetaInfServices(WebServer.class)` annotation to
95+
your class
96+
97+
```java
98+
@MetaInfServices(WebServer.class)
99+
public class JettyServer extends AbstractWebServer<JettySettings> {
100+
101+
// attributes, methods, ...
81102

82103
}
83104
```
84105

85-
If you want to make your embedded server plugable for Pippo than you must add file
86-
`ro.pippo.core.WebServer` in _src/main/resources/META-INF/services_ folder with your class name that implements
87-
WebServer as content (for a Tomcat integration the content file should be _ro.pippo.tomcat.TomcatServer_).
106+
Are some situations when the settings provided by an `WebServer` instance are not enough for you.
107+
In these situations you need to create a custom WebServer.
108+
The idea is to create a custom WebServer if you want to override some aspects (methods) of that server or
109+
if you want free access to the servlet container (Jetty, Tomcat, ...).
110+
111+
Show below the code for a `JettyServer` with persistent sessions
112+
113+
```java
114+
public class MyJettyServer extends JettyServer {
115+
116+
@Override
117+
protected ServletContextHandler createPippoHandler() {
118+
ServletContextHandler handler = super.createPippoHandler();
119+
120+
// set session manager with persistence
121+
HashSessionManager sessionManager = new HashSessionManager();
122+
try {
123+
sessionManager.setStoreDirectory(new File("sessions-storage"));
124+
} catch (IOException e) {
125+
throw new PippoRuntimeException(e);
126+
}
127+
sessionManager.setLazyLoad(true); // other possible option
128+
handler.setSessionHandler(new SessionHandler(sessionManager));
129+
130+
return handler;
131+
}
132+
133+
}
134+
135+
136+
public class Main {
137+
138+
public static void main(String[] args) {
139+
new Pippo(new MyApplication()).setServer(new MyJettyServer()).start();
140+
}
141+
142+
}
143+
```
144+
88145

0 commit comments

Comments
 (0)