Search in sources :

Example 1 with PushBuilder

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);
}
Also used : MockHttpServletRequest(org.springframework.web.testfixture.servlet.MockHttpServletRequest) PushBuilder(jakarta.servlet.http.PushBuilder) MethodParameter(org.springframework.core.MethodParameter) ServletWebRequest(org.springframework.web.context.request.ServletWebRequest) MockHttpServletResponse(org.springframework.web.testfixture.servlet.MockHttpServletResponse) Test(org.junit.jupiter.api.Test)

Example 2 with 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>");
    }
}
Also used : PushBuilder(jakarta.servlet.http.PushBuilder) PrintWriter(java.io.PrintWriter)

Aggregations

PushBuilder (jakarta.servlet.http.PushBuilder)2 PrintWriter (java.io.PrintWriter)1 Test (org.junit.jupiter.api.Test)1 MethodParameter (org.springframework.core.MethodParameter)1 ServletWebRequest (org.springframework.web.context.request.ServletWebRequest)1 MockHttpServletRequest (org.springframework.web.testfixture.servlet.MockHttpServletRequest)1 MockHttpServletResponse (org.springframework.web.testfixture.servlet.MockHttpServletResponse)1