org.springframework.web.util.NestedServletException Java Examples

The following examples show how to use org.springframework.web.util.NestedServletException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RestControllerV2Test.java    From molgenis with GNU Lesser General Public License v3.0 8 votes vote down vote up
@Test
void testCopyEntityDuplicateEntity() throws Throwable {
  @SuppressWarnings("unchecked")
  Repository<Entity> repositoryToCopy = mock(Repository.class);
  mocksForCopyEntitySuccess(repositoryToCopy);

  String content = "{newEntityName: 'duplicateEntity'}";
  try {
    mockMvc.perform(post(HREF_COPY_ENTITY).content(content).contentType(APPLICATION_JSON));
  } catch (NestedServletException e) {
    Exception exception =
        assertThrows(
            RepositoryAlreadyExistsException.class,
            () -> {
              throw e.getCause();
            });
    assertThat(exception.getMessage())
        .containsPattern("repository:org_molgenis_blah_duplicateEntity");
  }
}
 
Example #2
Source File: ElidePropertiesTest.java    From elide-spring-boot with Apache License 2.0 7 votes vote down vote up
@Transactional
@Test(expected = NullPointerException.class)
public void testDisableDI() throws Throwable {
  MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(wac).build();

  try {
    String postBook = "{\"data\": {\"type\": \"account\",\"attributes\": {\"username\": \"username\",\"password\": \"password\"}}}";

    mockMvc.perform(post("/api/account")
        .contentType(JSON_API_CONTENT_TYPE)
        .content(postBook)
        .accept(JSON_API_CONTENT_TYPE))
        .andExpect(content().contentType(JSON_API_RESPONSE))
        .andExpect(status().isCreated());
  } catch (NestedServletException e) {
    throw e.getCause();
  }
}
 
Example #3
Source File: RestControllerV2Test.java    From molgenis with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Test
void testCopyEntityNoReadPermissions() throws Throwable {
  @SuppressWarnings("unchecked")
  Repository<Entity> repositoryToCopy = mock(Repository.class);
  mocksForCopyEntitySuccess(repositoryToCopy);

  // Override mock
  when(permissionService.hasPermission(
          new EntityTypeIdentity("entity"), EntityTypePermission.READ_DATA))
      .thenReturn(false);

  String content = "{newEntityName: 'newEntity'}";
  try {
    mockMvc.perform(post(HREF_COPY_ENTITY).content(content).contentType(APPLICATION_JSON));
  } catch (NestedServletException e) {
    Exception exception =
        assertThrows(
            EntityTypePermissionDeniedException.class,
            () -> {
              throw e.getCause();
            });
    assertThat(exception.getMessage())
        .containsPattern("permission:READ_DATA entityTypeId:entity");
  }
}
 
Example #4
Source File: RestControllerV2Test.java    From molgenis with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Test
void testCreateEntitiesUnknownEntityTypeException() throws Throwable {
  String unknownEntityTypeId = "entity2";
  doThrow(new UnknownEntityTypeException(unknownEntityTypeId))
      .when(dataService)
      .getEntityType(unknownEntityTypeId);

  try {
    mockMvc.perform(
        post(BASE_URI + "/" + unknownEntityTypeId)
            .content("{entities:[{email:'[email protected]', extraAttribute:'test'}]}")
            .contentType(APPLICATION_JSON));
  } catch (NestedServletException e) {
    Exception exception =
        assertThrows(
            UnknownEntityTypeException.class,
            () -> {
              throw e.getCause();
            });
    assertThat(exception.getMessage()).containsPattern("id:entity2");
  }
}
 
Example #5
Source File: RestControllerV2Test.java    From molgenis with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Test
void retrieveResourceCollectionUnknownEntityType() throws Throwable {
  String unknownEntityTypeId = "unknown";
  doThrow(new UnknownEntityTypeException(unknownEntityTypeId))
      .when(dataService)
      .getRepository(unknownEntityTypeId);

  try {
    mockMvc.perform(get(BASE_URI + '/' + unknownEntityTypeId));
  } catch (NestedServletException e) {
    Exception exception =
        assertThrows(
            UnknownEntityTypeException.class,
            () -> {
              throw e.getCause();
            });
    assertThat(exception.getMessage()).containsPattern("id:unknown");
  }
}
 
