BAEL-3908_http2_client_in_jetty (#8981)
* BAEL-3908 http2 in jetty - initial commit * BAEL-3908 - HTTP2 client in jetty * BAEL-3908 - http2 in jetty - code cleanup * BAEL-3908 - fixed indentation
This commit is contained in:
parent
7186e90e46
commit
591c168f24
|
@ -5,6 +5,7 @@
|
|||
<artifactId>libraries-server</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<name>libraries-server</name>
|
||||
<packaging>war</packaging>
|
||||
|
||||
<parent>
|
||||
<groupId>com.baeldung</groupId>
|
||||
|
@ -105,12 +106,51 @@
|
|||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.eclipse.jetty</groupId>
|
||||
<artifactId>jetty-maven-plugin</artifactId>
|
||||
<version>${jetty.version}</version>
|
||||
<configuration>
|
||||
<stopPort>8888</stopPort>
|
||||
<stopKey>quit</stopKey>
|
||||
<jvmArgs>
|
||||
-Xbootclasspath/p:${settings.localRepository}/org/mortbay/jetty/alpn/alpn-boot/${alpn.version}/alpn-boot-${alpn.version}.jar
|
||||
</jvmArgs>
|
||||
<jettyXml>${basedir}/src/main/config/jetty.xml</jettyXml>
|
||||
<webApp>
|
||||
<contextPath>/</contextPath>
|
||||
</webApp>
|
||||
</configuration>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty.http2</groupId>
|
||||
<artifactId>http2-server</artifactId>
|
||||
<version>${jetty.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty</groupId>
|
||||
<artifactId>jetty-alpn-openjdk8-server</artifactId>
|
||||
<version>${jetty.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty</groupId>
|
||||
<artifactId>jetty-servlets</artifactId>
|
||||
<version>${jetty.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
<properties>
|
||||
<assertj.version>3.6.2</assertj.version>
|
||||
<httpclient.version>4.5.3</httpclient.version>
|
||||
<jetty.version>9.4.8.v20171121</jetty.version>
|
||||
<jetty.version>9.4.27.v20200227</jetty.version>
|
||||
<netty.version>4.1.20.Final</netty.version>
|
||||
<alpn.version>8.1.11.v20170118</alpn.version>
|
||||
<tomcat.version>8.5.24</tomcat.version>
|
||||
<smack.version>4.3.1</smack.version>
|
||||
<eclipse.paho.client.mqttv3.version>1.2.0</eclipse.paho.client.mqttv3.version>
|
||||
|
|
|
@ -0,0 +1,79 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure_9_0.dtd">
|
||||
|
||||
<Configure id="Server" class="org.eclipse.jetty.server.Server">
|
||||
|
||||
<New id="sslContextFactory" class="org.eclipse.jetty.util.ssl.SslContextFactory">
|
||||
<Set name="keyStorePath">src/main/resources/keystore.jks</Set>
|
||||
<Set name="keyStorePassword">storepwd</Set>
|
||||
<Set name="trustStorePath">src/main/resources/truststore.jks</Set>
|
||||
<Set name="trustStorePassword">storepwd</Set>
|
||||
<Set name="protocol">TLSv1.2</Set>
|
||||
</New>
|
||||
<New id="httpConfig" class="org.eclipse.jetty.server.HttpConfiguration"/>
|
||||
|
||||
<Call name="addConnector">
|
||||
<Arg>
|
||||
<New class="org.eclipse.jetty.server.ServerConnector">
|
||||
<Arg name="server">
|
||||
<Ref id="Server"/>
|
||||
</Arg>
|
||||
<Arg name="factories">
|
||||
<Array type="org.eclipse.jetty.server.ConnectionFactory">
|
||||
<Item>
|
||||
<New class="org.eclipse.jetty.server.SslConnectionFactory">
|
||||
<Arg name="sslContextFactory">
|
||||
<Ref id="sslContextFactory"/>
|
||||
</Arg>
|
||||
<Arg name="next">http/1.1</Arg>
|
||||
</New>
|
||||
</Item>
|
||||
<Item>
|
||||
<New class="org.eclipse.jetty.server.HttpConnectionFactory">
|
||||
<Arg name="config">
|
||||
<Ref id="httpConfig"/>
|
||||
</Arg>
|
||||
</New>
|
||||
</Item>
|
||||
</Array>
|
||||
</Arg>
|
||||
<Set name="port">8443</Set>
|
||||
</New>
|
||||
</Arg>
|
||||
</Call>
|
||||
|
||||
<Call name="addConnector">
|
||||
<Arg>
|
||||
<New class="org.eclipse.jetty.server.ServerConnector">
|
||||
<Arg name="server">
|
||||
<Ref id="Server"/>
|
||||
</Arg>
|
||||
<Arg name="factories">
|
||||
<Array type="org.eclipse.jetty.server.ConnectionFactory">
|
||||
<Item>
|
||||
<New class="org.eclipse.jetty.server.SslConnectionFactory">
|
||||
<Arg name="sslContextFactory">
|
||||
<Ref id="sslContextFactory"/>
|
||||
</Arg>
|
||||
<Arg name="next">alpn</Arg>
|
||||
</New>
|
||||
</Item>
|
||||
<Item>
|
||||
<New class="org.eclipse.jetty.alpn.server.ALPNServerConnectionFactory">
|
||||
<Arg>h2,h2-17</Arg>
|
||||
</New>
|
||||
</Item>
|
||||
<Item>
|
||||
<New class="org.eclipse.jetty.http2.server.HTTP2ServerConnectionFactory">
|
||||
<Arg name="config">
|
||||
<Ref id="httpConfig"/>
|
||||
</Arg>
|
||||
</New>
|
||||
</Item>
|
||||
</Array>
|
||||
</Arg>
|
||||
<Set name="Port">8444</Set>
|
||||
</New>
|
||||
</Arg>
|
||||
</Call>
|
||||
</Configure>
|
|
@ -0,0 +1,29 @@
|
|||
package com.baeldung.jetty.http2;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServlet;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
public class Http2JettyServlet extends HttpServlet {
|
||||
|
||||
@Override
|
||||
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
||||
response.addHeader("Cache-control", "no-store, no-cache, must-revalidate");
|
||||
response.addDateHeader("Last-Modified", 0);
|
||||
response.addDateHeader("Expires", 0);
|
||||
|
||||
String requestPath = request.getRequestURI();
|
||||
InputStream input = getServletContext().getResourceAsStream(requestPath);
|
||||
OutputStream output = response.getOutputStream();
|
||||
byte[] buffer = new byte[1024];
|
||||
int read;
|
||||
while ((read = input.read(buffer)) >= 0) {
|
||||
output.write(buffer, 0, read);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Binary file not shown.
Binary file not shown.
|
@ -0,0 +1,33 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
|
||||
version="3.1">
|
||||
|
||||
<servlet>
|
||||
<servlet-name>http2Jetty</servlet-name>
|
||||
<servlet-class>com.baeldung.jetty.http2.Http2JettyServlet</servlet-class>
|
||||
</servlet>
|
||||
<servlet-mapping>
|
||||
<servlet-name>http2Jetty</servlet-name>
|
||||
<url-pattern>/images/*</url-pattern>
|
||||
</servlet-mapping>
|
||||
|
||||
<filter>
|
||||
<filter-name>push</filter-name>
|
||||
<filter-class>org.eclipse.jetty.servlets.PushCacheFilter</filter-class>
|
||||
<init-param>
|
||||
<param-name>ports</param-name>
|
||||
<param-value>8444</param-value>
|
||||
</init-param>
|
||||
<init-param>
|
||||
<param-name>maxAssociations</param-name>
|
||||
<param-value>32</param-value>
|
||||
</init-param>
|
||||
</filter>
|
||||
<filter-mapping>
|
||||
<filter-name>push</filter-name>
|
||||
<url-pattern>/*</url-pattern>
|
||||
</filter-mapping>
|
||||
|
||||
</web-app>
|
|
@ -0,0 +1,14 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Baeldung HTTP/2 Client in Jetty</title>
|
||||
</head>
|
||||
<body>
|
||||
<h2>HTTP/2 Demo</h2>
|
||||
<div>
|
||||
<img src="images/homepage-latest_articles.jpg" alt="latest articles" />
|
||||
<img src="images/homepage-rest_with_spring.jpg" alt="rest with spring" />
|
||||
<img src="images/homepage-weekly_reviews.jpg" alt="weekly reviews" />
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
Binary file not shown.
After Width: | Height: | Size: 18 KiB |
Binary file not shown.
After Width: | Height: | Size: 18 KiB |
Binary file not shown.
After Width: | Height: | Size: 20 KiB |
|
@ -0,0 +1,12 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Baeldung: HTTP2 Client in Jetty</title>
|
||||
</head>
|
||||
<body style="margin:100px 200px">
|
||||
<a href="https://localhost:8443/http2.html"><h1>HTTP/1.1</h1></a>
|
||||
<br />
|
||||
<a href="https://localhost:8444/http2.html"><h1>HTTP/2 Push</h1></a>
|
||||
<br />
|
||||
</body>
|
||||
</html>
|
Loading…
Reference in New Issue