WICKET-6194 Introduce Http2Settings, PushBuilder-like class and Jetty9 implementation
Project: http://git-wip-us.apache.org/repos/asf/wicket/repo Commit: http://git-wip-us.apache.org/repos/asf/wicket/commit/cc6357dd Tree: http://git-wip-us.apache.org/repos/asf/wicket/tree/cc6357dd Diff: http://git-wip-us.apache.org/repos/asf/wicket/diff/cc6357dd Branch: refs/heads/master Commit: cc6357dd6dea889142d400dc421487db20f5dc4d Parents: 3b02d06 Author: Martin Tzvetanov Grigorov <[email protected]> Authored: Sat Jul 2 14:06:43 2016 +0200 Committer: Tobias Soloschenko <[email protected]> Committed: Sat Jul 9 06:30:38 2016 +0200 ---------------------------------------------------------------------- wicket-experimental/pom.xml | 1 + wicket-experimental/wicket-http2/pom.xml | 1 + .../wicket-http2/wicket-http2-core/pom.xml | 4 -- .../org/apache/wicket/http2/Http2Settings.java | 73 ++++++++++++++++++++ .../http2/markup/head/NoopPushBuilder.java | 41 +++++++++++ .../wicket/http2/markup/head/PushBuilder.java | 27 ++++++++ .../http2/markup/head/PushHeaderItem.java | 31 ++++++--- .../wicket/http2/markup/head/PushItem.java | 16 +++++ .../wicket-http2/wicket-http2-jetty/pom.xml | 42 ++++++++++- .../org/apache/wicket/http2/Initializer.java | 39 +++++++++++ .../http2/markup/head/Jetty9PushBuilder.java | 44 ++++++++++++ .../services/org.apache.wicket.IInitializer | 1 + 12 files changed, 304 insertions(+), 16 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/wicket/blob/cc6357dd/wicket-experimental/pom.xml ---------------------------------------------------------------------- diff --git a/wicket-experimental/pom.xml b/wicket-experimental/pom.xml index d6aa6a0..99b02eb 100644 --- a/wicket-experimental/pom.xml +++ b/wicket-experimental/pom.xml @@ -30,6 +30,7 @@ <description>Wicket-Experimental contains experimental Wicket modules that may or may not be supported in the future.</description> <modules> <module>wicket-atmosphere</module> + <module>wicket-http2</module> <module>wicket-metrics</module> </modules> <build> http://git-wip-us.apache.org/repos/asf/wicket/blob/cc6357dd/wicket-experimental/wicket-http2/pom.xml ---------------------------------------------------------------------- diff --git a/wicket-experimental/wicket-http2/pom.xml b/wicket-experimental/wicket-http2/pom.xml index 065b940..d7b554e 100644 --- a/wicket-experimental/wicket-http2/pom.xml +++ b/wicket-experimental/wicket-http2/pom.xml @@ -33,5 +33,6 @@ </description> <modules> <module>wicket-http2-core</module> + <module>wicket-http2-jetty</module> </modules> </project> http://git-wip-us.apache.org/repos/asf/wicket/blob/cc6357dd/wicket-experimental/wicket-http2/wicket-http2-core/pom.xml ---------------------------------------------------------------------- diff --git a/wicket-experimental/wicket-http2/wicket-http2-core/pom.xml b/wicket-experimental/wicket-http2/wicket-http2-core/pom.xml index d5e6d4b..ec49de5 100644 --- a/wicket-experimental/wicket-http2/wicket-http2-core/pom.xml +++ b/wicket-experimental/wicket-http2/wicket-http2-core/pom.xml @@ -37,9 +37,5 @@ <groupId>org.apache.wicket</groupId> <artifactId>wicket-core</artifactId> </dependency> - <dependency> - <groupId>org.apache.wicket</groupId> - <artifactId>wicket-request</artifactId> - </dependency> </dependencies> </project> http://git-wip-us.apache.org/repos/asf/wicket/blob/cc6357dd/wicket-experimental/wicket-http2/wicket-http2-core/src/main/java/org/apache/wicket/http2/Http2Settings.java ---------------------------------------------------------------------- diff --git a/wicket-experimental/wicket-http2/wicket-http2-core/src/main/java/org/apache/wicket/http2/Http2Settings.java b/wicket-experimental/wicket-http2/wicket-http2-core/src/main/java/org/apache/wicket/http2/Http2Settings.java new file mode 100644 index 0000000..4a161d7 --- /dev/null +++ b/wicket-experimental/wicket-http2/wicket-http2-core/src/main/java/org/apache/wicket/http2/Http2Settings.java @@ -0,0 +1,73 @@ +/* + * 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.MetaDataKey; +import org.apache.wicket.http2.markup.head.NoopPushBuilder; +import org.apache.wicket.http2.markup.head.PushBuilder; +import org.apache.wicket.util.lang.Args; + +/** + * + */ +public class Http2Settings +{ + private static final MetaDataKey<Http2Settings> KEY = new MetaDataKey<Http2Settings>() + { + }; + + /** + * Holds this Http2Settings in the Application's metadata. + * This way wicket-core module doesn't have reference to wicket-http2-core + */ + public static final class Holder + { + public static Http2Settings get(Application application) + { + Http2Settings settings = application.getMetaData(KEY); + if (settings == null) + { + synchronized (application) + { + if (settings == null) + { + settings = new Http2Settings(); + set(application, settings); + } + } + } + return settings; + } + + public static void set(Application application, Http2Settings settings) + { + application.setMetaData(KEY, settings); + } + } + + private PushBuilder pushBuilder = NoopPushBuilder.INSTANCE; + + public Http2Settings setPushBuilder(PushBuilder pushBuilder) { + this.pushBuilder = Args.notNull(pushBuilder, "pushBuilder"); + return this; + } + + public PushBuilder getPushBuilder() { + return pushBuilder; + } +} http://git-wip-us.apache.org/repos/asf/wicket/blob/cc6357dd/wicket-experimental/wicket-http2/wicket-http2-core/src/main/java/org/apache/wicket/http2/markup/head/NoopPushBuilder.java ---------------------------------------------------------------------- diff --git a/wicket-experimental/wicket-http2/wicket-http2-core/src/main/java/org/apache/wicket/http2/markup/head/NoopPushBuilder.java b/wicket-experimental/wicket-http2/wicket-http2-core/src/main/java/org/apache/wicket/http2/markup/head/NoopPushBuilder.java new file mode 100644 index 0000000..b2ddc82 --- /dev/null +++ b/wicket-experimental/wicket-http2/wicket-http2-core/src/main/java/org/apache/wicket/http2/markup/head/NoopPushBuilder.java @@ -0,0 +1,41 @@ +/* + * 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.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * + */ +public class NoopPushBuilder implements PushBuilder +{ + private static final Logger LOG = LoggerFactory.getLogger(NoopPushBuilder.class); + + public static final NoopPushBuilder INSTANCE = new NoopPushBuilder(); + + private NoopPushBuilder() + {} + + @Override + public void push(HttpServletRequest httpServletRequest, String... paths) + { + LOG.warn("This PushBuilder does nothing. Please use one of the other implementations - Jetty9 or Tomcat8.5+"); + } +} http://git-wip-us.apache.org/repos/asf/wicket/blob/cc6357dd/wicket-experimental/wicket-http2/wicket-http2-core/src/main/java/org/apache/wicket/http2/markup/head/PushBuilder.java ---------------------------------------------------------------------- diff --git a/wicket-experimental/wicket-http2/wicket-http2-core/src/main/java/org/apache/wicket/http2/markup/head/PushBuilder.java b/wicket-experimental/wicket-http2/wicket-http2-core/src/main/java/org/apache/wicket/http2/markup/head/PushBuilder.java new file mode 100644 index 0000000..07f31b2 --- /dev/null +++ b/wicket-experimental/wicket-http2/wicket-http2-core/src/main/java/org/apache/wicket/http2/markup/head/PushBuilder.java @@ -0,0 +1,27 @@ +/* + * 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; + +/** + * + */ +public interface PushBuilder +{ + void push(HttpServletRequest httpServletRequest, String... paths); +} http://git-wip-us.apache.org/repos/asf/wicket/blob/cc6357dd/wicket-experimental/wicket-http2/wicket-http2-core/src/main/java/org/apache/wicket/http2/markup/head/PushHeaderItem.java ---------------------------------------------------------------------- diff --git a/wicket-experimental/wicket-http2/wicket-http2-core/src/main/java/org/apache/wicket/http2/markup/head/PushHeaderItem.java b/wicket-experimental/wicket-http2/wicket-http2-core/src/main/java/org/apache/wicket/http2/markup/head/PushHeaderItem.java index a56b8bd..f3f0034 100644 --- a/wicket-experimental/wicket-http2/wicket-http2-core/src/main/java/org/apache/wicket/http2/markup/head/PushHeaderItem.java +++ b/wicket-experimental/wicket-http2/wicket-http2-core/src/main/java/org/apache/wicket/http2/markup/head/PushHeaderItem.java @@ -1,3 +1,19 @@ +/* + * 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 java.util.List; @@ -6,8 +22,10 @@ import java.util.TreeSet; import javax.servlet.http.HttpServletRequest; +import org.apache.wicket.Application; import org.apache.wicket.Page; import org.apache.wicket.WicketRuntimeException; +import org.apache.wicket.http2.Http2Settings; import org.apache.wicket.markup.head.HeaderItem; import org.apache.wicket.request.IRequestHandler; import org.apache.wicket.request.Request; @@ -43,7 +61,7 @@ public class PushHeaderItem extends HeaderItem /** * The URLs of resources to be pushed to the client */ - private Set<String> urls = new ConcurrentHashSet<String>(new TreeSet<String>()); + private Set<String> urls = new ConcurrentHashSet<>(new TreeSet<>()); /** * Uses the URLs that has already been pushed to the client to ensure not to push them again @@ -69,14 +87,9 @@ public class PushHeaderItem extends HeaderItem // Check if the protocol is http/2 or http/2.0 to only push the resources in this case if (isHttp2(request)) { - for (String url : urls) - { - // TODO Jetty has to switch to the javax.servlet-api classes and handle - // SETTINGS_ENABLE_PUSH settings frame value and implement the default API against - // it. - org.eclipse.jetty.server.Request.getBaseRequest(request).getPushBuilder() - .path(url.toString()).push(); - } + Http2Settings http2Settings = Http2Settings.Holder.get(Application.get()); + PushBuilder pushBuilder = http2Settings.getPushBuilder(); + pushBuilder.push(request, urls.toArray(new String[urls.size()])); } } http://git-wip-us.apache.org/repos/asf/wicket/blob/cc6357dd/wicket-experimental/wicket-http2/wicket-http2-core/src/main/java/org/apache/wicket/http2/markup/head/PushItem.java ---------------------------------------------------------------------- diff --git a/wicket-experimental/wicket-http2/wicket-http2-core/src/main/java/org/apache/wicket/http2/markup/head/PushItem.java b/wicket-experimental/wicket-http2/wicket-http2-core/src/main/java/org/apache/wicket/http2/markup/head/PushItem.java index 402ecb4..e6f1f8d 100644 --- a/wicket-experimental/wicket-http2/wicket-http2-core/src/main/java/org/apache/wicket/http2/markup/head/PushItem.java +++ b/wicket-experimental/wicket-http2/wicket-http2-core/src/main/java/org/apache/wicket/http2/markup/head/PushItem.java @@ -1,3 +1,19 @@ +/* + * 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 org.apache.wicket.Component; http://git-wip-us.apache.org/repos/asf/wicket/blob/cc6357dd/wicket-experimental/wicket-http2/wicket-http2-jetty/pom.xml ---------------------------------------------------------------------- diff --git a/wicket-experimental/wicket-http2/wicket-http2-jetty/pom.xml b/wicket-experimental/wicket-http2/wicket-http2-jetty/pom.xml index 8dfb469..026763e 100644 --- a/wicket-experimental/wicket-http2/wicket-http2-jetty/pom.xml +++ b/wicket-experimental/wicket-http2/wicket-http2-jetty/pom.xml @@ -18,12 +18,12 @@ <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.wicket7</groupId> + <groupId>org.apache.wicket.experimental.wicket8</groupId> <artifactId>wicket-http2</artifactId> <version>0.1-SNAPSHOT</version> <relativePath>../pom.xml</relativePath> </parent> - <artifactId>wicket-http2-core</artifactId> + <artifactId>wicket-http2-jetty</artifactId> <packaging>jar</packaging> <name>Wicket Http/2 Jetty</name> <description> @@ -33,6 +33,42 @@ provide the IInitializer. </description> <dependencies> - <!-- TODO --> + <dependency> + <groupId>org.apache.wicket.experimental.wicket8</groupId> + <artifactId>wicket-http2-core</artifactId> + <version>0.1-SNAPSHOT</version> + </dependency> + <dependency> + <groupId>org.eclipse.jetty.aggregate</groupId> + <artifactId>jetty-all</artifactId> + <version>9.3.9.M1</version> + <type>POM</type> + <scope>compile</scope> + <exclusions> + <exclusion> + <artifactId>javax.servlet-api</artifactId> + <groupId>javax.servlet</groupId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>org.eclipse.jetty</groupId> + <artifactId>jetty-alpn-server</artifactId> + <version>9.3.9.M1</version> + <scope>test</scope> + <exclusions> + <exclusion> + <artifactId>javax.servlet-api</artifactId> + <groupId>javax.servlet</groupId> + </exclusion> + </exclusions> + </dependency> + + <dependency> + <groupId>org.eclipse.jetty.alpn</groupId> + <artifactId>alpn-api</artifactId> + <version>1.1.2.v20150522</version> + <scope>test</scope> + </dependency> </dependencies> </project> http://git-wip-us.apache.org/repos/asf/wicket/blob/cc6357dd/wicket-experimental/wicket-http2/wicket-http2-jetty/src/main/java/org/apache/wicket/http2/Initializer.java ---------------------------------------------------------------------- diff --git a/wicket-experimental/wicket-http2/wicket-http2-jetty/src/main/java/org/apache/wicket/http2/Initializer.java b/wicket-experimental/wicket-http2/wicket-http2-jetty/src/main/java/org/apache/wicket/http2/Initializer.java new file mode 100644 index 0000000..2defabe --- /dev/null +++ b/wicket-experimental/wicket-http2/wicket-http2-jetty/src/main/java/org/apache/wicket/http2/Initializer.java @@ -0,0 +1,39 @@ +/* + * 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.Jetty9PushBuilder; + +/** + * + */ +public class Initializer implements IInitializer +{ + @Override + public void init(Application application) + { + Http2Settings http2Settings = Http2Settings.Holder.get(application); + http2Settings.setPushBuilder(new Jetty9PushBuilder()); + } + + @Override + public void destroy(Application application) + { + } +} http://git-wip-us.apache.org/repos/asf/wicket/blob/cc6357dd/wicket-experimental/wicket-http2/wicket-http2-jetty/src/main/java/org/apache/wicket/http2/markup/head/Jetty9PushBuilder.java ---------------------------------------------------------------------- diff --git a/wicket-experimental/wicket-http2/wicket-http2-jetty/src/main/java/org/apache/wicket/http2/markup/head/Jetty9PushBuilder.java b/wicket-experimental/wicket-http2/wicket-http2-jetty/src/main/java/org/apache/wicket/http2/markup/head/Jetty9PushBuilder.java new file mode 100644 index 0000000..34a7300 --- /dev/null +++ b/wicket-experimental/wicket-http2/wicket-http2-jetty/src/main/java/org/apache/wicket/http2/markup/head/Jetty9PushBuilder.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.markup.head; + +import javax.servlet.http.HttpServletRequest; + +import org.apache.wicket.request.Request; +import org.apache.wicket.request.cycle.RequestCycle; + +/** + * + */ +public class Jetty9PushBuilder implements PushBuilder +{ + @Override + public void push(HttpServletRequest httpServletRequest, String... paths) + { + // TODO Jetty has to switch to the javax.servlet-api classes and handle + // SETTINGS_ENABLE_PUSH settings frame value and implement the default API against + // it. + Request request = RequestCycle.get().getRequest(); + HttpServletRequest httpRequest = (HttpServletRequest) request.getContainerRequest(); +// org.eclipse.jetty.server.PushBuilder pushBuilder = org.eclipse.jetty.server.Request.getBaseRequest(httpRequest).getPushBuilder(); +// for (String path : paths) +// { +// pushBuilder.path(path); +// } +// pushBuilder.push(); + } +} http://git-wip-us.apache.org/repos/asf/wicket/blob/cc6357dd/wicket-experimental/wicket-http2/wicket-http2-jetty/src/resources/META-INF/services/org.apache.wicket.IInitializer ---------------------------------------------------------------------- diff --git a/wicket-experimental/wicket-http2/wicket-http2-jetty/src/resources/META-INF/services/org.apache.wicket.IInitializer b/wicket-experimental/wicket-http2/wicket-http2-jetty/src/resources/META-INF/services/org.apache.wicket.IInitializer new file mode 100644 index 0000000..f721b3e --- /dev/null +++ b/wicket-experimental/wicket-http2/wicket-http2-jetty/src/resources/META-INF/services/org.apache.wicket.IInitializer @@ -0,0 +1 @@ +org.apache.wicket.http2.Initializer