Example #6
Source File: IdentitiesApiControllerTest.java    From molgenis with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Test
void testRemoveMembershipUnknownGroup() throws Throwable {
  when(userPermissionEvaluator.hasPermission(new GroupIdentity("devs"), REMOVE_MEMBERSHIP))
      .thenReturn(true);
  when(groupMetadata.getId()).thenReturn("Group");
  when(attribute.getName()).thenReturn("Name");
  doThrow(new UnknownEntityException(groupMetadata, attribute, "devs"))
      .when(groupService)
      .getGroup("devs");
  try {
    mockMvc.perform(delete("/api/identities/group/devs/member/henkie"));
  } catch (NestedServletException e) {
    Exception exception =
        assertThrows(
            UnknownEntityException.class,
            () -> {
              throw e.getCause();
            });
    assertThat(exception.getMessage()).containsPattern("type:Group id:devs attribute:Name");
  }
}
 
Example #7
Source File: IdentitiesApiControllerTest.java    From molgenis with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Test
void testRemoveMembershipPermissionDenied() throws Throwable {
  when(userPermissionEvaluator.hasPermission(new GroupIdentity("devs"), REMOVE_MEMBERSHIP))
      .thenReturn(false);
  try {
    mockMvc.perform(delete("/api/identities/group/devs/member/henkie"));
  } catch (NestedServletException e) {
    Exception exception =
        assertThrows(
            GroupPermissionDeniedException.class,
            () -> {
              throw e.getCause();
            });
    assertThat(exception.getMessage())
        .containsPattern("permission:REMOVE_MEMBERSHIP groupName:devs");
  }
}
 
Example #8
Source File: IdentitiesApiControllerTest.java    From molgenis with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Test
void testAddMembershipUnknownUser() throws Throwable {
  when(userPermissionEvaluator.hasPermission(new GroupIdentity("devs"), ADD_MEMBERSHIP))
      .thenReturn(true);
  when(groupService.getGroup("devs")).thenReturn(group);
  when(roleService.getRole("DEVS_EDITOR")).thenReturn(editor);
  when(userMetadata.getId()).thenReturn("User");
  when(attribute.getName()).thenReturn("Name");
  doThrow(new UnknownEntityException(userMetadata, attribute, "henkie"))
      .when(userService)
      .getUser("user");
  try {
    mockMvc.perform(
        post(GROUP_END_POINT + "/devs/member")
            .contentType(APPLICATION_JSON_UTF8)
            .content(gson.toJson(addGroupMember("user", "DEVS_EDITOR"))));
  } catch (NestedServletException e) {
    Exception exception =
        assertThrows(
            UnknownEntityException.class,
            () -> {
              throw e.getCause();
            });
    assertThat(exception.getMessage()).containsPattern("type:User id:henkie attribute:Name");
  }
}
 
Example #9
Source File: IdentitiesApiControllerTest.java    From molgenis with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Test
void testRemoveMembershipUnknownUser() throws Throwable {
  when(groupService.getGroup("devs")).thenReturn(group);
  when(userService.getUser("henkie"))
      .thenThrow(new UnknownEntityException(UserMetadata.USER, "henkie"));
  when(userPermissionEvaluator.hasPermission(new GroupIdentity("devs"), REMOVE_MEMBERSHIP))
      .thenReturn(true);
  try {
    mockMvc.perform(delete("/api/identities/group/devs/member/henkie"));
  } catch (NestedServletException e) {
    Exception exception =
        assertThrows(
            UnknownEntityException.class,
            () -> {
              throw e.getCause();
            });
    assertThat(exception.getMessage())
        .containsPattern("type:sys_sec_User id:henkie attribute:null");
  }
}
 
Example #10
Source File: RestControllerTest.java    From molgenis with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Test
void retrieveAttributeUnknownEntity() throws Throwable {
  String entityTypeId = "unknown";
  when(dataService.getEntityType(entityTypeId))
      .thenThrow(new UnknownEntityTypeException(entityTypeId));
  String HREF_UNKNOWN_ENTITY_META = BASE_URI + "/" + entityTypeId + "/meta";
  try {
    mockMvc.perform(get(HREF_UNKNOWN_ENTITY_META + "/attribute"));
  } catch (NestedServletException e) {
    Exception exception =
        assertThrows(
            UnknownEntityTypeException.class,
            () -> {
              throw e.getCause();
            });
    assertThat(exception.getMessage()).containsPattern("id:unknown");
  }
}
 
