use of org.springframework.web.context.support.GenericWebApplicationContext in project cas by apereo.
the class Cas20ResponseViewTests method verifyView.
@Test
public void verifyView() throws Exception {
val modelAndView = this.getModelAndViewUponServiceValidationWithSecurePgtUrl(RegisteredServiceTestUtils.getService("https://www.casinthecloud.com"));
val req = new MockHttpServletRequest(new MockServletContext());
req.setAttribute(RequestContext.WEB_APPLICATION_CONTEXT_ATTRIBUTE, new GenericWebApplicationContext(req.getServletContext()));
val resp = new MockHttpServletResponse();
val delegatedView = new View() {
@Override
public String getContentType() {
return MediaType.TEXT_HTML_VALUE;
}
@Override
public void render(final Map<String, ?> map, final HttpServletRequest request, final HttpServletResponse response) {
map.forEach(request::setAttribute);
}
};
val view = new Cas20ResponseView(true, new NoOpProtocolAttributeEncoder(), null, delegatedView, new DefaultAuthenticationAttributeReleasePolicy("attribute"), new DefaultAuthenticationServiceSelectionPlan(), NoOpProtocolAttributesRenderer.INSTANCE);
view.render(modelAndView.getModel(), req, resp);
assertNotNull(req.getAttribute(CasViewConstants.MODEL_ATTRIBUTE_NAME_CHAINED_AUTHENTICATIONS));
assertNotNull(req.getAttribute(CasViewConstants.MODEL_ATTRIBUTE_NAME_PRIMARY_AUTHENTICATION));
assertNotNull(req.getAttribute(CasViewConstants.MODEL_ATTRIBUTE_NAME_PRINCIPAL));
assertNotNull(req.getAttribute(CasProtocolConstants.VALIDATION_CAS_MODEL_PROXY_GRANTING_TICKET_IOU));
}
use of org.springframework.web.context.support.GenericWebApplicationContext in project cas by apereo.
the class Cas30ResponseViewTests method renderView.
protected Map<?, ?> renderView() throws Exception {
val modelAndView = this.getModelAndViewUponServiceValidationWithSecurePgtUrl(DEFAULT_SERVICE);
LOGGER.debug("Retrieved model and view [{}]", modelAndView.getModel());
val req = new MockHttpServletRequest(new MockServletContext());
req.setAttribute(RequestContext.WEB_APPLICATION_CONTEXT_ATTRIBUTE, new GenericWebApplicationContext(req.getServletContext()));
val encoder = new DefaultCasProtocolAttributeEncoder(this.servicesManager, CipherExecutor.noOpOfStringToString());
val view = getCasViewToRender(encoder, getDelegatedView());
val resp = new MockHttpServletResponse();
view.render(modelAndView.getModel(), req, resp);
return getRenderedViewModelMap(req);
}
use of org.springframework.web.context.support.GenericWebApplicationContext in project spring-framework by spring-projects.
the class EnvironmentSystemIntegrationTests method webApplicationContext.
@Test
void webApplicationContext() {
GenericWebApplicationContext ctx = new GenericWebApplicationContext(newBeanFactoryWithEnvironmentAwareBean());
assertHasStandardServletEnvironment(ctx);
ctx.setEnvironment(prodWebEnv);
ctx.refresh();
assertHasEnvironment(ctx, prodWebEnv);
assertEnvironmentBeanRegistered(ctx);
assertEnvironmentAwareInvoked(ctx, prodWebEnv);
}
use of org.springframework.web.context.support.GenericWebApplicationContext in project flow by vaadin.
the class DevModeBrowserLauncher method launchBrowserInDevelopmentMode.
/**
* Launch the default browser and open the given application base URL if
* running in development mode.
*
* Does nothing if the application is running in production mode.
*
* @param appContext
* the application context
*/
private void launchBrowserInDevelopmentMode(ApplicationContext appContext) {
if (isLaunched()) {
// Only launch browser on startup, not on reload
return;
}
if (!(appContext instanceof GenericWebApplicationContext)) {
getLogger().warn("Unable to determine production mode for an Spring Boot application context of type " + appContext.getClass().getName());
return;
}
GenericWebApplicationContext webAppContext = (GenericWebApplicationContext) appContext;
if (!DevModeBrowserLauncher.isProductionMode(webAppContext)) {
String location = getUrl(webAppContext);
String outputOnFailure = "Application started at " + location;
try {
BrowserLauncher.launch(location, outputOnFailure);
setLaunched();
} catch (Exception | NoClassDefFoundError e) {
// NOSONAR
// NoClassDefFoundError happens if vaadin-dev-server is not on
// the classpath
getLogger().info(outputOnFailure);
}
}
}
use of org.springframework.web.context.support.GenericWebApplicationContext in project spring-framework by spring-projects.
the class RequestHeaderMethodArgumentResolverTests method setUp.
@Before
@SuppressWarnings("resource")
public void setUp() throws Exception {
GenericWebApplicationContext context = new GenericWebApplicationContext();
context.refresh();
resolver = new RequestHeaderMethodArgumentResolver(context.getBeanFactory());
Method method = ReflectionUtils.findMethod(getClass(), "params", (Class<?>[]) null);
paramNamedDefaultValueStringHeader = new SynthesizingMethodParameter(method, 0);
paramNamedValueStringArray = new SynthesizingMethodParameter(method, 1);
paramSystemProperty = new SynthesizingMethodParameter(method, 2);
paramContextPath = new SynthesizingMethodParameter(method, 3);
paramResolvedNameWithExpression = new SynthesizingMethodParameter(method, 4);
paramResolvedNameWithPlaceholder = new SynthesizingMethodParameter(method, 5);
paramNamedValueMap = new SynthesizingMethodParameter(method, 6);
paramDate = new SynthesizingMethodParameter(method, 7);
paramInstant = new SynthesizingMethodParameter(method, 8);
servletRequest = new MockHttpServletRequest();
webRequest = new ServletWebRequest(servletRequest, new MockHttpServletResponse());
// Expose request to the current thread (for SpEL expressions)
RequestContextHolder.setRequestAttributes(webRequest);
}
Aggregations