Java 类org.springframework.web.servlet.view.InternalResourceView 实例源码

项目:nixmash-blog    文件:SolrProductControllerTests.java   
@Test
public void autoCompleteShouldReturnJson() throws Exception {

    integrationMvc = standaloneSetup(new SolrController(productService))
            .setSingleView(new InternalResourceView("/products/search.html")).build();

    MvcResult result = integrationMvc
            .perform(get(String.format("/products/autocomplete?term=%s", AUTOCOMPLETE_FRAGMENT))
                    .accept(MediaType.APPLICATION_JSON_UTF8))
            .andExpect(status().isOk()).andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8)).andReturn();

    // Using Jackson ObjectMapper on JSON
    //
    // ObjectMapper mapper = new ObjectMapper();
    // List<String> fragments = Arrays.asList(mapper.readValue(body, String[].class));

    String body = result.getResponse().getContentAsString();
    String[] fragments = body.replaceAll("[\\p{Ps}\\p{Pe}\\\"]", "").split(",");

    for (String string : fragments) {
        assert(string.contains(AUTOCOMPLETE_FRAGMENT));
    }
}
项目:spring4-understanding    文件:DispatcherPortletTests.java   
@Test
public void portletModeMappingViewRenderRequestWithUnauthorizedUserRole() throws Exception {
    MockRenderRequest request = new MockRenderRequest();
    MockRenderResponse response = new MockRenderResponse();
    request.setPortletMode(PortletMode.VIEW);
    request.addUserRole("role3");
    request.setParameter("action", "not mapped");
    request.setParameter("myParam", "not mapped");
    complexDispatcherPortlet.doDispatch(request, response);
    Map<?, ?> model = (Map<?, ?>) request.getAttribute(ViewRendererServlet.MODEL_ATTRIBUTE);
    Exception exception = (Exception) model.get("exception");
    assertNotNull(exception);
    assertTrue(exception.getClass().equals(PortletSecurityException.class));
    InternalResourceView view = (InternalResourceView) request.getAttribute(ViewRendererServlet.VIEW_ATTRIBUTE);
    assertEquals("failed-default-1", view.getBeanName());
}
项目:spring4-understanding    文件:DispatcherPortletTests.java   
@Test
public void noDetectAllHandlerMappingsWithParameterRenderRequest() throws Exception {
    DispatcherPortlet complexDispatcherPortlet = new DispatcherPortlet();
    complexDispatcherPortlet.setContextClass(ComplexPortletApplicationContext.class);
    complexDispatcherPortlet.setNamespace("test");
    complexDispatcherPortlet.setDetectAllHandlerMappings(false);
    complexDispatcherPortlet.init(new MockPortletConfig(getPortletContext(), "complex"));
    MockRenderRequest request = new MockRenderRequest();
    MockRenderResponse response = new MockRenderResponse();
    request.setParameter("myParam", "test1");
    complexDispatcherPortlet.doDispatch(request, response);
    Map<?, ?> model = (Map<?, ?>) request.getAttribute(ViewRendererServlet.MODEL_ATTRIBUTE);
    Exception exception = (Exception) model.get("exception");
    assertTrue(exception.getClass().equals(NoHandlerFoundException.class));
    InternalResourceView view = (InternalResourceView) request.getAttribute(ViewRendererServlet.VIEW_ATTRIBUTE);
    assertEquals("failed-unavailable", view.getBeanName());
}
项目:fortress-saml-demo    文件:MetadataController.java   
@RequestMapping( value = "/generate" )
public ModelAndView generateMetadata(HttpServletRequest request) throws KeyStoreException
{

    ModelAndView model = new ModelAndView( new InternalResourceView( "/WEB-INF/security/metadataGenerator.jsp",
        true ) );
    MetadataForm defaultForm = new MetadataForm();

    model.addObject( "availableKeys", getAvailablePrivateKeys() );
    defaultForm.setBaseURL( getBaseURL( request ) );
    defaultForm.setEntityId( getEntityId( request ) );
    defaultForm.setNameID( MetadataGenerator.defaultNameID.toArray( new String[MetadataGenerator.defaultNameID
        .size()] ) );

    model.addObject( "metadata", defaultForm );
    return model;

}
项目:psi-probe    文件:BaseUndeployContextController.java   
@Override
protected ModelAndView handleContext(String contextName, Context context,
    HttpServletRequest request, HttpServletResponse response) throws Exception {
  try {
    if (request.getContextPath().equals(contextName)) {
      throw new IllegalStateException(
          getMessageSourceAccessor().getMessage("probe.src.contextAction.cannotActOnSelf"));
    }

    getContainerWrapper().getTomcatContainer().remove(contextName);
    // Logging action
    Authentication auth = SecurityContextHolder.getContext().getAuthentication();
    // get username logger
    String name = auth.getName();
    logger.info(getMessageSourceAccessor().getMessage("probe.src.log.undeploy"), name,
        contextName);

  } catch (Exception e) {
    request.setAttribute("errorMessage", e.getMessage());
    logger.error("Error during undeploy of '{}'", contextName, e);
    return new ModelAndView(new InternalResourceView(
        getFailureViewName() == null ? getViewName() : getFailureViewName()));
  }
  return new ModelAndView(new RedirectView(request.getContextPath() + getViewName()));
}
项目:psi-probe    文件:AbstractNoSelfContextHandlerController.java   
@Override
protected ModelAndView handleContext(String contextName, Context context,
    HttpServletRequest request, HttpServletResponse response) throws Exception {

  try {
    if (request.getContextPath().equals(contextName)) {
      throw new IllegalStateException(
          getMessageSourceAccessor().getMessage("probe.src.contextAction.cannotActOnSelf"));
    }

    executeAction(contextName);
  } catch (Exception e) {
    request.setAttribute("errorMessage", e.getMessage());
    logger.error("Error during invocation", e);
    return new ModelAndView(new InternalResourceView(getViewName()));
  }
  return new ModelAndView(new RedirectView(request.getContextPath() + getViewName()
      + (isPassQueryString() ? "?" + request.getQueryString() : "")));
}
项目:class-guard    文件:DispatcherPortletTests.java   
public void testNoDetectAllHandlerMappingsWithParameterRenderRequest() throws Exception {
    DispatcherPortlet complexDispatcherPortlet = new DispatcherPortlet();
    complexDispatcherPortlet.setContextClass(ComplexPortletApplicationContext.class);
    complexDispatcherPortlet.setNamespace("test");
    complexDispatcherPortlet.setDetectAllHandlerMappings(false);
    complexDispatcherPortlet.init(new MockPortletConfig(getPortletContext(), "complex"));
    MockRenderRequest request = new MockRenderRequest();
    MockRenderResponse response = new MockRenderResponse();
    request.setParameter("myParam", "test1");
    complexDispatcherPortlet.doDispatch(request, response);
    Map model = (Map) request.getAttribute(ViewRendererServlet.MODEL_ATTRIBUTE);
    Exception exception = (Exception) model.get("exception");
    assertTrue(exception.getClass().equals(NoHandlerFoundException.class));
    InternalResourceView view = (InternalResourceView) request.getAttribute(ViewRendererServlet.VIEW_ATTRIBUTE);
    assertEquals("failed-unavailable", view.getBeanName());
}
项目:psi-probe-plus    文件:DeployContextController.java   
public ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception {

        String contextName = ServletRequestUtils.getStringParameter(request, "context", null);

        if (contextName != null) {
            try {
                if (getContainerWrapper().getTomcatContainer().installContext(contextName)) {
                    request.setAttribute("successMessage", getMessageSourceAccessor().getMessage("probe.src.deploy.context.success", new Object[]{contextName}));
                } else {
                    request.setAttribute("errorMessage", getMessageSourceAccessor().getMessage("probe.src.deploy.context.failure", new Object[]{contextName}));
                }
            } catch (Exception e) {
                request.setAttribute("errorMessage", e.getMessage());
            }
        }

        return new ModelAndView(new InternalResourceView(getViewName()));
    }
