Skip to content

Commit 48aa72b

Browse files
committed
Clean up example execution
Motivation: - example/pom.xml has quite a bit of duplication. - We expect that we depend on npn-boot in more than one module in the near future. (e.g. handler, codec-http, and codec-http2) Modification: - Deduplicate the profiles in example/pom.xml - Move the build configuration related with npn-boot to the parent pom. - Add run-example.sh that helps a user launch an example easily Result: - Cleaner build files - Easier to add a new example - Easier to launch an example - Easier to run the tests that relies on npn-boot in the future
1 parent b168ffe commit 48aa72b

5 files changed

Lines changed: 218 additions & 192 deletions

File tree

example/pom.xml

Lines changed: 27 additions & 170 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,6 @@
2929

3030
<name>Netty/Example</name>
3131

32-
<properties>
33-
<npn.version>1.1.6.v20130911</npn.version>
34-
</properties>
3532
<dependencies>
3633
<dependency>
3734
<groupId>${project.groupId}</groupId>
@@ -67,6 +64,10 @@
6764
<artifactId>netty-tcnative</artifactId>
6865
<classifier>${os.detected.classifier}</classifier>
6966
</dependency>
67+
<dependency>
68+
<groupId>org.eclipse.jetty.npn</groupId>
69+
<artifactId>npn-api</artifactId>
70+
</dependency>
7071
<dependency>
7172
<groupId>com.jcraft</groupId>
7273
<artifactId>jzlib</artifactId>
@@ -77,10 +78,6 @@
7778
<artifactId>javassist</artifactId>
7879
<scope>runtime</scope>
7980
</dependency>
80-
<dependency>
81-
<groupId>org.eclipse.jetty.npn</groupId>
82-
<artifactId>npn-api</artifactId>
83-
</dependency>
8481

8582
<!-- see https://github.com/netty/netty/issues/874 -->
8683
<dependency>
@@ -99,179 +96,39 @@
9996
</dependency>
10097
</dependencies>
10198

