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

View file

@ -8,6 +8,8 @@ import io.netty.handler.ssl.SslContext;
import io.netty.handler.ssl.SslContextBuilder; import io.netty.handler.ssl.SslContextBuilder;
import io.netty.handler.ssl.SslProvider; import io.netty.handler.ssl.SslProvider;
import org.xbib.netty.http.common.HttpAddress; 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.server.api.security.ServerCertificateProvider;
import org.xbib.netty.http.common.security.SecurityUtil; import org.xbib.netty.http.common.security.SecurityUtil;
import org.xbib.netty.http.server.api.ServerRequest; import org.xbib.netty.http.server.api.ServerRequest;
@ -33,33 +35,29 @@ import java.security.spec.InvalidKeySpecException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
import java.util.LinkedHashSet;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Objects; import java.util.Objects;
import java.util.ServiceLoader; import java.util.ServiceLoader;
import java.util.Set;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; 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 static final String EMPTY = "";
private final String name; private final String name;
private final Set<String> aliases;
private final HttpAddress httpAddress; private final HttpAddress httpAddress;
private final SslContext sslContext; private final SslContext sslContext;
private final List<HttpEndpointResolver> httpEndpointResolvers; private final Collection<HttpEndpointResolver> httpEndpointResolvers;
private final Collection<? extends X509Certificate> certificates; private final Collection<? extends X509Certificate> certificates;
@ -67,19 +65,16 @@ public class Domain {
* Constructs a {@code NamedServer} with the given name. * Constructs a {@code NamedServer} with the given name.
* *
* @param name the name, or null if it is the default server * @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 httpAddress HTTP address, used for determining if named server is secure or not
* @param httpEndpointResolvers the endpoint resolvers * @param httpEndpointResolvers the endpoint resolvers
* @param sslContext SSL context or null * @param sslContext SSL context or null
*/ */
private Domain(String name, private HttpServerDomain(String name,
Set<String> aliases,
HttpAddress httpAddress, HttpAddress httpAddress,
List<HttpEndpointResolver> httpEndpointResolvers, Collection<HttpEndpointResolver> httpEndpointResolvers,
SslContext sslContext, SslContext sslContext,
Collection<? extends X509Certificate> certificates) { Collection<? extends X509Certificate> certificates) {
this.name = name; this.name = name;
this.aliases = aliases;
this.httpAddress = httpAddress; this.httpAddress = httpAddress;
this.httpEndpointResolvers = httpEndpointResolvers; this.httpEndpointResolvers = httpEndpointResolvers;
this.sslContext = sslContext; this.sslContext = sslContext;
@ -94,7 +89,7 @@ public class Domain {
return new Builder(httpAddress).setServerName(serverName); return new Builder(httpAddress).setServerName(serverName);
} }
public static Builder builder(Domain domain) { public static Builder builder(Domain<? extends EndpointResolver<?>> domain) {
return new Builder(domain); return new Builder(domain);
} }
@ -103,6 +98,7 @@ public class Domain {
* *
* @return the HTTP address * @return the HTTP address
*/ */
@Override
public HttpAddress getHttpAddress() { public HttpAddress getHttpAddress() {
return httpAddress; return httpAddress;
} }
@ -112,23 +108,21 @@ public class Domain {
* *
* @return the name, or null if it is the default server * @return the name, or null if it is the default server
*/ */
@Override
public String getName() { public String getName() {
return name; return name;
} }
/** @Override
* Returns the aliases. public Collection<HttpEndpointResolver> getHttpEndpointResolvers() {
* return httpEndpointResolvers;
* @return the (unmodifiable) set of aliases (which may be empty)
*/
public Set<String> getAliases() {
return aliases;
} }
/** /**
* Returns SSL context. * Returns SSL context.
* @return the SSL context * @return the SSL context
*/ */
@Override
public SslContext getSslContext() { public SslContext getSslContext() {
return sslContext; return sslContext;
} }
@ -137,6 +131,7 @@ public class Domain {
* Get certificate chain. * Get certificate chain.
* @return the certificate chain or null if not secure * @return the certificate chain or null if not secure
*/ */
@Override
public Collection<? extends X509Certificate> getCertificateChain() { public Collection<? extends X509Certificate> getCertificateChain() {
return certificates; return certificates;
} }
@ -149,13 +144,14 @@ public class Domain {
* @return the context path * @return the context path
* @throws IOException if handling fails * @throws IOException if handling fails
*/ */
public String findContextOf(ServerRequest serverRequest) throws IOException { @Override
public String findContextPathOf(ServerRequest serverRequest) throws IOException {
if (serverRequest == null) { if (serverRequest == null) {
return EMPTY; return EMPTY;
} }
Map.Entry<HttpEndpointResolver, List<HttpEndpoint>> resolved = resolve(serverRequest); Map.Entry<HttpEndpointResolver, List<HttpEndpoint>> resolved = resolve(serverRequest);
if (resolved != null) { if (resolved != null) {
resolved.getKey().handle(resolved.getValue(), serverRequest, null, false); resolved.getKey().resolve(resolved.getValue(), serverRequest);
return serverRequest.getContextPath(); return serverRequest.getContextPath();
} }
return null; return null;
@ -167,22 +163,28 @@ public class Domain {
* @param serverResponse the server response * @param serverResponse the server response
* @throws IOException if handling server request fails * @throws IOException if handling server request fails
*/ */
@Override
public void handle(ServerRequest serverRequest, ServerResponse serverResponse) throws IOException { public void handle(ServerRequest serverRequest, ServerResponse serverResponse) throws IOException {
Map.Entry<HttpEndpointResolver, List<HttpEndpoint>> resolved = resolve(serverRequest); Map.Entry<HttpEndpointResolver, List<HttpEndpoint>> resolved = resolve(serverRequest);
if (resolved != null) { if (resolved != null) {
resolved.getKey().handle(resolved.getValue(), serverRequest, serverResponse, true); resolved.getKey().handle(resolved.getValue(), serverRequest, serverResponse);
} else { } else {
ServerResponse.write(serverResponse, HttpResponseStatus.NOT_IMPLEMENTED, ServerResponse.write(serverResponse, HttpResponseStatus.NOT_FOUND,
"text/plain", "No endpoint match for request " + serverRequest); "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. * Just resolve a server request to a matching endpoint resolver with endpoints matched.
* @param serverRequest the server request * @param serverRequest the server request
* @return the endpoint resolver together with the matching endpoints * @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) { for (HttpEndpointResolver httpEndpointResolver : httpEndpointResolvers) {
List<HttpEndpoint> matchingEndpoints = httpEndpointResolver.matchingEndpointsFor(serverRequest); List<HttpEndpoint> matchingEndpoints = httpEndpointResolver.matchingEndpointsFor(serverRequest);
if (!matchingEndpoints.isEmpty()) { if (!matchingEndpoints.isEmpty()) {
@ -192,20 +194,13 @@ public class Domain {
return null; return null;
} }
@Override
public String toString() {
return name + " (" + httpAddress + ") aliases=" + aliases;
}
public static class Builder { public static class Builder {
private final HttpAddress httpAddress; private final HttpAddress httpAddress;
private String serverName; private String serverName;
private final Set<String> aliases; private final Collection<HttpEndpointResolver> httpEndpointResolvers;
private final List<HttpEndpointResolver> httpEndpointResolvers;
private SslContext sslContext; private SslContext sslContext;
@ -228,7 +223,6 @@ public class Domain {
private Builder(HttpAddress httpAddress) { private Builder(HttpAddress httpAddress) {
Objects.requireNonNull(httpAddress); Objects.requireNonNull(httpAddress);
this.httpAddress = httpAddress; this.httpAddress = httpAddress;
this.aliases = new LinkedHashSet<>();
this.httpEndpointResolvers = new ArrayList<>(); this.httpEndpointResolvers = new ArrayList<>();
this.trustManagerFactory = SecurityUtil.Defaults.DEFAULT_TRUST_MANAGER_FACTORY; this.trustManagerFactory = SecurityUtil.Defaults.DEFAULT_TRUST_MANAGER_FACTORY;
this.sslProvider = SecurityUtil.Defaults.DEFAULT_SSL_PROVIDER; this.sslProvider = SecurityUtil.Defaults.DEFAULT_SSL_PROVIDER;
@ -236,12 +230,12 @@ public class Domain {
this.cipherSuiteFilter = SecurityUtil.Defaults.DEFAULT_CIPHER_SUITE_FILTER; this.cipherSuiteFilter = SecurityUtil.Defaults.DEFAULT_CIPHER_SUITE_FILTER;
} }
private Builder(Domain domain) { @SuppressWarnings("unchecked")
this.httpAddress = domain.httpAddress; private Builder(Domain<? extends EndpointResolver<?>> domain) {
this.aliases = new LinkedHashSet<>(); this.httpAddress = domain.getHttpAddress();
this.httpEndpointResolvers = new ArrayList<>(domain.httpEndpointResolvers); this.httpEndpointResolvers = new ArrayList<>((List<HttpEndpointResolver>) domain.getHttpEndpointResolvers());
this.sslContext = domain.sslContext; this.sslContext = domain.getSslContext();
this.keyCertChain = domain.certificates; this.keyCertChain = domain.getCertificateChain();
} }
public Builder setServerName(String serverName) { public Builder setServerName(String serverName) {
@ -338,18 +332,6 @@ public class Domain {
return this; 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) { public Builder addEndpointResolver(HttpEndpointResolver httpEndpointResolver) {
Objects.requireNonNull(httpEndpointResolver); Objects.requireNonNull(httpEndpointResolver);
this.httpEndpointResolvers.add(httpEndpointResolver); this.httpEndpointResolvers.add(httpEndpointResolver);
@ -399,7 +381,7 @@ public class Domain {
return this; return this;
} }
public Domain build() { public HttpServerDomain build() {
if (httpEndpointResolvers.isEmpty()) { if (httpEndpointResolvers.isEmpty()) {
throw new IllegalArgumentException("domain must have at least one endpoint resolver"); throw new IllegalArgumentException("domain must have at least one endpoint resolver");
} }
@ -420,14 +402,14 @@ public class Domain {
} }
this.sslContext = sslContextBuilder.build(); this.sslContext = sslContextBuilder.build();
} }
return new Domain(serverName, aliases, return new HttpServerDomain(serverName,
httpAddress, httpEndpointResolvers, httpAddress, httpEndpointResolvers,
sslContext, keyCertChain); sslContext, keyCertChain);
} catch (Exception e) { } catch (Exception e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
} else { } else {
return new Domain(serverName, aliases, return new HttpServerDomain(serverName,
httpAddress, httpEndpointResolvers, httpAddress, httpEndpointResolvers,
null, null); 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.NetworkUtils;
import org.xbib.netty.http.common.HttpChannelInitializer; import org.xbib.netty.http.common.HttpChannelInitializer;
import org.xbib.netty.http.common.TransportProvider; 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.ServerProtocolProvider;
import org.xbib.netty.http.server.api.ServerRequest; import org.xbib.netty.http.server.api.ServerRequest;
import org.xbib.netty.http.server.api.ServerResponse; import org.xbib.netty.http.server.api.ServerResponse;
import org.xbib.netty.http.server.api.ServerTransport; 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.security.CertificateUtils;
import org.xbib.netty.http.server.transport.HttpServerRequest; import org.xbib.netty.http.server.transport.HttpServerRequest;
import java.io.IOException; import java.io.IOException;
@ -71,7 +74,7 @@ public final class Server implements AutoCloseable {
private static final AtomicLong responseCounter = new AtomicLong(0); private static final AtomicLong responseCounter = new AtomicLong(0);
private final ServerConfig serverConfig; private final DefaultServerConfig serverConfig;
private final EventLoopGroup parentEventLoopGroup; private final EventLoopGroup parentEventLoopGroup;
@ -98,7 +101,7 @@ public final class Server implements AutoCloseable {
* @param socketChannelClass socket channel class * @param socketChannelClass socket channel class
*/ */
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
private Server(ServerConfig serverConfig, private Server(DefaultServerConfig serverConfig,
ByteBufAllocator byteBufAllocator, ByteBufAllocator byteBufAllocator,
EventLoopGroup parentEventLoopGroup, EventLoopGroup parentEventLoopGroup,
EventLoopGroup childEventLoopGroup, EventLoopGroup childEventLoopGroup,
@ -133,7 +136,7 @@ public final class Server implements AutoCloseable {
.childOption(ChannelOption.SO_RCVBUF, serverConfig.getTcpReceiveBufferSize()) .childOption(ChannelOption.SO_RCVBUF, serverConfig.getTcpReceiveBufferSize())
.childOption(ChannelOption.CONNECT_TIMEOUT_MILLIS, serverConfig.getConnectTimeoutMillis()) .childOption(ChannelOption.CONNECT_TIMEOUT_MILLIS, serverConfig.getConnectTimeoutMillis())
.childOption(ChannelOption.WRITE_BUFFER_WATER_MARK, serverConfig.getWriteBufferWaterMark()); .childOption(ChannelOption.WRITE_BUFFER_WATER_MARK, serverConfig.getWriteBufferWaterMark());
if (serverConfig.isTrafficDebug()) { if (serverConfig.isDebug()) {
bootstrap.handler(new LoggingHandler("bootstrap-server", serverConfig.getTrafficDebugLogLevel())); bootstrap.handler(new LoggingHandler("bootstrap-server", serverConfig.getTrafficDebugLogLevel()));
} }
if (serverConfig.getDefaultDomain() == null) { if (serverConfig.getDefaultDomain() == null) {
@ -141,13 +144,13 @@ public final class Server implements AutoCloseable {
} }
// translate domains into Netty mapping // translate domains into Netty mapping
Mapping<String, SslContext> domainNameMapping = null; Mapping<String, SslContext> domainNameMapping = null;
Domain defaultDomain = serverConfig.getDefaultDomain(); Domain<? extends EndpointResolver<?>> defaultDomain = serverConfig.getDefaultDomain();
if (serverConfig.getAddress().isSecure() && if (serverConfig.getAddress().isSecure() &&
defaultDomain != null && defaultDomain != null &&
defaultDomain.getSslContext() != null) { defaultDomain.getSslContext() != null) {
DomainWildcardMappingBuilder<SslContext> mappingBuilder = DomainWildcardMappingBuilder<SslContext> mappingBuilder =
new DomainWildcardMappingBuilder<>(defaultDomain.getSslContext()); new DomainWildcardMappingBuilder<>(defaultDomain.getSslContext());
for (Domain domain : serverConfig.getDomains()) { for (Domain<? extends EndpointResolver<?>> domain : serverConfig.getDomains()) {
if (!domain.getName().equals(defaultDomain.getName())) { if (!domain.getName().equals(defaultDomain.getName())) {
mappingBuilder.add(domain.getName(), domain.getSslContext()); mappingBuilder.add(domain.getName(), domain.getSslContext());
} }
@ -168,11 +171,11 @@ public final class Server implements AutoCloseable {
} }
} }
public static Builder builder(Domain defaultDomain) { public static Builder builder(HttpServerDomain httpServerDomain) {
return new Builder(defaultDomain); return new Builder(httpServerDomain);
} }
public ServerConfig getServerConfig() { public DefaultServerConfig getServerConfig() {
return serverConfig; return serverConfig;
} }
@ -199,7 +202,7 @@ public final class Server implements AutoCloseable {
* @param serverRequest the server request * @param serverRequest the server request
* @return the domain * @return the domain
*/ */
public Domain getDomain(ServerRequest serverRequest) { public Domain<? extends EndpointResolver<?>> getDomain(ServerRequest serverRequest) {
return getDomain(getBaseURL(serverRequest)); return getDomain(getBaseURL(serverRequest));
} }
@ -208,7 +211,7 @@ public final class Server implements AutoCloseable {
* @param url the URL * @param url the URL
* @return the domain * @return the domain
*/ */
public Domain getDomain(URL url) { public Domain<? extends EndpointResolver<?>> getDomain(URL url) {
return getDomain(hostAndPort(url)); return getDomain(hostAndPort(url));
} }
@ -219,7 +222,7 @@ public final class Server implements AutoCloseable {
* default domain * default domain
* @return the virtual host with the given name or the 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); return serverConfig.getDomain(name);
} }
@ -277,13 +280,16 @@ public final class Server implements AutoCloseable {
*/ */
public URL getContextURL(ServerRequest serverRequest) throws IOException { public URL getContextURL(ServerRequest serverRequest) throws IOException {
URL baseURL = getBaseURL(serverRequest); URL baseURL = getBaseURL(serverRequest);
Domain domain = getDomain(baseURL); Domain<? extends EndpointResolver<?>> domain = getDomain(baseURL);
String context = domain.findContextOf(serverRequest); String context = domain.findContextPathOf(serverRequest);
if (!context.endsWith("/")) {
context = context + "/";
}
return baseURL.resolve(context); return baseURL.resolve(context);
} }
public void handle(HttpServerRequest serverRequest, ServerResponse serverResponse) throws IOException { 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); logger.log(Level.FINEST, () -> "found domain " + domain + " for " + serverRequest);
if (executor != null) { if (executor != null) {
executor.submit(() -> { executor.submit(() -> {
@ -393,7 +399,7 @@ public final class Server implements AutoCloseable {
throw new IllegalStateException("no channel initializer found for major version " + majorVersion); 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 parentEventLoopGroup ) {
EventLoopGroup eventLoopGroup = parentEventLoopGroup; EventLoopGroup eventLoopGroup = parentEventLoopGroup;
if (eventLoopGroup == null) { if (eventLoopGroup == null) {
@ -411,7 +417,7 @@ public final class Server implements AutoCloseable {
return eventLoopGroup; return eventLoopGroup;
} }
private static EventLoopGroup createChildEventLoopGroup(ServerConfig serverConfig, private static EventLoopGroup createChildEventLoopGroup(DefaultServerConfig serverConfig,
EventLoopGroup childEventLoopGroup ) { EventLoopGroup childEventLoopGroup ) {
EventLoopGroup eventLoopGroup = childEventLoopGroup; EventLoopGroup eventLoopGroup = childEventLoopGroup;
if (eventLoopGroup == null) { if (eventLoopGroup == null) {
@ -429,7 +435,7 @@ public final class Server implements AutoCloseable {
return eventLoopGroup; 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> socketChannelClass) {
Class<? extends ServerSocketChannel> channelClass = socketChannelClass; Class<? extends ServerSocketChannel> channelClass = socketChannelClass;
if (channelClass == null) { if (channelClass == null) {
@ -536,16 +542,21 @@ public final class Server implements AutoCloseable {
private Class<? extends ServerSocketChannel> socketChannelClass; private Class<? extends ServerSocketChannel> socketChannelClass;
private final ServerConfig serverConfig; private final DefaultServerConfig serverConfig;
private Builder(Domain defaultDomain) { private Builder(HttpServerDomain httpServerDomain) {
this.serverConfig = new ServerConfig(); this.serverConfig = new DefaultServerConfig();
this.serverConfig.setAddress(defaultDomain.getHttpAddress()); this.serverConfig.setAddress(httpServerDomain.getHttpAddress());
addDomain(defaultDomain); addDomain(httpServerDomain);
} }
public Builder enableDebug() { public Builder enableDebug() {
this.serverConfig.enableDebug(); this.serverConfig.setDebug(true);
return this;
}
public Builder setDebug(boolean debug) {
this.serverConfig.setDebug(debug);
return this; return this;
} }
@ -684,8 +695,8 @@ public final class Server implements AutoCloseable {
return this; return this;
} }
public Builder addDomain(Domain domain) { public Builder addDomain(Domain<HttpEndpointResolver> domain) {
this.serverConfig.checkAndAddDomain(domain); this.serverConfig.addDomain(domain);
return this; return this;
} }
@ -700,7 +711,7 @@ public final class Server implements AutoCloseable {
} }
if (serverConfig.isAutoDomain()) { if (serverConfig.isAutoDomain()) {
// unpack subject alternative names into separate domains // unpack subject alternative names into separate domains
for (Domain domain : serverConfig.getDomains()) { for (Domain<? extends EndpointResolver<?>> domain : serverConfig.getDomains()) {
try { try {
CertificateUtils.processSubjectAlternativeNames(domain.getCertificateChain(), CertificateUtils.processSubjectAlternativeNames(domain.getCertificateChain(),
new CertificateUtils.SubjectAlternativeNamesProcessor() { new CertificateUtils.SubjectAlternativeNamesProcessor() {
@ -710,7 +721,7 @@ public final class Server implements AutoCloseable {
@Override @Override
public void setSubjectAlternativeName(String subjectAlternativeName) { public void setSubjectAlternativeName(String subjectAlternativeName) {
Domain alternativeDomain = Domain.builder(domain) HttpServerDomain alternativeDomain = HttpServerDomain.builder(domain)
.setServerName(subjectAlternativeName) .setServerName(subjectAlternativeName)
.build(); .build();
addDomain(alternativeDomain); 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) { if (domain.getCertificateChain() != null) {
for (X509Certificate certificate : domain.getCertificateChain()) { for (X509Certificate certificate : domain.getCertificateChain()) {
try { 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.ServerRequest;
import org.xbib.netty.http.server.api.ServerResponse; import org.xbib.netty.http.server.api.ServerResponse;
import org.xbib.netty.http.server.api.Filter; import org.xbib.netty.http.server.api.Filter;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Comparator; 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.common.util.LimitedConcurrentHashMap;
import org.xbib.netty.http.server.api.EndpointDispatcher; 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.ServerRequest;
import org.xbib.netty.http.server.api.ServerResponse; import org.xbib.netty.http.server.api.ServerResponse;
import org.xbib.netty.http.server.api.annotation.Endpoint; import org.xbib.netty.http.server.api.annotation.Endpoint;
@ -16,7 +17,7 @@ import java.util.Map;
import java.util.Objects; import java.util.Objects;
import java.util.stream.Collectors; import java.util.stream.Collectors;
public class HttpEndpointResolver { public class HttpEndpointResolver implements EndpointResolver<HttpEndpoint> {
private static final int DEFAULT_LIMIT = 1024; private static final int DEFAULT_LIMIT = 1024;
@ -40,6 +41,7 @@ public class HttpEndpointResolver {
* @param serverRequest the server request * @param serverRequest the server request
* @return a * @return a
*/ */
@Override
public List<HttpEndpoint> matchingEndpointsFor(ServerRequest serverRequest) { public List<HttpEndpoint> matchingEndpointsFor(ServerRequest serverRequest) {
HttpEndpointDescriptor httpEndpointDescriptor = new HttpEndpointDescriptor(serverRequest); HttpEndpointDescriptor httpEndpointDescriptor = new HttpEndpointDescriptor(serverRequest);
endpointDescriptors.putIfAbsent(httpEndpointDescriptor, endpoints.stream() endpointDescriptors.putIfAbsent(httpEndpointDescriptor, endpoints.stream()
@ -49,23 +51,30 @@ public class HttpEndpointResolver {
return endpointDescriptors.get(httpEndpointDescriptor); 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, public void handle(List<HttpEndpoint> matchingEndpoints,
ServerRequest serverRequest, ServerRequest serverRequest,
ServerResponse serverResponse, ServerResponse serverResponse) throws IOException {
boolean dispatch) throws IOException {
Objects.requireNonNull(matchingEndpoints); Objects.requireNonNull(matchingEndpoints);
for (HttpEndpoint endpoint : matchingEndpoints) { for (HttpEndpoint endpoint : matchingEndpoints) {
endpoint.resolveUriTemplate(serverRequest); endpoint.resolveUriTemplate(serverRequest);
endpoint.before(serverRequest, serverResponse); endpoint.before(serverRequest, serverResponse);
if (dispatch) {
endpointDispatcher.dispatch(endpoint, serverRequest, serverResponse); endpointDispatcher.dispatch(endpoint, serverRequest, serverResponse);
endpoint.after(serverRequest, serverResponse); endpoint.after(serverRequest, serverResponse);
if (serverResponse != null && serverResponse.getStatus() != null) { if (serverResponse != null && serverResponse.getStatus() != null) {
break; break;
} }
} else {
break;
}
} }
} }

View file

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

View file

@ -8,6 +8,7 @@ import io.netty.handler.codec.http.HttpResponseStatus;
import io.netty.handler.stream.ChunkedNioStream; import io.netty.handler.stream.ChunkedNioStream;
import org.xbib.netty.http.common.util.DateTimeUtil; import org.xbib.netty.http.common.util.DateTimeUtil;
import org.xbib.netty.http.server.api.Filter; 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.Resource;
import org.xbib.netty.http.server.api.ServerRequest; import org.xbib.netty.http.server.api.ServerRequest;
import org.xbib.netty.http.server.api.ServerResponse; 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()); private static final Logger logger = Logger.getLogger(ResourceService.class.getName());
public void initialize(FilterConfig filterConfig) {
}
@Override @Override
public void handle(ServerRequest serverRequest, ServerResponse serverResponse) throws IOException { public void handle(ServerRequest serverRequest, ServerResponse serverResponse) throws IOException {
handleCachedResource(serverRequest, serverResponse, createResource(serverRequest, serverResponse)); 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.handler.ssl.SslHandler;
import io.netty.util.Mapping; import io.netty.util.Mapping;
import org.xbib.netty.http.common.HttpAddress; 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.net.InetSocketAddress;
import java.util.Arrays; import java.util.Arrays;
import java.util.logging.Level; 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 static final Logger logger = Logger.getLogger(ExtendedSNIHandler.class.getName());
private final ServerConfig serverConfig; private final DefaultServerConfig serverConfig;
private final HttpAddress httpAddress; private final HttpAddress httpAddress;
public ExtendedSNIHandler(Mapping<? super String, ? extends SslContext> mapping, public ExtendedSNIHandler(Mapping<? super String, ? extends SslContext> mapping,
ServerConfig serverConfig, HttpAddress httpAddress) { DefaultServerConfig serverConfig, HttpAddress httpAddress) {
super(mapping); super(mapping);
this.serverConfig = serverConfig; this.serverConfig = serverConfig;
this.httpAddress = httpAddress; this.httpAddress = httpAddress;
@ -35,7 +35,7 @@ public class ExtendedSNIHandler extends SniHandler {
} }
private static SslHandler newSslHandler(SslContext sslContext, private static SslHandler newSslHandler(SslContext sslContext,
ServerConfig serverConfig, DefaultServerConfig serverConfig,
ByteBufAllocator allocator, ByteBufAllocator allocator,
HttpAddress httpAddress) { HttpAddress httpAddress) {
InetSocketAddress peer = httpAddress.getInetSocketAddress(); 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.logging.LogLevel;
import io.netty.handler.ssl.SslContext; import io.netty.handler.ssl.SslContext;
import io.netty.handler.stream.ChunkedWriteHandler; import io.netty.handler.stream.ChunkedWriteHandler;
import io.netty.handler.timeout.ReadTimeoutHandler;
import io.netty.util.Mapping; import io.netty.util.Mapping;
import org.xbib.netty.http.common.HttpAddress; import org.xbib.netty.http.common.HttpAddress;
import org.xbib.netty.http.server.Server; 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.common.HttpChannelInitializer;
import org.xbib.netty.http.server.handler.ExtendedSNIHandler; import org.xbib.netty.http.server.handler.ExtendedSNIHandler;
import org.xbib.netty.http.server.handler.IdleTimeoutHandler; import org.xbib.netty.http.server.handler.IdleTimeoutHandler;
@ -39,7 +40,7 @@ public class Http1ChannelInitializer extends ChannelInitializer<Channel>
private final Server server; private final Server server;
private final ServerConfig serverConfig; private final DefaultServerConfig serverConfig;
private final HttpAddress httpAddress; private final HttpAddress httpAddress;
@ -58,7 +59,7 @@ public class Http1ChannelInitializer extends ChannelInitializer<Channel>
public void initChannel(Channel channel) { public void initChannel(Channel channel) {
ServerTransport transport = server.newTransport(httpAddress.getVersion()); ServerTransport transport = server.newTransport(httpAddress.getVersion());
channel.attr(ServerTransport.TRANSPORT_ATTRIBUTE_KEY).set(transport); channel.attr(ServerTransport.TRANSPORT_ATTRIBUTE_KEY).set(transport);
if (serverConfig.isTrafficDebug()) { if (serverConfig.isDebug()) {
channel.pipeline().addLast(new TrafficLoggingHandler(LogLevel.DEBUG)); channel.pipeline().addLast(new TrafficLoggingHandler(LogLevel.DEBUG));
} }
if (httpAddress.isSecure()) { if (httpAddress.isSecure()) {
@ -66,7 +67,7 @@ public class Http1ChannelInitializer extends ChannelInitializer<Channel>
} else { } else {
configureCleartext(channel); configureCleartext(channel);
} }
if (serverConfig.isTrafficDebug()) { if (serverConfig.isDebug()) {
logger.log(Level.FINE, "HTTP 1.1 server channel initialized: " + logger.log(Level.FINE, "HTTP 1.1 server channel initialized: " +
" address=" + httpAddress + " pipeline=" + channel.pipeline().names()); " address=" + httpAddress + " pipeline=" + channel.pipeline().names());
} }
@ -80,7 +81,10 @@ public class Http1ChannelInitializer extends ChannelInitializer<Channel>
private void configureCleartext(Channel channel) { private void configureCleartext(Channel channel) {
ChannelPipeline pipeline = channel.pipeline(); 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", pipeline.addLast("http-server-codec",
new HttpServerCodec(serverConfig.getMaxInitialLineLength(), new HttpServerCodec(serverConfig.getMaxInitialLineLength(),
serverConfig.getMaxHeadersSize(), serverConfig.getMaxChunkSize())); 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.logging.LogLevel;
import io.netty.handler.ssl.SslContext; import io.netty.handler.ssl.SslContext;
import io.netty.handler.stream.ChunkedWriteHandler; import io.netty.handler.stream.ChunkedWriteHandler;
import io.netty.handler.timeout.ReadTimeoutHandler;
import io.netty.util.AsciiString; import io.netty.util.AsciiString;
import io.netty.util.Mapping; import io.netty.util.Mapping;
import org.xbib.netty.http.common.HttpAddress; import org.xbib.netty.http.common.HttpAddress;
import org.xbib.netty.http.server.Server; 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.common.HttpChannelInitializer;
import org.xbib.netty.http.server.handler.ExtendedSNIHandler; import org.xbib.netty.http.server.handler.ExtendedSNIHandler;
import org.xbib.netty.http.server.handler.IdleTimeoutHandler; import org.xbib.netty.http.server.handler.IdleTimeoutHandler;
@ -51,7 +52,7 @@ public class Http2ChannelInitializer extends ChannelInitializer<Channel>
private final Server server; private final Server server;
private final ServerConfig serverConfig; private final DefaultServerConfig serverConfig;
private final HttpAddress httpAddress; private final HttpAddress httpAddress;
@ -70,7 +71,7 @@ public class Http2ChannelInitializer extends ChannelInitializer<Channel>
public void initChannel(Channel channel) { public void initChannel(Channel channel) {
ServerTransport transport = server.newTransport(httpAddress.getVersion()); ServerTransport transport = server.newTransport(httpAddress.getVersion());
channel.attr(ServerTransport.TRANSPORT_ATTRIBUTE_KEY).set(transport); channel.attr(ServerTransport.TRANSPORT_ATTRIBUTE_KEY).set(transport);
if (serverConfig.isTrafficDebug()) { if (serverConfig.isDebug()) {
channel.pipeline().addLast(new TrafficLoggingHandler(LogLevel.DEBUG)); channel.pipeline().addLast(new TrafficLoggingHandler(LogLevel.DEBUG));
} }
if (httpAddress.isSecure()) { if (httpAddress.isSecure()) {
@ -78,7 +79,7 @@ public class Http2ChannelInitializer extends ChannelInitializer<Channel>
} else { } else {
configureCleartext(channel); configureCleartext(channel);
} }
if (serverConfig.isTrafficDebug()) { if (serverConfig.isDebug()) {
logger.log(Level.FINE, "HTTP/2 server channel initialized: " + logger.log(Level.FINE, "HTTP/2 server channel initialized: " +
" address=" + httpAddress + " pipeline=" + channel.pipeline().names()); " address=" + httpAddress + " pipeline=" + channel.pipeline().names());
} }
@ -97,6 +98,8 @@ public class Http2ChannelInitializer extends ChannelInitializer<Channel>
ServerTransport transport = server.newTransport(httpAddress.getVersion()); ServerTransport transport = server.newTransport(httpAddress.getVersion());
channel.attr(ServerTransport.TRANSPORT_ATTRIBUTE_KEY).set(transport); channel.attr(ServerTransport.TRANSPORT_ATTRIBUTE_KEY).set(transport);
ChannelPipeline pipeline = channel.pipeline(); ChannelPipeline pipeline = channel.pipeline();
pipeline.addLast("server-read-timeout",
new ReadTimeoutHandler(serverConfig.getReadTimeoutMillis()));
pipeline.addLast("server-frame-converter", pipeline.addLast("server-frame-converter",
new Http2StreamFrameToHttpObjectCodec(true)); new Http2StreamFrameToHttpObjectCodec(true));
if (serverConfig.isCompressionEnabled()) { if (serverConfig.isCompressionEnabled()) {
@ -114,7 +117,7 @@ public class Http2ChannelInitializer extends ChannelInitializer<Channel>
}; };
Http2MultiplexCodecBuilder multiplexCodecBuilder = Http2MultiplexCodecBuilder.forServer(channelHandler) Http2MultiplexCodecBuilder multiplexCodecBuilder = Http2MultiplexCodecBuilder.forServer(channelHandler)
.initialSettings(Http2Settings.defaultSettings()); .initialSettings(Http2Settings.defaultSettings());
if (serverConfig.isTrafficDebug()) { if (serverConfig.isDebug()) {
multiplexCodecBuilder.frameLogger(new Http2FrameLogger(LogLevel.DEBUG, "server")); multiplexCodecBuilder.frameLogger(new Http2FrameLogger(LogLevel.DEBUG, "server"));
} }
Http2MultiplexCodec multiplexCodec = multiplexCodecBuilder.build(); Http2MultiplexCodec multiplexCodec = multiplexCodecBuilder.build();
@ -159,7 +162,6 @@ public class Http2ChannelInitializer extends ChannelInitializer<Channel>
@Override @Override
public void userEventTriggered(ChannelHandlerContext ctx, Object evt) { public void userEventTriggered(ChannelHandlerContext ctx, Object evt) {
ServerTransport transport = ctx.channel().attr(ServerTransport.TRANSPORT_ATTRIBUTE_KEY).get();
ctx.fireUserEventTriggered(evt); 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.HttpResponseStatus;
import io.netty.handler.codec.http.HttpVersion; import io.netty.handler.codec.http.HttpVersion;
import org.xbib.netty.http.server.Server; 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.ServerRequest;
import org.xbib.netty.http.server.api.ServerResponse; import org.xbib.netty.http.server.api.ServerResponse;
import org.xbib.netty.http.server.api.ServerTransport; import org.xbib.netty.http.server.api.ServerTransport;
@ -39,7 +39,7 @@ abstract class BaseTransport implements ServerTransport {
* @param serverResponse the response * @param serverResponse the response
* @return whether further processing should be performed * @return whether further processing should be performed
*/ */
static boolean acceptRequest(ServerConfig serverConfig, static boolean acceptRequest(DefaultServerConfig serverConfig,
ServerRequest serverRequest, ServerRequest serverRequest,
ServerResponse serverResponse) { ServerResponse serverResponse) {
HttpVersion version = serverConfig.getAddress().getVersion(); 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.http.HttpResponseStatus;
import io.netty.handler.codec.http2.Http2Settings; import io.netty.handler.codec.http2.Http2Settings;
import io.netty.handler.codec.http2.HttpConversionUtil; 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.Server;
import org.xbib.netty.http.server.api.ServerResponse; import org.xbib.netty.http.server.api.ServerResponse;
@ -29,6 +30,10 @@ public class Http2Transport extends BaseTransport {
serverRequest.setSequenceId(sequenceId); serverRequest.setSequenceId(sequenceId);
serverRequest.setRequestId(server.getRequestCounter().incrementAndGet()); serverRequest.setRequestId(server.getRequestCounter().incrementAndGet());
serverRequest.setStreamId(fullHttpRequest.headers().getInt(HttpConversionUtil.ExtensionHeaderNames.STREAM_ID.text())); 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); ServerResponse serverResponse = new Http2ServerResponse(server, serverRequest, ctx);
if (acceptRequest(server.getServerConfig(), serverRequest, serverResponse)) { if (acceptRequest(server.getServerConfig(), serverRequest, serverResponse)) {
serverRequest.handleParameters(); 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.common.HttpAddress;
import org.xbib.netty.http.server.Server; import org.xbib.netty.http.server.Server;
import org.xbib.netty.http.server.api.ServerResponse; 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.io.IOException;
import java.net.BindException; import java.net.BindException;
@ -18,7 +18,7 @@ class BindExceptionTest {
@Test @Test
void testDoubleServer() throws IOException { 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")) .singleEndpoint("/", (request, response) -> ServerResponse.write(response, "Hello World"))
.build(); .build();
Server server1 = Server.builder(domain).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.junit.jupiter.api.extension.ExtendWith;
import org.xbib.net.URL; import org.xbib.net.URL;
import org.xbib.netty.http.common.HttpAddress; 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.Server;
import org.xbib.netty.http.server.api.ServerRequest; import org.xbib.netty.http.server.api.ServerRequest;
import org.xbib.netty.http.server.endpoint.HttpEndpoint; import org.xbib.netty.http.server.endpoint.HttpEndpoint;
@ -35,10 +35,10 @@ public class ContextURLTest {
.setDispatcher((endpoint, serverRequest, serverResponse) -> {}) .setDispatcher((endpoint, serverRequest, serverResponse) -> {})
.build(); .build();
Domain one = Domain.builder(httpAddress, "domain.one:8008") HttpServerDomain one = HttpServerDomain.builder(httpAddress, "domain.one:8008")
.addEndpointResolver(endpointResolver1) .addEndpointResolver(endpointResolver1)
.build(); .build();
Domain two = Domain.builder(one) HttpServerDomain two = HttpServerDomain.builder(one)
.setServerName("domain.two:8008") .setServerName("domain.two:8008")
.addEndpointResolver(endpointResolver2) .addEndpointResolver(endpointResolver2)
.addEndpointResolver(endpointResolver3) .addEndpointResolver(endpointResolver3)
@ -49,27 +49,27 @@ public class ContextURLTest {
.build(); .build();
URL url0 = server.getContextURL(); 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"); DefaultFullHttpRequest fullHttpRequest1 = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, "/one");
fullHttpRequest1.headers().add("host", "domain.one:8008"); fullHttpRequest1.headers().add("host", "domain.one:8008");
ServerRequest serverRequest1 = new HttpServerRequest(fullHttpRequest1); ServerRequest serverRequest1 = new HttpServerRequest(fullHttpRequest1);
URL url1 = server.getContextURL(serverRequest1); URL url1 = server.getContextURL(serverRequest1);
assertEquals("domain.one", url1.getHost()); assertEquals("domain.one", url1.getHost());
assertEquals("/one", url1.getPath()); assertEquals("/one/", url1.getPath());
DefaultFullHttpRequest fullHttpRequest2 = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, "/two"); DefaultFullHttpRequest fullHttpRequest2 = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, "/two");
fullHttpRequest2.headers().add("host", "domain.two:8008"); fullHttpRequest2.headers().add("host", "domain.two:8008");
ServerRequest serverRequest2 = new HttpServerRequest(fullHttpRequest2); ServerRequest serverRequest2 = new HttpServerRequest(fullHttpRequest2);
URL url2 = server.getContextURL(serverRequest2); URL url2 = server.getContextURL(serverRequest2);
assertEquals("domain.two", url2.getHost()); assertEquals("domain.two", url2.getHost());
assertEquals("/two", url2.getPath()); assertEquals("/two/", url2.getPath());
DefaultFullHttpRequest fullHttpRequest3 = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, "/three"); DefaultFullHttpRequest fullHttpRequest3 = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, "/three");
fullHttpRequest3.headers().add("host", "domain.two:8008"); fullHttpRequest3.headers().add("host", "domain.two:8008");
ServerRequest serverRequest3 = new HttpServerRequest(fullHttpRequest3); ServerRequest serverRequest3 = new HttpServerRequest(fullHttpRequest3);
URL url3 = server.getContextURL(serverRequest3); URL url3 = server.getContextURL(serverRequest3);
assertEquals("domain.two", url3.getHost()); 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.Client;
import org.xbib.netty.http.client.api.Request; import org.xbib.netty.http.client.api.Request;
import org.xbib.netty.http.common.HttpAddress; 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.Server;
import org.xbib.netty.http.server.api.ServerResponse; import org.xbib.netty.http.server.api.ServerResponse;
import java.io.InputStream; import java.io.InputStream;
@ -32,12 +32,12 @@ class MultiDomainSecureServerTest {
return; return;
} }
HttpAddress httpAddress = HttpAddress.secureHttp2("localhost", 8443); 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) .setKeyCertChain(certInputStream)
.setKey(keyInputStream, null) .setKey(keyInputStream, null)
.singleEndpoint("/", (request, response) -> ServerResponse.write(response, "Hello fl.hbz-nrw.de")) .singleEndpoint("/", (request, response) -> ServerResponse.write(response, "Hello fl.hbz-nrw.de"))
.build(); .build();
Domain zfl2 = Domain.builder(fl) HttpServerDomain zfl2 = HttpServerDomain.builder(fl)
.setServerName("zfl2.hbz-nrw.de") .setServerName("zfl2.hbz-nrw.de")
.singleEndpoint("/", (request, response) -> ServerResponse.write(response, "Hello zfl2.hbz-nrw.de")) .singleEndpoint("/", (request, response) -> ServerResponse.write(response, "Hello zfl2.hbz-nrw.de"))
.build(); .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.common.HttpAddress;
import org.xbib.netty.http.server.Server; import org.xbib.netty.http.server.Server;
import org.xbib.netty.http.server.api.ServerResponse; 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.nio.charset.StandardCharsets;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
@ -23,10 +23,10 @@ class MultiDomainServerTest {
@Test @Test
void testServer() throws Exception { void testServer() throws Exception {
HttpAddress httpAddress = HttpAddress.http1("localhost", 8008); 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")) .singleEndpoint("/", (request, response) -> ServerResponse.write(response, "Hello fl.hbz-nrw.de"))
.build(); .build();
Domain zfl2 = Domain.builder(fl) HttpServerDomain zfl2 = HttpServerDomain.builder(fl)
.setServerName("zfl2.hbz-nrw.de") .setServerName("zfl2.hbz-nrw.de")
.singleEndpoint("/", (request, response) -> ServerResponse.write(response, "Hello zfl2.hbz-nrw.de")) .singleEndpoint("/", (request, response) -> ServerResponse.write(response, "Hello zfl2.hbz-nrw.de"))
.build(); .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.common.HttpAddress;
import org.xbib.netty.http.server.Server; import org.xbib.netty.http.server.Server;
import org.xbib.netty.http.server.api.ServerResponse; 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.io.IOException;
import java.util.Set; import java.util.Set;
@ -23,7 +23,7 @@ class ThreadLeakTest {
@Test @Test
void testForLeaks() throws IOException { 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")) .singleEndpoint("/", (request, response) -> ServerResponse.write(response, "Hello World"))
.build(); .build();
Server server = Server.builder(domain) 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.client.api.ClientTransport;
import org.xbib.netty.http.common.HttpAddress; import org.xbib.netty.http.common.HttpAddress;
import org.xbib.netty.http.common.HttpResponse; 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.Server;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicInteger;
@ -26,7 +26,7 @@ class TransportLayerSecurityServerTest {
@Test @Test
void testTLS12() throws Exception { void testTLS12() throws Exception {
HttpAddress httpAddress = HttpAddress.secureHttp1("localhost", 8143); HttpAddress httpAddress = HttpAddress.secureHttp1("localhost", 8143);
Server server = Server.builder(Domain.builder(httpAddress) Server server = Server.builder(HttpServerDomain.builder(httpAddress)
.setSelfCert() .setSelfCert()
.singleEndpoint("/", (request, response) -> .singleEndpoint("/", (request, response) ->
response.withStatus(HttpResponseStatus.OK) response.withStatus(HttpResponseStatus.OK)
@ -64,7 +64,7 @@ class TransportLayerSecurityServerTest {
@Test @Test
void testTLS13() throws Exception { void testTLS13() throws Exception {
HttpAddress httpAddress = HttpAddress.secureHttp2("localhost", 8143); HttpAddress httpAddress = HttpAddress.secureHttp2("localhost", 8143);
Server server = Server.builder(Domain.builder(httpAddress) Server server = Server.builder(HttpServerDomain.builder(httpAddress)
.setSelfCert() .setSelfCert()
.singleEndpoint("/", (request, response) -> .singleEndpoint("/", (request, response) ->
response.withStatus(HttpResponseStatus.OK) 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.client.api.Request;
import org.xbib.netty.http.common.HttpAddress; import org.xbib.netty.http.common.HttpAddress;
import org.xbib.netty.http.server.Server; 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.endpoint.service.ClassLoaderService;
import org.xbib.netty.http.server.test.NettyHttpTestExtension; import org.xbib.netty.http.server.test.NettyHttpTestExtension;
@ -27,7 +27,7 @@ class ClassloaderServiceTest {
@Test @Test
void testClassloaderFileResource() throws Exception { void testClassloaderFileResource() throws Exception {
HttpAddress httpAddress = HttpAddress.http1("localhost", 8008); HttpAddress httpAddress = HttpAddress.http1("localhost", 8008);
Domain domain = Domain.builder(httpAddress) HttpServerDomain domain = HttpServerDomain.builder(httpAddress)
.singleEndpoint("/classloader", "/**", .singleEndpoint("/classloader", "/**",
new ClassLoaderService(ClassloaderServiceTest.class, "/cl")) new ClassLoaderService(ClassloaderServiceTest.class, "/cl"))
.build(); .build();
@ -65,7 +65,7 @@ class ClassloaderServiceTest {
@Test @Test
void testClassloaderDirectoryResource() throws Exception { void testClassloaderDirectoryResource() throws Exception {
HttpAddress httpAddress = HttpAddress.http1("localhost", 8008); HttpAddress httpAddress = HttpAddress.http1("localhost", 8008);
Domain domain = Domain.builder(httpAddress) HttpServerDomain domain = HttpServerDomain.builder(httpAddress)
.singleEndpoint("/classloader", "/**", .singleEndpoint("/classloader", "/**",
new ClassLoaderService(ClassloaderServiceTest.class, "/cl")) new ClassLoaderService(ClassloaderServiceTest.class, "/cl"))
.build(); .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.api.ServerResponse;
import org.xbib.netty.http.server.endpoint.HttpEndpoint; import org.xbib.netty.http.server.endpoint.HttpEndpoint;
import org.xbib.netty.http.server.endpoint.HttpEndpointResolver; 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.endpoint.service.FileService;
import org.xbib.netty.http.server.test.NettyHttpTestExtension; import org.xbib.netty.http.server.test.NettyHttpTestExtension;
@ -46,7 +46,7 @@ class EndpointTest {
fileService.handle(req, resp); fileService.handle(req, resp);
}) })
.build(); .build();
Domain domain = Domain.builder(httpAddress) HttpServerDomain domain = HttpServerDomain.builder(httpAddress)
.addEndpointResolver(httpEndpointResolver) .addEndpointResolver(httpEndpointResolver)
.build(); .build();
Server server = Server.builder(domain) Server server = Server.builder(domain)
@ -87,7 +87,7 @@ class EndpointTest {
fileService.handle(req, resp); fileService.handle(req, resp);
}) })
.build(); .build();
Domain domain = Domain.builder(httpAddress) HttpServerDomain domain = HttpServerDomain.builder(httpAddress)
.addEndpointResolver(httpEndpointResolver) .addEndpointResolver(httpEndpointResolver)
.build(); .build();
Server server = Server.builder(domain) Server server = Server.builder(domain)
@ -130,7 +130,7 @@ class EndpointTest {
fileService.handle(req, resp); fileService.handle(req, resp);
}) })
.build(); .build();
Domain domain = Domain.builder(httpAddress) HttpServerDomain domain = HttpServerDomain.builder(httpAddress)
.addEndpointResolver(httpEndpointResolver) .addEndpointResolver(httpEndpointResolver)
.build(); .build();
Server server = Server.builder(domain) Server server = Server.builder(domain)
@ -196,7 +196,7 @@ class EndpointTest {
fileService.handle(req, resp); fileService.handle(req, resp);
}) })
.build(); .build();
Domain domain = Domain.builder(httpAddress) HttpServerDomain domain = HttpServerDomain.builder(httpAddress)
.addEndpointResolver(httpEndpointResolver) .addEndpointResolver(httpEndpointResolver)
.build(); .build();
Server server = Server.builder(domain) Server server = Server.builder(domain)
@ -293,7 +293,7 @@ class EndpointTest {
fileService3.handle(req, resp); fileService3.handle(req, resp);
}) })
.build(); .build();
Domain domain = Domain.builder(httpAddress) HttpServerDomain domain = HttpServerDomain.builder(httpAddress)
.addEndpointResolver(httpEndpointResolver1) .addEndpointResolver(httpEndpointResolver1)
.addEndpointResolver(httpEndpointResolver2) .addEndpointResolver(httpEndpointResolver2)
.addEndpointResolver(httpEndpointResolver3) .addEndpointResolver(httpEndpointResolver3)
@ -376,7 +376,7 @@ class EndpointTest {
.setPath("/" + i + "/**") .setPath("/" + i + "/**")
.build()); .build());
} }
Domain domain = Domain.builder(httpAddress) HttpServerDomain domain = HttpServerDomain.builder(httpAddress)
.addEndpointResolver(endpointResolverBuilder .addEndpointResolver(endpointResolverBuilder
.setDispatcher((endpoint,req, resp) -> ServerResponse.write(resp, HttpResponseStatus.OK)) .setDispatcher((endpoint,req, resp) -> ServerResponse.write(resp, HttpResponseStatus.OK))
.build()) .build())
@ -415,7 +415,7 @@ class EndpointTest {
HttpAddress httpAddress = HttpAddress.http1("localhost", 8008); HttpAddress httpAddress = HttpAddress.http1("localhost", 8008);
HttpEndpointResolver.Builder endpointResolverBuilder = HttpEndpointResolver.builder() HttpEndpointResolver.Builder endpointResolverBuilder = HttpEndpointResolver.builder()
.setPrefix("/static"); .setPrefix("/static");
Domain.Builder domainBuilder = Domain.builder(httpAddress); HttpServerDomain.Builder domainBuilder = HttpServerDomain.builder(httpAddress);
for (int i = 0; i < max; i++) { for (int i = 0; i < max; i++) {
domainBuilder.addEndpointResolver(endpointResolverBuilder.addEndpoint(HttpEndpoint.builder() domainBuilder.addEndpointResolver(endpointResolverBuilder.addEndpoint(HttpEndpoint.builder()
.setPath("/" + i + "/**").build()) .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.client.api.Request;
import org.xbib.netty.http.common.HttpAddress; import org.xbib.netty.http.common.HttpAddress;
import org.xbib.netty.http.server.Server; 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.endpoint.service.FileService;
import org.xbib.netty.http.server.test.NettyHttpTestExtension; import org.xbib.netty.http.server.test.NettyHttpTestExtension;
@ -32,7 +32,7 @@ class FileServiceTest {
void testFileServiceHttp1() throws Exception { void testFileServiceHttp1() throws Exception {
Path vartmp = Paths.get("/var/tmp/"); Path vartmp = Paths.get("/var/tmp/");
HttpAddress httpAddress = HttpAddress.http1("localhost", 8008); HttpAddress httpAddress = HttpAddress.http1("localhost", 8008);
Domain domain = Domain.builder(httpAddress) HttpServerDomain domain = HttpServerDomain.builder(httpAddress)
.singleEndpoint("/static", "/**", new FileService(vartmp)) .singleEndpoint("/static", "/**", new FileService(vartmp))
.build(); .build();
Server server = Server.builder(domain) Server server = Server.builder(domain)
@ -65,7 +65,7 @@ class FileServiceTest {
void testFileServiceHttp2() throws Exception { void testFileServiceHttp2() throws Exception {
Path vartmp = Paths.get("/var/tmp/"); Path vartmp = Paths.get("/var/tmp/");
HttpAddress httpAddress = HttpAddress.http2("localhost", 8008); HttpAddress httpAddress = HttpAddress.http2("localhost", 8008);
Domain domain = Domain.builder(httpAddress) HttpServerDomain domain = HttpServerDomain.builder(httpAddress)
.singleEndpoint("/static", "/**", new FileService(vartmp)) .singleEndpoint("/static", "/**", new FileService(vartmp))
.build(); .build();
Server server = Server.builder(domain) Server server = Server.builder(domain)
@ -101,7 +101,7 @@ class FileServiceTest {
Files.createDirectories(vartmpforward); Files.createDirectories(vartmpforward);
Files.write(vartmpforward.resolve("test.txt"), "Hello Jörg".getBytes(StandardCharsets.UTF_8)); Files.write(vartmpforward.resolve("test.txt"), "Hello Jörg".getBytes(StandardCharsets.UTF_8));
HttpAddress httpAddress = HttpAddress.http1("localhost", 8008); HttpAddress httpAddress = HttpAddress.http1("localhost", 8008);
Domain domain = Domain.builder(httpAddress) HttpServerDomain domain = HttpServerDomain.builder(httpAddress)
.singleEndpoint("/static", "/**", new FileService(vartmp, "test.txt")) .singleEndpoint("/static", "/**", new FileService(vartmp, "test.txt"))
.build(); .build();
Server server = Server.builder(domain) Server server = Server.builder(domain)
@ -138,7 +138,7 @@ class FileServiceTest {
Files.createDirectories(vartmpforward); Files.createDirectories(vartmpforward);
Files.write(vartmpforward.resolve("test.txt"), "Hello Jörg".getBytes(StandardCharsets.UTF_8)); Files.write(vartmpforward.resolve("test.txt"), "Hello Jörg".getBytes(StandardCharsets.UTF_8));
HttpAddress httpAddress = HttpAddress.http2("localhost", 8008); HttpAddress httpAddress = HttpAddress.http2("localhost", 8008);
Domain domain = Domain.builder(httpAddress) HttpServerDomain domain = HttpServerDomain.builder(httpAddress)
.singleEndpoint("/static", "/**", new FileService(vartmp, "test.txt")) .singleEndpoint("/static", "/**", new FileService(vartmp, "test.txt"))
.build(); .build();
Server server = Server.builder(domain) Server server = Server.builder(domain)
@ -178,7 +178,7 @@ class FileServiceTest {
Files.createDirectories(vartmpforward); Files.createDirectories(vartmpforward);
Files.write(vartmpforward.resolve("test.txt"), "Hello Jörg".getBytes(StandardCharsets.UTF_8)); Files.write(vartmpforward.resolve("test.txt"), "Hello Jörg".getBytes(StandardCharsets.UTF_8));
HttpAddress httpAddress = HttpAddress.http1("localhost", 8008); HttpAddress httpAddress = HttpAddress.http1("localhost", 8008);
Domain domain = Domain.builder(httpAddress) HttpServerDomain domain = HttpServerDomain.builder(httpAddress)
.singleEndpoint("/static", "/**", .singleEndpoint("/static", "/**",
new FileService(vartmp, "test.txt")) new FileService(vartmp, "test.txt"))
.build(); .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.client.api.Request;
import org.xbib.netty.http.common.HttpAddress; import org.xbib.netty.http.common.HttpAddress;
import org.xbib.netty.http.server.Server; 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.endpoint.service.FileService;
import org.xbib.netty.http.server.test.NettyHttpTestExtension; import org.xbib.netty.http.server.test.NettyHttpTestExtension;
@ -32,7 +32,7 @@ class SecureFileServiceTest {
void testSecureFileServerHttp1() throws Exception { void testSecureFileServerHttp1() throws Exception {
Path vartmp = Paths.get("/var/tmp/"); Path vartmp = Paths.get("/var/tmp/");
HttpAddress httpAddress = HttpAddress.secureHttp1("localhost", 8143); HttpAddress httpAddress = HttpAddress.secureHttp1("localhost", 8143);
Server server = Server.builder(Domain.builder(httpAddress, "*") Server server = Server.builder(HttpServerDomain.builder(httpAddress, "*")
.setJdkSslProvider() .setJdkSslProvider()
.setSelfCert() .setSelfCert()
.singleEndpoint("/static", "/**", new FileService(vartmp)) .singleEndpoint("/static", "/**", new FileService(vartmp))
@ -68,7 +68,7 @@ class SecureFileServiceTest {
void testSecureFileServerHttp2() throws Exception { void testSecureFileServerHttp2() throws Exception {
Path vartmp = Paths.get("/var/tmp/"); Path vartmp = Paths.get("/var/tmp/");
HttpAddress httpAddress = HttpAddress.secureHttp2("localhost", 8143); HttpAddress httpAddress = HttpAddress.secureHttp2("localhost", 8143);
Server server = Server.builder(Domain.builder(httpAddress, "*") Server server = Server.builder(HttpServerDomain.builder(httpAddress, "*")
.setOpenSSLSslProvider() .setOpenSSLSslProvider()
//.setJdkSslProvider() //.setJdkSslProvider()
.setSelfCert() .setSelfCert()
@ -112,7 +112,7 @@ class SecureFileServiceTest {
void testSecureFileServerMixHttp1Http2() throws Exception { void testSecureFileServerMixHttp1Http2() throws Exception {
Path vartmp = Paths.get("/var/tmp/"); Path vartmp = Paths.get("/var/tmp/");
HttpAddress httpAddress = HttpAddress.secureHttp2("localhost", 8143); HttpAddress httpAddress = HttpAddress.secureHttp2("localhost", 8143);
Server server = Server.builder(Domain.builder(httpAddress, "*") Server server = Server.builder(HttpServerDomain.builder(httpAddress, "*")
.setOpenSSLSslProvider() .setOpenSSLSslProvider()
.setSelfCert() .setSelfCert()
.singleEndpoint("/static", "/**", new FileService(vartmp)) .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.HttpAddress;
import org.xbib.netty.http.common.HttpResponse; import org.xbib.netty.http.common.HttpResponse;
import org.xbib.netty.http.server.Server; 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.api.ServerResponse;
import org.xbib.netty.http.server.test.NettyHttpTestExtension; import org.xbib.netty.http.server.test.NettyHttpTestExtension;
@ -33,7 +33,7 @@ class CleartextTest {
@Test @Test
void testSimpleClearTextHttp1() throws Exception { void testSimpleClearTextHttp1() throws Exception {
HttpAddress httpAddress = HttpAddress.http1("localhost", 8008); HttpAddress httpAddress = HttpAddress.http1("localhost", 8008);
Domain domain = Domain.builder(httpAddress) HttpServerDomain domain = HttpServerDomain.builder(httpAddress)
.singleEndpoint("/**", (request, response) -> .singleEndpoint("/**", (request, response) ->
ServerResponse.write(response, HttpResponseStatus.OK, "text/plain", ServerResponse.write(response, HttpResponseStatus.OK, "text/plain",
request.getContent().toString(StandardCharsets.UTF_8))) request.getContent().toString(StandardCharsets.UTF_8)))
@ -67,7 +67,7 @@ class CleartextTest {
void testPooledClearTextHttp1() throws Exception { void testPooledClearTextHttp1() throws Exception {
int loop = 1; int loop = 1;
HttpAddress httpAddress = HttpAddress.http1("localhost", 8008); HttpAddress httpAddress = HttpAddress.http1("localhost", 8008);
Domain domain = Domain.builder(httpAddress) HttpServerDomain domain = HttpServerDomain.builder(httpAddress)
.singleEndpoint("/**", (request, response) -> .singleEndpoint("/**", (request, response) ->
ServerResponse.write(response, HttpResponseStatus.OK, "text/plain", ServerResponse.write(response, HttpResponseStatus.OK, "text/plain",
request.getContent().toString(StandardCharsets.UTF_8))) request.getContent().toString(StandardCharsets.UTF_8)))
@ -112,7 +112,7 @@ class CleartextTest {
int threads = 4; int threads = 4;
int loop = 1024; int loop = 1024;
HttpAddress httpAddress = HttpAddress.http1("localhost", 8008); HttpAddress httpAddress = HttpAddress.http1("localhost", 8008);
Domain domain = Domain.builder(httpAddress) HttpServerDomain domain = HttpServerDomain.builder(httpAddress)
.singleEndpoint("/**", (request, response) -> .singleEndpoint("/**", (request, response) ->
ServerResponse.write(response, HttpResponseStatus.OK, "text/plain", ServerResponse.write(response, HttpResponseStatus.OK, "text/plain",
request.getContent().toString(StandardCharsets.UTF_8))) 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.HttpAddress;
import org.xbib.netty.http.common.HttpResponse; import org.xbib.netty.http.common.HttpResponse;
import org.xbib.netty.http.server.Server; 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 org.xbib.netty.http.server.test.NettyHttpTestExtension;
import java.io.IOException; import java.io.IOException;
@ -32,7 +32,7 @@ class EncryptedTest {
@Test @Test
void testSimpleSecureHttp1() throws Exception { void testSimpleSecureHttp1() throws Exception {
HttpAddress httpAddress = HttpAddress.secureHttp1("localhost", 8143); HttpAddress httpAddress = HttpAddress.secureHttp1("localhost", 8143);
Server server = Server.builder(Domain.builder(httpAddress) Server server = Server.builder(HttpServerDomain.builder(httpAddress)
.setSelfCert() .setSelfCert()
.singleEndpoint("/", (request, response) -> .singleEndpoint("/", (request, response) ->
response.withStatus(HttpResponseStatus.OK) response.withStatus(HttpResponseStatus.OK)
@ -63,7 +63,7 @@ class EncryptedTest {
void testPooledSecureHttp1() throws Exception { void testPooledSecureHttp1() throws Exception {
int loop = 4096; int loop = 4096;
HttpAddress httpAddress = HttpAddress.secureHttp1("localhost", 8143); HttpAddress httpAddress = HttpAddress.secureHttp1("localhost", 8143);
Server server = Server.builder(Domain.builder(httpAddress) Server server = Server.builder(HttpServerDomain.builder(httpAddress)
.setSelfCert() .setSelfCert()
.singleEndpoint("/", (request, response) -> .singleEndpoint("/", (request, response) ->
response.withStatus(HttpResponseStatus.OK) response.withStatus(HttpResponseStatus.OK)
@ -107,7 +107,7 @@ class EncryptedTest {
int threads = 4; int threads = 4;
int loop = 4 * 1024; int loop = 4 * 1024;
HttpAddress httpAddress = HttpAddress.secureHttp1("localhost", 8143); HttpAddress httpAddress = HttpAddress.secureHttp1("localhost", 8143);
Server server = Server.builder(Domain.builder(httpAddress) Server server = Server.builder(HttpServerDomain.builder(httpAddress)
.setSelfCert() .setSelfCert()
.singleEndpoint("/", (request, response) -> .singleEndpoint("/", (request, response) ->
response.withStatus(HttpResponseStatus.OK) 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.HttpAddress;
import org.xbib.netty.http.common.HttpParameters; import org.xbib.netty.http.common.HttpParameters;
import org.xbib.netty.http.common.HttpResponse; 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.Server;
import org.xbib.netty.http.server.test.NettyHttpTestExtension; import org.xbib.netty.http.server.test.NettyHttpTestExtension;
import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicBoolean;
@ -33,7 +33,7 @@ class FlushTest {
@Test @Test
void testFlushHttp1() throws Exception { void testFlushHttp1() throws Exception {
HttpAddress httpAddress = HttpAddress.http1("localhost", 8008); HttpAddress httpAddress = HttpAddress.http1("localhost", 8008);
Domain domain = Domain.builder(httpAddress) HttpServerDomain domain = HttpServerDomain.builder(httpAddress)
.singleEndpoint("/flush", "/**", (req, resp) -> { .singleEndpoint("/flush", "/**", (req, resp) -> {
HttpParameters parameters = req.getParameters(); HttpParameters parameters = req.getParameters();
logger.log(Level.INFO, "got request " + parameters.toString() + ", sending 302 Found"); 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.HttpAddress;
import org.xbib.netty.http.common.HttpParameters; import org.xbib.netty.http.common.HttpParameters;
import org.xbib.netty.http.common.HttpResponse; 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.Server;
import org.xbib.netty.http.server.api.ServerResponse; import org.xbib.netty.http.server.api.ServerResponse;
import org.xbib.netty.http.server.test.NettyHttpTestExtension; import org.xbib.netty.http.server.test.NettyHttpTestExtension;
@ -33,7 +33,7 @@ class MimeUploadTest {
void testMimetHttp1() throws Exception { void testMimetHttp1() throws Exception {
final AtomicBoolean success1 = new AtomicBoolean(false); final AtomicBoolean success1 = new AtomicBoolean(false);
HttpAddress httpAddress = HttpAddress.http1("localhost", 8008); HttpAddress httpAddress = HttpAddress.http1("localhost", 8008);
Domain domain = Domain.builder(httpAddress) HttpServerDomain domain = HttpServerDomain.builder(httpAddress)
.singleEndpoint("/upload", "/**", (req, resp) -> { .singleEndpoint("/upload", "/**", (req, resp) -> {
HttpParameters parameters = req.getParameters(); HttpParameters parameters = req.getParameters();
logger.log(Level.INFO, "got request, headers = " + req.getHeaders() + 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.HttpAddress;
import org.xbib.netty.http.common.HttpParameters; import org.xbib.netty.http.common.HttpParameters;
import org.xbib.netty.http.common.HttpResponse; 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.Server;
import org.xbib.netty.http.server.api.ServerResponse; import org.xbib.netty.http.server.api.ServerResponse;
import org.xbib.netty.http.server.test.NettyHttpTestExtension; import org.xbib.netty.http.server.test.NettyHttpTestExtension;
@ -32,7 +32,7 @@ class PostTest {
final AtomicBoolean success2 = new AtomicBoolean(false); final AtomicBoolean success2 = new AtomicBoolean(false);
final AtomicBoolean success3 = new AtomicBoolean(false); final AtomicBoolean success3 = new AtomicBoolean(false);
HttpAddress httpAddress = HttpAddress.http1("localhost", 8008); HttpAddress httpAddress = HttpAddress.http1("localhost", 8008);
Domain domain = Domain.builder(httpAddress) HttpServerDomain domain = HttpServerDomain.builder(httpAddress)
.singleEndpoint("/post", "/**", (req, resp) -> { .singleEndpoint("/post", "/**", (req, resp) -> {
HttpParameters parameters = req.getParameters(); HttpParameters parameters = req.getParameters();
logger.log(Level.INFO, "got request " + parameters.toString() + ", sending OK"); logger.log(Level.INFO, "got request " + parameters.toString() + ", sending OK");
@ -82,7 +82,7 @@ class PostTest {
final AtomicBoolean success2 = new AtomicBoolean(false); final AtomicBoolean success2 = new AtomicBoolean(false);
final AtomicBoolean success3 = new AtomicBoolean(false); final AtomicBoolean success3 = new AtomicBoolean(false);
HttpAddress httpAddress = HttpAddress.http1("localhost", 8008); HttpAddress httpAddress = HttpAddress.http1("localhost", 8008);
Domain domain = Domain.builder(httpAddress) HttpServerDomain domain = HttpServerDomain.builder(httpAddress)
.singleEndpoint("/post", "/**", (req, resp) -> { .singleEndpoint("/post", "/**", (req, resp) -> {
HttpParameters parameters = req.getParameters(); HttpParameters parameters = req.getParameters();
logger.log(Level.INFO, "got request " + parameters.toString() + ", sending OK"); logger.log(Level.INFO, "got request " + parameters.toString() + ", sending OK");
@ -133,7 +133,7 @@ class PostTest {
final AtomicBoolean success3 = new AtomicBoolean(false); final AtomicBoolean success3 = new AtomicBoolean(false);
final AtomicBoolean success4 = new AtomicBoolean(false); final AtomicBoolean success4 = new AtomicBoolean(false);
HttpAddress httpAddress = HttpAddress.http1("localhost", 8008); HttpAddress httpAddress = HttpAddress.http1("localhost", 8008);
Domain domain = Domain.builder(httpAddress) HttpServerDomain domain = HttpServerDomain.builder(httpAddress)
.singleEndpoint("/post", "/**", (req, resp) -> { .singleEndpoint("/post", "/**", (req, resp) -> {
HttpParameters parameters = req.getParameters(); HttpParameters parameters = req.getParameters();
logger.log(Level.INFO, "got request " + parameters.toString() + ", sending OK"); logger.log(Level.INFO, "got request " + parameters.toString() + ", sending OK");
@ -190,7 +190,7 @@ class PostTest {
final AtomicBoolean success3 = new AtomicBoolean(false); final AtomicBoolean success3 = new AtomicBoolean(false);
final AtomicBoolean success4 = new AtomicBoolean(false); final AtomicBoolean success4 = new AtomicBoolean(false);
HttpAddress httpAddress = HttpAddress.http1("localhost", 8008); HttpAddress httpAddress = HttpAddress.http1("localhost", 8008);
Domain domain = Domain.builder(httpAddress) HttpServerDomain domain = HttpServerDomain.builder(httpAddress)
.singleEndpoint("/post", "/**", (req, resp) -> { .singleEndpoint("/post", "/**", (req, resp) -> {
HttpParameters parameters = req.getParameters(); HttpParameters parameters = req.getParameters();
logger.log(Level.INFO, "got request " + parameters.toString() + ", sending OK"); logger.log(Level.INFO, "got request " + parameters.toString() + ", sending OK");
@ -247,7 +247,7 @@ class PostTest {
final AtomicBoolean success2 = new AtomicBoolean(false); final AtomicBoolean success2 = new AtomicBoolean(false);
final AtomicBoolean success3 = new AtomicBoolean(false); final AtomicBoolean success3 = new AtomicBoolean(false);
HttpAddress httpAddress = HttpAddress.http1("localhost", 8008); HttpAddress httpAddress = HttpAddress.http1("localhost", 8008);
Domain domain = Domain.builder(httpAddress) HttpServerDomain domain = HttpServerDomain.builder(httpAddress)
.singleEndpoint("/post", "/**", (req, resp) -> { .singleEndpoint("/post", "/**", (req, resp) -> {
HttpParameters parameters = req.getParameters(); HttpParameters parameters = req.getParameters();
logger.log(Level.INFO, "got request " + parameters.toString() + ", sending OK"); 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.client.api.ResponseListener;
import org.xbib.netty.http.common.HttpAddress; import org.xbib.netty.http.common.HttpAddress;
import org.xbib.netty.http.common.HttpResponse; 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.Server;
import org.xbib.netty.http.server.api.ServerResponse; import org.xbib.netty.http.server.api.ServerResponse;
import org.xbib.netty.http.server.test.NettyHttpTestExtension; import org.xbib.netty.http.server.test.NettyHttpTestExtension;
@ -32,7 +32,7 @@ class PutTest {
final AtomicBoolean success1 = new AtomicBoolean(false); final AtomicBoolean success1 = new AtomicBoolean(false);
final AtomicBoolean success2 = new AtomicBoolean(false); final AtomicBoolean success2 = new AtomicBoolean(false);
HttpAddress httpAddress = HttpAddress.http1("localhost", 8008); HttpAddress httpAddress = HttpAddress.http1("localhost", 8008);
Domain domain = Domain.builder(httpAddress) HttpServerDomain domain = HttpServerDomain.builder(httpAddress)
.singleEndpoint("/put", "/**", (req, resp) -> { .singleEndpoint("/put", "/**", (req, resp) -> {
logger.log(Level.INFO, "got request " + logger.log(Level.INFO, "got request " +
req.getContent().toString(StandardCharsets.UTF_8)); req.getContent().toString(StandardCharsets.UTF_8));
@ -80,7 +80,7 @@ class PutTest {
outputStream.write(1); outputStream.write(1);
} }
HttpAddress httpAddress = HttpAddress.http1("localhost", 8008); HttpAddress httpAddress = HttpAddress.http1("localhost", 8008);
Domain domain = Domain.builder(httpAddress) HttpServerDomain domain = HttpServerDomain.builder(httpAddress)
.singleEndpoint("/put", "/**", (req, resp) -> { .singleEndpoint("/put", "/**", (req, resp) -> {
logger.log(Level.INFO, "got request, length = " + logger.log(Level.INFO, "got request, length = " +
req.getContent().readableBytes()); 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.Client;
import org.xbib.netty.http.client.api.Request; import org.xbib.netty.http.client.api.Request;
import org.xbib.netty.http.common.HttpAddress; 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.Server;
import org.xbib.netty.http.server.test.NettyHttpTestExtension; import org.xbib.netty.http.server.test.NettyHttpTestExtension;
@ -24,7 +24,7 @@ class StreamTest {
@Test @Test
void testServerBodyInputStreamHttp1() throws Exception { void testServerBodyInputStreamHttp1() throws Exception {
HttpAddress httpAddress = HttpAddress.http1("localhost", 8008); HttpAddress httpAddress = HttpAddress.http1("localhost", 8008);
Domain domain = Domain.builder(httpAddress) HttpServerDomain domain = HttpServerDomain.builder(httpAddress)
.singleEndpoint("/", (request, response) -> { .singleEndpoint("/", (request, response) -> {
ByteBufInputStream inputStream = request.getInputStream(); ByteBufInputStream inputStream = request.getInputStream();
String content = inputStream.readLine(); 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.common.HttpResponse;
import org.xbib.netty.http.server.Server; import org.xbib.netty.http.server.Server;
import org.xbib.netty.http.server.api.ServerResponse; 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 org.xbib.netty.http.server.test.NettyHttpTestExtension;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
@ -32,7 +32,7 @@ class CleartextTest {
@Test @Test
void testSimpleCleartextHttp2() throws Exception { void testSimpleCleartextHttp2() throws Exception {
HttpAddress httpAddress = HttpAddress.http2("localhost", 8008); HttpAddress httpAddress = HttpAddress.http2("localhost", 8008);
Domain domain = Domain.builder(httpAddress) HttpServerDomain domain = HttpServerDomain.builder(httpAddress)
.singleEndpoint("/", (request, response) -> .singleEndpoint("/", (request, response) ->
ServerResponse.write(response, HttpResponseStatus.OK, "text.plain", ServerResponse.write(response, HttpResponseStatus.OK, "text.plain",
request.getContent().toString(StandardCharsets.UTF_8))) request.getContent().toString(StandardCharsets.UTF_8)))
@ -77,7 +77,7 @@ class CleartextTest {
void testPooledClearTextHttp2() throws Exception { void testPooledClearTextHttp2() throws Exception {
int loop = 1024; int loop = 1024;
HttpAddress httpAddress = HttpAddress.http2("localhost", 8008); HttpAddress httpAddress = HttpAddress.http2("localhost", 8008);
Domain domain = Domain.builder(httpAddress) HttpServerDomain domain = HttpServerDomain.builder(httpAddress)
.singleEndpoint("/", (request, response) -> .singleEndpoint("/", (request, response) ->
response.withStatus(HttpResponseStatus.OK) response.withStatus(HttpResponseStatus.OK)
.withContentType("text/plain") .withContentType("text/plain")
@ -129,7 +129,7 @@ class CleartextTest {
int threads = 4; int threads = 4;
int loop = 1024; int loop = 1024;
HttpAddress httpAddress = HttpAddress.http2("localhost", 8008); HttpAddress httpAddress = HttpAddress.http2("localhost", 8008);
Domain domain = Domain.builder(httpAddress) HttpServerDomain domain = HttpServerDomain.builder(httpAddress)
.singleEndpoint("/**", (request, response) -> .singleEndpoint("/**", (request, response) ->
ServerResponse.write(response, HttpResponseStatus.OK, "text/plain", ServerResponse.write(response, HttpResponseStatus.OK, "text/plain",
request.getContent().toString(StandardCharsets.UTF_8))) request.getContent().toString(StandardCharsets.UTF_8)))
@ -198,7 +198,7 @@ class CleartextTest {
int loop = 1000; int loop = 1000;
HttpAddress httpAddress1 = HttpAddress.http2("localhost", 8008); HttpAddress httpAddress1 = HttpAddress.http2("localhost", 8008);
AtomicInteger counter1 = new AtomicInteger(); AtomicInteger counter1 = new AtomicInteger();
Domain domain1 = Domain.builder(httpAddress1) HttpServerDomain domain1 = HttpServerDomain.builder(httpAddress1)
.singleEndpoint("/", (request, response) -> { .singleEndpoint("/", (request, response) -> {
ServerResponse.write(response, HttpResponseStatus.OK, "text.plain", ServerResponse.write(response, HttpResponseStatus.OK, "text.plain",
request.getContent().toString(StandardCharsets.UTF_8)); request.getContent().toString(StandardCharsets.UTF_8));
@ -210,7 +210,7 @@ class CleartextTest {
server1.accept(); server1.accept();
HttpAddress httpAddress2 = HttpAddress.http2("localhost", 8009); HttpAddress httpAddress2 = HttpAddress.http2("localhost", 8009);
AtomicInteger counter2 = new AtomicInteger(); AtomicInteger counter2 = new AtomicInteger();
Domain domain2 = Domain.builder(httpAddress2) HttpServerDomain domain2 = HttpServerDomain.builder(httpAddress2)
.singleEndpoint("/", (request, response) -> { .singleEndpoint("/", (request, response) -> {
ServerResponse.write(response, HttpResponseStatus.OK, "text/plain", ServerResponse.write(response, HttpResponseStatus.OK, "text/plain",
request.getContent().toString(StandardCharsets.UTF_8)); 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.HttpAddress;
import org.xbib.netty.http.common.HttpResponse; import org.xbib.netty.http.common.HttpResponse;
import org.xbib.netty.http.server.Server; 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 org.xbib.netty.http.server.test.NettyHttpTestExtension;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
@ -31,7 +31,7 @@ class EncryptedTest {
@Test @Test
void testSimpleSecureHttp2() throws Exception { void testSimpleSecureHttp2() throws Exception {
HttpAddress httpAddress = HttpAddress.secureHttp2("localhost", 8143); HttpAddress httpAddress = HttpAddress.secureHttp2("localhost", 8143);
Server server = Server.builder(Domain.builder(httpAddress) Server server = Server.builder(HttpServerDomain.builder(httpAddress)
.setSelfCert() .setSelfCert()
.singleEndpoint("/", (request, response) -> .singleEndpoint("/", (request, response) ->
response.withStatus(HttpResponseStatus.OK) response.withStatus(HttpResponseStatus.OK)
@ -72,7 +72,7 @@ class EncryptedTest {
void testPooledSecureHttp2() throws Exception { void testPooledSecureHttp2() throws Exception {
int loop = 1024; int loop = 1024;
HttpAddress httpAddress = HttpAddress.secureHttp2("localhost", 8143); HttpAddress httpAddress = HttpAddress.secureHttp2("localhost", 8143);
Domain domain = Domain.builder(httpAddress) HttpServerDomain domain = HttpServerDomain.builder(httpAddress)
.setSelfCert() .setSelfCert()
.singleEndpoint("/", (request, response) -> .singleEndpoint("/", (request, response) ->
response.withStatus(HttpResponseStatus.OK) response.withStatus(HttpResponseStatus.OK)
@ -126,7 +126,7 @@ class EncryptedTest {
int threads = 4; int threads = 4;
int loop = 1024; int loop = 1024;
HttpAddress httpAddress = HttpAddress.secureHttp2("localhost", 8143); HttpAddress httpAddress = HttpAddress.secureHttp2("localhost", 8143);
Server server = Server.builder(Domain.builder(httpAddress) Server server = Server.builder(HttpServerDomain.builder(httpAddress)
.setSelfCert() .setSelfCert()
.singleEndpoint("/", (request, response) -> .singleEndpoint("/", (request, response) ->
response.withStatus(HttpResponseStatus.OK) 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.HttpAddress;
import org.xbib.netty.http.common.HttpParameters; import org.xbib.netty.http.common.HttpParameters;
import org.xbib.netty.http.common.HttpResponse; 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.Server;
import org.xbib.netty.http.server.test.NettyHttpTestExtension; import org.xbib.netty.http.server.test.NettyHttpTestExtension;
import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicBoolean;
@ -30,7 +30,7 @@ class FlushTest {
@Test @Test
void testFlushHttp2() throws Exception { void testFlushHttp2() throws Exception {
HttpAddress httpAddress = HttpAddress.http2("localhost", 8008); HttpAddress httpAddress = HttpAddress.http2("localhost", 8008);
Domain domain = Domain.builder(httpAddress) HttpServerDomain domain = HttpServerDomain.builder(httpAddress)
.singleEndpoint("/flush", "/**", (req, resp) -> { .singleEndpoint("/flush", "/**", (req, resp) -> {
HttpParameters parameters = req.getParameters(); HttpParameters parameters = req.getParameters();
logger.log(Level.INFO, "got request " + parameters.toString() + ", sending 302 Found"); 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.Request;
import org.xbib.netty.http.client.api.ClientTransport; import org.xbib.netty.http.client.api.ClientTransport;
import org.xbib.netty.http.common.HttpAddress; 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.Server;
import org.xbib.netty.http.server.api.ServerResponse; import org.xbib.netty.http.server.api.ServerResponse;
import org.xbib.netty.http.server.test.NettyHttpTestExtension; import org.xbib.netty.http.server.test.NettyHttpTestExtension;
@ -21,7 +21,7 @@ class MixedProtocolTest {
@Test @Test
void testHttp1ClientHttp2Server() throws Exception { void testHttp1ClientHttp2Server() throws Exception {
HttpAddress httpAddress = HttpAddress.http2("localhost", 8008); HttpAddress httpAddress = HttpAddress.http2("localhost", 8008);
Domain domain = Domain.builder(httpAddress) HttpServerDomain domain = HttpServerDomain.builder(httpAddress)
.singleEndpoint("/", (request, response) -> { .singleEndpoint("/", (request, response) -> {
ServerResponse.write(response, HttpResponseStatus.OK); ServerResponse.write(response, HttpResponseStatus.OK);
}) })
@ -55,7 +55,7 @@ class MixedProtocolTest {
@Test @Test
void testHttp2ClientHttp1Server() throws Exception { void testHttp2ClientHttp1Server() throws Exception {
HttpAddress httpAddress = HttpAddress.http1("localhost", 8008); HttpAddress httpAddress = HttpAddress.http1("localhost", 8008);
Domain domain = Domain.builder(httpAddress) HttpServerDomain domain = HttpServerDomain.builder(httpAddress)
.singleEndpoint("/", (request, response) -> { .singleEndpoint("/", (request, response) -> {
ServerResponse.write(response, HttpResponseStatus.OK); ServerResponse.write(response, HttpResponseStatus.OK);
}) })
@ -92,7 +92,7 @@ class MixedProtocolTest {
@Test @Test
void testHttp1ClientHttp2ServerWithNegotiation() throws Exception { void testHttp1ClientHttp2ServerWithNegotiation() throws Exception {
HttpAddress httpAddress = HttpAddress.secureHttp2("localhost", 8143); HttpAddress httpAddress = HttpAddress.secureHttp2("localhost", 8143);
Domain domain = Domain.builder(httpAddress) HttpServerDomain domain = HttpServerDomain.builder(httpAddress)
.setSelfCert() .setSelfCert()
.singleEndpoint("/", (request, response) -> { .singleEndpoint("/", (request, response) -> {
ServerResponse.write(response, HttpResponseStatus.OK); 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.common.HttpResponse;
import org.xbib.netty.http.server.Server; import org.xbib.netty.http.server.Server;
import org.xbib.netty.http.server.api.ServerResponse; 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 org.xbib.netty.http.server.test.NettyHttpTestExtension;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
@ -33,7 +33,7 @@ class PostTest {
final AtomicBoolean success2 = new AtomicBoolean(false); final AtomicBoolean success2 = new AtomicBoolean(false);
final AtomicBoolean success3 = new AtomicBoolean(false); final AtomicBoolean success3 = new AtomicBoolean(false);
HttpAddress httpAddress = HttpAddress.http2("localhost", 8008); HttpAddress httpAddress = HttpAddress.http2("localhost", 8008);
Domain domain = Domain.builder(httpAddress) HttpServerDomain domain = HttpServerDomain.builder(httpAddress)
.singleEndpoint("/post", "/**", (req, resp) -> { .singleEndpoint("/post", "/**", (req, resp) -> {
HttpParameters parameters = req.getParameters(); HttpParameters parameters = req.getParameters();
logger.log(Level.INFO, "got request " + parameters.toString() + " , sending, OK"); logger.log(Level.INFO, "got request " + parameters.toString() + " , sending, OK");
@ -83,7 +83,7 @@ class PostTest {
final AtomicBoolean success2 = new AtomicBoolean(false); final AtomicBoolean success2 = new AtomicBoolean(false);
final AtomicBoolean success3 = new AtomicBoolean(false); final AtomicBoolean success3 = new AtomicBoolean(false);
HttpAddress httpAddress = HttpAddress.http2("localhost", 8008); HttpAddress httpAddress = HttpAddress.http2("localhost", 8008);
Domain domain = Domain.builder(httpAddress) HttpServerDomain domain = HttpServerDomain.builder(httpAddress)
.singleEndpoint("/post", "/**", (req, resp) -> { .singleEndpoint("/post", "/**", (req, resp) -> {
HttpParameters parameters = req.getParameters(); HttpParameters parameters = req.getParameters();
logger.log(Level.INFO, "got request " + parameters.toString() + " , sending, OK"); 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.client.api.ResponseListener;
import org.xbib.netty.http.common.HttpAddress; import org.xbib.netty.http.common.HttpAddress;
import org.xbib.netty.http.common.HttpResponse; 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.Server;
import org.xbib.netty.http.server.api.ServerResponse; import org.xbib.netty.http.server.api.ServerResponse;
import org.xbib.netty.http.server.test.NettyHttpTestExtension; import org.xbib.netty.http.server.test.NettyHttpTestExtension;
@ -31,7 +31,7 @@ class PutTest {
final AtomicBoolean success1 = new AtomicBoolean(false); final AtomicBoolean success1 = new AtomicBoolean(false);
final AtomicBoolean success2 = new AtomicBoolean(false); final AtomicBoolean success2 = new AtomicBoolean(false);
HttpAddress httpAddress = HttpAddress.http2("localhost", 8008); HttpAddress httpAddress = HttpAddress.http2("localhost", 8008);
Domain domain = Domain.builder(httpAddress) HttpServerDomain domain = HttpServerDomain.builder(httpAddress)
.singleEndpoint("/put", "/**", (req, resp) -> { .singleEndpoint("/put", "/**", (req, resp) -> {
logger.log(Level.INFO, "got request " + logger.log(Level.INFO, "got request " +
req.getContent().toString(StandardCharsets.UTF_8)); req.getContent().toString(StandardCharsets.UTF_8));
@ -80,7 +80,7 @@ class PutTest {
outputStream.write(1); outputStream.write(1);
} }
HttpAddress httpAddress = HttpAddress.http2("localhost", 8008); HttpAddress httpAddress = HttpAddress.http2("localhost", 8008);
Domain domain = Domain.builder(httpAddress) HttpServerDomain domain = HttpServerDomain.builder(httpAddress)
.singleEndpoint("/put", "/**", (req, resp) -> { .singleEndpoint("/put", "/**", (req, resp) -> {
logger.log(Level.INFO, "got request, length = " + logger.log(Level.INFO, "got request, length = " +
req.getContent().readableBytes()); 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.Client;
import org.xbib.netty.http.client.api.Request; import org.xbib.netty.http.client.api.Request;
import org.xbib.netty.http.common.HttpAddress; 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.Server;
import org.xbib.netty.http.server.test.NettyHttpTestExtension; import org.xbib.netty.http.server.test.NettyHttpTestExtension;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
@ -14,7 +14,6 @@ import java.util.concurrent.atomic.AtomicInteger;
import io.netty.buffer.ByteBufInputStream; import io.netty.buffer.ByteBufInputStream;
import io.netty.buffer.ByteBufOutputStream; import io.netty.buffer.ByteBufOutputStream;
import io.netty.handler.codec.http.HttpResponseStatus; import io.netty.handler.codec.http.HttpResponseStatus;
import io.netty.handler.codec.http.HttpVersion;
@ExtendWith(NettyHttpTestExtension.class) @ExtendWith(NettyHttpTestExtension.class)
class StreamTest { class StreamTest {
@ -22,7 +21,7 @@ class StreamTest {
@Test @Test
void testServerBodyInputStreamHttp2() throws Exception { void testServerBodyInputStreamHttp2() throws Exception {
HttpAddress httpAddress = HttpAddress.http2("localhost", 8008); HttpAddress httpAddress = HttpAddress.http2("localhost", 8008);
Domain domain = Domain.builder(httpAddress) HttpServerDomain domain = HttpServerDomain.builder(httpAddress)
.singleEndpoint("/", (request, response) -> { .singleEndpoint("/", (request, response) -> {
ByteBufInputStream inputStream = request.getInputStream(); ByteBufInputStream inputStream = request.getInputStream();
String content = inputStream.readLine(); String content = inputStream.readLine();