项目:psi-probe-plus    文件:UndeployContextController.java   
protected ModelAndView handleContext(String contextName, Context context,
                                         HttpServletRequest request, HttpServletResponse response) throws Exception {
    try {
        if (request.getContextPath().equals(contextName)) {
            throw new IllegalStateException(getMessageSourceAccessor().getMessage("probe.src.contextAction.cannotActOnSelf"));
        }

        getContainerWrapper().getTomcatContainer().remove(contextName);

    } catch (Exception e) {
        request.setAttribute("errorMessage", e.getMessage());
        logger.error(e);
        return new ModelAndView(new InternalResourceView(getFailureViewName() == null ? getViewName() : getFailureViewName()));
    }
    return new ModelAndView(new RedirectView(request.getContextPath() + getViewName()));
}
项目:psi-probe-plus    文件:ExpireSessionsController.java   
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception {
    String[] sidWebApps = ServletRequestUtils.getStringParameters(request, "sid_webapp");
    for (int i = 0; i < sidWebApps.length; i++) {
        if (sidWebApps[i] != null) {
            String[] ss = sidWebApps[i].split(";");
            if (ss.length == 2) {
                String sessionId = ss[0];
                String appName = ss[1];
                Context context = getContainerWrapper().getTomcatContainer().findContext(appName);
                if (context != null) {
                    Manager manager = context.getManager();
                    Session session = manager.findSession(sessionId);
                    if (session != null && session.isValid()) {
                        session.expire();
                    }
                } else {
                    return new ModelAndView("errors/paramerror");
                }
            } else {
                return new ModelAndView("errors/paramerror");
            }
        }
    }
    return new ModelAndView(new InternalResourceView(getViewName()));
}
项目:springboot-shiro-cas-mybatis    文件:RegisteredServiceThemeBasedViewResolver.java   
/**
 * Uses the viewName and the theme associated with the service.
 * being requested and returns the appropriate view.
 * @param viewName the name of the view to be resolved
 * @return a theme-based UrlBasedView
 * @throws Exception an exception
 */