Example #11
Source File: RestControllerTest.java    From molgenis with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Test
void retrieveEntityAttributeUnknownAttribute() throws Throwable {
  @SuppressWarnings("unchecked")
  Repository<Entity> repo = mock(Repository.class);

  EntityType entityType = mock(EntityType.class);
  when(entityType.getId()).thenReturn(ENTITY_NAME);
  when(entityType.getLabel("en")).thenReturn("My Entity");
  when(entityType.getAttribute("name")).thenReturn(null);
  Attribute idAttr = when(mock(Attribute.class).getDataType()).thenReturn(STRING).getMock();
  when(entityType.getIdAttribute()).thenReturn(idAttr);
  when(repo.getEntityType()).thenReturn(entityType);
  when(dataService.getEntityType(ENTITY_NAME)).thenReturn(entityType);
  when(dataService.getRepository(ENTITY_NAME)).thenReturn(repo);
  try {
    mockMvc.perform(get(HREF_ENTITY_ID + "/name"));
  } catch (NestedServletException e) {
    Exception exception =
        assertThrows(
            UnknownAttributeException.class,
            () -> {
              throw e.getCause();
            });
    assertThat(exception.getMessage()).containsPattern("type:Person attribute:name");
  }
}
 
Example #12
Source File: RestControllerTest.java    From molgenis with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Test
void retrieveEntityAttributeUnknownEntity() throws Throwable {
  EntityType entityType = mock(EntityType.class);
  when(entityType.getId()).thenReturn(ENTITY_NAME);
  when(entityType.getLabel("en")).thenReturn("My entity type");
  when(dataService.getEntityType(ENTITY_NAME)).thenReturn(entityType);
  Attribute idAttribute = mock(Attribute.class);
  when(entityType.getIdAttribute()).thenReturn(idAttribute);
  when(idAttribute.getDataType()).thenReturn(STRING);
  when(dataService.findOneById(ENTITY_NAME, ENTITY_UNTYPED_ID)).thenReturn(null);
  try {
    mockMvc.perform(get(HREF_ENTITY_ID + "/name"));
  } catch (NestedServletException e) {
    Exception exception =
        assertThrows(
            UnknownAttributeException.class,
            () -> {
              throw e.getCause();
            });
    assertThat(exception.getMessage()).containsPattern("type:Person attribute:name");
  }
}
 
Example #13
Source File: RestControllerTest.java    From molgenis with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Test
void updateInternalRepoIdAttributeIsNull() throws Throwable {
  @SuppressWarnings("unchecked")
  Repository<Entity> repo = mock(Repository.class);
  when(dataService.getRepository(ENTITY_NAME)).thenReturn(repo);
  EntityType entityType = mock(EntityType.class);
  when(entityType.getIdAttribute()).thenReturn(null);
  when(repo.getEntityType()).thenReturn(entityType);
  when(dataService.getEntityType(ENTITY_NAME)).thenReturn(entityType);
  try {
    mockMvc.perform(
        MockMvcRequestBuilders.put(HREF_ENTITY_ID)
            .content("{name:Klaas}")
            .contentType(APPLICATION_JSON));
  } catch (NestedServletException e) {
    Exception exception =
        assertThrows(
            IllegalArgumentException.class,
            () -> {
              throw e.getCause();
            });
    assertThat(exception.getMessage()).containsPattern("Person does not have an id attribute");
  }
}
 
Example #14
Source File: RestControllerTest.java    From molgenis with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Test
void updateInternalRepoExistingIsNull() throws Throwable {
  when(dataService.findOneById(
          ArgumentMatchers.eq(ENTITY_NAME),
          ArgumentMatchers.eq(ENTITY_UNTYPED_ID),
          any(Fetch.class)))
      .thenReturn(null);

  try {
    mockMvc.perform(
        MockMvcRequestBuilders.put(HREF_ENTITY_ID)
            .content("{name:Klaas}")
            .contentType(APPLICATION_JSON));
  } catch (NestedServletException e) {
    Exception exception =
        assertThrows(
            UnknownEntityException.class,
            () -> {
              throw e.getCause();
            });
    assertThat(exception.getMessage()).containsPattern("type:Person id:p1 attribute:id");
  }
}
 
