context URL, better interface and parameterized types for Domain and EndpointResolver

This commit is contained in:
Jörg Prante 2020-07-24 15:30:32 +02:00
parent 4fc61db40d
commit fb062ebf04
41 changed files with 394 additions and 252 deletions

View file

@ -1,6 +1,6 @@
group = org.xbib
name = netty-http
version = 4.1.51.1
version = 4.1.51.2
gradle.wrapper.version = 6.4.1
netty.version = 4.1.51.Final

View file

@ -0,0 +1,24 @@
package org.xbib.netty.http.server.api;
import io.netty.handler.ssl.SslContext;
import org.xbib.netty.http.common.HttpAddress;
import java.io.IOException;
import java.security.cert.X509Certificate;
import java.util.Collection;
public interface Domain<R extends EndpointResolver<?>> {
HttpAddress getHttpAddress();
String getName();
Collection<R> getHttpEndpointResolvers();
SslContext getSslContext();
Collection<? extends X509Certificate> getCertificateChain();
String findContextPathOf(ServerRequest serverRequest) throws IOException;
void handle(ServerRequest serverRequest, ServerResponse serverResponse) throws IOException;
}

View file

@ -0,0 +1,16 @@
package org.xbib.netty.http.server.api;
import java.io.IOException;
import java.util.List;
public interface EndpointResolver<E extends Endpoint<? extends EndpointDescriptor>> {
List<E> matchingEndpointsFor(ServerRequest serverRequest);
void resolve(List<E> matchingEndpoints,
ServerRequest serverRequest) throws IOException;
void handle(List<E> matchingEndpoints,
ServerRequest serverRequest,
ServerResponse serverResponse) throws IOException;
}

View file

@ -0,0 +1,4 @@
package org.xbib.netty.http.server.api;
public interface FilterConfig {
}

View file

@ -0,0 +1,95 @@
package org.xbib.netty.http.server.api;
import io.netty.channel.WriteBufferWaterMark;
import io.netty.handler.codec.http2.Http2Settings;
import io.netty.handler.logging.LogLevel;
import io.netty.handler.ssl.CipherSuiteFilter;
import io.netty.handler.ssl.SslProvider;
import org.xbib.netty.http.common.HttpAddress;
import java.security.KeyStore;
import java.security.Provider;
import java.util.Collection;
import javax.net.ssl.TrustManagerFactory;
public interface ServerConfig {
boolean isDebug();
LogLevel getTrafficDebugLogLevel();
String getTransportProviderName();
int getParentThreadCount();
int getChildThreadCount();
int getBlockingThreadCount();
int getBlockingQueueCount();
boolean isReuseAddr();
boolean isTcpNodelay();
int getTcpSendBufferSize();
int getTcpReceiveBufferSize();
int getBackLogSize();
int getConnectTimeoutMillis();
int getReadTimeoutMillis();
int getIdleTimeoutMillis();
HttpAddress getAddress();
int getMaxInitialLineLength();
int getMaxHeadersSize();
int getMaxChunkSize();
int getMaxContentLength();
int getPipeliningCapacity();
int getMaxCompositeBufferComponents();
WriteBufferWaterMark getWriteBufferWaterMark();
boolean isCompressionEnabled();
int getCompressionThreshold();
boolean isDecompressionEnabled();
boolean isInstallHttp2Upgrade();
Http2Settings getHttp2Settings();
TrustManagerFactory getTrustManagerFactory();
KeyStore getTrustManagerKeyStore();
SslProvider getSslProvider();
Provider getSslContextProvider();
String[] getProtocols();
Iterable<String> getCiphers();
CipherSuiteFilter getCipherSuiteFilter();
boolean isAutoDomain();
boolean isAcceptInvalidCertificates();
Collection<Domain<? extends EndpointResolver<?>>> getDomains();
Domain<? extends EndpointResolver<?>> getDomain(String name);
Domain<? extends EndpointResolver<?>> getDefaultDomain();
}

View file

