use of javax.servlet.http.HttpServletResponse in project tomcat by apache.
the class TestExpiresFilter method testUseMajorTypeExpiresConfiguration.
@Test
public void testUseMajorTypeExpiresConfiguration() throws Exception {
HttpServlet servlet = new HttpServlet() {
private static final long serialVersionUID = 1L;
@Override
protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType("text/json; charset=iso-8859-1");
response.getWriter().print("Hello world");
}
};
validate(servlet, Integer.valueOf(7 * 60));
}
use of javax.servlet.http.HttpServletResponse in project tomcat by apache.
the class AsyncStockServlet method writeStock.
public void writeStock(AsyncContext actx, Stock stock) {
HttpServletResponse response = (HttpServletResponse) actx.getResponse();
try {
PrintWriter writer = response.getWriter();
//make client parsing easier
writer.write("STOCK#");
writer.write(stock.getSymbol());
writer.write("#");
writer.write(stock.getValueAsString());
writer.write("#");
writer.write(stock.getLastChangeAsString());
writer.write("#");
writer.write(String.valueOf(stock.getCnt()));
writer.write("\n");
writer.flush();
response.flushBuffer();
} catch (IOException x) {
try {
actx.complete();
} catch (Exception ignore) {
/* Ignore */
}
}
}
use of javax.servlet.http.HttpServletResponse in project zeppelin by apache.
the class CorsFilter method doFilter.
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain filterChain) throws IOException, ServletException {
String sourceHost = ((HttpServletRequest) request).getHeader("Origin");
String origin = "";
try {
if (SecurityUtils.isValidOrigin(sourceHost, ZeppelinConfiguration.create())) {
origin = sourceHost;
}
} catch (URISyntaxException e) {
LOGGER.error("Exception in WebDriverManager while getWebDriver ", e);
}
if (((HttpServletRequest) request).getMethod().equals("OPTIONS")) {
HttpServletResponse resp = ((HttpServletResponse) response);
addCorsHeaders(resp, origin);
return;
}
if (response instanceof HttpServletResponse) {
HttpServletResponse alteredResponse = ((HttpServletResponse) response);
addCorsHeaders(alteredResponse, origin);
}
filterChain.doFilter(request, response);
}
use of javax.servlet.http.HttpServletResponse in project zeppelin by apache.
the class CorsFilterTest method InvalidCorsFilterTest.
@Test
@SuppressWarnings("rawtypes")
public void InvalidCorsFilterTest() throws IOException, ServletException {
CorsFilter filter = new CorsFilter();
HttpServletResponse mockResponse = mock(HttpServletResponse.class);
FilterChain mockedFilterChain = mock(FilterChain.class);
HttpServletRequest mockRequest = mock(HttpServletRequest.class);
when(mockRequest.getHeader("Origin")).thenReturn("http://evillocalhost:8080");
when(mockRequest.getMethod()).thenReturn("Empty");
when(mockRequest.getServerName()).thenReturn("evillocalhost");
doAnswer(new Answer() {
@Override
public Object answer(InvocationOnMock invocationOnMock) throws Throwable {
headers[count] = invocationOnMock.getArguments()[1].toString();
count++;
return null;
}
}).when(mockResponse).addHeader(anyString(), anyString());
filter.doFilter(mockRequest, mockResponse, mockedFilterChain);
Assert.assertTrue(headers[0].equals(""));
}
use of javax.servlet.http.HttpServletResponse in project cas by apereo.
the class LogoutAction method doInternalExecute.
@Override
protected Event doInternalExecute(final HttpServletRequest request, final HttpServletResponse response, final RequestContext context) throws Exception {
boolean needFrontSlo = false;
final List<LogoutRequest> logoutRequests = WebUtils.getLogoutRequests(context);
if (logoutRequests != null) {
// if some logout request must still be attempted
needFrontSlo = logoutRequests.stream().anyMatch(logoutRequest -> logoutRequest.getStatus() == LogoutRequestStatus.NOT_ATTEMPTED);
}
final String paramName = StringUtils.defaultIfEmpty(logoutProperties.getRedirectParameter(), CasProtocolConstants.PARAMETER_SERVICE);
LOGGER.debug("Using parameter name [{}] to detect destination service, if any", paramName);
final String service = request.getParameter(paramName);
LOGGER.debug("Located target service [{}] for redirection after logout", paramName);
if (logoutProperties.isFollowServiceRedirects() && StringUtils.isNotBlank(service)) {
final Service webAppService = webApplicationServiceFactory.createService(service);
final RegisteredService rService = this.servicesManager.findServiceBy(webAppService);
if (rService != null && rService.getAccessStrategy().isServiceAccessAllowed()) {
LOGGER.debug("Redirecting to service [{}]", service);
WebUtils.putLogoutRedirectUrl(context, service);
} else {
LOGGER.warn("Cannot redirect to [{}] given the service is unauthorized to use CAS. " + "Ensure the service is registered with CAS and is enabled to allowed access", service);
}
} else {
LOGGER.debug("No target service is located for redirection after logout, or CAS is not allowed to follow redirects after logout");
}
// there are some front services to logout, perform front SLO
if (needFrontSlo) {
LOGGER.debug("Proceeding forward with front-channel single logout");
return new Event(this, FRONT_EVENT);
}
LOGGER.debug("Moving forward to finish the logout process");
return new Event(this, FINISH_EVENT);
}
Aggregations