Example #15
Source File: RestControllerTest.java    From molgenis with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Test
void updateAttribute_unknownEntity() throws Throwable {
  String entityTypeId = "unknownentity";
  when(dataService.getEntityType(entityTypeId))
      .thenThrow(new UnknownEntityTypeException(entityTypeId));
  try {
    mockMvc.perform(
        post(BASE_URI + "/" + entityTypeId + "/" + ENTITY_UNTYPED_ID + "/name")
            .param("_method", "PUT")
            .content("Klaas")
            .contentType(APPLICATION_JSON));
  } catch (NestedServletException e) {
    Exception exception =
        assertThrows(
            UnknownEntityTypeException.class,
            () -> {
              throw e.getCause();
            });
    assertThat(exception.getMessage()).containsPattern("id:unknownentity");
  }
}
 
Example #16
Source File: RestControllerTest.java    From molgenis with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Test
void updateAttribute_unknownEntityId() throws Throwable {
  try {
    mockMvc.perform(
        post(HREF_ENTITY + "/666" + "/name")
            .param("_method", "PUT")
            .content("Klaas")
            .contentType(APPLICATION_JSON));
  } catch (NestedServletException e) {
    Exception exception =
        assertThrows(
            UnknownEntityException.class,
            () -> {
              throw e.getCause();
            });
    assertThat(exception.getMessage()).containsPattern("type:Person id:666 attribute:id");
  }
}
 
Example #17
Source File: IdentitiesApiControllerTest.java    From molgenis with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Test
void testUpdateMembershipPermissionDenied() throws Throwable {
  when(userPermissionEvaluator.hasPermission(new GroupIdentity("devs"), UPDATE_MEMBERSHIP))
      .thenReturn(false);

  try {
    mockMvc.perform(
        put(GROUP_END_POINT + "/devs/member/henkie")
            .contentType(APPLICATION_JSON_UTF8)
            .content(gson.toJson(updateGroupMember("DEVS_MANAGER"))));
  } catch (NestedServletException e) {
    Exception exception =
        assertThrows(
            GroupPermissionDeniedException.class,
            () -> {
              throw e.getCause();
            });
    assertThat(exception.getMessage())
        .containsPattern("permission:UPDATE_MEMBERSHIP groupName:devs");
  }
}
 
Example #18
Source File: IdentitiesApiControllerTest.java    From molgenis with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Test
void testAddMembershipUnknownGroup() throws Throwable {
  when(userPermissionEvaluator.hasPermission(new GroupIdentity("devs"), ADD_MEMBERSHIP))
      .thenReturn(true);

  when(groupMetadata.getId()).thenReturn("Group");
  when(attribute.getName()).thenReturn("Name");
  doThrow(new UnknownEntityException(groupMetadata, attribute, "devs"))
      .when(groupService)
      .getGroup("devs");
  try {
    mockMvc.perform(
        post(GROUP_END_POINT + "/devs/member")
            .contentType(APPLICATION_JSON_UTF8)
            .content(gson.toJson(addGroupMember("user", "DEVS_EDITOR"))));
  } catch (NestedServletException e) {
    Exception exception =
        assertThrows(
            UnknownEntityException.class,
            () -> {
              throw e.getCause();
            });
    assertThat(exception.getMessage()).containsPattern("type:Group id:devs attribute:Name");
  }
}
 
Example #19
Source File: IdentitiesApiControllerTest.java    From molgenis with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Test
void testAddMembershipPermissionDenied() throws Throwable {
  when(userPermissionEvaluator.hasPermission(new GroupIdentity("devs"), ADD_MEMBERSHIP))
      .thenReturn(false);
  try {
    mockMvc.perform(
        post(GROUP_END_POINT + "/devs/member")
            .contentType(APPLICATION_JSON_UTF8)
            .content(gson.toJson(addGroupMember("user", "DEVS_EDITOR"))));
  } catch (NestedServletException e) {
    Exception exception =
        assertThrows(
            GroupPermissionDeniedException.class,
            () -> {
              throw e.getCause();
            });
    assertThat(exception.getMessage())
        .containsPattern("permission:ADD_MEMBERSHIP groupName:devs");
  }
}
 
