Details | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 771 | blopes | 1 | /* |
| 2 | * Licensed to the Apache Software Foundation (ASF) under one or more |
||
| 3 | * contributor license agreements. See the NOTICE file distributed with |
||
| 4 | * this work for additional information regarding copyright ownership. |
||
| 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 |
||
| 6 | * (the "License"); you may not use this file except in compliance with |
||
| 7 | * the License. You may obtain a copy of the License at |
||
| 8 | * |
||
| 9 | * http://www.apache.org/licenses/LICENSE-2.0 |
||
| 10 | * |
||
| 11 | * Unless required by applicable law or agreed to in writing, software |
||
| 12 | * distributed under the License is distributed on an "AS IS" BASIS, |
||
| 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||
| 14 | * See the License for the specific language governing permissions and |
||
| 15 | * limitations under the License. |
||
| 16 | */ |
||
| 17 | package http2; |
||
| 18 | |||
| 19 | import java.io.IOException; |
||
| 20 | import java.io.PrintWriter; |
||
| 21 | |||
| 22 | import javax.servlet.ServletException; |
||
| 23 | import javax.servlet.http.HttpServlet; |
||
| 24 | import javax.servlet.http.HttpServletRequest; |
||
| 25 | import javax.servlet.http.HttpServletResponse; |
||
| 26 | import javax.servlet.http.PushBuilder; |
||
| 27 | |||
| 28 | public class SimpleImagePush extends HttpServlet { |
||
| 29 | |||
| 30 | private static final long serialVersionUID = 1L; |
||
| 31 | |||
| 32 | @Override |
||
| 33 | protected void doGet(HttpServletRequest req, HttpServletResponse resp) |
||
| 34 | throws ServletException, IOException { |
||
| 35 | |||
| 36 | resp.setCharacterEncoding("UTF-8"); |
||
| 37 | resp.setContentType("text/html"); |
||
| 38 | PrintWriter pw = resp.getWriter(); |
||
| 39 | |||
| 40 | PushBuilder pb = req.newPushBuilder(); |
||
| 41 | if (pb != null) { |
||
| 42 | pb.path("servlets/images/code.gif"); |
||
| 43 | pb.push(); |
||
| 44 | pw.println("<html>"); |
||
| 45 | pw.println("<body>"); |
||
| 46 | pw.println("<p>The following image was provided via a push request.</p>"); |
||
| 47 | pw.println("<img src=\"" + getServletContext().getContextPath() + "/servlets/images/code.gif\"/>"); |
||
| 48 | pw.println("</body>"); |
||
| 49 | pw.println("</html>"); |
||
| 50 | pw.flush(); |
||
| 51 | } else { |
||
| 52 | pw.println("<html>"); |
||
| 53 | pw.println("<body>"); |
||
| 54 | pw.println("<p>Server push requests are not supported by this protocol.</p>"); |
||
| 55 | pw.println("</body>"); |
||
| 56 | pw.println("</html>"); |
||
| 57 | } |
||
| 58 | } |
||
| 59 | } |