
org.continuity.api.rest.RestEndpoint Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of continuity.api Show documentation
Show all versions of continuity.api Show documentation
Library of continuITy defining exchange entities
The newest version!
package org.continuity.api.rest;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Stack;
import org.springframework.web.bind.annotation.RequestMethod;
/**
* Represents one REST endpoint of a service, containing the service name, the path incl. path
* parameters and the request method.
*
* @author Henning Schulz
*
*/
public class RestEndpoint {
private final String serviceName;
private final String root;
private final List elements;
private final RequestMethod method;
private RestEndpoint(String serviceName, String root, List elements, RequestMethod method) {
this.serviceName = serviceName;
this.root = root;
this.elements = elements;
this.method = method;
}
/**
* Creates a new instance.
*
* @param serviceName
* The name of the service.
* @param root
* The root path element.
* @param path
* The path (without the root).
* @param method
* The request method.
* @return The new RestEndpoint instance.
*/
protected static RestEndpoint of(String serviceName, String root, String path, RequestMethod method) {
if (path.startsWith("/")) {
path = path.substring(1);
}
String[] pathElements = path.split("\\/");
List elements = new ArrayList<>();
for (String elem : pathElements) {
if (elem.startsWith("{")) {
elements.add(StringOrPar.of(PathPar.of(elem.substring(1, elem.length() - 1))));
} else {
elements.add(StringOrPar.of(elem));
}
}
return new RestEndpoint(serviceName, root, elements, method);
}
/**
* Returns the represented generic path, e.g., /my/path/{id}
where
* {id}
denotes a parameter.
*
* @return The generic path as string.
*/
public String genericPath() {
return elements.stream().reduce(StringOrPar.of(root), StringOrPar::concat).toString();
}
/**
* Returns the represented path with parameter instance values, e.g., /my/path/MyId
* for the generic path /my/path/{id}
.
*
* @param values
* The parameter values to fill in the parameters.
* @return The path as string.
*/
public String path(Object... values) {
List
© 2015 - 2025 Weber Informatics LLC | Privacy Policy