use of org.springframework.web.servlet.mvc.multiaction.NoSuchRequestHandlingMethodException in project ORCID-Source by ORCID.
the class ClaimControllerTest method testClaim.
@Test
@Transactional
public void testClaim() {
String email = "public_0000-0000-0000-0001@test.orcid.org";
SecurityContextHolder.getContext().setAuthentication(null);
when(profileEntityCacheManager.retrieve(Mockito.anyString())).thenReturn(getProfileEntityToTestClam(false));
when(encryptionManager.decryptForExternalUse(any(String.class))).thenReturn(email);
HttpServletRequest request = mock(HttpServletRequest.class);
HttpServletResponse response = mock(HttpServletResponse.class);
when(request.getAttribute(DispatcherServlet.LOCALE_RESOLVER_ATTRIBUTE)).thenReturn(null);
when(request.getLocale()).thenReturn(java.util.Locale.US);
String orcid = "0000-0000-0000-0001";
when(emailManager.findOrcidIdByEmail(email)).thenReturn(orcid);
when(profileEntityManager.claimProfileAndUpdatePreferences(any(String.class), any(String.class), any(Locale.class), any(Claim.class))).thenReturn(true);
Claim claim = new Claim();
claim.setActivitiesVisibilityDefault(org.orcid.pojo.ajaxForm.Visibility.valueOf(Visibility.PRIVATE));
claim.setPassword(Text.valueOf("passwordTest1"));
claim.setPasswordConfirm(Text.valueOf("passwordTest1"));
Checkbox checked = new Checkbox();
checked.setValue(true);
claim.setSendChangeNotifications(checked);
claim.setSendOrcidNews(checked);
claim.setTermsOfUse(checked);
try {
claim = claimController.submitClaimJson(request, response, email, claim);
assertNotNull(claim);
assertTrue(claim.getErrors().isEmpty());
assertTrue("Value was: " + claim.getUrl(), claim.getUrl().endsWith("/my-orcid?recordClaimed"));
} catch (NoSuchRequestHandlingMethodException e) {
fail();
} catch (UnsupportedEncodingException e) {
fail();
}
}
use of org.springframework.web.servlet.mvc.multiaction.NoSuchRequestHandlingMethodException in project com.revolsys.open by revolsys.
the class AnnotationHandlerMethodResolver method resolveHandlerMethod.
public WebMethodHandler resolveHandlerMethod(final HttpServletRequest request) throws ServletException {
final String lookupPath = this.adapter.urlPathHelper.getLookupPathForRequest(request);
final Comparator<String> pathComparator = this.adapter.pathMatcher.getPatternComparator(lookupPath);
final Map<RequestMappingInfo, WebMethodHandler> targetHandlerMethods = new LinkedHashMap<>();
final Set<String> allowedMethods = new LinkedHashSet<>(7);
String resolvedMethodName = null;
for (final WebMethodHandler webMethodHandler : this.handlerMethods) {
final Method handlerMethod = webMethodHandler.getMethod();
final RequestMappingInfo mappingInfo = new RequestMappingInfo();
final RequestMapping mapping = AnnotationUtils.findAnnotation(handlerMethod, RequestMapping.class);
mappingInfo.paths = mapping.value();
if (!hasTypeLevelMapping() || !Arrays.equals(mapping.method(), this.typeLevelMapping.method())) {
mappingInfo.methods = mapping.method();
}
boolean match = false;
if (mappingInfo.paths.length > 0) {
final List<String> matchedPaths = new ArrayList<>(mappingInfo.paths.length);
for (final String methodLevelPattern : mappingInfo.paths) {
final String matchedPattern = getMatchedPattern(methodLevelPattern, lookupPath, request);
if (matchedPattern != null) {
if (mappingInfo.matches(request)) {
match = true;
matchedPaths.add(matchedPattern);
} else {
for (final RequestMethod requestMethod : mappingInfo.methods) {
allowedMethods.add(requestMethod.toString());
}
break;
}
}
}
Collections.sort(matchedPaths, pathComparator);
mappingInfo.matchedPaths = matchedPaths;
} else {
// No paths specified: parameter match sufficient.
match = mappingInfo.matches(request);
if (match && mappingInfo.methods.length == 0 && resolvedMethodName != null && !resolvedMethodName.equals(handlerMethod.getName())) {
match = false;
} else {
for (final RequestMethod requestMethod : mappingInfo.methods) {
allowedMethods.add(requestMethod.toString());
}
}
}
if (match) {
WebMethodHandler oldMappedMethod = targetHandlerMethods.put(mappingInfo, webMethodHandler);
if (oldMappedMethod != null && oldMappedMethod != webMethodHandler) {
if (this.adapter.methodNameResolver != null && mappingInfo.paths.length == 0) {
if (!oldMappedMethod.getMethod().getName().equals(handlerMethod.getName())) {
if (resolvedMethodName == null) {
resolvedMethodName = this.adapter.methodNameResolver.getHandlerMethodName(request);
}
if (!resolvedMethodName.equals(oldMappedMethod.getMethod().getName())) {
oldMappedMethod = null;
}
if (!resolvedMethodName.equals(handlerMethod.getName())) {
if (oldMappedMethod != null) {
targetHandlerMethods.put(mappingInfo, oldMappedMethod);
oldMappedMethod = null;
} else {
targetHandlerMethods.remove(mappingInfo);
}
}
}
}
if (oldMappedMethod != null) {
throw new IllegalStateException("Ambiguous handler methods mapped for HTTP path '" + lookupPath + "': {" + oldMappedMethod + ", " + handlerMethod + "}. If you intend to handle the same path in multiple methods, then factor " + "them out into a dedicated handler class with that path mapped at the type level!");
}
}
}
}
if (!targetHandlerMethods.isEmpty()) {
final List<RequestMappingInfo> matches = new ArrayList<>(targetHandlerMethods.keySet());
final RequestMappingInfoComparator requestMappingInfoComparator = new RequestMappingInfoComparator(pathComparator);
Collections.sort(matches, requestMappingInfoComparator);
final RequestMappingInfo bestMappingMatch = matches.get(0);
final String bestMatchedPath = bestMappingMatch.bestMatchedPath();
if (bestMatchedPath != null) {
extractHandlerMethodUriTemplates(bestMatchedPath, lookupPath, request);
}
return targetHandlerMethods.get(bestMappingMatch);
} else {
if (!allowedMethods.isEmpty()) {
throw new HttpRequestMethodNotSupportedException(request.getMethod(), StringUtils.toStringArray(allowedMethods));
} else {
throw new NoSuchRequestHandlingMethodException(lookupPath, request.getMethod(), request.getParameterMap());
}
}
}
Aggregations