Example #20
Source File: IdentitiesApiControllerTest.java    From molgenis with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Test
void testGetMembersUnknownGroup() throws Throwable {
  when(userPermissionEvaluator.hasPermission(new GroupIdentity("devs"), VIEW_MEMBERSHIP))
      .thenReturn(true);
  when(groupMetadata.getId()).thenReturn("Group");
  when(attribute.getName()).thenReturn("Name");
  doThrow(new UnknownEntityException(groupMetadata, attribute, "devs"))
      .when(groupService)
      .getGroup("devs");
  try {
    mockMvc.perform(get(GROUP_END_POINT + "/devs/member"));
  } catch (NestedServletException e) {
    Exception exception =
        assertThrows(
            UnknownEntityException.class,
            () -> {
              throw e.getCause();
            });
    assertThat(exception.getMessage()).containsPattern("type:Group id:devs attribute:Name");
  }
}
 
Example #21
Source File: IdentitiesApiControllerTest.java    From molgenis with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Test
void testGetMembersPermissionDenied() throws Throwable {
  when(userPermissionEvaluator.hasPermission(new GroupIdentity("devs"), VIEW_MEMBERSHIP))
      .thenReturn(false);
  try {
    mockMvc.perform(get(GROUP_END_POINT + "/devs/member"));
  } catch (NestedServletException e) {
    Exception exception =
        assertThrows(
            GroupPermissionDeniedException.class,
            () -> {
              throw e.getCause();
            });
    assertThat(exception.getMessage())
        .containsPattern("permission:VIEW_MEMBERSHIP groupName:devs");
  }
}
 
Example #22
Source File: IdentitiesApiControllerTest.java    From molgenis with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Test
@WithMockUser("henkie")
void testCreateGroupUnavailableGroupName() throws Throwable {
  when(groupService.isGroupNameAvailable(any())).thenReturn(false);
  try {
    mockMvc
        .perform(
            post(GROUP_END_POINT)
                .contentType(APPLICATION_JSON_UTF8)
                .content(gson.toJson(createGroup("devs", "Developers"))))
        .andExpect(status().isBadRequest());
  } catch (NestedServletException e) {
    verifyNoMoreInteractions(groupService);
    verifyNoMoreInteractions(groupPermissionService);
    verifyNoMoreInteractions(roleMembershipService);
    Exception exception =
        assertThrows(
            GroupNameNotAvailableException.class,
            () -> {
              throw e.getCause();
            });
    assertThat(exception.getMessage()).containsPattern("groupName:devs");
  }
}
 
Example #23
Source File: AppControllerTest.java    From molgenis with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Test
void testServeAppNoPermissions() throws Throwable {
  PluginIdentity pluginIdentity = new PluginIdentity(APP_PREFIX + "app1");
  when(userPermissionEvaluator.hasPermission(pluginIdentity, VIEW_PLUGIN)).thenReturn(false);
  try {
    mockMvc.perform(get(AppController.URI + "/app1/"));
  } catch (NestedServletException e) {
    Exception exception =
        assertThrows(
            PluginPermissionDeniedException.class,
            () -> {
              throw e.getCause();
            });
    assertThat(exception.getMessage())
        .containsPattern("pluginPermission: VIEW_PLUGIN, pluginId:app1");
  }
}
 
Example #24
Source File: TraceFilterIntegrationTests.java    From spring-cloud-sleuth with Apache License 2.0 6 votes vote down vote up
@Test
public void should_log_tracing_information_when_500_exception_was_thrown()
		throws Exception {
	Long expectedTraceId = new Random().nextLong();

	try {
		whenSentToExceptionThrowingEndpoint(expectedTraceId);
		fail("Should fail");
	}
	catch (NestedServletException e) {
		then(e).hasRootCauseInstanceOf(RuntimeException.class);
	}

	// we need to dump the span cause it's not in TracingFilter since TF
	// has also error dispatch and the ErrorController would report the span
	then(this.spans).hasSize(1);
	then(this.spans.get(0).error()).hasMessageContaining(
			"Request processing failed; nested exception is java.lang.RuntimeException");
}
 