@Override
protected AbstractUrlBasedView buildView(final String viewName) throws Exception {
    final RequestContext requestContext = RequestContextHolder.getRequestContext();
    final WebApplicationService service = WebUtils.getService(requestContext);
    final RegisteredService registeredService = this.servicesManager.findServiceBy(service);

    final String themeId = service != null && registeredService != null
            && registeredService.getAccessStrategy().isServiceAccessAllowed()
            && StringUtils.hasText(registeredService.getTheme()) ? registeredService.getTheme() : defaultThemeId;

    final String themePrefix = String.format("%s/%s/ui/", pathPrefix, themeId);
    LOGGER.debug("Prefix {} set for service {} with theme {}", themePrefix, service, themeId);

    //Build up the view like the base classes do, but we need to forcefully set the prefix for each request.
    //From UrlBasedViewResolver.buildView
    final InternalResourceView view = (InternalResourceView) BeanUtils.instantiateClass(getViewClass());
    view.setUrl(themePrefix + viewName + getSuffix());
    final String contentType = getContentType();
    if (contentType != null) {
        view.setContentType(contentType);
    }
    view.setRequestContextAttribute(getRequestContextAttribute());
    view.setAttributesMap(getAttributesMap());

    //From InternalResourceViewResolver.buildView
    view.setAlwaysInclude(false);
    view.setExposeContextBeansAsAttributes(false);
    view.setPreventDispatchLoop(true);

    LOGGER.debug("View resolved: {}", view.getUrl());

    return view;
}
项目:nixmash-blog    文件:SolrProductControllerTests.java   
@Test
public void badSimplyQueryShouldDisplayError() throws Exception {

    integrationMvc = standaloneSetup(new SolrController(productService))
            .setSingleView(new InternalResourceView("/WEB-INF/views/products/list.html")).build();

    integrationMvc.perform(get("/products/list").param("query", "name1:memory")).andExpect(status().isOk())
            .andExpect(model().attributeHasFieldErrorCode("userQuery", "query", "product.search.error"))
            .andExpect(view().name("products/search"));

}
项目:nixmash-blog    文件:SolrProductControllerTests.java   
@Test
public void badLocationShouldThrowGeoLocationException() {

    integrationMvc = standaloneSetup(new SolrController(productService))
            .setSingleView(new InternalResourceView("/WEB-INF/views/products/map.html")).build();

    try {
        integrationMvc.perform(get("/products/map/bad")).andDo(print()).andReturn();
    } catch (Exception ex) {
        Assert.assertTrue(ex.getCause() instanceof GeoLocationException);
    }
}
项目:spring4-understanding    文件:DispatcherPortletTests.java   
@Test
public void portletModeParameterMappingInvalidHelpRenderRequest() throws Exception {
    MockRenderRequest request = new MockRenderRequest();
    MockRenderResponse response = new MockRenderResponse();
    request.setPortletMode(PortletMode.HELP);
    request.setParameter("action", "help3");
    complexDispatcherPortlet.doDispatch(request, response);
    Map<?, ?> model = (Map<?, ?>) request.getAttribute(ViewRendererServlet.MODEL_ATTRIBUTE);
    assertTrue(model.get("exception").getClass().equals(NoHandlerFoundException.class));
    InternalResourceView view = (InternalResourceView) request.getAttribute(ViewRendererServlet.VIEW_ATTRIBUTE);
    assertEquals("failed-unavailable", view.getBeanName());
}
项目:spring4-understanding    文件:DispatcherPortletTests.java   
@Test
public void portletModeMappingValidViewRenderRequest() throws Exception {
    MockRenderRequest request = new MockRenderRequest();
    MockRenderResponse response = new MockRenderResponse();
    request.setPortletMode(PortletMode.VIEW);
    request.addUserRole("role2");
    request.setParameter("action", "not mapped");
    request.setParameter("myParam", "not mapped");
    complexDispatcherPortlet.doDispatch(request, response);
    Map<?, ?> model = (Map<?, ?>) request.getAttribute(ViewRendererServlet.MODEL_ATTRIBUTE);
    assertEquals("view was here", model.get("result"));
    InternalResourceView view = (InternalResourceView) request.getAttribute(ViewRendererServlet.VIEW_ATTRIBUTE);
    assertEquals("someViewName", view.getBeanName());
}
项目:spring4-understanding    文件:DispatcherPortletTests.java   
@Test
public void unknownHandlerRenderRequest() throws Exception {
    MockRenderRequest request = new MockRenderRequest();
    MockRenderResponse response = new MockRenderResponse();
    request.setParameter("myParam", "unknown");
    complexDispatcherPortlet.doDispatch(request, response);
    Map<?, ?> model = (Map<?, ?>) request.getAttribute(ViewRendererServlet.MODEL_ATTRIBUTE);
    Exception exception = (Exception)model.get("exception");
    assertTrue(exception.getClass().equals(PortletException.class));
    assertTrue(exception.getMessage().indexOf("No adapter for handler") != -1);
    InternalResourceView view = (InternalResourceView) request.getAttribute(ViewRendererServlet.VIEW_ATTRIBUTE);
    assertEquals("failed-default-1", view.getBeanName());
}
项目:spring4-understanding    文件:DispatcherPortletTests.java   
@Test
public void incorrectLocaleInRequest() throws Exception {
    MockRenderRequest request = new MockRenderRequest();
    MockRenderResponse response = new MockRenderResponse();
    request.setParameter("myParam", "requestLocaleChecker");
    request.addPreferredLocale(Locale.ENGLISH);
    complexDispatcherPortlet.doDispatch(request, response);
    Map<?, ?> model = (Map<?, ?>) request.getAttribute(ViewRendererServlet.MODEL_ATTRIBUTE);
    Exception exception = (Exception) model.get("exception");
    assertTrue(exception.getClass().equals(PortletException.class));
    assertEquals("Incorrect Locale in RenderRequest", exception.getMessage());
    InternalResourceView view = (InternalResourceView) request.getAttribute(ViewRendererServlet.VIEW_ATTRIBUTE);
    assertEquals("failed-default-1", view.getBeanName());
}
项目:spring4-understanding    文件:DispatcherPortletTests.java   
@Test
public void incorrectLocaleInLocalContextHolder() throws Exception {
    MockRenderRequest request = new MockRenderRequest();
    MockRenderResponse response = new MockRenderResponse();
    request.setParameter("myParam", "contextLocaleChecker");
    request.addPreferredLocale(Locale.ENGLISH);
    complexDispatcherPortlet.doDispatch(request, response);
    Map<?, ?> model = (Map<?, ?>) request.getAttribute(ViewRendererServlet.MODEL_ATTRIBUTE);
    Exception exception = (Exception) model.get("exception");
    assertTrue(exception.getClass().equals(PortletException.class));
    assertEquals("Incorrect Locale in LocaleContextHolder", exception.getMessage());
    InternalResourceView view = (InternalResourceView) request.getAttribute(ViewRendererServlet.VIEW_ATTRIBUTE);
    assertEquals("failed-default-1", view.getBeanName());
}
项目:spring4-understanding    文件:DispatcherPortletTests.java   
@Test
public void handlerInterceptorNotClearingModelAndView() throws Exception {
    MockRenderRequest request = new MockRenderRequest();
    MockRenderResponse response = new MockRenderResponse();
    request.setPortletMode(PortletMode.VIEW);
    request.addUserRole("role1");
    request.addParameter("noView", "false");
    complexDispatcherPortlet.doDispatch(request, response);
    Map<?, ?> model = (Map<?, ?>) request.getAttribute(ViewRendererServlet.MODEL_ATTRIBUTE);
    assertEquals("view was here", model.get("result"));
    InternalResourceView view = (InternalResourceView) request.getAttribute(ViewRendererServlet.VIEW_ATTRIBUTE);
    assertEquals("someViewName", view.getBeanName());
}
项目:spring4-understanding    文件:DispatcherPortletTests.java   
@Test
public void handlerInterceptorClearingModelAndView() throws Exception {
    MockRenderRequest request = new MockRenderRequest();
    MockRenderResponse response = new MockRenderResponse();
    request.setPortletMode(PortletMode.VIEW);
    request.addUserRole("role1");
    request.addParameter("noView", "true");
    complexDispatcherPortlet.doDispatch(request, response);
    Map<?, ?> model = (Map<?, ?>) request.getAttribute(ViewRendererServlet.MODEL_ATTRIBUTE);
    assertNull(model);
    InternalResourceView view = (InternalResourceView) request.getAttribute(ViewRendererServlet.VIEW_ATTRIBUTE);
    assertNull(view);
}
项目:spring4-understanding    文件:DispatcherPortletTests.java   
@Test
public void modelAndViewDefiningExceptionInMappedHandler() throws Exception {
    MockRenderRequest request = new MockRenderRequest();
    request.setPortletMode(PortletMode.HELP);
    request.addParameter("myParam", "exception1");
    request.addParameter("fail", "yes");
    MockRenderResponse response = new MockRenderResponse();
    complexDispatcherPortlet.doDispatch(request, response);
    InternalResourceView view = (InternalResourceView) request.getAttribute(ViewRendererServlet.VIEW_ATTRIBUTE);
    assertEquals("failed-modelandview", view.getBeanName());
}
项目:spring4-understanding    文件:DispatcherPortletTests.java   
@Test
public void modelAndViewDefiningExceptionInUnmappedHandler() throws Exception {
    MockRenderRequest request = new MockRenderRequest();
    request.setPortletMode(PortletMode.HELP);
    request.addParameter("myParam", "exception2");
    request.addParameter("fail", "yes");
    MockRenderResponse response = new MockRenderResponse();
    complexDispatcherPortlet.doDispatch(request, response);
    InternalResourceView view = (InternalResourceView) request.getAttribute(ViewRendererServlet.VIEW_ATTRIBUTE);
    assertEquals("failed-modelandview", view.getBeanName());
}
项目:spring4-understanding    文件:DispatcherPortletTests.java   
@Test
public void illegalAccessExceptionInMappedHandler() throws Exception {
    MockRenderRequest request = new MockRenderRequest();
    request.setPortletMode(PortletMode.HELP);
    request.addParameter("myParam", "exception1");
    request.addParameter("access", "illegal");
    MockRenderResponse response = new MockRenderResponse();
    complexDispatcherPortlet.doDispatch(request, response);
    InternalResourceView view = (InternalResourceView) request.getAttribute(ViewRendererServlet.VIEW_ATTRIBUTE);
    assertEquals("failed-exception", view.getBeanName());
}
项目:spring4-understanding    文件:DispatcherPortletTests.java   
@Test
public void illegalAccessExceptionInUnmappedHandler() throws Exception {
    MockRenderRequest request = new MockRenderRequest();
    request.setPortletMode(PortletMode.HELP);
    request.addParameter("myParam", "exception2");
    request.addParameter("access", "illegal");
    MockRenderResponse response = new MockRenderResponse();
    complexDispatcherPortlet.doDispatch(request, response);
    InternalResourceView view = (InternalResourceView) request.getAttribute(ViewRendererServlet.VIEW_ATTRIBUTE);
    assertEquals("failed-illegalaccess", view.getBeanName());
}
项目:spring4-understanding    文件:DispatcherPortletTests.java   
@Test
public void portletRequestBindingExceptionInMappedHandler() throws Exception {
    MockRenderRequest request = new MockRenderRequest();
    request.setPortletMode(PortletMode.HELP);
    request.addParameter("myParam", "exception1");
    request.addParameter("binding", "should fail");
    MockRenderResponse response = new MockRenderResponse();
    complexDispatcherPortlet.doDispatch(request, response);
    InternalResourceView view = (InternalResourceView) request.getAttribute(ViewRendererServlet.VIEW_ATTRIBUTE);
    assertEquals("failed-exception", view.getBeanName());
}
项目:spring4-understanding    文件:DispatcherPortletTests.java   
@Test
public void portletRequestBindingExceptionInUnmappedHandler() throws Exception {
    MockRenderRequest request = new MockRenderRequest();
    request.setPortletMode(PortletMode.HELP);
    request.addParameter("myParam", "exception2");
    request.addParameter("binding", "should fail");
    MockRenderResponse response = new MockRenderResponse();
    complexDispatcherPortlet.doDispatch(request, response);
    InternalResourceView view = (InternalResourceView) request.getAttribute(ViewRendererServlet.VIEW_ATTRIBUTE);
    assertEquals("failed-binding", view.getBeanName());
}
项目:spring4-understanding    文件:DispatcherPortletTests.java   
@Test
public void illegalArgumentExceptionInMappedHandler() throws Exception {
    MockRenderRequest request = new MockRenderRequest();
    request.setPortletMode(PortletMode.HELP);
    request.addParameter("myParam", "exception1");
    request.addParameter("unknown", "");
    MockRenderResponse response = new MockRenderResponse();
    complexDispatcherPortlet.doDispatch(request, response);
    InternalResourceView view = (InternalResourceView) request.getAttribute(ViewRendererServlet.VIEW_ATTRIBUTE);
    assertEquals("failed-runtime", view.getBeanName());
}
项目:spring4-understanding    文件:DispatcherPortletTests.java   
@Test
public void illegalArgumentExceptionInUnmappedHandler() throws Exception {
    MockRenderRequest request = new MockRenderRequest();
    request.setPortletMode(PortletMode.HELP);
    request.addParameter("myParam", "exception2");
    request.addParameter("unknown", "");
    MockRenderResponse response = new MockRenderResponse();
    complexDispatcherPortlet.doDispatch(request, response);
    InternalResourceView view = (InternalResourceView) request.getAttribute(ViewRendererServlet.VIEW_ATTRIBUTE);
    assertEquals("failed-default-1", view.getBeanName());
}
项目:spring4-understanding    文件:DispatcherPortletTests.java   
@Test
public void exceptionInMappedHandler() throws Exception {
    MockRenderRequest request = new MockRenderRequest();
    request.setPortletMode(PortletMode.HELP);
    request.addParameter("myParam", "exception1");
    request.addParameter("generic", "123");
    MockRenderResponse response = new MockRenderResponse();
    complexDispatcherPortlet.doDispatch(request, response);
    InternalResourceView view = (InternalResourceView) request.getAttribute(ViewRendererServlet.VIEW_ATTRIBUTE);
    assertEquals("failed-exception", view.getBeanName());
}
项目:spring4-understanding    文件:DispatcherPortletTests.java   
@Test
public void exceptionInUnmappedHandler() throws Exception {
    MockRenderRequest request = new MockRenderRequest();
    request.setPortletMode(PortletMode.HELP);
    request.addParameter("myParam", "exception2");
    request.addParameter("generic", "123");
    MockRenderResponse response = new MockRenderResponse();
    complexDispatcherPortlet.doDispatch(request, response);
    InternalResourceView view = (InternalResourceView) request.getAttribute(ViewRendererServlet.VIEW_ATTRIBUTE);
    assertEquals("failed-default-1", view.getBeanName());
}
项目:spring4-understanding    文件:DispatcherPortletTests.java   
@Test
public void runtimeExceptionInMappedHandler() throws Exception {
    MockRenderRequest request = new MockRenderRequest();
    request.setPortletMode(PortletMode.HELP);
    request.addParameter("myParam", "exception1");
    request.addParameter("runtime", "true");
    MockRenderResponse response = new MockRenderResponse();
    complexDispatcherPortlet.doDispatch(request, response);
    InternalResourceView view = (InternalResourceView) request.getAttribute(ViewRendererServlet.VIEW_ATTRIBUTE);
    assertEquals("failed-runtime", view.getBeanName());
}
项目:spring4-understanding    文件:DispatcherPortletTests.java   
@Test
public void runtimeExceptionInUnmappedHandler() throws Exception {
    MockRenderRequest request = new MockRenderRequest();
    request.setPortletMode(PortletMode.HELP);
    request.addParameter("myParam", "exception2");
    request.addParameter("runtime", "true");
    MockRenderResponse response = new MockRenderResponse();
    complexDispatcherPortlet.doDispatch(request, response);
    InternalResourceView view = (InternalResourceView) request.getAttribute(ViewRendererServlet.VIEW_ATTRIBUTE);
    assertEquals("failed-default-1", view.getBeanName());
}
项目:spring4-understanding    文件:FreeMarkerViewTests.java   
@Test
public void freeMarkerViewResolver() throws Exception {
    FreeMarkerConfigurer configurer = new FreeMarkerConfigurer();
    configurer.setConfiguration(new TestConfiguration());

    StaticWebApplicationContext wac = new StaticWebApplicationContext();
    wac.setServletContext(new MockServletContext());
    wac.getBeanFactory().registerSingleton("configurer", configurer);
    wac.refresh();

    FreeMarkerViewResolver vr = new FreeMarkerViewResolver();
    vr.setPrefix("prefix_");
    vr.setSuffix("_suffix");
    vr.setApplicationContext(wac);

    View view = vr.resolveViewName("test", Locale.CANADA);
    assertEquals("Correct view class", FreeMarkerView.class, view.getClass());
    assertEquals("Correct URL", "prefix_test_suffix", ((FreeMarkerView) view).getUrl());

    view = vr.resolveViewName("non-existing", Locale.CANADA);
    assertNull(view);

    view = vr.resolveViewName("redirect:myUrl", Locale.getDefault());
    assertEquals("Correct view class", RedirectView.class, view.getClass());
    assertEquals("Correct URL", "myUrl", ((RedirectView) view).getUrl());

    view = vr.resolveViewName("forward:myUrl", Locale.getDefault());
    assertEquals("Correct view class", InternalResourceView.class, view.getClass());
    assertEquals("Correct URL", "myUrl", ((InternalResourceView) view).getUrl());
}
项目:spring4-understanding    文件:VelocityViewResolverTests.java   
@Test
public void testVelocityViewResolver() throws Exception {
    VelocityConfig vc = new VelocityConfig() {
        @Override
        public VelocityEngine getVelocityEngine() {
            return new TestVelocityEngine("prefix_test_suffix", new Template());
        }
    };

    StaticWebApplicationContext wac = new StaticWebApplicationContext();
    wac.getBeanFactory().registerSingleton("configurer", vc);
    wac.refresh();

    VelocityViewResolver vr = new VelocityViewResolver();
    vr.setPrefix("prefix_");
    vr.setSuffix("_suffix");
    vr.setApplicationContext(wac);

    View view = vr.resolveViewName("test", Locale.CANADA);
    assertEquals("Correct view class", VelocityView.class, view.getClass());
    assertEquals("Correct URL", "prefix_test_suffix", ((VelocityView) view).getUrl());

    view = vr.resolveViewName("non-existing", Locale.CANADA);
    assertNull(view);

    view = vr.resolveViewName("redirect:myUrl", Locale.getDefault());
    assertEquals("Correct view class", RedirectView.class, view.getClass());
    assertEquals("Correct URL", "myUrl", ((RedirectView) view).getUrl());

    view = vr.resolveViewName("forward:myUrl", Locale.getDefault());
    assertEquals("Correct view class", InternalResourceView.class, view.getClass());
    assertEquals("Correct URL", "myUrl", ((InternalResourceView) view).getUrl());
}
项目:spring4-understanding    文件:ViewMethodReturnValueHandlerTests.java   
@Test
public void returnView() throws Exception {
    InternalResourceView view = new InternalResourceView("testView");
    this.handler.handleReturnValue(view, createReturnValueParam("view"), this.mavContainer, this.webRequest);

    assertSame(view, this.mavContainer.getView());
}
项目:anyline    文件:TemplateResourceViewResolver.java   
public TemplateResourceViewResolver() {
    Class viewClass = requiredViewClass();
    if (viewClass.equals(InternalResourceView.class))
        viewClass = TemplateView.class;

    setViewClass(viewClass);
}
项目:cas4.1.9    文件:RegisteredServiceThemeBasedViewResolver.java   
/**
 * Uses the viewName and the theme associated with the service.
 * being requested and returns the appropriate view.
 * @param viewName the name of the view to be resolved
 * @return a theme-based UrlBasedView
 * @throws Exception an exception
 */
