Java Code Examples for javax.servlet.http.HttpServletRequest.newPushBuilder()

The following are Jave code examples for showing how to use newPushBuilder() of the javax.servlet.http.HttpServletRequest class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: servlet4-demo   File: GreetingController.java   View Source Code Vote up 7 votes
/**
 * Method to receive a GET request for a Greeting.
 * @param request the HTTP request.
 * @param name the string containing the name
 * @return a Greeting
 */
@RequestMapping("/greeting")
public Greeting greeting(ServletRequest request,
    @RequestParam(value = "name", defaultValue = "World") String name) {

  HttpServletRequest httpServletRequest = (HttpServletRequest) request;
  if (httpServletRequest != null) {
    LOG.info("can cast to HttpServletRequest");
    if (null != httpServletRequest.newPushBuilder()) {
      PushBuilder pushBuilder = httpServletRequest.newPushBuilder();
      pushBuilder.path("/push-greeting?name=push");
      pushBuilder.push();
      LOG.info("##### has pushbuilder");
    } else {
      LOG.info("##### has no pushbuilder");
    }
  }

  jettyServerPushFunction.jettyServerPush(request);

  return new Greeting(counter.incrementAndGet(),
      String.format(template, name));
}
 
Example 2
Project: javaee8-applications   File: DukeServlet.java   View Source Code Vote up 6 votes
@Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) {

        PushBuilder pushBuilder = req.newPushBuilder();
        if (pushBuilder != null) {
            pushBuilder
                    .path("resources/images/dukewaving.gif")
                    .addHeader("content-type", "image/gif")
                    .push();
            // Push more than one resource
//            pushBuilder
//                    .path("resources/images/dukewaving.gif")
//                    .addHeader("content-type", "image/gif")
//                    .push();
        }
        try (PrintWriter respWriter = resp.getWriter();) {
            respWriter.write("<html>"
                    + "<img src='resources/images/dukewaving.gif'>"
                    + "</html>");
        } catch (IOException ex) {
            System.out.println(ex);
        }
    }
 
Example 3
Project: servlet4-demo   File: Http2Servlet.java   View Source Code Vote up 5 votes
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
    throws ServletException, IOException {

  resp.setContentType("text/html;charset=UTF-8");
  PushBuilder pushBuilder = req.newPushBuilder();
  if (pushBuilder != null) {
    pushBuilder
        .path("images/cat.png")
        .addHeader("content-type", "image/jpeg")
        .push();
    pushBuilder
        .path("http2-json")
        .addHeader("content-type", "application/json")
        .push();
  }
  try (PrintWriter respWriter = resp.getWriter()) {
    respWriter.write(new StringBuilder()
                         .append("<html>")
                         .append("<img src='images/cat.jpg'>")
                         .append("<p>Image by <a href=\"https://flic.kr/p/HPf9R1\">")
                         .append("Andy Miccone</a></p>")
                         .append("<p>License: <a href=\"https://creativecommons.org/")
                         .append("publicdomain/zero/1.0/\">")
                         .append("CC0 1.0 Universal (CC0 1.0) \n")
                         .append("Public Domain Dedication</a></p>")
                         .append("</html>")
                         .toString());
  }
}
 
Example 4
Project: servlet4-demo   File: GreetingController.java   View Source Code Vote up 5 votes
/**
 * Method to receive a GET request for a Greeting.
 * @param request the HTTP request.
 * @param name the string containing the name
 * @return a Greeting
 */
@RequestMapping("/greeting")
public Greeting greeting(
    HttpServletRequest request,
    @RequestParam(value = "name", defaultValue = "World") String name) {

  PushBuilder pushBuilder = request.newPushBuilder();
  pushBuilder.path("/push-greeting?name=push");
  pushBuilder.push();

  return new Greeting(counter.incrementAndGet(),
      String.format(TEMPLATE, name));
}