You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by ts...@apache.org on 2017/09/24 11:16:26 UTC
wicket git commit: Added wicket-http2-servlet4 module
Repository: wicket
Updated Branches:
refs/heads/master e15993c09 -> b8359c8a3
Added wicket-http2-servlet4 module
* provides support for the servlet 4 api
Project: http://git-wip-us.apache.org/repos/asf/wicket/repo
Commit: http://git-wip-us.apache.org/repos/asf/wicket/commit/b8359c8a
Tree: http://git-wip-us.apache.org/repos/asf/wicket/tree/b8359c8a
Diff: http://git-wip-us.apache.org/repos/asf/wicket/diff/b8359c8a
Branch: refs/heads/master
Commit: b8359c8a360544f82e2bd53523e583fcab4ec9ae
Parents: e15993c
Author: Tobias Soloschenko <ts...@apache.org>
Authored: Sun Sep 24 13:14:02 2017 +0200
Committer: Tobias Soloschenko <ts...@apache.org>
Committed: Sun Sep 24 13:15:31 2017 +0200
----------------------------------------------------------------------
.../wicket-http2/wicket-http2-servlet4/pom.xml | 47 ++++++++++++++
.../org/apache/wicket/http2/Initializer.java | 44 +++++++++++++
.../http2/markup/head/Servlet4PushBuilder.java | 65 ++++++++++++++++++++
.../services/org.apache.wicket.IInitializer | 1 +
.../util/license/ApacheLicenceHeaderTest.java | 34 ++++++++++
5 files changed, 191 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/wicket/blob/b8359c8a/wicket-experimental/wicket-http2/wicket-http2-servlet4/pom.xml
----------------------------------------------------------------------
diff --git a/wicket-experimental/wicket-http2/wicket-http2-servlet4/pom.xml b/wicket-experimental/wicket-http2/wicket-http2-servlet4/pom.xml
new file mode 100644
index 0000000..442d24d
--- /dev/null
+++ b/wicket-experimental/wicket-http2/wicket-http2-servlet4/pom.xml
@@ -0,0 +1,47 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.apache.wicket.experimental.wicket8</groupId>
+ <artifactId>wicket-http2</artifactId>
+ <version>0.2-SNAPSHOT</version>
+ <relativePath>../pom.xml</relativePath>
+ </parent>
+ <artifactId>wicket-http2-servlet4</artifactId>
+ <packaging>bundle</packaging>
+ <name>Wicket Http/2 Servlet 4</name>
+ <description>
+ Wicket’s implementation to use the PushBuilder API
+ to serve resource via http/2 with less requests. This
+ is the Servlet 4 implementation to resolve the PushBuilder API and
+ provide the IInitializer.
+ </description>
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.wicket.experimental.wicket8</groupId>
+ <artifactId>wicket-http2-core</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>javax.servlet</groupId>
+ <artifactId>javax.servlet-api</artifactId>
+ <version>4.0.0</version><!--$NO-MVN-MAN-VER$-->
+ <scope>provided</scope>
+ </dependency>
+ </dependencies>
+</project>
http://git-wip-us.apache.org/repos/asf/wicket/blob/b8359c8a/wicket-experimental/wicket-http2/wicket-http2-servlet4/src/main/java/org/apache/wicket/http2/Initializer.java
----------------------------------------------------------------------
diff --git a/wicket-experimental/wicket-http2/wicket-http2-servlet4/src/main/java/org/apache/wicket/http2/Initializer.java b/wicket-experimental/wicket-http2/wicket-http2-servlet4/src/main/java/org/apache/wicket/http2/Initializer.java
new file mode 100644
index 0000000..8d40bba
--- /dev/null
+++ b/wicket-experimental/wicket-http2/wicket-http2-servlet4/src/main/java/org/apache/wicket/http2/Initializer.java
@@ -0,0 +1,44 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.wicket.http2;
+
+import org.apache.wicket.Application;
+import org.apache.wicket.IInitializer;
+import org.apache.wicket.http2.markup.head.Servlet4PushBuilder;
+
+/**
+ * Initializes the servlet 4 specific push builder API and makes it available through the HTTP2
+ * settings
+ */
+public class Initializer implements IInitializer
+{
+ /**
+ * Initializes the push builder API of Servlet 4
+ */
+ @Override
+ public void init(Application application)
+ {
+ Http2Settings http2Settings = Http2Settings.Holder.get(application);
+ http2Settings.setPushBuilder(new Servlet4PushBuilder());
+ }
+
+ @Override
+ public void destroy(Application application)
+ {
+ // NOOP
+ }
+}
http://git-wip-us.apache.org/repos/asf/wicket/blob/b8359c8a/wicket-experimental/wicket-http2/wicket-http2-servlet4/src/main/java/org/apache/wicket/http2/markup/head/Servlet4PushBuilder.java
----------------------------------------------------------------------
diff --git a/wicket-experimental/wicket-http2/wicket-http2-servlet4/src/main/java/org/apache/wicket/http2/markup/head/Servlet4PushBuilder.java b/wicket-experimental/wicket-http2/wicket-http2-servlet4/src/main/java/org/apache/wicket/http2/markup/head/Servlet4PushBuilder.java
new file mode 100644
index 0000000..fe2a804
--- /dev/null
+++ b/wicket-experimental/wicket-http2/wicket-http2-servlet4/src/main/java/org/apache/wicket/http2/markup/head/Servlet4PushBuilder.java
@@ -0,0 +1,65 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.wicket.http2.markup.head;
+
+import javax.servlet.http.HttpServletRequest;
+
+import org.apache.wicket.http2.markup.head.PushItemHeaderValue.HeaderOperation;
+import org.apache.wicket.request.Request;
+import org.apache.wicket.request.cycle.RequestCycle;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Allows to push resources with the Servlet 4 specific push builder API
+ *
+ * @author Tobias Soloschenko
+ */
+public class Servlet4PushBuilder implements PushBuilder
+{
+ private static final Logger LOG = LoggerFactory.getLogger(Servlet4PushBuilder.class);
+
+ @Override
+ public void push(HttpServletRequest httpServletRequest, PushItem... pushItems)
+ {
+ Request request = RequestCycle.get().getRequest();
+ HttpServletRequest httpRequest = (HttpServletRequest) request.getContainerRequest();
+ javax.servlet.http.PushBuilder pushBuilder = httpRequest.newPushBuilder();
+ if (pushBuilder != null)
+ {
+ for (PushItem pushItem : pushItems)
+ {
+ pushBuilder.path(pushItem.getUrl());
+ pushItem.getHeaders().entrySet().stream().forEach(pushHeader -> {
+ String key = pushHeader.getKey();
+ PushItemHeaderValue value = pushHeader.getValue();
+ if(value.getOperation() == HeaderOperation.ADD){
+ pushBuilder.addHeader(key, value.getValue());
+ }else{
+ pushBuilder.setHeader(key, value.getValue());
+ }
+ });
+ pushBuilder.push();
+ }
+ }
+ else
+ {
+ LOG.warn("Attempted to use HTTP2 Push but it is not supported for the current request: {}!",
+ httpRequest);
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/wicket/blob/b8359c8a/wicket-experimental/wicket-http2/wicket-http2-servlet4/src/main/resources/META-INF/services/org.apache.wicket.IInitializer
----------------------------------------------------------------------
diff --git a/wicket-experimental/wicket-http2/wicket-http2-servlet4/src/main/resources/META-INF/services/org.apache.wicket.IInitializer b/wicket-experimental/wicket-http2/wicket-http2-servlet4/src/main/resources/META-INF/services/org.apache.wicket.IInitializer
new file mode 100644
index 0000000..f721b3e
--- /dev/null
+++ b/wicket-experimental/wicket-http2/wicket-http2-servlet4/src/main/resources/META-INF/services/org.apache.wicket.IInitializer
@@ -0,0 +1 @@
+org.apache.wicket.http2.Initializer
http://git-wip-us.apache.org/repos/asf/wicket/blob/b8359c8a/wicket-experimental/wicket-http2/wicket-http2-servlet4/src/test/java/org/apache/wicket/util/license/ApacheLicenceHeaderTest.java
----------------------------------------------------------------------
diff --git a/wicket-experimental/wicket-http2/wicket-http2-servlet4/src/test/java/org/apache/wicket/util/license/ApacheLicenceHeaderTest.java b/wicket-experimental/wicket-http2/wicket-http2-servlet4/src/test/java/org/apache/wicket/util/license/ApacheLicenceHeaderTest.java
new file mode 100644
index 0000000..7efc3af
--- /dev/null
+++ b/wicket-experimental/wicket-http2/wicket-http2-servlet4/src/test/java/org/apache/wicket/util/license/ApacheLicenceHeaderTest.java
@@ -0,0 +1,34 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.wicket.util.license;
+
+/**
+ * Test that the license headers are in place in this project. The tests are run from
+ * {@link ApacheLicenseHeaderTestCase}, but you can add project specific tests here if needed.
+ *
+ * @author Frank Bille Jensen (frankbille)
+ */
+public class ApacheLicenceHeaderTest extends ApacheLicenseHeaderTestCase
+{
+ /**
+ * Construct.
+ */
+ public ApacheLicenceHeaderTest()
+ {
+ // addHeaders = true;
+ }
+}