Java Code Examples for org.springframework.web.util.UriTemplate#expand()

The following examples show how to use org.springframework.web.util.UriTemplate#expand() . 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: DependencyToggleBox.java    From nb-springboot with Apache License 2.0 5 votes vote down vote up
@Override
public void actionPerformed(ActionEvent e) {
    JComponent c = (JComponent) e.getSource();
    final Object urlTemplate = c.getClientProperty(PROP_REFERENCE_TEMPLATE_URL);
    if (urlTemplate != null && currentBootVersion != null) {
        try {
            UriTemplate template = new UriTemplate(urlTemplate.toString());
            final URI uri = template.expand(currentBootVersion);
            HtmlBrowser.URLDisplayer.getDefault().showURL(uri.toURL());
        } catch (MalformedURLException ex) {
            Exceptions.printStackTrace(ex);
        }
    }
}
 
Example 2
Source File: DependencyToggleBox.java    From nb-springboot with Apache License 2.0 5 votes vote down vote up
@Override
public void actionPerformed(ActionEvent e) {
    JComponent c = (JComponent) e.getSource();
    final Object urlTemplate = c.getClientProperty(PROP_GUIDE_TEMPLATE_URL);
    if (urlTemplate != null && currentBootVersion != null) {
        try {
            UriTemplate template = new UriTemplate(urlTemplate.toString());
            final URI uri = template.expand(currentBootVersion);
            HtmlBrowser.URLDisplayer.getDefault().showURL(uri.toURL());
        } catch (MalformedURLException ex) {
            Exceptions.printStackTrace(ex);
        }
    }
}
 
Example 3
Source File: SetPathGatewayFilterFactory.java    From spring-cloud-gateway with Apache License 2.0 5 votes vote down vote up
@Override
public GatewayFilter apply(Config config) {
	UriTemplate uriTemplate = new UriTemplate(config.template);

	return new GatewayFilter() {
		@Override
		public Mono<Void> filter(ServerWebExchange exchange,
				GatewayFilterChain chain) {
			ServerHttpRequest req = exchange.getRequest();
			addOriginalRequestUrl(exchange, req.getURI());

			Map<String, String> uriVariables = getUriTemplateVariables(exchange);

			URI uri = uriTemplate.expand(uriVariables);
			String newPath = uri.getRawPath();

			exchange.getAttributes().put(GATEWAY_REQUEST_URL_ATTR, uri);

			ServerHttpRequest request = req.mutate().path(newPath).build();

			return chain.filter(exchange.mutate().request(request).build());
		}

		@Override
		public String toString() {
			return filterToStringCreator(SetPathGatewayFilterFactory.this)
					.append("template", config.getTemplate()).toString();
		}
	};
}
 
Example 4
Source File: HttpSpringStarterInitializer.java    From ogham with Apache License 2.0 5 votes vote down vote up
@Override
public Project<SpringBootProjectParams> initialize(Path parentFolder, String identifier, SpringBootProjectParams variables) throws ProjectInitializationException {
	// @formatter:off
	String url = springStarterProperties.getUrl()
			+ "?name={artifactId}"
			+ "&groupId=fr.sii"
			+ "&artifactId={artifactId}"
			+ "&version={version}"
			+ "&description="
			+ "&packageName=fr.sii.spring.boot.runtime.testing"
			+ "&type={type}"
			+ "&packaging=jar"
			+ "&javaVersion={javaVersion}"
			+ "&language=java"
			+ "&bootVersion={springBootVersion}";
	// @formatter:on
	for (SpringBootDependency dependency : variables.getSpringBootDependencies()) {
		url += "&dependencies=" + dependency.getModule();
	}
	UriTemplate template = new UriTemplate(url);
	URI expanded = template.expand(identifier,
			identifier,
			oghamProperties.getOghamVersion(),
			variables.getBuildTool().getType(),
			variables.getJavaVersion().getVersion(),
			variables.getSpringBootVersion());
	log.debug("Starter resolved url: {}", expanded);
	RequestEntity<Void> request = RequestEntity.get(expanded)
									.header(USER_AGENT, "ogham/"+oghamProperties.getOghamVersion())
									.build();
	ResponseEntity<byte[]> response = restTemplate.exchange(request, byte[].class);
	if(response.getStatusCode().is2xxSuccessful()) {
		try {
			return new Project<>(unzip(response.getBody(), identifier, parentFolder), variables);
		} catch(IOException | ZipException | RuntimeException e) {
			throw new ProjectInitializationException("Failed to initialize Spring Boot project while trying to unzip Spring starter zip", e);
		}
	}
	throw new ProjectInitializationException("Failed to download Spring starter zip");
}