Search in sources :

Example 11 with ServletOutputStream

use of jakarta.servlet.ServletOutputStream in project spring-security by spring-projects.

the class HttpSessionSecurityContextRepositoryTests method outputStreamFlushesDelegate.

// SEC-SEC-2055
@Test
public void outputStreamFlushesDelegate() throws Exception {
    HttpSessionSecurityContextRepository repo = new HttpSessionSecurityContextRepository();
    repo.setSpringSecurityContextKey("imTheContext");
    MockHttpServletRequest request = new MockHttpServletRequest();
    HttpServletResponse response = mock(HttpServletResponse.class);
    ServletOutputStream outputstream = mock(ServletOutputStream.class);
    given(response.getOutputStream()).willReturn(outputstream);
    HttpRequestResponseHolder holder = new HttpRequestResponseHolder(request, response);
    SecurityContextHolder.setContext(repo.loadContext(holder));
    SecurityContextHolder.getContext().setAuthentication(this.testToken);
    holder.getResponse().getOutputStream().flush();
    verify(outputstream).flush();
}
Also used : ServletOutputStream(jakarta.servlet.ServletOutputStream) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) HttpServletResponse(jakarta.servlet.http.HttpServletResponse) Test(org.junit.jupiter.api.Test)

Example 12 with ServletOutputStream

use of jakarta.servlet.ServletOutputStream in project spring-security by spring-projects.

the class HttpSessionSecurityContextRepositoryTests method outputStreamCloseDelegate.

// SEC-SEC-2055
@Test
public void outputStreamCloseDelegate() throws Exception {
    HttpSessionSecurityContextRepository repo = new HttpSessionSecurityContextRepository();
    repo.setSpringSecurityContextKey("imTheContext");
    MockHttpServletRequest request = new MockHttpServletRequest();
    HttpServletResponse response = mock(HttpServletResponse.class);
    ServletOutputStream outputstream = mock(ServletOutputStream.class);
    given(response.getOutputStream()).willReturn(outputstream);
    HttpRequestResponseHolder holder = new HttpRequestResponseHolder(request, response);
    SecurityContextHolder.setContext(repo.loadContext(holder));
    SecurityContextHolder.getContext().setAuthentication(this.testToken);
    holder.getResponse().getOutputStream().close();
    verify(outputstream).close();
}
Also used : ServletOutputStream(jakarta.servlet.ServletOutputStream) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) HttpServletResponse(jakarta.servlet.http.HttpServletResponse) Test(org.junit.jupiter.api.Test)

Example 13 with ServletOutputStream

use of jakarta.servlet.ServletOutputStream in project spring-framework by spring-projects.

the class AbstractFeedView method renderMergedOutputModel.

@Override
protected final void renderMergedOutputModel(Map<String, Object> model, HttpServletRequest request, HttpServletResponse response) throws Exception {
    T wireFeed = newFeed();
    buildFeedMetadata(model, wireFeed, request);
    buildFeedEntries(model, wireFeed, request, response);
    setResponseContentType(request, response);
    if (!StringUtils.hasText(wireFeed.getEncoding())) {
        wireFeed.setEncoding("UTF-8");
    }
    WireFeedOutput feedOutput = new WireFeedOutput();
    ServletOutputStream out = response.getOutputStream();
    feedOutput.output(wireFeed, new OutputStreamWriter(out, wireFeed.getEncoding()));
    out.flush();
}
Also used : ServletOutputStream(jakarta.servlet.ServletOutputStream) WireFeedOutput(com.rometools.rome.io.WireFeedOutput) OutputStreamWriter(java.io.OutputStreamWriter)

Aggregations

ServletOutputStream (jakarta.servlet.ServletOutputStream)13 HttpServletResponse (jakarta.servlet.http.HttpServletResponse)5 IOException (java.io.IOException)3 Test (org.junit.jupiter.api.Test)3 ServletResponse (jakarta.servlet.ServletResponse)2 InputStream (java.io.InputStream)2 OutputStreamWriter (java.io.OutputStreamWriter)2 PrintWriter (java.io.PrintWriter)2 ResponseFacade (org.apache.catalina.connector.ResponseFacade)2 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)2 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)2 WireFeedOutput (com.rometools.rome.io.WireFeedOutput)1 ServletResponseWrapper (jakarta.servlet.ServletResponseWrapper)1 WriteListener (jakarta.servlet.WriteListener)1 HttpServletRequest (jakarta.servlet.http.HttpServletRequest)1 BufferedInputStream (java.io.BufferedInputStream)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 FileInputStream (java.io.FileInputStream)1 FileNotFoundException (java.io.FileNotFoundException)1