Java Code Examples for org.springframework.web.util.UriComponents#toUri()

The following examples show how to use org.springframework.web.util.UriComponents#toUri() . 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: BuildURIFromHttpRequest.java    From levelup-java-examples with Apache License 2.0 6 votes vote down vote up
@Test
public void replace_path () {

	MockHttpServletRequest request = new MockHttpServletRequest();
	request.setPathInfo("/java/examples");

	UriComponents ucb =
	        ServletUriComponentsBuilder
		        .fromRequest(request)
		        .replacePath("/java/exercises")
		        .build()
	            .encode();
	
	URI uri = ucb.toUri();
	
	assertEquals("http://localhost/java/exercises", uri.toString());
}
 
Example 2
Source File: BuildURIFromHttpRequest.java    From levelup-java-examples with Apache License 2.0 5 votes vote down vote up
@Test
public void create_URI_from_http_request () {
	
	MockHttpServletRequest request = new MockHttpServletRequest();
	
	UriComponents ucb =
	        ServletUriComponentsBuilder
		        .fromContextPath(request)
		        .path("/examples/java")
		        .build();

	URI uri = ucb.toUri();
	
	assertEquals("http://localhost/examples/java", uri.toString());
}
 
Example 3
Source File: AppCenterManager.java    From carina with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings({ "rawtypes", "unchecked" })
private RequestEntity<String> buildRequestEntity(String hostUrl, String path,
                                                 HttpMethod httpMethod) {

    UriComponents uriComponents = UriComponentsBuilder.newInstance()
            .scheme("https")
            .host(hostUrl)
            .path(path)
            .build();

    return new RequestEntity(setHeaders(), httpMethod, uriComponents.toUri());
}
 
Example 4
Source File: AppCenterManager.java    From carina with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings({ "rawtypes", "unchecked" })
private RequestEntity<String> buildRequestEntity(String hostUrl, String path,
                                                 MultiValueMap<String, String> listQueryParams, HttpMethod httpMethod) {

    UriComponents uriComponents = UriComponentsBuilder.newInstance()
            .scheme("https")
            .host(hostUrl)
            .path(path)
            .queryParams(listQueryParams)
            .build();

    return new RequestEntity(setHeaders(), httpMethod, uriComponents.toUri());
}