use of jakarta.servlet.http.PushBuilder in project spring-framework by spring-projects.
the class ServletRequestMethodArgumentResolverTests method pushBuilder.
@Test
public void pushBuilder() throws Exception {
final PushBuilder pushBuilder = Mockito.mock(PushBuilder.class);
servletRequest = new MockHttpServletRequest("GET", "") {
@Override
public PushBuilder newPushBuilder() {
return pushBuilder;
}
};
ServletWebRequest webRequest = new ServletWebRequest(servletRequest, new MockHttpServletResponse());
MethodParameter pushBuilderParameter = new MethodParameter(method, 11);
assertThat(resolver.supportsParameter(pushBuilderParameter)).as("PushBuilder not supported").isTrue();
Object result = resolver.resolveArgument(pushBuilderParameter, null, webRequest, null);
assertThat(result).as("Invalid result").isSameAs(pushBuilder);
}
use of jakarta.servlet.http.PushBuilder in project tomcat by apache.
the class SimpleImagePush method doGet.
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
resp.setCharacterEncoding("UTF-8");
resp.setContentType("text/html");
PrintWriter pw = resp.getWriter();
PushBuilder pb = req.newPushBuilder();
if (pb != null) {
pb.path("servlets/images/code.gif");
pb.push();
pw.println("<html>");
pw.println("<body>");
pw.println("<p>The following image was provided via a push request.</p>");
pw.println("<img src=\"" + req.getContextPath() + "/servlets/images/code.gif\"/>");
pw.println("</body>");
pw.println("</html>");
pw.flush();
} else {
pw.println("<html>");
pw.println("<body>");
pw.println("<p>Server push requests are not supported by this protocol.</p>");
pw.println("</body>");
pw.println("</html>");
}
}
Aggregations