102-
<build>
103-
<plugins>
104-
<plugin>
105-
<artifactId>maven-dependency-plugin</artifactId>
106-
<executions>
107-
<execution>
108-
<id>copy</id>
109-
<phase>generate-resources</phase>
110-
<goals>
111-
<goal>copy</goal>
112-
</goals>
113-
<configuration>
114-
<artifactItems>
115-
<artifactItem>
116-
<groupId>org.mortbay.jetty.npn</groupId>
117-
<artifactId>npn-boot</artifactId>
118-
<version>${npn.version}</version>
119-
<type>jar</type>
120-
<overWrite>false</overWrite>
121-
<outputDirectory>${project.build.directory}/npn</outputDirectory>
122-
</artifactItem>
123-
</artifactItems>
124-
</configuration>
125-
</execution>
126-
</executions>
127-
</plugin>
128-
</plugins>
129-
</build>
130-
13199
<profiles>
132100
<profile>
133101
<id>spdy-server</id>
134-
<build>
135-
<plugins>
136-
<plugin>
137-
<groupId>org.codehaus.mojo</groupId>
138-
<artifactId>exec-maven-plugin</artifactId>
139-
<configuration>
140-
<executable>${java.home}/bin/java</executable>
141-
<arguments>
142-
<argument>-Xbootclasspath/p:${project.build.directory}/npn/npn-boot-${npn.version}.jar</argument>
143-
<argument>-classpath</argument>
144-
<classpath />
145-
<argument>io.netty.example.spdy.server.SpdyServer</argument>
146-
</arguments>
147-
<classpathScope>runtime</classpathScope>
148-
</configuration>
149-
</plugin>
150-
</plugins>
151-
</build>
152-
</profile>
153-
<profile>
154-
<id>spdy-client</id>
155-
<build>
156-
<plugins>
157-
<plugin>
158-
<groupId>org.codehaus.mojo</groupId>
159-
<artifactId>exec-maven-plugin</artifactId>
160-
<configuration>
161-
<executable>${java.home}/bin/java</executable>
162-
<arguments>
163-
<argument>-Xbootclasspath/p:${project.build.directory}/npn/npn-boot-${npn.version}.jar</argument>
164-
<argument>-classpath</argument>
165-
<classpath />
166-
<argument>io.netty.example.spdy.client.SpdyClient</argument>
167-
</arguments>
168-
<classpathScope>runtime</classpathScope>
169-
</configuration>
170-
</plugin>
171-
</plugins>
172-
</build>
173-
</profile>
174-
175-
<!--
176-
profiles for the various npn vs OpenJDK version as found on:
177-
http://www.eclipse.org/jetty/documentation/current/npn-chapter.html#npn-versions
178-
-->
179-
<profile>
180-
<id>7u9</id>
181-
<activation>
182-
<property>
183-
<name>java.version</name>
184-
<value>1.7.0_9</value>
185-
</property>
186-
</activation>
187102
<properties>
188-
<npn.version>1.1.3.v20130313</npn.version>
103+
<exampleClass>io.netty.example.spdy.server.SpdyServer</exampleClass>
189104
</properties>
190105
</profile>
191106
<profile>
192-
<id>7u10</id>
193-
<activation>
194-
<property>
195-
<name>java.version</name>
196-
<value>1.7.0_10</value>
197-
</property>
198-
</activation>
199-
<properties>
200-
<npn.version>1.1.3.v20130313</npn.version>
201-
</properties>
202-
</profile>
203-
<profile>
204-
<id>7u11</id>
205-
<activation>
206-
<property>
207-
<name>java.version</name>
208-
<value>1.7.0_11</value>
209-
</property>
210-
</activation>
211-
<properties>
212-
<npn.version>1.1.3.v20130313</npn.version>
213-
</properties>
214-
</profile>
215-
<profile>
216-
<id>7u13</id>
217-
<activation>
218-
<property>
219-
<name>java.version</name>
220-
<value>1.7.0_13</value>
221-
</property>
222-
</activation>
223-
<properties>
224-
<npn.version>1.1.4.v20130313</npn.version>
225-
</properties>
226-
</profile>
227-
<profile>
228-
<id>7u15</id>
229-
<activation>
230-
<property>
231-
<name>java.version</name>
232-
<value>1.7.0_15</value>
233-
</property>
234-
</activation>
235-
<properties>
236-
<npn.version>1.1.5.v20130313</npn.version>
237-
</properties>
238-
</profile>
239-
<profile>
240-
<id>7u17</id>
241-
<activation>
242-
<property>
243-
<name>java.version</name>
244-
<value>1.7.0_17</value>
245-
</property>
246-
</activation>
247-
<properties>
248-
<npn.version>1.1.5.v20130313</npn.version>
249-
</properties>
250-
</profile>
251-
<profile>
252-
<id>7u21</id>
253-
<activation>
254-
<property>
255-
<name>java.version</name>
256-
<value>1.7.0_21</value>
257-
</property>
258-
</activation>
259-
<properties>
260-
<npn.version>1.1.5.v20130313</npn.version>
261-
</properties>
262-
</profile>
263-
<profile>
264-
<id>7u25</id>
265-
<activation>
266-
<property>
267-
<name>java.version</name>
268-
<value>1.7.0_25</value>
269-
</property>
270-
</activation>
107+
<id>spdy-client</id>
271108
<properties>
272-
<npn.version>1.1.5.v20130313</npn.version>
109+
<exampleClass>io.netty.example.spdy.client.SpdyClient</exampleClass>
273110
</properties>
274111
</profile>
275112
</profiles>
113+
114+
<build>
115+
<plugins>
116+
<plugin>
117+
<groupId>org.codehaus.mojo</groupId>
118+
<artifactId>exec-maven-plugin</artifactId>
119+
<configuration>
120+
<executable>${java.home}/bin/java</executable>
121+
<commandlineArgs>
122+
${argLine.common}
123+
${argLine.leak}
124+
${argLine.coverage}
125+
-classpath %classpath
126+
${exampleClass}
127+
</commandlineArgs>
128+
<classpathScope>runtime</classpathScope>
129+
</configuration>
130+
</plugin>
131+
</plugins>
132+
</build>
276133
</project>
277134

example/src/main/java/io/netty/example/spdy/server/SpdyServer.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import io.netty.channel.nio.NioEventLoopGroup;
2323
import io.netty.channel.socket.nio.NioServerSocketChannel;
2424
import io.netty.handler.ssl.SslContext;
25+
import io.netty.handler.ssl.SslProvider;
2526
import io.netty.handler.ssl.util.SelfSignedCertificate;
2627

2728
/**
@@ -84,7 +85,7 @@ public static void main(String[] args) throws Exception {
8485

8586
// Configure SSL.
8687
SelfSignedCertificate ssc = new SelfSignedCertificate();
87-
SslContext sslCtx = SslContext.newServerContext(ssc.certificate(), ssc.privateKey());
88+
SslContext sslCtx = SslContext.newServerContext(SslProvider.JDK, ssc.certificate(), ssc.privateKey());
8889
new SpdyServer(sslCtx, port).run();
8990
}
9091
}

example/src/main/java/io/netty/example/spdy/server/SpdyServerInitializer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public void initChannel(SocketChannel ch) throws Exception {
4141

4242
SslHandler sslHandler = sslCtx.newHandler(ch.alloc());
4343
SSLEngine engine = sslHandler.engine();
44-
p.addLast("ssl", new SslHandler(engine));
44+
p.addLast("ssl", sslHandler);
4545

4646
// Setup NextProtoNego with our server provider
4747
NextProtoNego.put(engine, new SpdyServerProvider());

0 commit comments

Comments
 (0)