use of org.springframework.web.util.UrlPathHelper in project ma-core-public by infiniteautomation.
the class MangoRestSpringConfiguration method getUrlPathHelper.
/**
* Create a Path helper that will not URL Decode
* the context path and request URI but will
* decode the path variables...
*/
public UrlPathHelper getUrlPathHelper() {
UrlPathHelper helper = new UrlPathHelper();
helper.setUrlDecode(false);
return helper;
}
use of org.springframework.web.util.UrlPathHelper in project BroadleafCommerce by BroadleafCommerce.
the class AdminBasicEntityController method viewEntityForm.
/**
* Renders the main entity form for the specified entity
*
* @param request
* @param response
* @param model
* @param pathVars
* @param id
* @return the return view path
* @throws Exception
*/
@RequestMapping(value = "/{id}", method = RequestMethod.GET)
public String viewEntityForm(HttpServletRequest request, HttpServletResponse response, Model model, @PathVariable Map<String, String> pathVars, @PathVariable("id") String id) throws Exception {
String sectionKey = getSectionKey(pathVars);
String sectionClassName = getClassNameForSection(sectionKey);
List<SectionCrumb> crumbs = getSectionCrumbs(request, sectionKey, id);
PersistencePackageRequest ppr = getSectionPersistencePackageRequest(sectionClassName, crumbs, pathVars);
ClassMetadata cmd = service.getClassMetadata(ppr).getDynamicResultSet().getClassMetaData();
Entity entity = service.getRecord(ppr, id, cmd, false).getDynamicResultSet().getRecords()[0];
Map<String, DynamicResultSet> subRecordsMap = getViewSubRecords(request, pathVars, cmd, entity, crumbs);
EntityForm entityForm = formService.createEntityForm(cmd, entity, subRecordsMap, crumbs);
if (isAddRequest(entity)) {
modifyAddEntityForm(entityForm, pathVars);
} else {
modifyEntityForm(entityForm, pathVars);
}
if (request.getParameter("headerFlash") != null) {
model.addAttribute("headerFlash", request.getParameter("headerFlash"));
}
// Set the sectionKey again incase this is a typed entity
entityForm.setSectionKey(sectionKey);
// Build the current url in the cast that this is a typed entity
String originatingUri = new UrlPathHelper().getOriginatingRequestUri(request);
int startIndex = request.getContextPath().length();
// Remove the context path from servlet path
String currentUrl = originatingUri.substring(startIndex);
model.addAttribute("entity", entity);
model.addAttribute("entityForm", entityForm);
model.addAttribute("currentUrl", currentUrl);
setModelAttributes(model, sectionKey);
// We want to replace author ids with their names
addAuditableDisplayFields(entityForm);
if (isAjaxRequest(request)) {
entityForm.setReadOnly();
model.addAttribute("viewType", "modal/entityView");
model.addAttribute("modalHeaderType", ModalHeaderType.VIEW_ENTITY.getType());
return "modules/modalContainer";
} else {
model.addAttribute("useAjaxUpdate", true);
model.addAttribute("viewType", "entityEdit");
return "modules/defaultContainer";
}
}
use of org.springframework.web.util.UrlPathHelper in project spring-framework by spring-projects.
the class RequestMappingInfoHandlerMappingTests method handleMatchUriTemplateVariablesDecode.
@SuppressWarnings("unchecked")
// SPR-9098
@PathPatternsParameterizedTest
void handleMatchUriTemplateVariablesDecode(TestRequestMappingInfoHandlerMapping mapping) {
RequestMappingInfo key = RequestMappingInfo.paths("/{group}/{identifier}").build();
MockHttpServletRequest request = new MockHttpServletRequest("GET", "/group/a%2Fb");
UrlPathHelper pathHelper = new UrlPathHelper();
pathHelper.setUrlDecode(false);
String lookupPath = pathHelper.getLookupPathForRequest(request);
mapping.setUrlPathHelper(pathHelper);
mapping.handleMatch(key, lookupPath, request);
String name = HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE;
Map<String, String> uriVariables = (Map<String, String>) request.getAttribute(name);
assertThat(uriVariables).isNotNull();
assertThat(uriVariables.get("group")).isEqualTo("group");
assertThat(uriVariables.get("identifier")).isEqualTo("a/b");
}
use of org.springframework.web.util.UrlPathHelper in project spring-framework by spring-projects.
the class RequestMappingInfoHandlerMappingTests method handleMatchMatrixVariablesDecoding.
// SPR-10140, SPR-16867
@PathPatternsParameterizedTest
void handleMatchMatrixVariablesDecoding(TestRequestMappingInfoHandlerMapping mapping) {
if (mapping.getPatternParser() == null) {
UrlPathHelper urlPathHelper = new UrlPathHelper();
urlPathHelper.setUrlDecode(false);
urlPathHelper.setRemoveSemicolonContent(false);
mapping.setUrlPathHelper(urlPathHelper);
}
MockHttpServletRequest request = new MockHttpServletRequest("GET", "/cars;mvar=a%2Fb");
handleMatch(mapping, request, "/{cars}", request.getRequestURI());
MultiValueMap<String, String> matrixVariables = getMatrixVariables(request, "cars");
Map<String, String> uriVariables = getUriTemplateVariables(request);
assertThat(matrixVariables).isNotNull();
assertThat(matrixVariables.get("mvar")).isEqualTo(Collections.singletonList("a/b"));
assertThat(uriVariables.get("cars")).isEqualTo("cars");
}
use of org.springframework.web.util.UrlPathHelper in project spring-framework by spring-projects.
the class RequestMappingInfoHandlerMappingTests method handleMatchUriTemplateVariables.
@SuppressWarnings("unchecked")
@PathPatternsParameterizedTest
void handleMatchUriTemplateVariables(TestRequestMappingInfoHandlerMapping mapping) {
RequestMappingInfo key = RequestMappingInfo.paths("/{path1}/{path2}").build();
MockHttpServletRequest request = new MockHttpServletRequest("GET", "/1/2");
String lookupPath = new UrlPathHelper().getLookupPathForRequest(request);
mapping.handleMatch(key, lookupPath, request);
String name = HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE;
Map<String, String> uriVariables = (Map<String, String>) request.getAttribute(name);
assertThat(uriVariables).isNotNull();
assertThat(uriVariables.get("path1")).isEqualTo("1");
assertThat(uriVariables.get("path2")).isEqualTo("2");
}
Aggregations