當前位置: 首頁>>代碼示例>>Java>>正文


Java UrlPathHelper類代碼示例

本文整理匯總了Java中org.springframework.web.util.UrlPathHelper的典型用法代碼示例。如果您正苦於以下問題:Java UrlPathHelper類的具體用法?Java UrlPathHelper怎麽用?Java UrlPathHelper使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


UrlPathHelper類屬於org.springframework.web.util包,在下文中一共展示了UrlPathHelper類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: PatternsRequestCondition

import org.springframework.web.util.UrlPathHelper; //導入依賴的package包/類
/**
 * Private constructor accepting a collection of patterns.
 */
private PatternsRequestCondition(Collection<String> patterns, UrlPathHelper urlPathHelper,
		PathMatcher pathMatcher, boolean useSuffixPatternMatch, boolean useTrailingSlashMatch,
		List<String> fileExtensions) {

	this.patterns = Collections.unmodifiableSet(prependLeadingSlash(patterns));
	this.pathHelper = (urlPathHelper != null ? urlPathHelper : new UrlPathHelper());
	this.pathMatcher = (pathMatcher != null ? pathMatcher : new AntPathMatcher());
	this.useSuffixPatternMatch = useSuffixPatternMatch;
	this.useTrailingSlashMatch = useTrailingSlashMatch;
	if (fileExtensions != null) {
		for (String fileExtension : fileExtensions) {
			if (fileExtension.charAt(0) != '.') {
				fileExtension = "." + fileExtension;
			}
			this.fileExtensions.add(fileExtension);
		}
	}
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:22,代碼來源:PatternsRequestCondition.java

示例2: registerUrlPathHelper

import org.springframework.web.util.UrlPathHelper; //導入依賴的package包/類
/**
 * Adds an alias to an existing well-known name or registers a new instance of a {@link UrlPathHelper}
 * under that well-known name, unless already registered.
 * @return a RuntimeBeanReference to this {@link UrlPathHelper} instance
 */
public static RuntimeBeanReference registerUrlPathHelper(RuntimeBeanReference urlPathHelperRef, ParserContext parserContext, Object source) {
	if (urlPathHelperRef != null) {
		if (parserContext.getRegistry().isAlias(URL_PATH_HELPER_BEAN_NAME)) {
			parserContext.getRegistry().removeAlias(URL_PATH_HELPER_BEAN_NAME);
		}
		parserContext.getRegistry().registerAlias(urlPathHelperRef.getBeanName(), URL_PATH_HELPER_BEAN_NAME);
	}
	else if (!parserContext.getRegistry().isAlias(URL_PATH_HELPER_BEAN_NAME)
			&& !parserContext.getRegistry().containsBeanDefinition(URL_PATH_HELPER_BEAN_NAME)) {
		RootBeanDefinition urlPathHelperDef = new RootBeanDefinition(UrlPathHelper.class);
		urlPathHelperDef.setSource(source);
		urlPathHelperDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
		parserContext.getRegistry().registerBeanDefinition(URL_PATH_HELPER_BEAN_NAME, urlPathHelperDef);
		parserContext.registerComponent(new BeanComponentDefinition(urlPathHelperDef, URL_PATH_HELPER_BEAN_NAME));
	}
	return new RuntimeBeanReference(URL_PATH_HELPER_BEAN_NAME);
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:23,代碼來源:MvcNamespaceUtils.java

示例3: uriTemplateVariables

import org.springframework.web.util.UrlPathHelper; //導入依賴的package包/類
@Test
public void uriTemplateVariables() {
	PatternsRequestCondition patterns = new PatternsRequestCondition("/{path1}/{path2}");
	RequestMappingInfo key = new RequestMappingInfo(patterns, null, null, null, null, null, null);
	MockHttpServletRequest request = new MockHttpServletRequest("GET", "/1/2");
	String lookupPath = new UrlPathHelper().getLookupPathForRequest(request);
	this.handlerMapping.handleMatch(key, lookupPath, request);

	@SuppressWarnings("unchecked")
	Map<String, String> uriVariables =
		(Map<String, String>) request.getAttribute(
				HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE);

	assertNotNull(uriVariables);
	assertEquals("1", uriVariables.get("path1"));
	assertEquals("2", uriVariables.get("path2"));
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:18,代碼來源:RequestMappingInfoHandlerMappingTests.java

示例4: uriTemplateVariablesDecode

import org.springframework.web.util.UrlPathHelper; //導入依賴的package包/類
@Test
public void uriTemplateVariablesDecode() {
	PatternsRequestCondition patterns = new PatternsRequestCondition("/{group}/{identifier}");
	RequestMappingInfo key = new RequestMappingInfo(patterns, null, null, null, null, null, null);
	MockHttpServletRequest request = new MockHttpServletRequest("GET", "/group/a%2Fb");

	UrlPathHelper pathHelper = new UrlPathHelper();
	pathHelper.setUrlDecode(false);
	String lookupPath = pathHelper.getLookupPathForRequest(request);

	this.handlerMapping.setUrlPathHelper(pathHelper);
	this.handlerMapping.handleMatch(key, lookupPath, request);

	@SuppressWarnings("unchecked")
	Map<String, String> uriVariables =
		(Map<String, String>) request.getAttribute(HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE);

	assertNotNull(uriVariables);
	assertEquals("group", uriVariables.get("group"));
	assertEquals("a/b", uriVariables.get("identifier"));
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:22,代碼來源:RequestMappingInfoHandlerMappingTests.java

示例5: matrixVariablesDecoding

import org.springframework.web.util.UrlPathHelper; //導入依賴的package包/類
@Test
public void matrixVariablesDecoding() {

	MockHttpServletRequest request;

	UrlPathHelper urlPathHelper = new UrlPathHelper();
	urlPathHelper.setUrlDecode(false);
	urlPathHelper.setRemoveSemicolonContent(false);

	this.handlerMapping.setUrlPathHelper(urlPathHelper );

	request = new MockHttpServletRequest();
	testHandleMatch(request, "/path{filter}", "/path;mvar=a%2fb");

	MultiValueMap<String, String> matrixVariables = getMatrixVariables(request, "filter");
	Map<String, String> uriVariables = getUriTemplateVariables(request);

	assertNotNull(matrixVariables);
	assertEquals(Arrays.asList("a/b"), matrixVariables.get("mvar"));
	assertEquals(";mvar=a/b", uriVariables.get("filter"));
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:22,代碼來源:RequestMappingInfoHandlerMappingTests.java

示例6: setUp

import org.springframework.web.util.UrlPathHelper; //導入依賴的package包/類
@Before
public void setUp() {
    MockitoAnnotations.initMocks(this);
    CounterFactory.initialize(new EmptyCounterFactory());
    this.request = new MockHttpServletRequest();
    this.response = new MockHttpServletResponse();
    rateLimitKeyGenerator = new DefaultRateLimitKeyGenerator(this.properties());
    UrlPathHelper urlPathHelper = new UrlPathHelper();
    this.filter = new RateLimitPreFilter(this.properties(), this.routeLocator(), urlPathHelper, this.rateLimiter, rateLimitKeyGenerator);
    this.context = new RequestContext();
    RequestContext.testSetCurrentContext(this.context);
    RequestContextHolder.setRequestAttributes(requestAttributes);
    this.context.clear();
    this.context.setRequest(this.request);
    this.context.setResponse(this.response);
}
 
開發者ID:marcosbarbero,項目名稱:spring-cloud-zuul-ratelimit,代碼行數:17,代碼來源:BaseRateLimitPreFilterTest.java

示例7: doFilterInternal

import org.springframework.web.util.UrlPathHelper; //導入依賴的package包/類
@Override
protected void doFilterInternal(HttpServletRequest request,
		HttpServletResponse response, FilterChain chain)
				throws ServletException, IOException {
	StopWatch stopWatch = createStopWatchIfNecessary(request);
	String path = new UrlPathHelper().getPathWithinApplication(request);
	int status = HttpStatus.INTERNAL_SERVER_ERROR.value();
	try {
		chain.doFilter(request, response);
		status = getStatus(response);
	}
	finally {
		if (!request.isAsyncStarted()) {
			stopWatch.stop();
			request.removeAttribute(ATTRIBUTE_STOP_WATCH);
			recordMetrics(request, path, status, stopWatch.getTotalTimeMillis());
		}
	}
}
 
開發者ID:vikrammane23,項目名稱:https-github.com-g0t4-jenkins2-course-spring-boot,代碼行數:20,代碼來源:MetricsFilter.java

示例8: getMatchingCondition

import org.springframework.web.util.UrlPathHelper; //導入依賴的package包/類
@Override
public StoreCondition getMatchingCondition(HttpServletRequest request) {
	String path = new UrlPathHelper().getPathWithinApplication(request);
	String[] segments = path.split("/");
	if (segments.length < 3) {
		return null;
	}
	ContentStoreInfo info = ContentStoreUtils.findStore(stores, segments[1]);
	if (info != null && 
			(Store.class.isAssignableFrom(info.getInterface()) && "store".equals(storeType)) ||
			(ContentStore.class.isAssignableFrom(info.getInterface()) && "contentstore".equals(storeType))
		) {
		return this;
	}

	return null;
}
 
開發者ID:paulcwarren,項目名稱:spring-content,代碼行數:18,代碼來源:ContentHandlerMapping.java

示例9: compareTo

import org.springframework.web.util.UrlPathHelper; //導入依賴的package包/類
@Override
public int compareTo(StoreCondition other, HttpServletRequest request) {
	if (this.isMappingForRequest(request) && other.isMappingForRequest(request) == false)
		return 1;
	else if (this.isMappingForRequest(request) == false && other.isMappingForRequest(request))
		return -1;
	else {
		String path = new UrlPathHelper().getPathWithinApplication(request);
		String filename = FilenameUtils.getName(path);
		String extension = FilenameUtils.getExtension(filename);
		if (extension != null && "store".equals(storeType)) {
			return -1;
		} else if (extension != null && "contentstore".equals(storeType)) {
			return 1;
		}
		return 0;
	}
}
 
開發者ID:paulcwarren,項目名稱:spring-content,代碼行數:19,代碼來源:ContentHandlerMapping.java

示例10: getContent

import org.springframework.web.util.UrlPathHelper; //導入依賴的package包/類
@StoreType("store")
@RequestMapping(value = BASE_MAPPING, method = RequestMethod.GET, headers={"accept!=application/hal+json", /*"range"*/})
public void getContent(HttpServletRequest request, 
					   HttpServletResponse response,
					   @PathVariable String store) 
		throws ServletException, IOException {
	
	ContentStoreInfo info = ContentStoreUtils.findStore(storeService, store);
	if (info == null) {
		throw new IllegalArgumentException("Entity not a content repository");
	}
	
	String path = new UrlPathHelper().getPathWithinApplication(request);
	String pathToUse = path.substring(ContentStoreUtils.storePath(info).length() + 1);

	Resource r = ((Store)info.getImpementation()).getResource(pathToUse);
	if (r == null) {
		throw new ResourceNotFoundException();
	}

	request.setAttribute("SPRING_CONTENT_RESOURCE", r);

	handler.handleRequest(request, response);

	return;
}
 
開發者ID:paulcwarren,項目名稱:spring-content,代碼行數:27,代碼來源:StoreRestController.java

示例11: deleteContent

import org.springframework.web.util.UrlPathHelper; //導入依賴的package包/類
@StoreType("store")
@RequestMapping(value = BASE_MAPPING, method = RequestMethod.DELETE, headers="accept!=application/hal+json")
public void deleteContent(HttpServletRequest request, 
						  HttpServletResponse response,
						  @PathVariable String store) 
		throws HttpRequestMethodNotSupportedException {

	ContentStoreInfo info = ContentStoreUtils.findStore(storeService, store);
	if (info == null) {
		throw new IllegalArgumentException("Not a Store");
	}
	
	String path = new UrlPathHelper().getPathWithinApplication(request);
	String pathToUse = path.substring(ContentStoreUtils.storePath(info).length() + 1);

	Resource r = ((Store)info.getImpementation()).getResource(pathToUse);
	if (r == null) {
		throw new ResourceNotFoundException();
	}
	if (r instanceof DeletableResource == false) {
		throw new UnsupportedOperationException();
	}
	((DeletableResource)r).delete();
}
 
開發者ID:paulcwarren,項目名稱:spring-content,代碼行數:25,代碼來源:StoreRestController.java

示例12: initLookupPath

import org.springframework.web.util.UrlPathHelper; //導入依賴的package包/類
private void initLookupPath(ResourceUrlProvider urlProvider) {
        if (this.indexLookupPath == null) {
UrlPathHelper pathHelper = urlProvider.getUrlPathHelper();
String requestUri = pathHelper.getRequestUri(this.request);
String lookupPath = pathHelper.getLookupPathForRequest(this.request);
            this.indexLookupPath = requestUri.lastIndexOf(lookupPath);
            this.prefixLookupPath = requestUri.substring(0, this.indexLookupPath);

            if ("/".equals(lookupPath) && !"/".equals(requestUri)) {
	String contextPath = pathHelper.getContextPath(this.request);
                if (requestUri.equals(contextPath)) {
                    this.indexLookupPath = requestUri.length();
                    this.prefixLookupPath = requestUri;
                }
            }
        }
    }
 
開發者ID:af-not-found,項目名稱:blog-java2,代碼行數:18,代碼來源:CachingResourceUrlEncodingFilter.java

示例13: doFilter

import org.springframework.web.util.UrlPathHelper; //導入依賴的package包/類
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
    HttpServletRequest httpRequest = asHttp(request);
    HttpServletResponse httpResponse = asHttp(response);

    Optional<String> username = Optional.fromNullable(httpRequest.getHeader("X-Auth-Username"));
    Optional<String> password = Optional.fromNullable(httpRequest.getHeader("X-Auth-Password"));

    String resourcePath = new UrlPathHelper().getPathWithinApplication(httpRequest);

    try {
        if (postToManagementEndpoints(resourcePath)) {
            logger.debug("Trying to authenticate user {} for management endpoint by X-Auth-Username method", username);
            processManagementEndpointUsernamePasswordAuthentication(username, password);
        }

        logger.debug("ManagementEndpointAuthenticationFilter is passing request down the filter chain");
        chain.doFilter(request, response);
    } catch (AuthenticationException authenticationException) {
        SecurityContextHolder.clearContext();
        httpResponse.sendError(HttpServletResponse.SC_UNAUTHORIZED, authenticationException.getMessage());
    }
}
 
開發者ID:yopeio,項目名稱:payment-api,代碼行數:24,代碼來源:ManagementEndpointAuthenticationFilter.java

示例14: getURI

import org.springframework.web.util.UrlPathHelper; //導入依賴的package包/類
/**
 * 獲得第三個路徑分隔符的位置
 * 
 * @param request
 * @throws IllegalStateException
 *             訪問路徑錯誤,沒有三(四)個'/'
 */
private static String getURI(HttpServletRequest request)
		throws IllegalStateException {
	UrlPathHelper helper = new UrlPathHelper();
	String uri = helper.getOriginatingRequestUri(request);
	String ctxPath = helper.getOriginatingContextPath(request);
	int start = 0, i = 0, count = 2;
	if (!StringUtils.isBlank(ctxPath)) {
		count++;
	}
	while (i < count && start != -1) {
		start = uri.indexOf('/', start + 1);
		i++;
	}
	
	if (start <= 0) {
		throw new IllegalStateException(
				"admin access path not like '/jeeadmin/jeecms/...' pattern: "
						+ uri);
	}
	return uri.substring(start);
}
 
開發者ID:huanzhou,項目名稱:jeecms6,代碼行數:29,代碼來源:AdminContextInterceptor.java

示例15: PatternsRequestCondition

import org.springframework.web.util.UrlPathHelper; //導入依賴的package包/類
/**
 * Private constructor accepting a collection of patterns.
 */
private PatternsRequestCondition(Collection<String> patterns, UrlPathHelper urlPathHelper,
		PathMatcher pathMatcher, boolean useSuffixPatternMatch, boolean useTrailingSlashMatch,
		List<String> fileExtensions) {

	this.patterns = Collections.unmodifiableSet(prependLeadingSlash(patterns));
	this.pathHelper = urlPathHelper != null ? urlPathHelper : new UrlPathHelper();
	this.pathMatcher = pathMatcher != null ? pathMatcher : new AntPathMatcher();
	this.useSuffixPatternMatch = useSuffixPatternMatch;
	this.useTrailingSlashMatch = useTrailingSlashMatch;
	if (fileExtensions != null) {
		for (String fileExtension : fileExtensions) {
			if (fileExtension.charAt(0) != '.') {
				fileExtension = "." + fileExtension;
			}
			this.fileExtensions.add(fileExtension);
		}
	}
}
 
開發者ID:deathspeeder,項目名稱:class-guard,代碼行數:22,代碼來源:PatternsRequestCondition.java


注:本文中的org.springframework.web.util.UrlPathHelper類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。