add prefix to HttpService
This commit is contained in:
parent
65279dbed3
commit
a78d88bc47
8 changed files with 39 additions and 11 deletions
|
@ -25,6 +25,11 @@ public class BaseHttpService implements HttpService {
|
|||
return new BaseHttpServiceBuilder();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPrefix() {
|
||||
return builder.prefix;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPathSpecification() {
|
||||
return builder.pathSpec;
|
||||
|
|
|
@ -13,10 +13,12 @@ import java.util.Objects;
|
|||
|
||||
public class BaseHttpServiceBuilder implements HttpServiceBuilder {
|
||||
|
||||
protected Collection<HttpMethod> methods;
|
||||
protected String prefix;
|
||||
|
||||
protected String pathSpec;
|
||||
|
||||
protected Collection<HttpMethod> methods;
|
||||
|
||||
protected Collection<HttpHandler> handlers;
|
||||
|
||||
protected Collection<ParameterDefinition> parameterDefinitions;
|
||||
|
@ -24,19 +26,21 @@ public class BaseHttpServiceBuilder implements HttpServiceBuilder {
|
|||
protected HttpSecurityDomain securityDomain;
|
||||
|
||||
protected BaseHttpServiceBuilder() {
|
||||
this.prefix = "";
|
||||
this.pathSpec = "/**";
|
||||
this.methods = new HashSet<>();
|
||||
methods.add(HttpMethod.GET);
|
||||
this.pathSpec = "/**";
|
||||
this.handlers = null;
|
||||
this.securityDomain = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BaseHttpServiceBuilder setMethod(HttpMethod... method) {
|
||||
this.methods = new LinkedHashSet<>(Arrays.asList(method));
|
||||
public BaseHttpServiceBuilder setPrefix(String prefix) {
|
||||
this.prefix = prefix;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BaseHttpServiceBuilder setPath(String path) {
|
||||
if (path != null) {
|
||||
this.pathSpec = PathNormalizer.normalize(path);
|
||||
|
@ -44,6 +48,12 @@ public class BaseHttpServiceBuilder implements HttpServiceBuilder {
|
|||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BaseHttpServiceBuilder setMethod(HttpMethod... method) {
|
||||
this.methods = new LinkedHashSet<>(Arrays.asList(method));
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BaseHttpServiceBuilder setHandler(HttpHandler... handler) {
|
||||
this.handlers = Arrays.asList(handler);
|
||||
|
|
|
@ -7,6 +7,8 @@ import org.xbib.net.http.HttpMethod;
|
|||
|
||||
public interface HttpService extends HttpHandler {
|
||||
|
||||
String getPrefix();
|
||||
|
||||
String getPathSpecification();
|
||||
|
||||
Collection<HttpMethod> getMethods();
|
||||
|
|
|
@ -5,6 +5,8 @@ import org.xbib.net.http.HttpMethod;
|
|||
|
||||
public interface HttpServiceBuilder {
|
||||
|
||||
HttpServiceBuilder setPrefix(String prefix);
|
||||
|
||||
HttpServiceBuilder setPath(String path);
|
||||
|
||||
HttpServiceBuilder setMethod(HttpMethod... method);
|
||||
|
|
|
@ -32,8 +32,8 @@ public class DecoratingHttpService implements HttpService {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Collection<HttpMethod> getMethods() {
|
||||
return delegate.getMethods();
|
||||
public String getPrefix() {
|
||||
return delegate.getPrefix();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -41,6 +41,11 @@ public class DecoratingHttpService implements HttpService {
|
|||
return delegate.getPathSpecification();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<HttpMethod> getMethods() {
|
||||
return delegate.getMethods();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<HttpHandler> getHandlers() {
|
||||
return delegate.getHandlers();
|
||||
|
|
|
@ -90,6 +90,12 @@ public class BaseHttpRouteResolver<T> implements HttpRouteResolver<T> {
|
|||
this.sort = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HttpRouteResolver.Builder<T> setPrefix(String prefix) {
|
||||
this.prefix = prefix;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HttpRouteResolver.Builder<T> add(HttpAddress httpAddress, HttpMethod httpMethod, String path, T value) {
|
||||
add(new BaseHttpRoute(httpAddress, Set.of(httpMethod), prefix + path, false), value);
|
||||
|
@ -114,11 +120,6 @@ public class BaseHttpRouteResolver<T> implements HttpRouteResolver<T> {
|
|||
return this;
|
||||
}
|
||||
|
||||
public HttpRouteResolver.Builder<T> setPrefix(String prefix) {
|
||||
this.prefix = prefix;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BaseHttpRouteResolver<T> build() {
|
||||
if (sort) {
|
||||
|
|
|
@ -50,6 +50,7 @@ public class BaseHttpRouter implements HttpRouter {
|
|||
for (HttpService httpService : domain.getServices()) {
|
||||
logger.log(Level.FINE, "adding " + domain.getAddress() + " " + httpService.getMethods() + " " + httpService.getPathSpecification() + " " + httpService);
|
||||
HttpRoute httpRoute = new BaseHttpRoute(domain.getAddress(), httpService.getMethods(), httpService.getPathSpecification(), false);
|
||||
httpRouteResolverBuilder.setPrefix(httpService.getPrefix());
|
||||
httpRouteResolverBuilder.add(httpRoute, httpService);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,6 +13,8 @@ public interface HttpRouteResolver<T> {
|
|||
|
||||
interface Builder<T> {
|
||||
|
||||
Builder<T> setPrefix(String prefix);
|
||||
|
||||
Builder<T> add(HttpRoute route, T value);
|
||||
|
||||
Builder<T> add(HttpAddress httpAddress, HttpMethod httpMethod, String path, T value);
|
||||
|
|
Loading…
Reference in a new issue