@ -7,15 +7,18 @@ import io.netty.handler.ssl.CipherSuiteFilter;
import io.netty.handler.ssl.SslProvider;
import org.xbib.netty.http.common.HttpAddress;
import org.xbib.netty.http.common.security.SecurityUtil;
import org.xbib.netty.http.server.api.Domain;
import org.xbib.netty.http.server.api.EndpointResolver;
import org.xbib.netty.http.server.api.ServerConfig;
import java.security.KeyStore;
import java.security.Provider;
import java.util.Collection;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Deque;
import java.util.LinkedList;
import java.util.Optional;
import javax.net.ssl.TrustManagerFactory;
public class ServerConfig {
public class DefaultServerConfig implements ServerConfig {
interface Defaults {
@ -246,7 +249,7 @@ public class ServerConfig {
private boolean installHttp2Upgrade = Defaults.INSTALL_HTTP_UPGRADE2;
private final Map<String, Domain> domains;
private final Deque<Domain<? extends EndpointResolver<?>>> domains;
private SslProvider sslProvider = Defaults.SSL_PROVIDER;
@ -266,21 +269,17 @@ public class ServerConfig {
private boolean acceptInvalidCertificates = false;
public ServerConfig() {
this.domains = new LinkedHashMap<>();
public DefaultServerConfig() {
this.domains = new LinkedList<>();
}
public ServerConfig enableDebug() {
this.debug = true;
public ServerConfig setDebug(boolean debug) {
this.debug = debug;
return this;
}
public ServerConfig disableDebug() {
this.debug = false;
return this;
}
public boolean isTrafficDebug() {
@Override
public boolean isDebug() {
return debug;
}
@ -618,42 +617,27 @@ public class ServerConfig {
return acceptInvalidCertificates;
}
public ServerConfig checkAndAddDomain(Domain domain) {
if (domains.containsKey(domain.getName())) {
return this;
}
domains.put(domain.getName(), domain);
for (String alias : domain.getAliases()) {
domains.put(alias, domain);
}
public ServerConfig addDomain(Domain<? extends EndpointResolver<?>> domain) {
domains.add(domain);
return this;
}
public Collection<Domain> getDomains() {
return domains.values();
@Override
public Collection<Domain<? extends EndpointResolver<?>>> getDomains() {
return domains;
}
public ServerConfig removeDomain(String name) {
domains.remove(name);
return this;
@Override
public Domain<? extends EndpointResolver<?>> getDomain(String name) {
Optional<Domain<? extends EndpointResolver<?>>> domainOptional =
domains.stream().filter(d -> d.getName().equals(name)).findFirst();
return domainOptional.orElse(domains.getFirst());
}
public ServerConfig removeDomain(Domain domain) {
domains.remove(domain.getName());
for (String alias : domain.getAliases()) {
domains.remove(alias, domain);
}
return this;
}
public Domain getDomain(String name) {
Domain domain = domains.get(name);
return domain != null ? domain : getDefaultDomain();
}
public Domain getDefaultDomain() {
Domain defaultDomain = domains.get("*");
return defaultDomain != null ? defaultDomain :
!domains.isEmpty() ? domains.values().iterator().next() : null;
@Override
public Domain<? extends EndpointResolver<?>> getDefaultDomain() {
Optional<Domain<? extends EndpointResolver<?>>> domainOptional =
domains.stream().filter(d -> d.getName().equals("*")).findFirst();
return domainOptional.orElse(domains.getFirst());
}
}

View file

@ -8,6 +8,8 @@ import io.netty.handler.ssl.SslContext;
import io.netty.handler.ssl.SslContextBuilder;
import io.netty.handler.ssl.SslProvider;
import org.xbib.netty.http.common.HttpAddress;
import org.xbib.netty.http.server.api.Domain;
import org.xbib.netty.http.server.api.EndpointResolver;
import org.xbib.netty.http.server.api.security.ServerCertificateProvider;
import org.xbib.netty.http.common.security.SecurityUtil;
import org.xbib.netty.http.server.api.ServerRequest;
@ -33,33 +35,29 @@ import java.security.spec.InvalidKeySpecException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.ServiceLoader;
import java.util.Set;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
* The {@code Domain} class represents a virtual server with a name, with or without SSL.
* The {@code HttpServerDomain} class represents a virtual server with a name.
*/
public class Domain {
public class HttpServerDomain implements Domain<HttpEndpointResolver> {
private static final Logger logger = Logger.getLogger(Domain.class.getName());
private static final Logger logger = Logger.getLogger(HttpServerDomain.class.getName());
private static final String EMPTY = "";
private final String name;
private final Set<String> aliases;
private final HttpAddress httpAddress;
private final SslContext sslContext;
private final List<HttpEndpointResolver> httpEndpointResolvers;
private final Collection<HttpEndpointResolver> httpEndpointResolvers;
private final Collection<? extends X509Certificate> certificates;
@ -67,19 +65,16 @@ public class Domain {
* Constructs a {@code NamedServer} with the given name.
*
* @param name the name, or null if it is the default server
* @param aliases alias names for the named server
* @param httpAddress HTTP address, used for determining if named server is secure or not
* @param httpEndpointResolvers the endpoint resolvers
* @param sslContext SSL context or null
*/
private Domain(String name,
Set<String> aliases,
private HttpServerDomain(String name,
HttpAddress httpAddress,
List<HttpEndpointResolver> httpEndpointResolvers,
Collection<HttpEndpointResolver> httpEndpointResolvers,
SslContext sslContext,
Collection<? extends X509Certificate> certificates) {
this.name = name;
this.aliases = aliases;
this.httpAddress = httpAddress;
this.httpEndpointResolvers = httpEndpointResolvers;
this.sslContext = sslContext;
@ -94,7 +89,7 @@ public class Domain {
return new Builder(httpAddress).setServerName(serverName);
}
public static Builder builder(Domain domain) {
public static Builder builder(Domain<? extends EndpointResolver<?>> domain) {
return new Builder(domain);
}
@ -103,6 +98,7 @@ public class Domain {
*
* @return the HTTP address
*/
@Override
public HttpAddress getHttpAddress() {
return httpAddress;
}
@ -112,23 +108,21 @@ public class Domain {
*
* @return the name, or null if it is the default server
*/
@Override
public String getName() {
return name;
}
/**
* Returns the aliases.
*
* @return the (unmodifiable) set of aliases (which may be empty)
*/
public Set<String> getAliases() {
return aliases;
@Override
public Collection<HttpEndpointResolver> getHttpEndpointResolvers() {
return httpEndpointResolvers;
}
/**
* Returns SSL context.
* @return the SSL context
*/
@Override
public SslContext getSslContext() {
return sslContext;
}
@ -137,6 +131,7 @@ public class Domain {
* Get certificate chain.
* @return the certificate chain or null if not secure
*/
@Override
public Collection<? extends X509Certificate> getCertificateChain() {
return certificates;
}
@ -149,13 +144,14 @@ public class Domain {
* @return the context path
* @throws IOException if handling fails
*/
public String findContextOf(ServerRequest serverRequest) throws IOException {
@Override
public String findContextPathOf(ServerRequest serverRequest) throws IOException {
if (serverRequest == null) {
return EMPTY;
}
Map.Entry<HttpEndpointResolver, List<HttpEndpoint>> resolved = resolve(serverRequest);
if (resolved != null) {
resolved.getKey().handle(resolved.getValue(), serverRequest, null, false);
resolved.getKey().resolve(resolved.getValue(), serverRequest);
return serverRequest.getContextPath();
}
return null;
@ -167,22 +163,28 @@ public class Domain {
* @param serverResponse the server response
* @throws IOException if handling server request fails
*/
@Override
public void handle(ServerRequest serverRequest, ServerResponse serverResponse) throws IOException {
Map.Entry<HttpEndpointResolver, List<HttpEndpoint>> resolved = resolve(serverRequest);
if (resolved != null) {
resolved.getKey().handle(resolved.getValue(), serverRequest, serverResponse, true);
resolved.getKey().handle(resolved.getValue(), serverRequest, serverResponse);
} else {
ServerResponse.write(serverResponse, HttpResponseStatus.NOT_IMPLEMENTED,
"text/plain", "No endpoint match for request " + serverRequest);
ServerResponse.write(serverResponse, HttpResponseStatus.NOT_FOUND,
"text/plain", "No endpoint found to match request");
}
}
@Override
public String toString() {
return name + " (" + httpAddress + ")";
}
/**
* Just resolve a server request to a matching endpoint resolver with endpoints matched.
* @param serverRequest the server request
* @return the endpoint resolver together with the matching endpoints
*/
public Map.Entry<HttpEndpointResolver, List<HttpEndpoint>> resolve(ServerRequest serverRequest) {
private Map.Entry<HttpEndpointResolver, List<HttpEndpoint>> resolve(ServerRequest serverRequest) {
for (HttpEndpointResolver httpEndpointResolver : httpEndpointResolvers) {
List<HttpEndpoint> matchingEndpoints = httpEndpointResolver.matchingEndpointsFor(serverRequest);
if (!matchingEndpoints.isEmpty()) {
@ -192,20 +194,13 @@ public class Domain {
return null;
}
@Override
public String toString() {
return name + " (" + httpAddress + ") aliases=" + aliases;
}
public static class Builder {
private final HttpAddress httpAddress;
private String serverName;
private final Set<String> aliases;
private final List<HttpEndpointResolver> httpEndpointResolvers;
private final Collection<HttpEndpointResolver> httpEndpointResolvers;
private SslContext sslContext;
@ -228,7 +223,6 @@ public class Domain {
private Builder(HttpAddress httpAddress) {
Objects.requireNonNull(httpAddress);
this.httpAddress = httpAddress;
this.aliases = new LinkedHashSet<>();
this.httpEndpointResolvers = new ArrayList<>();
this.trustManagerFactory = SecurityUtil.Defaults.DEFAULT_TRUST_MANAGER_FACTORY;
this.sslProvider = SecurityUtil.Defaults.DEFAULT_SSL_PROVIDER;
@ -236,12 +230,12 @@ public class Domain {
this.cipherSuiteFilter = SecurityUtil.Defaults.DEFAULT_CIPHER_SUITE_FILTER;
}
private Builder(Domain domain) {
this.httpAddress = domain.httpAddress;
this.aliases = new LinkedHashSet<>();
this.httpEndpointResolvers = new ArrayList<>(domain.httpEndpointResolvers);
this.sslContext = domain.sslContext;
this.keyCertChain = domain.certificates;
@SuppressWarnings("unchecked")
private Builder(Domain<? extends EndpointResolver<?>> domain) {
this.httpAddress = domain.getHttpAddress();
this.httpEndpointResolvers = new ArrayList<>((List<HttpEndpointResolver>) domain.getHttpEndpointResolvers());
this.sslContext = domain.getSslContext();
this.keyCertChain = domain.getCertificateChain();
}
public Builder setServerName(String serverName) {
@ -338,18 +332,6 @@ public class Domain {
return this;
}
/**
* Adds an alias for this virtual server.
*
* @param alias the alias
* @return this builder
*/
public Builder addAlias(String alias) {
Objects.requireNonNull(alias);
aliases.add(alias);
return this;
}
public Builder addEndpointResolver(HttpEndpointResolver httpEndpointResolver) {
Objects.requireNonNull(httpEndpointResolver);
this.httpEndpointResolvers.add(httpEndpointResolver);
@ -399,7 +381,7 @@ public class Domain {
return this;
}
public Domain build() {
public HttpServerDomain build() {
if (httpEndpointResolvers.isEmpty()) {
throw new IllegalArgumentException("domain must have at least one endpoint resolver");
}
@ -420,14 +402,14 @@ public class Domain {
}
this.sslContext = sslContextBuilder.build();
}
return new Domain(serverName, aliases,
return new HttpServerDomain(serverName,
httpAddress, httpEndpointResolvers,
sslContext, keyCertChain);
} catch (Exception e) {
throw new RuntimeException(e);
}
} else {
return new Domain(serverName, aliases,
return new HttpServerDomain(serverName,
httpAddress, httpEndpointResolvers,
null, null);
}

View file

@ -19,10 +19,13 @@ import org.xbib.netty.http.common.HttpAddress;
import org.xbib.netty.http.common.NetworkUtils;
import org.xbib.netty.http.common.HttpChannelInitializer;
import org.xbib.netty.http.common.TransportProvider;
import org.xbib.netty.http.server.api.Domain;
import org.xbib.netty.http.server.api.EndpointResolver;
import org.xbib.netty.http.server.api.ServerProtocolProvider;
import org.xbib.netty.http.server.api.ServerRequest;
import org.xbib.netty.http.server.api.ServerResponse;
import org.xbib.netty.http.server.api.ServerTransport;
import org.xbib.netty.http.server.endpoint.HttpEndpointResolver;
import org.xbib.netty.http.server.security.CertificateUtils;
import org.xbib.netty.http.server.transport.HttpServerRequest;
import java.io.IOException;
@ -71,7 +74,7 @@ public final class Server implements AutoCloseable {
private static final AtomicLong responseCounter = new AtomicLong(0);
private final ServerConfig serverConfig;
private final DefaultServerConfig serverConfig;
private final EventLoopGroup parentEventLoopGroup;
@ -98,7 +101,7 @@ public final class Server implements AutoCloseable {
* @param socketChannelClass socket channel class
*/
@SuppressWarnings("unchecked")
private Server(ServerConfig serverConfig,
private Server(DefaultServerConfig serverConfig,
ByteBufAllocator byteBufAllocator,
EventLoopGroup parentEventLoopGroup,
EventLoopGroup childEventLoopGroup,
@ -133,7 +136,7 @@ public final class Server implements AutoCloseable {
.childOption(ChannelOption.SO_RCVBUF, serverConfig.getTcpReceiveBufferSize())
.childOption(ChannelOption.CONNECT_TIMEOUT_MILLIS, serverConfig.getConnectTimeoutMillis())
.childOption(ChannelOption.WRITE_BUFFER_WATER_MARK, serverConfig.getWriteBufferWaterMark());
if (serverConfig.isTrafficDebug()) {
if (serverConfig.isDebug()) {
bootstrap.handler(new LoggingHandler("bootstrap-server", serverConfig.getTrafficDebugLogLevel()));
}
if (serverConfig.getDefaultDomain() == null) {
@ -141,13 +144,13 @@ public final class Server implements AutoCloseable {
}
// translate domains into Netty mapping
Mapping<String, SslContext> domainNameMapping = null;
Domain defaultDomain = serverConfig.getDefaultDomain();
Domain<? extends EndpointResolver<?>> defaultDomain = serverConfig.getDefaultDomain();
if (serverConfig.getAddress().isSecure() &&
defaultDomain != null &&
defaultDomain.getSslContext() != null) {
DomainWildcardMappingBuilder<SslContext> mappingBuilder =
new DomainWildcardMappingBuilder<>(defaultDomain.getSslContext());
for (Domain domain : serverConfig.getDomains()) {
for (Domain<? extends EndpointResolver<?>> domain : serverConfig.getDomains()) {
if (!domain.getName().equals(defaultDomain.getName())) {
mappingBuilder.add(domain.getName(), domain.getSslContext());
}
@ -168,11 +171,11 @@ public final class Server implements AutoCloseable {
}
}
public static Builder builder(Domain defaultDomain) {
return new Builder(defaultDomain);
public static Builder builder(HttpServerDomain httpServerDomain) {
return new Builder(httpServerDomain);
}
public ServerConfig getServerConfig() {
public DefaultServerConfig getServerConfig() {
return serverConfig;
}
@ -199,7 +202,7 @@ public final class Server implements AutoCloseable {
* @param serverRequest the server request
* @return the domain
*/
public Domain getDomain(ServerRequest serverRequest) {
public Domain<? extends EndpointResolver<?>> getDomain(ServerRequest serverRequest) {
return getDomain(getBaseURL(serverRequest));
}
@ -208,7 +211,7 @@ public final class Server implements AutoCloseable {
* @param url the URL
* @return the domain
*/
public Domain getDomain(URL url) {
public Domain<? extends EndpointResolver<?>> getDomain(URL url) {
return getDomain(hostAndPort(url));
}
@ -219,7 +222,7 @@ public final class Server implements AutoCloseable {
* default domain
* @return the virtual host with the given name or the default domain
*/
public Domain getDomain(String name) {
public Domain<? extends EndpointResolver<?>> getDomain(String name) {
return serverConfig.getDomain(name);
}
@ -277,13 +280,16 @@ public final class Server implements AutoCloseable {
*/
public URL getContextURL(ServerRequest serverRequest) throws IOException {
URL baseURL = getBaseURL(serverRequest);
Domain domain = getDomain(baseURL);
String context = domain.findContextOf(serverRequest);
Domain<? extends EndpointResolver<?>> domain = getDomain(baseURL);
String context = domain.findContextPathOf(serverRequest);
if (!context.endsWith("/")) {
context = context + "/";
}
return baseURL.resolve(context);
}
public void handle(HttpServerRequest serverRequest, ServerResponse serverResponse) throws IOException {
Domain domain = getDomain(serverRequest);
Domain<? extends EndpointResolver<?>> domain = getDomain(serverRequest);
logger.log(Level.FINEST, () -> "found domain " + domain + " for " + serverRequest);
if (executor != null) {
executor.submit(() -> {
@ -393,7 +399,7 @@ public final class Server implements AutoCloseable {
throw new IllegalStateException("no channel initializer found for major version " + majorVersion);
}
private static EventLoopGroup createParentEventLoopGroup(ServerConfig serverConfig,
private static EventLoopGroup createParentEventLoopGroup(DefaultServerConfig serverConfig,
EventLoopGroup parentEventLoopGroup ) {
EventLoopGroup eventLoopGroup = parentEventLoopGroup;
if (eventLoopGroup == null) {
@ -411,7 +417,7 @@ public final class Server implements AutoCloseable {
return eventLoopGroup;
}
private static EventLoopGroup createChildEventLoopGroup(ServerConfig serverConfig,
private static EventLoopGroup createChildEventLoopGroup(DefaultServerConfig serverConfig,
EventLoopGroup childEventLoopGroup ) {
EventLoopGroup eventLoopGroup = childEventLoopGroup;
if (eventLoopGroup == null) {
@ -429,7 +435,7 @@ public final class Server implements AutoCloseable {
return eventLoopGroup;
}
private static Class<? extends ServerSocketChannel> createSocketChannelClass(ServerConfig serverConfig,
private static Class<? extends ServerSocketChannel> createSocketChannelClass(DefaultServerConfig serverConfig,
Class<? extends ServerSocketChannel> socketChannelClass) {
Class<? extends ServerSocketChannel> channelClass = socketChannelClass;
if (channelClass == null) {
@ -536,16 +542,21 @@ public final class Server implements AutoCloseable {
private Class<? extends ServerSocketChannel> socketChannelClass;
private final ServerConfig serverConfig;
private final DefaultServerConfig serverConfig;
private Builder(Domain defaultDomain) {
this.serverConfig = new ServerConfig();
this.serverConfig.setAddress(defaultDomain.getHttpAddress());
addDomain(defaultDomain);
private Builder(HttpServerDomain httpServerDomain) {
this.serverConfig = new DefaultServerConfig();
this.serverConfig.setAddress(httpServerDomain.getHttpAddress());
addDomain(httpServerDomain);
}
public Builder enableDebug() {
this.serverConfig.enableDebug();
this.serverConfig.setDebug(true);
return this;
}
public Builder setDebug(boolean debug) {
this.serverConfig.setDebug(debug);
return this;
}
@ -684,8 +695,8 @@ public final class Server implements AutoCloseable {
return this;
}
public Builder addDomain(Domain domain) {
this.serverConfig.checkAndAddDomain(domain);
public Builder addDomain(Domain<HttpEndpointResolver> domain) {
this.serverConfig.addDomain(domain);
return this;
}
@ -700,7 +711,7 @@ public final class Server implements AutoCloseable {
}
if (serverConfig.isAutoDomain()) {
// unpack subject alternative names into separate domains
for (Domain domain : serverConfig.getDomains()) {
for (Domain<? extends EndpointResolver<?>> domain : serverConfig.getDomains()) {
try {
CertificateUtils.processSubjectAlternativeNames(domain.getCertificateChain(),
new CertificateUtils.SubjectAlternativeNamesProcessor() {
@ -710,7 +721,7 @@ public final class Server implements AutoCloseable {
@Override
public void setSubjectAlternativeName(String subjectAlternativeName) {
Domain alternativeDomain = Domain.builder(domain)
HttpServerDomain alternativeDomain = HttpServerDomain.builder(domain)
.setServerName(subjectAlternativeName)
.build();
addDomain(alternativeDomain);
@ -721,7 +732,7 @@ public final class Server implements AutoCloseable {
}
}
}
for (Domain domain : serverConfig.getDomains()) {
for (Domain<? extends EndpointResolver<?>> domain : serverConfig.getDomains()) {
if (domain.getCertificateChain() != null) {
for (X509Certificate certificate : domain.getCertificateChain()) {
try {

View file

@ -9,7 +9,6 @@ import org.xbib.netty.http.server.api.Endpoint;
import org.xbib.netty.http.server.api.ServerRequest;
import org.xbib.netty.http.server.api.ServerResponse;
import org.xbib.netty.http.server.api.Filter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Comparator;

View file

@ -2,6 +2,7 @@ package org.xbib.netty.http.server.endpoint;
import org.xbib.netty.http.common.util.LimitedConcurrentHashMap;
import org.xbib.netty.http.server.api.EndpointDispatcher;
import org.xbib.netty.http.server.api.EndpointResolver;
import org.xbib.netty.http.server.api.ServerRequest;
import org.xbib.netty.http.server.api.ServerResponse;
import org.xbib.netty.http.server.api.annotation.Endpoint;
@ -16,7 +17,7 @@ import java.util.Map;
import java.util.Objects;
import java.util.stream.Collectors;
public class HttpEndpointResolver {
public class HttpEndpointResolver implements EndpointResolver<HttpEndpoint> {
private static final int DEFAULT_LIMIT = 1024;
@ -40,6 +41,7 @@ public class HttpEndpointResolver {
* @param serverRequest the server request
* @return a
*/
@Override
public List<HttpEndpoint> matchingEndpointsFor(ServerRequest serverRequest) {
HttpEndpointDescriptor httpEndpointDescriptor = new HttpEndpointDescriptor(serverRequest);
endpointDescriptors.putIfAbsent(httpEndpointDescriptor, endpoints.stream()
@ -49,23 +51,30 @@ public class HttpEndpointResolver {
return endpointDescriptors.get(httpEndpointDescriptor);
}
@Override
public void resolve(List<HttpEndpoint> matchingEndpoints,
ServerRequest serverRequest) throws IOException {
Objects.requireNonNull(matchingEndpoints);
for (HttpEndpoint endpoint : matchingEndpoints) {
endpoint.resolveUriTemplate(serverRequest);
endpoint.before(serverRequest, null);
break;
}
}
@Override
public void handle(List<HttpEndpoint> matchingEndpoints,
ServerRequest serverRequest,
ServerResponse serverResponse,
boolean dispatch) throws IOException {
ServerResponse serverResponse) throws IOException {
Objects.requireNonNull(matchingEndpoints);
for (HttpEndpoint endpoint : matchingEndpoints) {
endpoint.resolveUriTemplate(serverRequest);
endpoint.before(serverRequest, serverResponse);
if (dispatch) {
endpointDispatcher.dispatch(endpoint, serverRequest, serverResponse);
endpoint.after(serverRequest, serverResponse);
if (serverResponse != null && serverResponse.getStatus() != null) {
break;
}
} else {
break;
}
}
}

View file

@ -1,6 +1,7 @@
package org.xbib.netty.http.server.endpoint.service;
import org.xbib.netty.http.server.api.Filter;
import org.xbib.netty.http.server.api.FilterConfig;
import org.xbib.netty.http.server.api.ServerRequest;
import org.xbib.netty.http.server.api.ServerResponse;
@ -30,6 +31,9 @@ public class MethodService implements Filter {
}
}
public void initialize(FilterConfig filterConfig) {
}
@Override
public void handle(ServerRequest serverRequest, ServerResponse serverResponse) throws IOException {
try {

View file

@ -8,6 +8,7 @@ import io.netty.handler.codec.http.HttpResponseStatus;
import io.netty.handler.stream.ChunkedNioStream;
import org.xbib.netty.http.common.util.DateTimeUtil;
import org.xbib.netty.http.server.api.Filter;
import org.xbib.netty.http.server.api.FilterConfig;
import org.xbib.netty.http.server.api.Resource;
import org.xbib.netty.http.server.api.ServerRequest;
import org.xbib.netty.http.server.api.ServerResponse;
@ -39,6 +40,9 @@ public abstract class ResourceService implements Filter {
private static final Logger logger = Logger.getLogger(ResourceService.class.getName());
public void initialize(FilterConfig filterConfig) {
}
@Override
public void handle(ServerRequest serverRequest, ServerResponse serverResponse) throws IOException {
handleCachedResource(serverRequest, serverResponse, createResource(serverRequest, serverResponse));

View file

@ -6,7 +6,7 @@ import io.netty.handler.ssl.SslContext;
import io.netty.handler.ssl.SslHandler;
import io.netty.util.Mapping;
import org.xbib.netty.http.common.HttpAddress;
import org.xbib.netty.http.server.ServerConfig;
import org.xbib.netty.http.server.DefaultServerConfig;
import java.net.InetSocketAddress;
import java.util.Arrays;
import java.util.logging.Level;
@ -18,12 +18,12 @@ public class ExtendedSNIHandler extends SniHandler {
private static final Logger logger = Logger.getLogger(ExtendedSNIHandler.class.getName());
private final ServerConfig serverConfig;
private final DefaultServerConfig serverConfig;
private final HttpAddress httpAddress;
public ExtendedSNIHandler(Mapping<? super String, ? extends SslContext> mapping,
ServerConfig serverConfig, HttpAddress httpAddress) {
DefaultServerConfig serverConfig, HttpAddress httpAddress) {
super(mapping);
this.serverConfig = serverConfig;
this.httpAddress = httpAddress;
@ -35,7 +35,7 @@ public class ExtendedSNIHandler extends SniHandler {
}
private static SslHandler newSslHandler(SslContext sslContext,
ServerConfig serverConfig,
DefaultServerConfig serverConfig,
ByteBufAllocator allocator,
HttpAddress httpAddress) {
InetSocketAddress peer = httpAddress.getInetSocketAddress();

View file

@ -18,10 +18,11 @@ import io.netty.handler.codec.http.HttpVersion;
import io.netty.handler.logging.LogLevel;
import io.netty.handler.ssl.SslContext;
import io.netty.handler.stream.ChunkedWriteHandler;
import io.netty.handler.timeout.ReadTimeoutHandler;
import io.netty.util.Mapping;
import org.xbib.netty.http.common.HttpAddress;
import org.xbib.netty.http.server.Server;
import org.xbib.netty.http.server.ServerConfig;
import org.xbib.netty.http.server.DefaultServerConfig;
import org.xbib.netty.http.common.HttpChannelInitializer;
import org.xbib.netty.http.server.handler.ExtendedSNIHandler;
import org.xbib.netty.http.server.handler.IdleTimeoutHandler;
@ -39,7 +40,7 @@ public class Http1ChannelInitializer extends ChannelInitializer<Channel>
private final Server server;
private final ServerConfig serverConfig;
private final DefaultServerConfig serverConfig;
private final HttpAddress httpAddress;
@ -58,7 +59,7 @@ public class Http1ChannelInitializer extends ChannelInitializer<Channel>
public void initChannel(Channel channel) {
ServerTransport transport = server.newTransport(httpAddress.getVersion());
channel.attr(ServerTransport.TRANSPORT_ATTRIBUTE_KEY).set(transport);
if (serverConfig.isTrafficDebug()) {
if (serverConfig.isDebug()) {
channel.pipeline().addLast(new TrafficLoggingHandler(LogLevel.DEBUG));
}
if (httpAddress.isSecure()) {
@ -66,7 +67,7 @@ public class Http1ChannelInitializer extends ChannelInitializer<Channel>
} else {
configureCleartext(channel);
}
if (serverConfig.isTrafficDebug()) {
if (serverConfig.isDebug()) {
logger.log(Level.FINE, "HTTP 1.1 server channel initialized: " +
" address=" + httpAddress + " pipeline=" + channel.pipeline().names());
}
@ -80,7 +81,10 @@ public class Http1ChannelInitializer extends ChannelInitializer<Channel>
private void configureCleartext(Channel channel) {
ChannelPipeline pipeline = channel.pipeline();
pipeline.addLast("http-server-chunked-write", new ChunkedWriteHandler());
pipeline.addLast("http-server-read-timeout",
new ReadTimeoutHandler(serverConfig.getReadTimeoutMillis()));
pipeline.addLast("http-server-chunked-write",
new ChunkedWriteHandler());
pipeline.addLast("http-server-codec",
new HttpServerCodec(serverConfig.getMaxInitialLineLength(),
serverConfig.getMaxHeadersSize(), serverConfig.getMaxChunkSize()));

View file

@ -29,11 +29,12 @@ import io.netty.handler.codec.http2.Http2StreamFrameToHttpObjectCodec;
import io.netty.handler.logging.LogLevel;
import io.netty.handler.ssl.SslContext;
import io.netty.handler.stream.ChunkedWriteHandler;
import io.netty.handler.timeout.ReadTimeoutHandler;
import io.netty.util.AsciiString;
import io.netty.util.Mapping;
import org.xbib.netty.http.common.HttpAddress;
import org.xbib.netty.http.server.Server;
import org.xbib.netty.http.server.ServerConfig;
import org.xbib.netty.http.server.DefaultServerConfig;
import org.xbib.netty.http.common.HttpChannelInitializer;
import org.xbib.netty.http.server.handler.ExtendedSNIHandler;
import org.xbib.netty.http.server.handler.IdleTimeoutHandler;
@ -51,7 +52,7 @@ public class Http2ChannelInitializer extends ChannelInitializer<Channel>
private final Server server;
private final ServerConfig serverConfig;
private final DefaultServerConfig serverConfig;
private final HttpAddress httpAddress;
@ -70,7 +71,7 @@ public class Http2ChannelInitializer extends ChannelInitializer<Channel>
public void initChannel(Channel channel) {
ServerTransport transport = server.newTransport(httpAddress.getVersion());
channel.attr(ServerTransport.TRANSPORT_ATTRIBUTE_KEY).set(transport);
if (serverConfig.isTrafficDebug()) {
if (serverConfig.isDebug()) {
channel.pipeline().addLast(new TrafficLoggingHandler(LogLevel.DEBUG));
}
if (httpAddress.isSecure()) {
@ -78,7 +79,7 @@ public class Http2ChannelInitializer extends ChannelInitializer<Channel>
} else {
configureCleartext(channel);
}
if (serverConfig.isTrafficDebug()) {
if (serverConfig.isDebug()) {
logger.log(Level.FINE, "HTTP/2 server channel initialized: " +
" address=" + httpAddress + " pipeline=" + channel.pipeline().names());
}
@ -97,6 +98,8 @@ public class Http2ChannelInitializer extends ChannelInitializer<Channel>
ServerTransport transport = server.newTransport(httpAddress.getVersion());
channel.attr(ServerTransport.TRANSPORT_ATTRIBUTE_KEY).set(transport);
ChannelPipeline pipeline = channel.pipeline();
pipeline.addLast("server-read-timeout",
new ReadTimeoutHandler(serverConfig.getReadTimeoutMillis()));
pipeline.addLast("server-frame-converter",
new Http2StreamFrameToHttpObjectCodec(true));
if (serverConfig.isCompressionEnabled()) {
@ -114,7 +117,7 @@ public class Http2ChannelInitializer extends ChannelInitializer<Channel>
};
Http2MultiplexCodecBuilder multiplexCodecBuilder = Http2MultiplexCodecBuilder.forServer(channelHandler)
.initialSettings(Http2Settings.defaultSettings());
if (serverConfig.isTrafficDebug()) {
if (serverConfig.isDebug()) {
multiplexCodecBuilder.frameLogger(new Http2FrameLogger(LogLevel.DEBUG, "server"));
}
Http2MultiplexCodec multiplexCodec = multiplexCodecBuilder.build();
@ -159,7 +162,6 @@ public class Http2ChannelInitializer extends ChannelInitializer<Channel>
@Override
public void userEventTriggered(ChannelHandlerContext ctx, Object evt) {
ServerTransport transport = ctx.channel().attr(ServerTransport.TRANSPORT_ATTRIBUTE_KEY).get();
ctx.fireUserEventTriggered(evt);
}

View file

@ -6,7 +6,7 @@ import io.netty.handler.codec.http.HttpHeaders;
import io.netty.handler.codec.http.HttpResponseStatus;
import io.netty.handler.codec.http.HttpVersion;
import org.xbib.netty.http.server.Server;
import org.xbib.netty.http.server.ServerConfig;
import org.xbib.netty.http.server.DefaultServerConfig;
import org.xbib.netty.http.server.api.ServerRequest;
import org.xbib.netty.http.server.api.ServerResponse;
import org.xbib.netty.http.server.api.ServerTransport;
@ -39,7 +39,7 @@ abstract class BaseTransport implements ServerTransport {
* @param serverResponse the response
* @return whether further processing should be performed
*/
static boolean acceptRequest(ServerConfig serverConfig,
static boolean acceptRequest(DefaultServerConfig serverConfig,
ServerRequest serverRequest,
ServerResponse serverResponse) {
HttpVersion version = serverConfig.getAddress().getVersion();

View file

@ -5,6 +5,7 @@ import io.netty.handler.codec.http.FullHttpRequest;
import io.netty.handler.codec.http.HttpResponseStatus;
import io.netty.handler.codec.http2.Http2Settings;
import io.netty.handler.codec.http2.HttpConversionUtil;
import io.netty.handler.ssl.SslHandler;
import org.xbib.netty.http.server.Server;
import org.xbib.netty.http.server.api.ServerResponse;
@ -29,6 +30,10 @@ public class Http2Transport extends BaseTransport {
serverRequest.setSequenceId(sequenceId);
serverRequest.setRequestId(server.getRequestCounter().incrementAndGet());
serverRequest.setStreamId(fullHttpRequest.headers().getInt(HttpConversionUtil.ExtensionHeaderNames.STREAM_ID.text()));
SslHandler sslHandler = ctx.channel().pipeline().get(SslHandler.class);
if (sslHandler != null) {
serverRequest.setSession(sslHandler.engine().getSession());
}
ServerResponse serverResponse = new Http2ServerResponse(server, serverRequest, ctx);
if (acceptRequest(server.getServerConfig(), serverRequest, serverResponse)) {
serverRequest.handleParameters();

View file

@ -6,7 +6,7 @@ import org.junit.jupiter.api.Test;
import org.xbib.netty.http.common.HttpAddress;
import org.xbib.netty.http.server.Server;
import org.xbib.netty.http.server.api.ServerResponse;
import org.xbib.netty.http.server.Domain;
import org.xbib.netty.http.server.HttpServerDomain;
import java.io.IOException;
import java.net.BindException;
@ -18,7 +18,7 @@ class BindExceptionTest {
@Test
void testDoubleServer() throws IOException {
Domain domain = Domain.builder(HttpAddress.http1("localhost", 8008))
HttpServerDomain domain = HttpServerDomain.builder(HttpAddress.http1("localhost", 8008))
.singleEndpoint("/", (request, response) -> ServerResponse.write(response, "Hello World"))
.build();
Server server1 = Server.builder(domain).build();

View file

@ -8,7 +8,7 @@ import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.xbib.net.URL;
import org.xbib.netty.http.common.HttpAddress;
import org.xbib.netty.http.server.Domain;
import org.xbib.netty.http.server.HttpServerDomain;
import org.xbib.netty.http.server.Server;
import org.xbib.netty.http.server.api.ServerRequest;
import org.xbib.netty.http.server.endpoint.HttpEndpoint;
@ -35,10 +35,10 @@ public class ContextURLTest {
.setDispatcher((endpoint, serverRequest, serverResponse) -> {})
.build();
Domain one = Domain.builder(httpAddress, "domain.one:8008")
HttpServerDomain one = HttpServerDomain.builder(httpAddress, "domain.one:8008")
.addEndpointResolver(endpointResolver1)
.build();
Domain two = Domain.builder(one)
HttpServerDomain two = HttpServerDomain.builder(one)
.setServerName("domain.two:8008")
.addEndpointResolver(endpointResolver2)
.addEndpointResolver(endpointResolver3)
@ -49,27 +49,27 @@ public class ContextURLTest {
.build();
URL url0 = server.getContextURL();
assertEquals("http://localhost:8008", url0.toString());
assertEquals("http://localhost:8008/", url0.toString());
DefaultFullHttpRequest fullHttpRequest1 = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, "/one");
fullHttpRequest1.headers().add("host", "domain.one:8008");
ServerRequest serverRequest1 = new HttpServerRequest(fullHttpRequest1);
URL url1 = server.getContextURL(serverRequest1);
assertEquals("domain.one", url1.getHost());
assertEquals("/one", url1.getPath());
assertEquals("/one/", url1.getPath());
DefaultFullHttpRequest fullHttpRequest2 = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, "/two");
fullHttpRequest2.headers().add("host", "domain.two:8008");
ServerRequest serverRequest2 = new HttpServerRequest(fullHttpRequest2);
URL url2 = server.getContextURL(serverRequest2);
assertEquals("domain.two", url2.getHost());
assertEquals("/two", url2.getPath());
assertEquals("/two/", url2.getPath());
DefaultFullHttpRequest fullHttpRequest3 = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, "/three");
fullHttpRequest3.headers().add("host", "domain.two:8008");
ServerRequest serverRequest3 = new HttpServerRequest(fullHttpRequest3);
URL url3 = server.getContextURL(serverRequest3);
assertEquals("domain.two", url3.getHost());
assertEquals("/three", url3.getPath());
assertEquals("/three/", url3.getPath());
}
}

View file

@ -7,7 +7,7 @@ import org.junit.jupiter.api.extension.ExtendWith;
import org.xbib.netty.http.client.Client;
import org.xbib.netty.http.client.api.Request;
import org.xbib.netty.http.common.HttpAddress;
import org.xbib.netty.http.server.Domain;
import org.xbib.netty.http.server.HttpServerDomain;
import org.xbib.netty.http.server.Server;
import org.xbib.netty.http.server.api.ServerResponse;
import java.io.InputStream;
@ -32,12 +32,12 @@ class MultiDomainSecureServerTest {
return;
}
HttpAddress httpAddress = HttpAddress.secureHttp2("localhost", 8443);
Domain fl = Domain.builder(httpAddress, "fl.hbz-nrw.de")
HttpServerDomain fl = HttpServerDomain.builder(httpAddress, "fl.hbz-nrw.de")
.setKeyCertChain(certInputStream)
.setKey(keyInputStream, null)
.singleEndpoint("/", (request, response) -> ServerResponse.write(response, "Hello fl.hbz-nrw.de"))
.build();
Domain zfl2 = Domain.builder(fl)
HttpServerDomain zfl2 = HttpServerDomain.builder(fl)
.setServerName("zfl2.hbz-nrw.de")
.singleEndpoint("/", (request, response) -> ServerResponse.write(response, "Hello zfl2.hbz-nrw.de"))
.build();

View file

@ -9,7 +9,7 @@ import org.xbib.netty.http.client.api.Request;
import org.xbib.netty.http.common.HttpAddress;
import org.xbib.netty.http.server.Server;
import org.xbib.netty.http.server.api.ServerResponse;
import org.xbib.netty.http.server.Domain;
import org.xbib.netty.http.server.HttpServerDomain;
import java.nio.charset.StandardCharsets;
import java.util.logging.Level;
import java.util.logging.Logger;
@ -23,10 +23,10 @@ class MultiDomainServerTest {
@Test
void testServer() throws Exception {
HttpAddress httpAddress = HttpAddress.http1("localhost", 8008);
Domain fl = Domain.builder(httpAddress, "fl.hbz-nrw.de")
HttpServerDomain fl = HttpServerDomain.builder(httpAddress, "fl.hbz-nrw.de")
.singleEndpoint("/", (request, response) -> ServerResponse.write(response, "Hello fl.hbz-nrw.de"))
.build();
Domain zfl2 = Domain.builder(fl)
HttpServerDomain zfl2 = HttpServerDomain.builder(fl)
.setServerName("zfl2.hbz-nrw.de")
.singleEndpoint("/", (request, response) -> ServerResponse.write(response, "Hello zfl2.hbz-nrw.de"))
.build();

View file

@ -8,7 +8,7 @@ import org.junit.jupiter.api.extension.ExtendWith;
import org.xbib.netty.http.common.HttpAddress;
import org.xbib.netty.http.server.Server;
import org.xbib.netty.http.server.api.ServerResponse;
import org.xbib.netty.http.server.Domain;
import org.xbib.netty.http.server.HttpServerDomain;
import java.io.IOException;
import java.util.Set;
@ -23,7 +23,7 @@ class ThreadLeakTest {
@Test
void testForLeaks() throws IOException {
Domain domain = Domain.builder(HttpAddress.http1("localhost", 8008))
HttpServerDomain domain = HttpServerDomain.builder(HttpAddress.http1("localhost", 8008))
.singleEndpoint("/", (request, response) -> ServerResponse.write(response, "Hello World"))
.build();
Server server = Server.builder(domain)

View file

@ -11,7 +11,7 @@ import org.xbib.netty.http.client.api.ResponseListener;
import org.xbib.netty.http.client.api.ClientTransport;
import org.xbib.netty.http.common.HttpAddress;
import org.xbib.netty.http.common.HttpResponse;
import org.xbib.netty.http.server.Domain;
import org.xbib.netty.http.server.HttpServerDomain;
import org.xbib.netty.http.server.Server;
import java.nio.charset.StandardCharsets;
import java.util.concurrent.atomic.AtomicInteger;
@ -26,7 +26,7 @@ class TransportLayerSecurityServerTest {
@Test
void testTLS12() throws Exception {
HttpAddress httpAddress = HttpAddress.secureHttp1("localhost", 8143);
Server server = Server.builder(Domain.builder(httpAddress)
Server server = Server.builder(HttpServerDomain.builder(httpAddress)
.setSelfCert()
.singleEndpoint("/", (request, response) ->
response.withStatus(HttpResponseStatus.OK)
@ -64,7 +64,7 @@ class TransportLayerSecurityServerTest {
@Test
void testTLS13() throws Exception {
HttpAddress httpAddress = HttpAddress.secureHttp2("localhost", 8143);
Server server = Server.builder(Domain.builder(httpAddress)
Server server = Server.builder(HttpServerDomain.builder(httpAddress)
.setSelfCert()
.singleEndpoint("/", (request, response) ->
response.withStatus(HttpResponseStatus.OK)

View file

@ -8,7 +8,7 @@ import org.xbib.netty.http.client.Client;
import org.xbib.netty.http.client.api.Request;
import org.xbib.netty.http.common.HttpAddress;
import org.xbib.netty.http.server.Server;
import org.xbib.netty.http.server.Domain;
import org.xbib.netty.http.server.HttpServerDomain;
import org.xbib.netty.http.server.endpoint.service.ClassLoaderService;
import org.xbib.netty.http.server.test.NettyHttpTestExtension;
@ -27,7 +27,7 @@ class ClassloaderServiceTest {
@Test
void testClassloaderFileResource() throws Exception {
HttpAddress httpAddress = HttpAddress.http1("localhost", 8008);
Domain domain = Domain.builder(httpAddress)
HttpServerDomain domain = HttpServerDomain.builder(httpAddress)
.singleEndpoint("/classloader", "/**",
new ClassLoaderService(ClassloaderServiceTest.class, "/cl"))
.build();
@ -65,7 +65,7 @@ class ClassloaderServiceTest {
@Test
void testClassloaderDirectoryResource() throws Exception {
HttpAddress httpAddress = HttpAddress.http1("localhost", 8008);
Domain domain = Domain.builder(httpAddress)
HttpServerDomain domain = HttpServerDomain.builder(httpAddress)
.singleEndpoint("/classloader", "/**",
new ClassLoaderService(ClassloaderServiceTest.class, "/cl"))
.build();

View file

@ -11,7 +11,7 @@ import org.xbib.netty.http.server.Server;
import org.xbib.netty.http.server.api.ServerResponse;
import org.xbib.netty.http.server.endpoint.HttpEndpoint;
import org.xbib.netty.http.server.endpoint.HttpEndpointResolver;
import org.xbib.netty.http.server.Domain;
import org.xbib.netty.http.server.HttpServerDomain;
import org.xbib.netty.http.server.endpoint.service.FileService;
import org.xbib.netty.http.server.test.NettyHttpTestExtension;
@ -46,7 +46,7 @@ class EndpointTest {
fileService.handle(req, resp);
})
.build();
Domain domain = Domain.builder(httpAddress)
HttpServerDomain domain = HttpServerDomain.builder(httpAddress)
.addEndpointResolver(httpEndpointResolver)
.build();
Server server = Server.builder(domain)
@ -87,7 +87,7 @@ class EndpointTest {
fileService.handle(req, resp);
})
.build();
Domain domain = Domain.builder(httpAddress)
HttpServerDomain domain = HttpServerDomain.builder(httpAddress)
.addEndpointResolver(httpEndpointResolver)
.build();
Server server = Server.builder(domain)
@ -130,7 +130,7 @@ class EndpointTest {
fileService.handle(req, resp);
})
.build();
Domain domain = Domain.builder(httpAddress)
HttpServerDomain domain = HttpServerDomain.builder(httpAddress)
.addEndpointResolver(httpEndpointResolver)
.build();
Server server = Server.builder(domain)
@ -196,7 +196,7 @@ class EndpointTest {
fileService.handle(req, resp);
})
.build();
Domain domain = Domain.builder(httpAddress)
HttpServerDomain domain = HttpServerDomain.builder(httpAddress)
.addEndpointResolver(httpEndpointResolver)
.build();
Server server = Server.builder(domain)
@ -293,7 +293,7 @@ class EndpointTest {
fileService3.handle(req, resp);
})
.build();
Domain domain = Domain.builder(httpAddress)
HttpServerDomain domain = HttpServerDomain.builder(httpAddress)
.addEndpointResolver(httpEndpointResolver1)
.addEndpointResolver(httpEndpointResolver2)
.addEndpointResolver(httpEndpointResolver3)
@ -376,7 +376,7 @@ class EndpointTest {
.setPath("/" + i + "/**")
.build());
}
Domain domain = Domain.builder(httpAddress)
HttpServerDomain domain = HttpServerDomain.builder(httpAddress)
.addEndpointResolver(endpointResolverBuilder
.setDispatcher((endpoint,req, resp) -> ServerResponse.write(resp, HttpResponseStatus.OK))
.build())
@ -415,7 +415,7 @@ class EndpointTest {
HttpAddress httpAddress = HttpAddress.http1("localhost", 8008);
HttpEndpointResolver.Builder endpointResolverBuilder = HttpEndpointResolver.builder()
.setPrefix("/static");
Domain.Builder domainBuilder = Domain.builder(httpAddress);
HttpServerDomain.Builder domainBuilder = HttpServerDomain.builder(httpAddress);
for (int i = 0; i < max; i++) {
domainBuilder.addEndpointResolver(endpointResolverBuilder.addEndpoint(HttpEndpoint.builder()
.setPath("/" + i + "/**").build())

View file

@ -8,7 +8,7 @@ import org.xbib.netty.http.client.Client;
import org.xbib.netty.http.client.api.Request;
import org.xbib.netty.http.common.HttpAddress;
import org.xbib.netty.http.server.Server;
import org.xbib.netty.http.server.Domain;
import org.xbib.netty.http.server.HttpServerDomain;
import org.xbib.netty.http.server.endpoint.service.FileService;
import org.xbib.netty.http.server.test.NettyHttpTestExtension;
@ -32,7 +32,7 @@ class FileServiceTest {
void testFileServiceHttp1() throws Exception {
Path vartmp = Paths.get("/var/tmp/");
HttpAddress httpAddress = HttpAddress.http1("localhost", 8008);
Domain domain = Domain.builder(httpAddress)
HttpServerDomain domain = HttpServerDomain.builder(httpAddress)
.singleEndpoint("/static", "/**", new FileService(vartmp))
.build();
Server server = Server.builder(domain)
@ -65,7 +65,7 @@ class FileServiceTest {
void testFileServiceHttp2() throws Exception {
Path vartmp = Paths.get("/var/tmp/");
HttpAddress httpAddress = HttpAddress.http2("localhost", 8008);
Domain domain = Domain.builder(httpAddress)
HttpServerDomain domain = HttpServerDomain.builder(httpAddress)
.singleEndpoint("/static", "/**", new FileService(vartmp))
.build();
Server server = Server.builder(domain)
@ -101,7 +101,7 @@ class FileServiceTest {
Files.createDirectories(vartmpforward);
Files.write(vartmpforward.resolve("test.txt"), "Hello Jörg".getBytes(StandardCharsets.UTF_8));
HttpAddress httpAddress = HttpAddress.http1("localhost", 8008);
Domain domain = Domain.builder(httpAddress)
HttpServerDomain domain = HttpServerDomain.builder(httpAddress)
.singleEndpoint("/static", "/**", new FileService(vartmp, "test.txt"))
.build();
Server server = Server.builder(domain)
@ -138,7 +138,7 @@ class FileServiceTest {
Files.createDirectories(vartmpforward);
Files.write(vartmpforward.resolve("test.txt"), "Hello Jörg".getBytes(StandardCharsets.UTF_8));
HttpAddress httpAddress = HttpAddress.http2("localhost", 8008);
Domain domain = Domain.builder(httpAddress)
HttpServerDomain domain = HttpServerDomain.builder(httpAddress)
.singleEndpoint("/static", "/**", new FileService(vartmp, "test.txt"))
.build();
Server server = Server.builder(domain)
@ -178,7 +178,7 @@ class FileServiceTest {
Files.createDirectories(vartmpforward);
Files.write(vartmpforward.resolve("test.txt"), "Hello Jörg".getBytes(StandardCharsets.UTF_8));
HttpAddress httpAddress = HttpAddress.http1("localhost", 8008);
Domain domain = Domain.builder(httpAddress)
HttpServerDomain domain = HttpServerDomain.builder(httpAddress)
.singleEndpoint("/static", "/**",
new FileService(vartmp, "test.txt"))
.build();

View file

@ -8,7 +8,7 @@ import org.xbib.netty.http.client.Client;
import org.xbib.netty.http.client.api.Request;
import org.xbib.netty.http.common.HttpAddress;
import org.xbib.netty.http.server.Server;
import org.xbib.netty.http.server.Domain;
import org.xbib.netty.http.server.HttpServerDomain;
import org.xbib.netty.http.server.endpoint.service.FileService;
import org.xbib.netty.http.server.test.NettyHttpTestExtension;
@ -32,7 +32,7 @@ class SecureFileServiceTest {
void testSecureFileServerHttp1() throws Exception {
Path vartmp = Paths.get("/var/tmp/");
HttpAddress httpAddress = HttpAddress.secureHttp1("localhost", 8143);
Server server = Server.builder(Domain.builder(httpAddress, "*")
Server server = Server.builder(HttpServerDomain.builder(httpAddress, "*")
.setJdkSslProvider()
.setSelfCert()
.singleEndpoint("/static", "/**", new FileService(vartmp))
@ -68,7 +68,7 @@ class SecureFileServiceTest {
void testSecureFileServerHttp2() throws Exception {
Path vartmp = Paths.get("/var/tmp/");
HttpAddress httpAddress = HttpAddress.secureHttp2("localhost", 8143);
Server server = Server.builder(Domain.builder(httpAddress, "*")
Server server = Server.builder(HttpServerDomain.builder(httpAddress, "*")
.setOpenSSLSslProvider()
//.setJdkSslProvider()
.setSelfCert()
@ -112,7 +112,7 @@ class SecureFileServiceTest {
void testSecureFileServerMixHttp1Http2() throws Exception {
Path vartmp = Paths.get("/var/tmp/");
HttpAddress httpAddress = HttpAddress.secureHttp2("localhost", 8143);
Server server = Server.builder(Domain.builder(httpAddress, "*")
Server server = Server.builder(HttpServerDomain.builder(httpAddress, "*")
.setOpenSSLSslProvider()
.setSelfCert()
.singleEndpoint("/static", "/**", new FileService(vartmp))

View file

@ -11,7 +11,7 @@ import org.xbib.netty.http.client.api.ClientTransport;
import org.xbib.netty.http.common.HttpAddress;
import org.xbib.netty.http.common.HttpResponse;
import org.xbib.netty.http.server.Server;
import org.xbib.netty.http.server.Domain;
import org.xbib.netty.http.server.HttpServerDomain;
import org.xbib.netty.http.server.api.ServerResponse;
import org.xbib.netty.http.server.test.NettyHttpTestExtension;
@ -33,7 +33,7 @@ class CleartextTest {
@Test
void testSimpleClearTextHttp1() throws Exception {
HttpAddress httpAddress = HttpAddress.http1("localhost", 8008);
Domain domain = Domain.builder(httpAddress)
HttpServerDomain domain = HttpServerDomain.builder(httpAddress)
.singleEndpoint("/**", (request, response) ->
ServerResponse.write(response, HttpResponseStatus.OK, "text/plain",
request.getContent().toString(StandardCharsets.UTF_8)))
@ -67,7 +67,7 @@ class CleartextTest {
void testPooledClearTextHttp1() throws Exception {
int loop = 1;
HttpAddress httpAddress = HttpAddress.http1("localhost", 8008);
Domain domain = Domain.builder(httpAddress)
HttpServerDomain domain = HttpServerDomain.builder(httpAddress)
.singleEndpoint("/**", (request, response) ->
ServerResponse.write(response, HttpResponseStatus.OK, "text/plain",
request.getContent().toString(StandardCharsets.UTF_8)))
@ -112,7 +112,7 @@ class CleartextTest {
int threads = 4;
int loop = 1024;
HttpAddress httpAddress = HttpAddress.http1("localhost", 8008);
Domain domain = Domain.builder(httpAddress)
HttpServerDomain domain = HttpServerDomain.builder(httpAddress)
.singleEndpoint("/**", (request, response) ->
ServerResponse.write(response, HttpResponseStatus.OK, "text/plain",
request.getContent().toString(StandardCharsets.UTF_8)))

View file

@ -11,7 +11,7 @@ import org.xbib.netty.http.client.api.ClientTransport;
import org.xbib.netty.http.common.HttpAddress;
import org.xbib.netty.http.common.HttpResponse;
import org.xbib.netty.http.server.Server;
import org.xbib.netty.http.server.Domain;
import org.xbib.netty.http.server.HttpServerDomain;
import org.xbib.netty.http.server.test.NettyHttpTestExtension;
import java.io.IOException;
@ -32,7 +32,7 @@ class EncryptedTest {
@Test
void testSimpleSecureHttp1() throws Exception {
HttpAddress httpAddress = HttpAddress.secureHttp1("localhost", 8143);
Server server = Server.builder(Domain.builder(httpAddress)
Server server = Server.builder(HttpServerDomain.builder(httpAddress)
.setSelfCert()
.singleEndpoint("/", (request, response) ->
response.withStatus(HttpResponseStatus.OK)
@ -63,7 +63,7 @@ class EncryptedTest {
void testPooledSecureHttp1() throws Exception {
int loop = 4096;
HttpAddress httpAddress = HttpAddress.secureHttp1("localhost", 8143);
Server server = Server.builder(Domain.builder(httpAddress)
Server server = Server.builder(HttpServerDomain.builder(httpAddress)
.setSelfCert()
.singleEndpoint("/", (request, response) ->
response.withStatus(HttpResponseStatus.OK)
@ -107,7 +107,7 @@ class EncryptedTest {
int threads = 4;
int loop = 4 * 1024;
HttpAddress httpAddress = HttpAddress.secureHttp1("localhost", 8143);
Server server = Server.builder(Domain.builder(httpAddress)
Server server = Server.builder(HttpServerDomain.builder(httpAddress)
.setSelfCert()
.singleEndpoint("/", (request, response) ->
response.withStatus(HttpResponseStatus.OK)

View file

@ -11,7 +11,7 @@ import org.xbib.netty.http.client.api.ResponseListener;
import org.xbib.netty.http.common.HttpAddress;
import org.xbib.netty.http.common.HttpParameters;
import org.xbib.netty.http.common.HttpResponse;
import org.xbib.netty.http.server.Domain;
import org.xbib.netty.http.server.HttpServerDomain;
import org.xbib.netty.http.server.Server;
import org.xbib.netty.http.server.test.NettyHttpTestExtension;
import java.util.concurrent.atomic.AtomicBoolean;
@ -33,7 +33,7 @@ class FlushTest {
@Test
void testFlushHttp1() throws Exception {
HttpAddress httpAddress = HttpAddress.http1("localhost", 8008);
Domain domain = Domain.builder(httpAddress)
HttpServerDomain domain = HttpServerDomain.builder(httpAddress)
.singleEndpoint("/flush", "/**", (req, resp) -> {
HttpParameters parameters = req.getParameters();
logger.log(Level.INFO, "got request " + parameters.toString() + ", sending 302 Found");

View file

@ -15,7 +15,7 @@ import org.xbib.netty.http.client.api.ResponseListener;
import org.xbib.netty.http.common.HttpAddress;
import org.xbib.netty.http.common.HttpParameters;
import org.xbib.netty.http.common.HttpResponse;
import org.xbib.netty.http.server.Domain;
import org.xbib.netty.http.server.HttpServerDomain;
import org.xbib.netty.http.server.Server;
import org.xbib.netty.http.server.api.ServerResponse;
import org.xbib.netty.http.server.test.NettyHttpTestExtension;
@ -33,7 +33,7 @@ class MimeUploadTest {
void testMimetHttp1() throws Exception {
final AtomicBoolean success1 = new AtomicBoolean(false);
HttpAddress httpAddress = HttpAddress.http1("localhost", 8008);
Domain domain = Domain.builder(httpAddress)
HttpServerDomain domain = HttpServerDomain.builder(httpAddress)
.singleEndpoint("/upload", "/**", (req, resp) -> {
HttpParameters parameters = req.getParameters();
logger.log(Level.INFO, "got request, headers = " + req.getHeaders() +

View file

@ -9,7 +9,7 @@ import org.xbib.netty.http.client.api.ResponseListener;
import org.xbib.netty.http.common.HttpAddress;
import org.xbib.netty.http.common.HttpParameters;
import org.xbib.netty.http.common.HttpResponse;
import org.xbib.netty.http.server.Domain;
import org.xbib.netty.http.server.HttpServerDomain;
import org.xbib.netty.http.server.Server;
import org.xbib.netty.http.server.api.ServerResponse;
import org.xbib.netty.http.server.test.NettyHttpTestExtension;
@ -32,7 +32,7 @@ class PostTest {
final AtomicBoolean success2 = new AtomicBoolean(false);
final AtomicBoolean success3 = new AtomicBoolean(false);
HttpAddress httpAddress = HttpAddress.http1("localhost", 8008);
Domain domain = Domain.builder(httpAddress)
HttpServerDomain domain = HttpServerDomain.builder(httpAddress)
.singleEndpoint("/post", "/**", (req, resp) -> {
HttpParameters parameters = req.getParameters();
logger.log(Level.INFO, "got request " + parameters.toString() + ", sending OK");
@ -82,7 +82,7 @@ class PostTest {
final AtomicBoolean success2 = new AtomicBoolean(false);
final AtomicBoolean success3 = new AtomicBoolean(false);
HttpAddress httpAddress = HttpAddress.http1("localhost", 8008);
Domain domain = Domain.builder(httpAddress)
HttpServerDomain domain = HttpServerDomain.builder(httpAddress)
.singleEndpoint("/post", "/**", (req, resp) -> {
HttpParameters parameters = req.getParameters();
logger.log(Level.INFO, "got request " + parameters.toString() + ", sending OK");
@ -133,7 +133,7 @@ class PostTest {
final AtomicBoolean success3 = new AtomicBoolean(false);
final AtomicBoolean success4 = new AtomicBoolean(false);
HttpAddress httpAddress = HttpAddress.http1("localhost", 8008);
Domain domain = Domain.builder(httpAddress)
HttpServerDomain domain = HttpServerDomain.builder(httpAddress)
.singleEndpoint("/post", "/**", (req, resp) -> {
HttpParameters parameters = req.getParameters();
logger.log(Level.INFO, "got request " + parameters.toString() + ", sending OK");
@ -190,7 +190,7 @@ class PostTest {
final AtomicBoolean success3 = new AtomicBoolean(false);
final AtomicBoolean success4 = new AtomicBoolean(false);
HttpAddress httpAddress = HttpAddress.http1("localhost", 8008);
Domain domain = Domain.builder(httpAddress)
HttpServerDomain domain = HttpServerDomain.builder(httpAddress)
.singleEndpoint("/post", "/**", (req, resp) -> {
HttpParameters parameters = req.getParameters();
logger.log(Level.INFO, "got request " + parameters.toString() + ", sending OK");
@ -247,7 +247,7 @@ class PostTest {
final AtomicBoolean success2 = new AtomicBoolean(false);
final AtomicBoolean success3 = new AtomicBoolean(false);
HttpAddress httpAddress = HttpAddress.http1("localhost", 8008);
Domain domain = Domain.builder(httpAddress)
HttpServerDomain domain = HttpServerDomain.builder(httpAddress)
.singleEndpoint("/post", "/**", (req, resp) -> {
HttpParameters parameters = req.getParameters();
logger.log(Level.INFO, "got request " + parameters.toString() + ", sending OK");

View file

@ -8,7 +8,7 @@ import org.xbib.netty.http.client.api.Request;
import org.xbib.netty.http.client.api.ResponseListener;
import org.xbib.netty.http.common.HttpAddress;
import org.xbib.netty.http.common.HttpResponse;
import org.xbib.netty.http.server.Domain;
import org.xbib.netty.http.server.HttpServerDomain;
import org.xbib.netty.http.server.Server;
import org.xbib.netty.http.server.api.ServerResponse;
import org.xbib.netty.http.server.test.NettyHttpTestExtension;
@ -32,7 +32,7 @@ class PutTest {
final AtomicBoolean success1 = new AtomicBoolean(false);
final AtomicBoolean success2 = new AtomicBoolean(false);
HttpAddress httpAddress = HttpAddress.http1("localhost", 8008);
Domain domain = Domain.builder(httpAddress)
HttpServerDomain domain = HttpServerDomain.builder(httpAddress)
.singleEndpoint("/put", "/**", (req, resp) -> {
logger.log(Level.INFO, "got request " +
req.getContent().toString(StandardCharsets.UTF_8));
@ -80,7 +80,7 @@ class PutTest {
outputStream.write(1);
}
HttpAddress httpAddress = HttpAddress.http1("localhost", 8008);
Domain domain = Domain.builder(httpAddress)
HttpServerDomain domain = HttpServerDomain.builder(httpAddress)
.singleEndpoint("/put", "/**", (req, resp) -> {
logger.log(Level.INFO, "got request, length = " +
req.getContent().readableBytes());

View file

@ -9,7 +9,7 @@ import org.junit.jupiter.api.extension.ExtendWith;
import org.xbib.netty.http.client.Client;
import org.xbib.netty.http.client.api.Request;
import org.xbib.netty.http.common.HttpAddress;
import org.xbib.netty.http.server.Domain;
import org.xbib.netty.http.server.HttpServerDomain;
import org.xbib.netty.http.server.Server;
import org.xbib.netty.http.server.test.NettyHttpTestExtension;
@ -24,7 +24,7 @@ class StreamTest {
@Test
void testServerBodyInputStreamHttp1() throws Exception {
HttpAddress httpAddress = HttpAddress.http1("localhost", 8008);
Domain domain = Domain.builder(httpAddress)
HttpServerDomain domain = HttpServerDomain.builder(httpAddress)
.singleEndpoint("/", (request, response) -> {
ByteBufInputStream inputStream = request.getInputStream();
String content = inputStream.readLine();

View file

@ -11,7 +11,7 @@ import org.xbib.netty.http.common.HttpAddress;
import org.xbib.netty.http.common.HttpResponse;
import org.xbib.netty.http.server.Server;
import org.xbib.netty.http.server.api.ServerResponse;
import org.xbib.netty.http.server.Domain;
import org.xbib.netty.http.server.HttpServerDomain;
import org.xbib.netty.http.server.test.NettyHttpTestExtension;
import java.nio.charset.StandardCharsets;
@ -32,7 +32,7 @@ class CleartextTest {
@Test
void testSimpleCleartextHttp2() throws Exception {
HttpAddress httpAddress = HttpAddress.http2("localhost", 8008);
Domain domain = Domain.builder(httpAddress)
HttpServerDomain domain = HttpServerDomain.builder(httpAddress)
.singleEndpoint("/", (request, response) ->
ServerResponse.write(response, HttpResponseStatus.OK, "text.plain",
request.getContent().toString(StandardCharsets.UTF_8)))
@ -77,7 +77,7 @@ class CleartextTest {
void testPooledClearTextHttp2() throws Exception {
int loop = 1024;
HttpAddress httpAddress = HttpAddress.http2("localhost", 8008);
Domain domain = Domain.builder(httpAddress)
HttpServerDomain domain = HttpServerDomain.builder(httpAddress)
.singleEndpoint("/", (request, response) ->
response.withStatus(HttpResponseStatus.OK)
.withContentType("text/plain")
@ -129,7 +129,7 @@ class CleartextTest {
int threads = 4;
int loop = 1024;
HttpAddress httpAddress = HttpAddress.http2("localhost", 8008);
Domain domain = Domain.builder(httpAddress)
HttpServerDomain domain = HttpServerDomain.builder(httpAddress)
.singleEndpoint("/**", (request, response) ->
ServerResponse.write(response, HttpResponseStatus.OK, "text/plain",
request.getContent().toString(StandardCharsets.UTF_8)))
@ -198,7 +198,7 @@ class CleartextTest {
int loop = 1000;
HttpAddress httpAddress1 = HttpAddress.http2("localhost", 8008);
AtomicInteger counter1 = new AtomicInteger();
Domain domain1 = Domain.builder(httpAddress1)
HttpServerDomain domain1 = HttpServerDomain.builder(httpAddress1)
.singleEndpoint("/", (request, response) -> {
ServerResponse.write(response, HttpResponseStatus.OK, "text.plain",
request.getContent().toString(StandardCharsets.UTF_8));
@ -210,7 +210,7 @@ class CleartextTest {
server1.accept();
HttpAddress httpAddress2 = HttpAddress.http2("localhost", 8009);
AtomicInteger counter2 = new AtomicInteger();
Domain domain2 = Domain.builder(httpAddress2)
HttpServerDomain domain2 = HttpServerDomain.builder(httpAddress2)
.singleEndpoint("/", (request, response) -> {
ServerResponse.write(response, HttpResponseStatus.OK, "text/plain",
request.getContent().toString(StandardCharsets.UTF_8));

View file

@ -10,7 +10,7 @@ import org.xbib.netty.http.client.api.ClientTransport;
import org.xbib.netty.http.common.HttpAddress;
import org.xbib.netty.http.common.HttpResponse;
import org.xbib.netty.http.server.Server;
import org.xbib.netty.http.server.Domain;
import org.xbib.netty.http.server.HttpServerDomain;
import org.xbib.netty.http.server.test.NettyHttpTestExtension;
import java.nio.charset.StandardCharsets;
@ -31,7 +31,7 @@ class EncryptedTest {
@Test
void testSimpleSecureHttp2() throws Exception {
HttpAddress httpAddress = HttpAddress.secureHttp2("localhost", 8143);
Server server = Server.builder(Domain.builder(httpAddress)
Server server = Server.builder(HttpServerDomain.builder(httpAddress)
.setSelfCert()
.singleEndpoint("/", (request, response) ->
response.withStatus(HttpResponseStatus.OK)
@ -72,7 +72,7 @@ class EncryptedTest {
void testPooledSecureHttp2() throws Exception {
int loop = 1024;
HttpAddress httpAddress = HttpAddress.secureHttp2("localhost", 8143);
Domain domain = Domain.builder(httpAddress)
HttpServerDomain domain = HttpServerDomain.builder(httpAddress)
.setSelfCert()
.singleEndpoint("/", (request, response) ->
response.withStatus(HttpResponseStatus.OK)
@ -126,7 +126,7 @@ class EncryptedTest {
int threads = 4;
int loop = 1024;
HttpAddress httpAddress = HttpAddress.secureHttp2("localhost", 8143);
Server server = Server.builder(Domain.builder(httpAddress)
Server server = Server.builder(HttpServerDomain.builder(httpAddress)
.setSelfCert()
.singleEndpoint("/", (request, response) ->
response.withStatus(HttpResponseStatus.OK)

View file

@ -9,7 +9,7 @@ import org.xbib.netty.http.client.api.ResponseListener;
import org.xbib.netty.http.common.HttpAddress;
import org.xbib.netty.http.common.HttpParameters;
import org.xbib.netty.http.common.HttpResponse;
import org.xbib.netty.http.server.Domain;
import org.xbib.netty.http.server.HttpServerDomain;
import org.xbib.netty.http.server.Server;
import org.xbib.netty.http.server.test.NettyHttpTestExtension;
import java.util.concurrent.atomic.AtomicBoolean;
@ -30,7 +30,7 @@ class FlushTest {
@Test
void testFlushHttp2() throws Exception {
HttpAddress httpAddress = HttpAddress.http2("localhost", 8008);
Domain domain = Domain.builder(httpAddress)
HttpServerDomain domain = HttpServerDomain.builder(httpAddress)
.singleEndpoint("/flush", "/**", (req, resp) -> {
HttpParameters parameters = req.getParameters();
logger.log(Level.INFO, "got request " + parameters.toString() + ", sending 302 Found");

View file

@ -8,7 +8,7 @@ import org.xbib.netty.http.client.Client;
import org.xbib.netty.http.client.api.Request;
import org.xbib.netty.http.client.api.ClientTransport;
import org.xbib.netty.http.common.HttpAddress;
import org.xbib.netty.http.server.Domain;
import org.xbib.netty.http.server.HttpServerDomain;
import org.xbib.netty.http.server.Server;
import org.xbib.netty.http.server.api.ServerResponse;
import org.xbib.netty.http.server.test.NettyHttpTestExtension;
@ -21,7 +21,7 @@ class MixedProtocolTest {
@Test
void testHttp1ClientHttp2Server() throws Exception {
HttpAddress httpAddress = HttpAddress.http2("localhost", 8008);
Domain domain = Domain.builder(httpAddress)
HttpServerDomain domain = HttpServerDomain.builder(httpAddress)
.singleEndpoint("/", (request, response) -> {
ServerResponse.write(response, HttpResponseStatus.OK);
})
@ -55,7 +55,7 @@ class MixedProtocolTest {
@Test
void testHttp2ClientHttp1Server() throws Exception {
HttpAddress httpAddress = HttpAddress.http1("localhost", 8008);
Domain domain = Domain.builder(httpAddress)
HttpServerDomain domain = HttpServerDomain.builder(httpAddress)
.singleEndpoint("/", (request, response) -> {
ServerResponse.write(response, HttpResponseStatus.OK);
})
@ -92,7 +92,7 @@ class MixedProtocolTest {
@Test
void testHttp1ClientHttp2ServerWithNegotiation() throws Exception {
HttpAddress httpAddress = HttpAddress.secureHttp2("localhost", 8143);
Domain domain = Domain.builder(httpAddress)
HttpServerDomain domain = HttpServerDomain.builder(httpAddress)
.setSelfCert()
.singleEndpoint("/", (request, response) -> {
ServerResponse.write(response, HttpResponseStatus.OK);

View file

@ -12,7 +12,7 @@ import org.xbib.netty.http.common.HttpParameters;
import org.xbib.netty.http.common.HttpResponse;
import org.xbib.netty.http.server.Server;
import org.xbib.netty.http.server.api.ServerResponse;
import org.xbib.netty.http.server.Domain;
import org.xbib.netty.http.server.HttpServerDomain;
import org.xbib.netty.http.server.test.NettyHttpTestExtension;
import java.nio.charset.StandardCharsets;
@ -33,7 +33,7 @@ class PostTest {
final AtomicBoolean success2 = new AtomicBoolean(false);
final AtomicBoolean success3 = new AtomicBoolean(false);
HttpAddress httpAddress = HttpAddress.http2("localhost", 8008);
Domain domain = Domain.builder(httpAddress)
HttpServerDomain domain = HttpServerDomain.builder(httpAddress)
.singleEndpoint("/post", "/**", (req, resp) -> {
HttpParameters parameters = req.getParameters();
logger.log(Level.INFO, "got request " + parameters.toString() + " , sending, OK");
@ -83,7 +83,7 @@ class PostTest {
final AtomicBoolean success2 = new AtomicBoolean(false);
final AtomicBoolean success3 = new AtomicBoolean(false);
HttpAddress httpAddress = HttpAddress.http2("localhost", 8008);
Domain domain = Domain.builder(httpAddress)
HttpServerDomain domain = HttpServerDomain.builder(httpAddress)
.singleEndpoint("/post", "/**", (req, resp) -> {
HttpParameters parameters = req.getParameters();
logger.log(Level.INFO, "got request " + parameters.toString() + " , sending, OK");

View file

@ -8,7 +8,7 @@ import org.xbib.netty.http.client.api.Request;
import org.xbib.netty.http.client.api.ResponseListener;
import org.xbib.netty.http.common.HttpAddress;
import org.xbib.netty.http.common.HttpResponse;
import org.xbib.netty.http.server.Domain;
import org.xbib.netty.http.server.HttpServerDomain;
import org.xbib.netty.http.server.Server;
import org.xbib.netty.http.server.api.ServerResponse;
import org.xbib.netty.http.server.test.NettyHttpTestExtension;
@ -31,7 +31,7 @@ class PutTest {
final AtomicBoolean success1 = new AtomicBoolean(false);
final AtomicBoolean success2 = new AtomicBoolean(false);
HttpAddress httpAddress = HttpAddress.http2("localhost", 8008);
Domain domain = Domain.builder(httpAddress)
HttpServerDomain domain = HttpServerDomain.builder(httpAddress)
.singleEndpoint("/put", "/**", (req, resp) -> {
logger.log(Level.INFO, "got request " +
req.getContent().toString(StandardCharsets.UTF_8));
@ -80,7 +80,7 @@ class PutTest {
outputStream.write(1);
}
HttpAddress httpAddress = HttpAddress.http2("localhost", 8008);
Domain domain = Domain.builder(httpAddress)
HttpServerDomain domain = HttpServerDomain.builder(httpAddress)
.singleEndpoint("/put", "/**", (req, resp) -> {
logger.log(Level.INFO, "got request, length = " +
req.getContent().readableBytes());

View file

@ -6,7 +6,7 @@ import org.junit.jupiter.api.extension.ExtendWith;
import org.xbib.netty.http.client.Client;
import org.xbib.netty.http.client.api.Request;
import org.xbib.netty.http.common.HttpAddress;
import org.xbib.netty.http.server.Domain;
import org.xbib.netty.http.server.HttpServerDomain;
import org.xbib.netty.http.server.Server;
import org.xbib.netty.http.server.test.NettyHttpTestExtension;
import java.nio.charset.StandardCharsets;
@ -14,7 +14,6 @@ import java.util.concurrent.atomic.AtomicInteger;
import io.netty.buffer.ByteBufInputStream;
import io.netty.buffer.ByteBufOutputStream;
import io.netty.handler.codec.http.HttpResponseStatus;
import io.netty.handler.codec.http.HttpVersion;
@ExtendWith(NettyHttpTestExtension.class)
class StreamTest {
@ -22,7 +21,7 @@ class StreamTest {
@Test
void testServerBodyInputStreamHttp2() throws Exception {
HttpAddress httpAddress = HttpAddress.http2("localhost", 8008);
Domain domain = Domain.builder(httpAddress)
HttpServerDomain domain = HttpServerDomain.builder(httpAddress)
.singleEndpoint("/", (request, response) -> {
ByteBufInputStream inputStream = request.getInputStream();
String content = inputStream.readLine();