@Override
protected AbstractUrlBasedView buildView(final String viewName) throws Exception {
    final RequestContext requestContext = RequestContextHolder.getRequestContext();
    final WebApplicationService service = WebUtils.getService(requestContext);
    final RegisteredService registeredService = this.servicesManager.findServiceBy(service);

    final String themeId = service != null && registeredService != null
            && registeredService.getAccessStrategy().isServiceAccessAllowed()
            && StringUtils.hasText(registeredService.getTheme()) ? registeredService.getTheme() : defaultThemeId;

    final String themePrefix = String.format("%s/%s/ui/", pathPrefix, themeId);
    LOGGER.debug("Prefix {} set for service {} with theme {}", themePrefix, service, themeId);

    //Build up the view like the base classes do, but we need to forcefully set the prefix for each request.
    //From UrlBasedViewResolver.buildView
    final InternalResourceView view = (InternalResourceView) BeanUtils.instantiateClass(getViewClass());
    view.setUrl(themePrefix + viewName + getSuffix());
    final String contentType = getContentType();
    if (contentType != null) {
        view.setContentType(contentType);
    }
    view.setRequestContextAttribute(getRequestContextAttribute());
    view.setAttributesMap(getAttributesMap());

    //From InternalResourceViewResolver.buildView
    view.setAlwaysInclude(false);
    view.setExposeContextBeansAsAttributes(false);
    view.setPreventDispatchLoop(true);

    LOGGER.debug("View resolved: {}", view.getUrl());

    return view;
}
项目:spring-saml-angular2    文件:MetadataController.java   
@RequestMapping(value = "/provider")
public ModelAndView displayProvider(@RequestParam("providerIndex") int providerIndex) {

    ModelAndView model = new ModelAndView(new InternalResourceView("/WEB-INF/security/providerView.jsp", true));
    ExtendedMetadataDelegate delegate = metadataManager.getAvailableProviders().get(providerIndex);
    model.addObject("provider", delegate);
    model.addObject("providerIndex", providerIndex);
    return model;

}
项目:spring-saml-angular2    文件:MetadataController.java   
@RequestMapping(value = "/generate")
public ModelAndView generateMetadata(HttpServletRequest request) throws KeyStoreException {

    ModelAndView model = new ModelAndView(new InternalResourceView("/WEB-INF/security/metadataGenerator.jsp", true));
    MetadataForm defaultForm = new MetadataForm();

    model.addObject("availableKeys", getAvailablePrivateKeys());
    defaultForm.setBaseURL(getBaseURL(request));
    defaultForm.setEntityId(getEntityId(request));
    defaultForm.setNameID(MetadataGenerator.defaultNameID.toArray(new String[MetadataGenerator.defaultNameID.size()]));

    model.addObject("metadata", defaultForm);
    return model;

}
项目:spring-saml-angular2    文件:MetadataController.java   
protected ModelAndView displayMetadata(EntityDescriptor entityDescriptor, ExtendedMetadata extendedMetadata) throws MarshallingException {

        MetadataForm metadata = new MetadataForm();
        String fileName = getFileName(entityDescriptor);

        metadata.setLocal(extendedMetadata.isLocal());
        metadata.setSecurityProfile(extendedMetadata.getSecurityProfile());
        metadata.setSslSecurityProfile(extendedMetadata.getSslSecurityProfile());
        metadata.setSerializedMetadata(getMetadataAsString(entityDescriptor, extendedMetadata));
        metadata.setConfiguration(getConfiguration(fileName, extendedMetadata));
        metadata.setEntityId(entityDescriptor.getEntityID());
        metadata.setAlias(extendedMetadata.getAlias());
        metadata.setRequireArtifactResolveSigned(extendedMetadata.isRequireArtifactResolveSigned());
        metadata.setRequireLogoutRequestSigned(extendedMetadata.isRequireLogoutRequestSigned());
        metadata.setRequireLogoutResponseSigned(extendedMetadata.isRequireLogoutResponseSigned());
        metadata.setEncryptionKey(extendedMetadata.getEncryptionKey());
        metadata.setSigningKey(extendedMetadata.getSigningKey());
        metadata.setTlsKey(extendedMetadata.getTlsKey());
        metadata.setSslHostnameVerification(extendedMetadata.getSslHostnameVerification());

        metadata.setSignMetadata(extendedMetadata.isSignMetadata());
        metadata.setSigningAlgorithm(extendedMetadata.getSigningAlgorithm());

        metadata.setIncludeDiscovery(extendedMetadata.isIdpDiscoveryEnabled());
        metadata.setCustomDiscoveryURL(extendedMetadata.getIdpDiscoveryResponseURL());
        metadata.setCustomDiscoveryResponseURL(extendedMetadata.getIdpDiscoveryURL());

        // TODO other fields nameIDs

        ModelAndView model = new ModelAndView(new InternalResourceView("/WEB-INF/security/metadataView.jsp", true));
        model.addObject("metadata", metadata);
        model.addObject("storagePath", fileName);

        return model;

    }