Example #25
Source File: RestControllerV2Test.java    From molgenis with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Test
void testUpdateEntitiesSpecificAttributeInvalidId() throws Throwable {
  try {
    mockMvc.perform(
        put(BASE_URI + "/entity/email")
            .content("{\"entities\":[{\"id\":\"4\",\"email\":\"[email protected]\"}]}")
            .contentType(APPLICATION_JSON));
  } catch (NestedServletException e) {
    Exception exception =
        assertThrows(
            UnknownEntityException.class,
            () -> {
              throw e.getCause();
            });
    assertThat(exception.getMessage()).containsPattern("type:entity id:4 attribute:id");
  }
}
 
Example #26
Source File: HessianServiceExporter.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
/**
 * Processes the incoming Hessian request and creates a Hessian response.
 */
@Override
public void handleRequest(HttpServletRequest request, HttpServletResponse response)
		throws ServletException, IOException {

	if (!"POST".equals(request.getMethod())) {
		throw new HttpRequestMethodNotSupportedException(request.getMethod(),
				new String[] {"POST"}, "HessianServiceExporter only supports POST requests");
	}

	response.setContentType(CONTENT_TYPE_HESSIAN);
	try {
	  invoke(request.getInputStream(), response.getOutputStream());
	}
	catch (Throwable ex) {
	  throw new NestedServletException("Hessian skeleton invocation failed", ex);
	}
}
 
Example #27
Source File: RestControllerTest.java    From molgenis with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Test
void updateAttribute_unknownAttribute() throws Throwable {
  try {
    mockMvc.perform(
        post(HREF_ENTITY_ID + "/unknownattribute")
            .param("_method", "PUT")
            .content("Klaas")
            .contentType(APPLICATION_JSON));
  } catch (NestedServletException e) {
    Exception exception =
        assertThrows(
            UnknownAttributeException.class,
            () -> {
              throw e.getCause();
            });
    assertThat(exception.getMessage()).containsPattern("type:Person attribute:unknownattribute");
  }
}
 
Example #28
Source File: ServletAnnotationControllerTests.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@Test
public void equivalentMappingsWithSameMethodName() throws Exception {
	initServlet(ChildController.class);
	servlet.init(new MockServletConfig());

	MockHttpServletRequest request = new MockHttpServletRequest("GET", "/child/test");
	request.addParameter("childId", "100");
	MockHttpServletResponse response = new MockHttpServletResponse();
	try {
		servlet.service(request, response);
		fail("Didn't fail with due to ambiguous method mapping");
	}
	catch (NestedServletException ex) {
		assertTrue(ex.getCause() instanceof IllegalStateException);
		assertTrue(ex.getCause().getMessage().contains("doGet"));
	}
}
 
Example #29
Source File: ServletInvocableHandlerMethod.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
public ConcurrentResultHandlerMethod(final Object result, ConcurrentResultMethodParameter returnType) {
	super(new Callable<Object>() {
		@Override
		public Object call() throws Exception {
			if (result instanceof Exception) {
				throw (Exception) result;
			}
			else if (result instanceof Throwable) {
				throw new NestedServletException("Async processing failed", (Throwable) result);
			}
			return result;
		}
	}, CALLABLE_METHOD);
	setHandlerMethodReturnValueHandlers(ServletInvocableHandlerMethod.this.returnValueHandlers);
	this.returnType = returnType;
}
 
Example #30
Source File: VelocityView.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
/**
 * Merge the template with the context.
 * Can be overridden to customize the behavior.
 * @param template the template to merge
 * @param context the Velocity context to use for rendering
 * @param response servlet response (use this to get the OutputStream or Writer)
 * @throws Exception if thrown by Velocity
 * @see org.apache.velocity.Template#merge
 */
protected void mergeTemplate(
		Template template, Context context, HttpServletResponse response) throws Exception {

	try {
		template.merge(context, response.getWriter());
	}
	catch (MethodInvocationException ex) {
		Throwable cause = ex.getWrappedThrowable();
		throw new NestedServletException(
				"Method invocation failed during rendering of Velocity view with name '" +
				getBeanName() + "': " + ex.getMessage() + "; reference [" + ex.getReferenceName() +
				"], method '" + ex.getMethodName() + "'",
				cause==null ? ex : cause);
	}
}