add router task to release buffers after routing, refactor HTTP server API into application, domain, service subpackages

This commit is contained in:
Jörg Prante 2023-03-30 10:42:29 +02:00
parent 5c52f5149e
commit fc1beabb58
125 changed files with 587 additions and 640 deletions

View file

@ -1,5 +1,5 @@
group = org.xbib group = org.xbib
name = net-http name = net-http
version = 3.0.5 version = 3.1.0
org.gradle.warning.mode = ALL org.gradle.warning.mode = ALL

View file

@ -6,11 +6,11 @@ import org.xbib.config.ConfigLoader;
import org.xbib.config.ConfigLogger; import org.xbib.config.ConfigLogger;
import org.xbib.config.ConfigParams; import org.xbib.config.ConfigParams;
import org.xbib.config.SystemConfigLogger; import org.xbib.config.SystemConfigLogger;
import org.xbib.net.http.server.Application; import org.xbib.net.http.server.application.Application;
import org.xbib.net.http.server.BaseApplicationModule; import org.xbib.net.http.server.application.BaseApplicationModule;
import org.xbib.net.http.server.HttpRequest; import org.xbib.net.http.server.HttpRequest;
import org.xbib.net.http.server.HttpServerContext; import org.xbib.net.http.server.HttpServerContext;
import org.xbib.net.http.server.HttpService; import org.xbib.net.http.server.service.HttpService;
import org.xbib.settings.Settings; import org.xbib.settings.Settings;
public class ConfigApplicationModule extends BaseApplicationModule { public class ConfigApplicationModule extends BaseApplicationModule {

View file

@ -4,11 +4,11 @@ import org.xbib.jdbc.connection.pool.PoolConfig;
import org.xbib.jdbc.connection.pool.PoolDataSource; import org.xbib.jdbc.connection.pool.PoolDataSource;
import org.xbib.jdbc.query.DatabaseProvider; import org.xbib.jdbc.query.DatabaseProvider;
import org.xbib.jdbc.query.Flavor; import org.xbib.jdbc.query.Flavor;
import org.xbib.net.http.server.Application; import org.xbib.net.http.server.application.Application;
import org.xbib.net.http.server.BaseApplicationModule; import org.xbib.net.http.server.application.BaseApplicationModule;
import org.xbib.net.http.server.HttpRequest; import org.xbib.net.http.server.HttpRequest;
import org.xbib.net.http.server.HttpServerContext; import org.xbib.net.http.server.HttpServerContext;
import org.xbib.net.http.server.HttpService; import org.xbib.net.http.server.service.HttpService;
import org.xbib.settings.Settings; import org.xbib.settings.Settings;
import javax.sql.DataSource; import javax.sql.DataSource;

View file

@ -14,10 +14,10 @@ import org.xbib.net.http.HttpHeaderNames;
import org.xbib.net.http.HttpHeaderValues; import org.xbib.net.http.HttpHeaderValues;
import org.xbib.net.http.HttpResponseStatus; import org.xbib.net.http.HttpResponseStatus;
import org.xbib.net.http.HttpVersion; import org.xbib.net.http.HttpVersion;
import org.xbib.net.http.server.BaseHttpDomain; import org.xbib.net.http.server.domain.BaseHttpDomain;
import org.xbib.net.http.server.BaseHttpSecurityDomain; import org.xbib.net.http.server.domain.BaseHttpSecurityDomain;
import org.xbib.net.http.server.HttpSecurityDomain; import org.xbib.net.http.server.domain.HttpSecurityDomain;
import org.xbib.net.http.server.HttpService; import org.xbib.net.http.server.service.HttpService;
import org.xbib.net.http.server.auth.BasicAuthenticationHandler; import org.xbib.net.http.server.auth.BasicAuthenticationHandler;
import org.xbib.net.http.server.auth.FormAuthenticationHandler; import org.xbib.net.http.server.auth.FormAuthenticationHandler;
import org.xbib.net.http.server.ldap.LdapContextFactory; import org.xbib.net.http.server.ldap.LdapContextFactory;
@ -25,7 +25,7 @@ import org.xbib.net.http.server.ldap.LdapGroupMapping;
import org.xbib.net.http.server.ldap.LdapRealm; import org.xbib.net.http.server.ldap.LdapRealm;
import org.xbib.net.http.server.ldap.LdapUserMapping; import org.xbib.net.http.server.ldap.LdapUserMapping;
import org.xbib.net.http.server.route.BaseHttpRouter; import org.xbib.net.http.server.route.BaseHttpRouter;
import org.xbib.net.http.server.BaseHttpService; import org.xbib.net.http.server.service.BaseHttpService;
import org.xbib.net.http.server.netty.NettyHttpServer; import org.xbib.net.http.server.netty.NettyHttpServer;
import org.xbib.net.http.server.netty.buffer.NettyDataBufferFactory; import org.xbib.net.http.server.netty.buffer.NettyDataBufferFactory;
import org.xbib.net.http.server.netty.secure.HttpsAddress; import org.xbib.net.http.server.netty.secure.HttpsAddress;

View file

@ -4,7 +4,7 @@ import java.nio.file.Paths;
import java.time.Duration; import java.time.Duration;
import org.xbib.net.http.cookie.SameSite; import org.xbib.net.http.cookie.SameSite;
import org.xbib.net.http.server.BaseApplication; import org.xbib.net.http.server.application.BaseApplication;
import org.xbib.net.http.server.HttpHandler; import org.xbib.net.http.server.HttpHandler;
import org.xbib.net.http.server.HttpServerContext; import org.xbib.net.http.server.HttpServerContext;
import org.xbib.net.http.server.persist.Codec; import org.xbib.net.http.server.persist.Codec;

View file

@ -1,6 +1,6 @@
package org.xbib.net.http.server.application.web; package org.xbib.net.http.server.application.web;
import org.xbib.net.http.server.BaseApplicationBuilder; import org.xbib.net.http.server.application.BaseApplicationBuilder;
import org.xbib.settings.Settings; import org.xbib.settings.Settings;

View file

@ -9,7 +9,7 @@ import java.util.Optional;
import java.util.ServiceLoader; import java.util.ServiceLoader;
import org.xbib.net.http.HttpAddress; import org.xbib.net.http.HttpAddress;
import org.xbib.net.http.server.netty.NettyHttpServerConfig; import org.xbib.net.http.server.netty.NettyHttpServerConfig;
import org.xbib.net.http.server.HttpDomain; import org.xbib.net.http.server.domain.HttpDomain;
import java.util.Collection; import java.util.Collection;

View file

@ -17,9 +17,9 @@ import org.xbib.net.http.client.netty.HttpRequest;
import org.xbib.net.http.client.netty.NettyHttpClient; import org.xbib.net.http.client.netty.NettyHttpClient;
import org.xbib.net.http.client.netty.NettyHttpClientConfig; import org.xbib.net.http.client.netty.NettyHttpClientConfig;
import org.xbib.net.http.client.netty.secure.NettyHttpsClientConfig; import org.xbib.net.http.client.netty.secure.NettyHttpsClientConfig;
import org.xbib.net.http.server.BaseApplication; import org.xbib.net.http.server.application.BaseApplication;
import org.xbib.net.http.server.BaseHttpDomain; import org.xbib.net.http.server.domain.BaseHttpDomain;
import org.xbib.net.http.server.BaseHttpService; import org.xbib.net.http.server.service.BaseHttpService;
import org.xbib.net.http.server.netty.NettyHttpServer; import org.xbib.net.http.server.netty.NettyHttpServer;
import org.xbib.net.http.server.netty.secure.HttpsAddress; import org.xbib.net.http.server.netty.secure.HttpsAddress;
import org.xbib.net.http.server.netty.secure.HttpsRequest; import org.xbib.net.http.server.netty.secure.HttpsRequest;

View file

@ -17,9 +17,9 @@ import org.xbib.net.http.client.netty.HttpRequest;
import org.xbib.net.http.client.netty.NettyHttpClient; import org.xbib.net.http.client.netty.NettyHttpClient;
import org.xbib.net.http.client.netty.NettyHttpClientConfig; import org.xbib.net.http.client.netty.NettyHttpClientConfig;
import org.xbib.net.http.client.netty.secure.NettyHttpsClientConfig; import org.xbib.net.http.client.netty.secure.NettyHttpsClientConfig;
import org.xbib.net.http.server.BaseApplication; import org.xbib.net.http.server.application.BaseApplication;
import org.xbib.net.http.server.BaseHttpDomain; import org.xbib.net.http.server.domain.BaseHttpDomain;
import org.xbib.net.http.server.BaseHttpService; import org.xbib.net.http.server.service.BaseHttpService;
import org.xbib.net.http.server.netty.NettyHttpServer; import org.xbib.net.http.server.netty.NettyHttpServer;
import org.xbib.net.http.server.netty.secure.HttpsAddress; import org.xbib.net.http.server.netty.secure.HttpsAddress;
import org.xbib.net.http.server.netty.secure.HttpsRequest; import org.xbib.net.http.server.netty.secure.HttpsRequest;

View file

@ -13,9 +13,9 @@ import org.xbib.net.http.client.netty.HttpRequest;
import org.xbib.net.http.client.netty.NettyHttpClient; import org.xbib.net.http.client.netty.NettyHttpClient;
import org.xbib.net.http.client.netty.NettyHttpClientConfig; import org.xbib.net.http.client.netty.NettyHttpClientConfig;
import org.xbib.net.http.client.netty.secure.NettyHttpsClientConfig; import org.xbib.net.http.client.netty.secure.NettyHttpsClientConfig;
import org.xbib.net.http.server.BaseApplication; import org.xbib.net.http.server.application.BaseApplication;
import org.xbib.net.http.server.BaseHttpDomain; import org.xbib.net.http.server.domain.BaseHttpDomain;
import org.xbib.net.http.server.BaseHttpService; import org.xbib.net.http.server.service.BaseHttpService;
import org.xbib.net.http.server.netty.NettyHttpServer; import org.xbib.net.http.server.netty.NettyHttpServer;
import org.xbib.net.http.server.netty.secure.HttpsAddress; import org.xbib.net.http.server.netty.secure.HttpsAddress;
import org.xbib.net.http.server.netty.secure.HttpsRequest; import org.xbib.net.http.server.netty.secure.HttpsRequest;

View file

@ -20,14 +20,14 @@ import org.xbib.net.http.client.netty.HttpRequest;
import org.xbib.net.http.client.netty.NettyHttpClient; import org.xbib.net.http.client.netty.NettyHttpClient;
import org.xbib.net.http.client.netty.NettyHttpClientConfig; import org.xbib.net.http.client.netty.NettyHttpClientConfig;
import org.xbib.net.http.client.netty.secure.NettyHttpsClientConfig; import org.xbib.net.http.client.netty.secure.NettyHttpsClientConfig;
import org.xbib.net.http.server.BaseApplication; import org.xbib.net.http.server.application.BaseApplication;
import org.xbib.net.http.server.BaseHttpDomain; import org.xbib.net.http.server.domain.BaseHttpDomain;
import org.xbib.net.http.server.netty.NettyHttpServer; import org.xbib.net.http.server.netty.NettyHttpServer;
import org.xbib.net.http.server.netty.secure.HttpsAddress; import org.xbib.net.http.server.netty.secure.HttpsAddress;
import org.xbib.net.http.server.netty.secure.HttpsRequest; import org.xbib.net.http.server.netty.secure.HttpsRequest;
import org.xbib.net.http.server.netty.secure.NettyHttpsServerConfig; import org.xbib.net.http.server.netty.secure.NettyHttpsServerConfig;
import org.xbib.net.http.server.route.BaseHttpRouter; import org.xbib.net.http.server.route.BaseHttpRouter;
import org.xbib.net.http.server.BaseHttpService; import org.xbib.net.http.server.service.BaseHttpService;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.assertTrue;

View file

@ -9,7 +9,6 @@ import org.xbib.net.http.HttpMethod;
import org.xbib.net.http.HttpVersion; import org.xbib.net.http.HttpVersion;
import org.xbib.net.http.server.BaseHttpRequestBuilder; import org.xbib.net.http.server.BaseHttpRequestBuilder;
import java.io.IOException;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.nio.CharBuffer; import java.nio.CharBuffer;
@ -116,7 +115,7 @@ public class HttpRequestBuilder extends BaseHttpRequestBuilder {
} }
@Override @Override
public void close() throws IOException { public void release() {
if (fullHttpRequest != null) { if (fullHttpRequest != null) {
logger.log(Level.FINER, "releasing retained netty request"); logger.log(Level.FINER, "releasing retained netty request");
fullHttpRequest.release(); fullHttpRequest.release();

View file

@ -3,13 +3,9 @@ package org.xbib.net.http.server.netty;
import org.xbib.net.http.server.BaseHttpResponse; import org.xbib.net.http.server.BaseHttpResponse;
import java.io.IOException; import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
public class HttpResponse extends BaseHttpResponse { public class HttpResponse extends BaseHttpResponse {
private static final Logger logger = Logger.getLogger(HttpResponse.class.getName());
private final HttpResponseBuilder builder; private final HttpResponseBuilder builder;
protected HttpResponse(HttpResponseBuilder builder) { protected HttpResponse(HttpResponseBuilder builder) {
@ -23,7 +19,7 @@ public class HttpResponse extends BaseHttpResponse {
@Override @Override
public void close() throws IOException { public void close() throws IOException {
builder.close(); builder.release();
} }
@Override @Override

View file

@ -129,8 +129,9 @@ public class HttpResponseBuilder extends BaseHttpResponseBuilder {
} }
@Override @Override
public void close() throws IOException { public void release() {
if (ctx.channel().isOpen()) { super.release();
if (ctx != null && ctx.channel().isOpen()) {
logger.log(Level.FINER, "closing netty channel " + ctx.channel()); logger.log(Level.FINER, "closing netty channel " + ctx.channel());
ctx.close(); ctx.close();
} }
@ -185,7 +186,6 @@ public class HttpResponseBuilder extends BaseHttpResponseBuilder {
} }
HttpHeaders trailingHeaders = new DefaultHttpHeaders(); HttpHeaders trailingHeaders = new DefaultHttpHeaders();
super.trailingHeaders.entries().forEach(e -> trailingHeaders.add(e.getKey(), e.getValue())); super.trailingHeaders.entries().forEach(e -> trailingHeaders.add(e.getKey(), e.getValue()));
// retain Netty byteBuf because FullHttpResponse will be released in writeAndFlush()
FullHttpResponse fullHttpResponse = new DefaultFullHttpResponse(HttpVersion.valueOf(version.text()), FullHttpResponse fullHttpResponse = new DefaultFullHttpResponse(HttpVersion.valueOf(version.text()),
responseStatus, byteBuf.retain(), headers, trailingHeaders); responseStatus, byteBuf.retain(), headers, trailingHeaders);
if (!ctx.channel().isWritable()) { if (!ctx.channel().isWritable()) {
@ -204,7 +204,7 @@ public class HttpResponseBuilder extends BaseHttpResponseBuilder {
private void internalWrite(FileChannel fileChannel, int bufferSize, boolean keepAlive) { private void internalWrite(FileChannel fileChannel, int bufferSize, boolean keepAlive) {
if (!ctx.channel().isWritable()) { if (!ctx.channel().isWritable()) {
logger.log(Level.WARNING, "we have a problem, the channel " + ctx.channel() + " is not writable"); logger.log(Level.WARNING, "channel not writeable: " + ctx.channel());
} }
HttpResponseStatus responseStatus = HttpResponseStatus.valueOf(status.code()); HttpResponseStatus responseStatus = HttpResponseStatus.valueOf(status.code());
DefaultHttpResponse rsp = new DefaultHttpResponse(HttpVersion.HTTP_1_1, responseStatus); DefaultHttpResponse rsp = new DefaultHttpResponse(HttpVersion.HTTP_1_1, responseStatus);

View file

@ -15,7 +15,7 @@ import org.xbib.net.NetworkClass;
import org.xbib.net.NetworkUtils; import org.xbib.net.NetworkUtils;
import org.xbib.net.SocketConfig; import org.xbib.net.SocketConfig;
import org.xbib.net.http.HttpAddress; import org.xbib.net.http.HttpAddress;
import org.xbib.net.http.server.Application; import org.xbib.net.http.server.application.Application;
import org.xbib.net.http.server.HttpServer; import org.xbib.net.http.server.HttpServer;
import java.io.IOException; import java.io.IOException;

View file

@ -5,7 +5,7 @@ import io.netty.channel.EventLoopGroup;
import io.netty.channel.nio.NioEventLoopGroup; import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.ServerSocketChannel; import io.netty.channel.socket.ServerSocketChannel;
import io.netty.channel.socket.nio.NioServerSocketChannel; import io.netty.channel.socket.nio.NioServerSocketChannel;
import org.xbib.net.http.server.Application; import org.xbib.net.http.server.application.Application;
import org.xbib.net.http.server.HttpServerBuilder; import org.xbib.net.http.server.HttpServerBuilder;
import org.xbib.net.util.NamedThreadFactory; import org.xbib.net.util.NamedThreadFactory;

View file

@ -12,6 +12,8 @@ import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufInputStream; import io.netty.buffer.ByteBufInputStream;
import io.netty.buffer.ByteBufOutputStream; import io.netty.buffer.ByteBufOutputStream;
import io.netty.buffer.ByteBufUtil; import io.netty.buffer.ByteBufUtil;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.xbib.net.buffer.DataBuffer; import org.xbib.net.buffer.DataBuffer;
import org.xbib.net.buffer.PooledDataBuffer; import org.xbib.net.buffer.PooledDataBuffer;
@ -21,11 +23,12 @@ import org.xbib.net.buffer.PooledDataBuffer;
*/ */
public class NettyDataBuffer implements PooledDataBuffer { public class NettyDataBuffer implements PooledDataBuffer {
private static final Logger logger = Logger.getLogger(NettyDataBuffer.class.getName());
private final ByteBuf byteBuf; private final ByteBuf byteBuf;
private final NettyDataBufferFactory dataBufferFactory; private final NettyDataBufferFactory dataBufferFactory;
/** /**
* Create a new {@code NettyDataBuffer} based on the given {@code ByteBuff}. * Create a new {@code NettyDataBuffer} based on the given {@code ByteBuff}.
* @param byteBuf the buffer to base this buffer on * @param byteBuf the buffer to base this buffer on
@ -37,18 +40,17 @@ public class NettyDataBuffer implements PooledDataBuffer {
this.dataBufferFactory = dataBufferFactory; this.dataBufferFactory = dataBufferFactory;
} }
/** /**
* Directly exposes the native {@code ByteBuf} that this buffer is based on. * Directly exposes the native {@code ByteBuf} that this buffer is based on.
* @return the wrapped byte buffer * @return the wrapped byte buffer
*/ */
public ByteBuf getNativeBuffer() { public ByteBuf getNativeBuffer() {
return this.byteBuf; return byteBuf;
} }
@Override @Override
public NettyDataBufferFactory factory() { public NettyDataBufferFactory factory() {
return this.dataBufferFactory; return dataBufferFactory;
} }
@Override @Override
@ -57,11 +59,11 @@ public class NettyDataBuffer implements PooledDataBuffer {
if (fromIndex < 0) { if (fromIndex < 0) {
fromIndex = 0; fromIndex = 0;
} }
else if (fromIndex >= this.byteBuf.writerIndex()) { else if (fromIndex >= byteBuf.writerIndex()) {
return -1; return -1;
} }
int length = this.byteBuf.writerIndex() - fromIndex; int length = byteBuf.writerIndex() - fromIndex;
return this.byteBuf.forEachByte(fromIndex, length, predicate.negate()::test); return byteBuf.forEachByte(fromIndex, length, predicate.negate()::test);
} }
@Override @Override
@ -70,96 +72,96 @@ public class NettyDataBuffer implements PooledDataBuffer {
if (fromIndex < 0) { if (fromIndex < 0) {
return -1; return -1;
} }
fromIndex = Math.min(fromIndex, this.byteBuf.writerIndex() - 1); fromIndex = Math.min(fromIndex, byteBuf.writerIndex() - 1);
return this.byteBuf.forEachByteDesc(0, fromIndex + 1, predicate.negate()::test); return byteBuf.forEachByteDesc(0, fromIndex + 1, predicate.negate()::test);
} }
@Override @Override
public int readableByteCount() { public int readableByteCount() {
return this.byteBuf.readableBytes(); return byteBuf.readableBytes();
} }
@Override @Override
public int writableByteCount() { public int writableByteCount() {
return this.byteBuf.writableBytes(); return byteBuf.writableBytes();
} }
@Override @Override
public int readPosition() { public int readPosition() {
return this.byteBuf.readerIndex(); return byteBuf.readerIndex();
} }
@Override @Override
public NettyDataBuffer readPosition(int readPosition) { public NettyDataBuffer readPosition(int readPosition) {
this.byteBuf.readerIndex(readPosition); byteBuf.readerIndex(readPosition);
return this; return this;
} }
@Override @Override
public int writePosition() { public int writePosition() {
return this.byteBuf.writerIndex(); return byteBuf.writerIndex();
} }
@Override @Override
public NettyDataBuffer writePosition(int writePosition) { public NettyDataBuffer writePosition(int writePosition) {
this.byteBuf.writerIndex(writePosition); byteBuf.writerIndex(writePosition);
return this; return this;
} }
@Override @Override
public byte getByte(int index) { public byte getByte(int index) {
return this.byteBuf.getByte(index); return byteBuf.getByte(index);
} }
@Override @Override
public int capacity() { public int capacity() {
return this.byteBuf.capacity(); return byteBuf.capacity();
} }
@Override @Override
public NettyDataBuffer capacity(int capacity) { public NettyDataBuffer capacity(int capacity) {
this.byteBuf.capacity(capacity); byteBuf.capacity(capacity);
return this; return this;
} }
@Override @Override
public DataBuffer ensureCapacity(int capacity) { public DataBuffer ensureCapacity(int capacity) {
this.byteBuf.ensureWritable(capacity); byteBuf.ensureWritable(capacity);
return this; return this;
} }
@Override @Override
public byte read() { public byte read() {
return this.byteBuf.readByte(); return byteBuf.readByte();
} }
@Override @Override
public NettyDataBuffer read(byte[] destination) { public NettyDataBuffer read(byte[] destination) {
this.byteBuf.readBytes(destination); byteBuf.readBytes(destination);
return this; return this;
} }
@Override @Override
public NettyDataBuffer read(byte[] destination, int offset, int length) { public NettyDataBuffer read(byte[] destination, int offset, int length) {
this.byteBuf.readBytes(destination, offset, length); byteBuf.readBytes(destination, offset, length);
return this; return this;
} }
@Override @Override
public NettyDataBuffer write(byte b) { public NettyDataBuffer write(byte b) {
this.byteBuf.writeByte(b); byteBuf.writeByte(b);
return this; return this;
} }
@Override @Override
public NettyDataBuffer write(byte[] source) { public NettyDataBuffer write(byte[] source) {
this.byteBuf.writeBytes(source); byteBuf.writeBytes(source);
return this; return this;
} }
@Override @Override
public NettyDataBuffer write(byte[] source, int offset, int length) { public NettyDataBuffer write(byte[] source, int offset, int length) {
this.byteBuf.writeBytes(source, offset, length); byteBuf.writeBytes(source, offset, length);
return this; return this;
} }
@ -177,7 +179,6 @@ public class NettyDataBuffer implements PooledDataBuffer {
ByteBuffer[] byteBuffers = new ByteBuffer[buffers.length]; ByteBuffer[] byteBuffers = new ByteBuffer[buffers.length];
for (int i = 0; i < buffers.length; i++) { for (int i = 0; i < buffers.length; i++) {
byteBuffers[i] = buffers[i].asByteBuffer(); byteBuffers[i] = buffers[i].asByteBuffer();
} }
write(byteBuffers); write(byteBuffers);
} }
@ -196,9 +197,9 @@ public class NettyDataBuffer implements PooledDataBuffer {
@Override @Override
public NettyDataBuffer write(ByteBuffer... buffers) { public NettyDataBuffer write(ByteBuffer... buffers) {
if (buffers != null && buffers.length > 0) { if (buffers != null) {
for (ByteBuffer buffer : buffers) { for (ByteBuffer buffer : buffers) {
this.byteBuf.writeBytes(buffer); byteBuf.writeBytes(buffer);
} }
} }
return this; return this;
@ -211,9 +212,9 @@ public class NettyDataBuffer implements PooledDataBuffer {
* @return this buffer * @return this buffer
*/ */
public NettyDataBuffer write(ByteBuf... byteBufs) { public NettyDataBuffer write(ByteBuf... byteBufs) {
if (byteBufs != null && byteBufs.length > 0) { if (byteBufs != null) {
for (ByteBuf byteBuf : byteBufs) { for (ByteBuf byteBuf : byteBufs) {
this.byteBuf.writeBytes(byteBuf); byteBuf.writeBytes(byteBuf);
} }
} }
return this; return this;
@ -224,10 +225,10 @@ public class NettyDataBuffer implements PooledDataBuffer {
Objects.requireNonNull(charSequence, "CharSequence must not be null"); Objects.requireNonNull(charSequence, "CharSequence must not be null");
Objects.requireNonNull(charset, "Charset must not be null"); Objects.requireNonNull(charset, "Charset must not be null");
if (StandardCharsets.UTF_8.equals(charset)) { if (StandardCharsets.UTF_8.equals(charset)) {
ByteBufUtil.writeUtf8(this.byteBuf, charSequence); ByteBufUtil.writeUtf8(byteBuf, charSequence);
} }
else if (StandardCharsets.US_ASCII.equals(charset)) { else if (StandardCharsets.US_ASCII.equals(charset)) {
ByteBufUtil.writeAscii(this.byteBuf, charSequence); ByteBufUtil.writeAscii(byteBuf, charSequence);
} }
else { else {
return PooledDataBuffer.super.write(charSequence, charset); return PooledDataBuffer.super.write(charSequence, charset);
@ -237,88 +238,88 @@ public class NettyDataBuffer implements PooledDataBuffer {
@Override @Override
public NettyDataBuffer slice(int index, int length) { public NettyDataBuffer slice(int index, int length) {
ByteBuf slice = this.byteBuf.slice(index, length); ByteBuf slice = byteBuf.slice(index, length);
return new NettyDataBuffer(slice, this.dataBufferFactory); return new NettyDataBuffer(slice, dataBufferFactory);
} }
@Override @Override
public NettyDataBuffer retainedSlice(int index, int length) { public NettyDataBuffer retainedSlice(int index, int length) {
ByteBuf slice = this.byteBuf.retainedSlice(index, length); ByteBuf slice = byteBuf.retainedSlice(index, length);
return new NettyDataBuffer(slice, this.dataBufferFactory); return new NettyDataBuffer(slice, dataBufferFactory);
} }
@Override @Override
public ByteBuffer asByteBuffer() { public ByteBuffer asByteBuffer() {
return this.byteBuf.nioBuffer(); return byteBuf.nioBuffer();
} }
@Override @Override
public ByteBuffer asByteBuffer(int index, int length) { public ByteBuffer asByteBuffer(int index, int length) {
return this.byteBuf.nioBuffer(index, length); return byteBuf.nioBuffer(index, length);
} }
@Override @Override
public InputStream asInputStream() { public InputStream asInputStream() {
return new ByteBufInputStream(this.byteBuf); return new ByteBufInputStream(byteBuf);
} }
@Override @Override
public InputStream asInputStream(boolean releaseOnClose) { public InputStream asInputStream(boolean releaseOnClose) {
return new ByteBufInputStream(this.byteBuf, releaseOnClose); return new ByteBufInputStream(byteBuf, releaseOnClose);
} }
@Override @Override
public OutputStream asOutputStream() { public OutputStream asOutputStream() {
return new ByteBufOutputStream(this.byteBuf); return new ByteBufOutputStream(byteBuf);
} }
@Override @Override
public String toString(Charset charset) { public String toString(Charset charset) {
Objects.requireNonNull(charset, "Charset must not be null"); Objects.requireNonNull(charset, "Charset must not be null");
return this.byteBuf.toString(charset); return byteBuf.toString(charset);
} }
@Override @Override
public String toString(int index, int length, Charset charset) { public String toString(int index, int length, Charset charset) {
Objects.requireNonNull(charset, "Charset must not be null"); Objects.requireNonNull(charset, "Charset must not be null");
return this.byteBuf.toString(index, length, charset); return byteBuf.toString(index, length, charset);
} }
@Override @Override
public boolean isAllocated() { public boolean isAllocated() {
return this.byteBuf.refCnt() > 0; return byteBuf.refCnt() > 0;
} }
@Override @Override
public PooledDataBuffer retain() { public PooledDataBuffer retain() {
return new NettyDataBuffer(this.byteBuf.retain(), this.dataBufferFactory); return new NettyDataBuffer(byteBuf.retain(), dataBufferFactory);
} }
@Override @Override
public PooledDataBuffer touch(Object hint) { public PooledDataBuffer touch(Object hint) {
this.byteBuf.touch(hint); byteBuf.touch(hint);
return this; return this;
} }
@Override @Override
public boolean release() { public void release() {
return this.byteBuf.release(); boolean deallocated = byteBuf.release();
logger.log(Level.FINEST, "released " + byteBuf + " deallocated = " + deallocated);
} }
@Override @Override
public boolean equals(Object other) { public boolean equals(Object other) {
return (this == other || (other instanceof NettyDataBuffer && return (this == other || (other instanceof NettyDataBuffer &&
this.byteBuf.equals(((NettyDataBuffer) other).byteBuf))); byteBuf.equals(((NettyDataBuffer) other).byteBuf)));
} }
@Override @Override
public int hashCode() { public int hashCode() {
return this.byteBuf.hashCode(); return byteBuf.hashCode();
} }
@Override @Override
public String toString() { public String toString() {
return this.byteBuf.toString(); return byteBuf.toString();
} }
} }

View file

@ -44,18 +44,18 @@ public class NettyDataBufferFactory implements DataBufferFactory {
* Return the {@code ByteBufAllocator} used by this factory. * Return the {@code ByteBufAllocator} used by this factory.
*/ */
public ByteBufAllocator getByteBufAllocator() { public ByteBufAllocator getByteBufAllocator() {
return this.byteBufAllocator; return byteBufAllocator;
} }
@Override @Override
public NettyDataBuffer allocateBuffer() { public NettyDataBuffer allocateBuffer() {
ByteBuf byteBuf = this.byteBufAllocator.buffer(); ByteBuf byteBuf = byteBufAllocator.buffer();
return new NettyDataBuffer(byteBuf, this); return new NettyDataBuffer(byteBuf, this);
} }
@Override @Override
public NettyDataBuffer allocateBuffer(int initialCapacity) { public NettyDataBuffer allocateBuffer(int initialCapacity) {
ByteBuf byteBuf = this.byteBufAllocator.buffer(initialCapacity); ByteBuf byteBuf = byteBufAllocator.buffer(initialCapacity);
return new NettyDataBuffer(byteBuf, this); return new NettyDataBuffer(byteBuf, this);
} }
@ -93,7 +93,7 @@ public class NettyDataBufferFactory implements DataBufferFactory {
if (bufferCount == 1) { if (bufferCount == 1) {
return dataBuffers.get(0); return dataBuffers.get(0);
} }
CompositeByteBuf composite = this.byteBufAllocator.compositeBuffer(bufferCount); CompositeByteBuf composite = byteBufAllocator.compositeBuffer(bufferCount);
for (DataBuffer dataBuffer : dataBuffers) { for (DataBuffer dataBuffer : dataBuffers) {
if (!(dataBuffer instanceof NettyDataBuffer)) { if (!(dataBuffer instanceof NettyDataBuffer)) {
throw new IllegalArgumentException("dataBuffer"); throw new IllegalArgumentException("dataBuffer");
@ -112,8 +112,7 @@ public class NettyDataBufferFactory implements DataBufferFactory {
* @return the netty {@code ByteBuf} * @return the netty {@code ByteBuf}
*/ */
public static ByteBuf toByteBuf(DataBuffer buffer) { public static ByteBuf toByteBuf(DataBuffer buffer) {
if (buffer instanceof NettyDataBuffer) { if (buffer instanceof NettyDataBuffer nettyDataBuffer) {
NettyDataBuffer nettyDataBuffer = (NettyDataBuffer) buffer;
return nettyDataBuffer.getNativeBuffer(); return nettyDataBuffer.getNativeBuffer();
} }
else { else {
@ -123,6 +122,6 @@ public class NettyDataBufferFactory implements DataBufferFactory {
@Override @Override
public String toString() { public String toString() {
return "NettyDataBufferFactory (" + this.byteBufAllocator + ")"; return "NettyDataBufferFactory (" + byteBufAllocator + ")";
} }
} }

View file

@ -17,9 +17,9 @@ import org.xbib.net.http.HttpVersion;
import org.xbib.net.http.client.netty.HttpRequest; import org.xbib.net.http.client.netty.HttpRequest;
import org.xbib.net.http.client.netty.NettyHttpClient; import org.xbib.net.http.client.netty.NettyHttpClient;
import org.xbib.net.http.client.netty.NettyHttpClientConfig; import org.xbib.net.http.client.netty.NettyHttpClientConfig;
import org.xbib.net.http.server.BaseApplication; import org.xbib.net.http.server.application.BaseApplication;
import org.xbib.net.http.server.BaseHttpDomain; import org.xbib.net.http.server.domain.BaseHttpDomain;
import org.xbib.net.http.server.BaseHttpService; import org.xbib.net.http.server.service.BaseHttpService;
import org.xbib.net.http.server.netty.NettyHttpServer; import org.xbib.net.http.server.netty.NettyHttpServer;
import org.xbib.net.http.server.netty.NettyHttpServerConfig; import org.xbib.net.http.server.netty.NettyHttpServerConfig;
import org.xbib.net.http.server.route.BaseHttpRouter; import org.xbib.net.http.server.route.BaseHttpRouter;

View file

@ -16,9 +16,9 @@ import org.xbib.net.http.HttpVersion;
import org.xbib.net.http.client.netty.HttpRequest; import org.xbib.net.http.client.netty.HttpRequest;
import org.xbib.net.http.client.netty.NettyHttpClient; import org.xbib.net.http.client.netty.NettyHttpClient;
import org.xbib.net.http.client.netty.NettyHttpClientConfig; import org.xbib.net.http.client.netty.NettyHttpClientConfig;
import org.xbib.net.http.server.BaseApplication; import org.xbib.net.http.server.application.BaseApplication;
import org.xbib.net.http.server.BaseHttpDomain; import org.xbib.net.http.server.domain.BaseHttpDomain;
import org.xbib.net.http.server.BaseHttpService; import org.xbib.net.http.server.service.BaseHttpService;
import org.xbib.net.http.server.netty.NettyHttpServer; import org.xbib.net.http.server.netty.NettyHttpServer;
import org.xbib.net.http.server.netty.NettyHttpServerConfig; import org.xbib.net.http.server.netty.NettyHttpServerConfig;
import org.xbib.net.http.server.route.BaseHttpRouter; import org.xbib.net.http.server.route.BaseHttpRouter;

View file

@ -21,9 +21,9 @@ import org.xbib.net.http.HttpResponseStatus;
import org.xbib.net.http.client.netty.HttpRequest; import org.xbib.net.http.client.netty.HttpRequest;
import org.xbib.net.http.client.netty.NettyHttpClient; import org.xbib.net.http.client.netty.NettyHttpClient;
import org.xbib.net.http.client.netty.NettyHttpClientConfig; import org.xbib.net.http.client.netty.NettyHttpClientConfig;
import org.xbib.net.http.server.BaseApplication; import org.xbib.net.http.server.application.BaseApplication;
import org.xbib.net.http.server.BaseHttpDomain; import org.xbib.net.http.server.domain.BaseHttpDomain;
import org.xbib.net.http.server.BaseHttpService; import org.xbib.net.http.server.service.BaseHttpService;
import org.xbib.net.http.server.netty.NettyHttpServer; import org.xbib.net.http.server.netty.NettyHttpServer;
import org.xbib.net.http.server.netty.NettyHttpServerConfig; import org.xbib.net.http.server.netty.NettyHttpServerConfig;
import org.xbib.net.http.server.route.BaseHttpRouter; import org.xbib.net.http.server.route.BaseHttpRouter;

View file

@ -17,9 +17,9 @@ import org.xbib.net.http.HttpVersion;
import org.xbib.net.http.client.netty.HttpRequest; import org.xbib.net.http.client.netty.HttpRequest;
import org.xbib.net.http.client.netty.NettyHttpClient; import org.xbib.net.http.client.netty.NettyHttpClient;
import org.xbib.net.http.client.netty.NettyHttpClientConfig; import org.xbib.net.http.client.netty.NettyHttpClientConfig;
import org.xbib.net.http.server.BaseApplication; import org.xbib.net.http.server.application.BaseApplication;
import org.xbib.net.http.server.BaseHttpDomain; import org.xbib.net.http.server.domain.BaseHttpDomain;
import org.xbib.net.http.server.BaseHttpService; import org.xbib.net.http.server.service.BaseHttpService;
import org.xbib.net.http.server.netty.NettyHttpServer; import org.xbib.net.http.server.netty.NettyHttpServer;
import org.xbib.net.http.server.netty.NettyHttpServerConfig; import org.xbib.net.http.server.netty.NettyHttpServerConfig;
import org.xbib.net.http.server.route.BaseHttpRouter; import org.xbib.net.http.server.route.BaseHttpRouter;

View file

@ -13,10 +13,10 @@ import org.xbib.net.http.HttpResponseStatus;
import org.xbib.net.http.client.netty.HttpRequest; import org.xbib.net.http.client.netty.HttpRequest;
import org.xbib.net.http.client.netty.NettyHttpClient; import org.xbib.net.http.client.netty.NettyHttpClient;
import org.xbib.net.http.client.netty.NettyHttpClientConfig; import org.xbib.net.http.client.netty.NettyHttpClientConfig;
import org.xbib.net.http.server.BaseApplication; import org.xbib.net.http.server.application.BaseApplication;
import org.xbib.net.http.server.BaseHttpDomain; import org.xbib.net.http.server.domain.BaseHttpDomain;
import org.xbib.net.http.server.route.BaseHttpRouter; import org.xbib.net.http.server.route.BaseHttpRouter;
import org.xbib.net.http.server.BaseHttpService; import org.xbib.net.http.server.service.BaseHttpService;
import org.xbib.net.http.server.netty.NettyHttpServer; import org.xbib.net.http.server.netty.NettyHttpServer;
import org.xbib.net.http.server.netty.NettyHttpServerConfig; import org.xbib.net.http.server.netty.NettyHttpServerConfig;

View file

@ -7,7 +7,6 @@ import org.xbib.net.http.HttpMethod;
import org.xbib.net.http.HttpVersion; import org.xbib.net.http.HttpVersion;
import org.xbib.net.http.server.BaseHttpRequestBuilder; import org.xbib.net.http.server.BaseHttpRequestBuilder;
import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
@ -99,6 +98,6 @@ public class HttpRequestBuilder extends BaseHttpRequestBuilder {
} }
@Override @Override
public void close() throws IOException { public void release() {
} }
} }

View file

@ -116,6 +116,6 @@ public class HttpResponseBuilder extends BaseHttpResponseBuilder {
} }
@Override @Override
public void close() throws IOException { public void release() {
} }
} }

View file

@ -5,7 +5,7 @@ import org.xbib.net.http.HttpHeaderNames;
import org.xbib.net.http.HttpHeaders; import org.xbib.net.http.HttpHeaders;
import org.xbib.net.http.HttpMethod; import org.xbib.net.http.HttpMethod;
import org.xbib.net.http.HttpVersion; import org.xbib.net.http.HttpVersion;
import org.xbib.net.http.server.Application; import org.xbib.net.http.server.application.Application;
import org.xbib.net.http.server.HttpServer; import org.xbib.net.http.server.HttpServer;
import java.io.IOException; import java.io.IOException;

View file

@ -1,6 +1,6 @@
package org.xbib.net.http.server.nio; package org.xbib.net.http.server.nio;
import org.xbib.net.http.server.Application; import org.xbib.net.http.server.application.Application;
import org.xbib.net.http.server.HttpServerConfig; import org.xbib.net.http.server.HttpServerConfig;
public class NioHttpServerBuilder { public class NioHttpServerBuilder {

View file

@ -7,9 +7,9 @@ import org.xbib.net.http.HttpAddress;
import org.xbib.net.http.HttpHeaderNames; import org.xbib.net.http.HttpHeaderNames;
import org.xbib.net.http.HttpHeaderValues; import org.xbib.net.http.HttpHeaderValues;
import org.xbib.net.http.HttpResponseStatus; import org.xbib.net.http.HttpResponseStatus;
import org.xbib.net.http.server.BaseApplication; import org.xbib.net.http.server.application.BaseApplication;
import org.xbib.net.http.server.BaseHttpDomain; import org.xbib.net.http.server.domain.BaseHttpDomain;
import org.xbib.net.http.server.BaseHttpService; import org.xbib.net.http.server.service.BaseHttpService;
import org.xbib.net.http.server.route.BaseHttpRouter; import org.xbib.net.http.server.route.BaseHttpRouter;
import org.xbib.net.http.server.HttpServerConfig; import org.xbib.net.http.server.HttpServerConfig;
import org.xbib.net.http.server.nio.NioHttpServer; import org.xbib.net.http.server.nio.NioHttpServer;

View file

@ -7,10 +7,10 @@ import org.xbib.net.NetworkClass;
import org.xbib.net.http.HttpHeaderNames; import org.xbib.net.http.HttpHeaderNames;
import org.xbib.net.http.HttpHeaderValues; import org.xbib.net.http.HttpHeaderValues;
import org.xbib.net.http.HttpResponseStatus; import org.xbib.net.http.HttpResponseStatus;
import org.xbib.net.http.server.BaseApplication; import org.xbib.net.http.server.application.BaseApplication;
import org.xbib.net.http.server.BaseHttpDomain; import org.xbib.net.http.server.domain.BaseHttpDomain;
import org.xbib.net.http.server.route.BaseHttpRouter; import org.xbib.net.http.server.route.BaseHttpRouter;
import org.xbib.net.http.server.BaseHttpService; import org.xbib.net.http.server.service.BaseHttpService;
import org.xbib.net.http.server.HttpServerConfig; import org.xbib.net.http.server.HttpServerConfig;
import org.xbib.net.http.server.simple.SimpleHttpServer; import org.xbib.net.http.server.simple.SimpleHttpServer;

View file

@ -7,7 +7,6 @@ import org.xbib.net.http.HttpMethod;
import org.xbib.net.http.HttpVersion; import org.xbib.net.http.HttpVersion;
import org.xbib.net.http.server.BaseHttpRequestBuilder; import org.xbib.net.http.server.BaseHttpRequestBuilder;
import java.io.IOException;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
@ -100,7 +99,6 @@ public class HttpRequestBuilder extends BaseHttpRequestBuilder {
} }
@Override @Override
public void close() throws IOException { public void release() {
} }
} }

View file

@ -120,7 +120,6 @@ public class HttpResponseBuilder extends BaseHttpResponseBuilder {
} }
@Override @Override
public void close() throws IOException { public void release() {
} }
} }

View file

@ -5,7 +5,7 @@ import org.xbib.net.NetworkUtils;
import org.xbib.net.SocketConfig; import org.xbib.net.SocketConfig;
import org.xbib.net.http.HttpAddress; import org.xbib.net.http.HttpAddress;
import org.xbib.net.http.HttpHeaderNames; import org.xbib.net.http.HttpHeaderNames;
import org.xbib.net.http.server.Application; import org.xbib.net.http.server.application.Application;
import org.xbib.net.http.HttpHeaders; import org.xbib.net.http.HttpHeaders;
import org.xbib.net.http.HttpMethod; import org.xbib.net.http.HttpMethod;
import org.xbib.net.http.HttpVersion; import org.xbib.net.http.HttpVersion;

View file

@ -1,6 +1,6 @@
package org.xbib.net.http.server.simple; package org.xbib.net.http.server.simple;
import org.xbib.net.http.server.Application; import org.xbib.net.http.server.application.Application;
import org.xbib.net.http.server.HttpServerConfig; import org.xbib.net.http.server.HttpServerConfig;
public class SimpleHttpServerBuilder { public class SimpleHttpServerBuilder {

View file

@ -8,10 +8,10 @@ import org.xbib.net.http.HttpHeaderValues;
import org.xbib.net.http.HttpMethod; import org.xbib.net.http.HttpMethod;
import org.xbib.net.http.HttpResponseStatus; import org.xbib.net.http.HttpResponseStatus;
import org.xbib.net.http.HttpVersion; import org.xbib.net.http.HttpVersion;
import org.xbib.net.http.server.BaseApplication; import org.xbib.net.http.server.application.BaseApplication;
import org.xbib.net.http.server.BaseHttpDomain; import org.xbib.net.http.server.domain.BaseHttpDomain;
import org.xbib.net.http.server.route.BaseHttpRouter; import org.xbib.net.http.server.route.BaseHttpRouter;
import org.xbib.net.http.server.BaseHttpService; import org.xbib.net.http.server.service.BaseHttpService;
import org.xbib.net.http.server.simple.HttpRequest; import org.xbib.net.http.server.simple.HttpRequest;
import org.xbib.net.http.server.simple.HttpRequestBuilder; import org.xbib.net.http.server.simple.HttpRequestBuilder;
import org.xbib.net.http.server.simple.HttpResponse; import org.xbib.net.http.server.simple.HttpResponse;

View file

@ -7,10 +7,10 @@ import org.xbib.net.http.HttpAddress;
import org.xbib.net.http.HttpHeaderNames; import org.xbib.net.http.HttpHeaderNames;
import org.xbib.net.http.HttpHeaderValues; import org.xbib.net.http.HttpHeaderValues;
import org.xbib.net.http.HttpResponseStatus; import org.xbib.net.http.HttpResponseStatus;
import org.xbib.net.http.server.BaseApplication; import org.xbib.net.http.server.application.BaseApplication;
import org.xbib.net.http.server.BaseHttpDomain; import org.xbib.net.http.server.domain.BaseHttpDomain;
import org.xbib.net.http.server.route.BaseHttpRouter; import org.xbib.net.http.server.route.BaseHttpRouter;
import org.xbib.net.http.server.BaseHttpService; import org.xbib.net.http.server.service.BaseHttpService;
import org.xbib.net.http.server.HttpServerConfig; import org.xbib.net.http.server.HttpServerConfig;
import org.xbib.net.http.server.resource.FileResourceHandler; import org.xbib.net.http.server.resource.FileResourceHandler;
import org.xbib.net.http.server.simple.SimpleHttpServer; import org.xbib.net.http.server.simple.SimpleHttpServer;

View file

@ -1,12 +1,14 @@
import org.xbib.net.http.server.ApplicationModule; import org.xbib.net.http.server.application.ApplicationModule;
module org.xbib.net.http.server { module org.xbib.net.http.server {
uses ApplicationModule; uses ApplicationModule;
uses org.xbib.config.ConfigLogger; uses org.xbib.config.ConfigLogger;
exports org.xbib.net.http.server; exports org.xbib.net.http.server;
exports org.xbib.net.http.server.application;
exports org.xbib.net.http.server.auth; exports org.xbib.net.http.server.auth;
exports org.xbib.net.http.server.cookie; exports org.xbib.net.http.server.cookie;
exports org.xbib.net.http.server.decorate; exports org.xbib.net.http.server.decorate;
exports org.xbib.net.http.server.domain;
exports org.xbib.net.http.server.handler; exports org.xbib.net.http.server.handler;
exports org.xbib.net.http.server.ldap; exports org.xbib.net.http.server.ldap;
exports org.xbib.net.http.server.persist; exports org.xbib.net.http.server.persist;
@ -16,6 +18,7 @@ module org.xbib.net.http.server {
exports org.xbib.net.http.server.resource; exports org.xbib.net.http.server.resource;
exports org.xbib.net.http.server.resource.negotiate; exports org.xbib.net.http.server.resource.negotiate;
exports org.xbib.net.http.server.route; exports org.xbib.net.http.server.route;
exports org.xbib.net.http.server.service;
exports org.xbib.net.http.server.session; exports org.xbib.net.http.server.session;
exports org.xbib.net.http.server.session.file; exports org.xbib.net.http.server.session.file;
exports org.xbib.net.http.server.session.memory; exports org.xbib.net.http.server.session.memory;

View file

@ -1,13 +1,13 @@
package org.xbib.net.http.server; package org.xbib.net.http.server;
import java.net.InetSocketAddress;
import org.xbib.net.Attributes; import org.xbib.net.Attributes;
import org.xbib.net.Parameter; import org.xbib.net.Parameter;
import org.xbib.net.URL; import org.xbib.net.URL;
import org.xbib.net.http.HttpHeaders; import org.xbib.net.http.HttpHeaders;
import org.xbib.net.http.HttpMethod; import org.xbib.net.http.HttpMethod;
import org.xbib.net.http.HttpVersion; import org.xbib.net.http.HttpVersion;
import org.xbib.net.http.server.auth.BaseAttributes;
import java.net.InetSocketAddress;
public abstract class BaseHttpRequest implements HttpRequest { public abstract class BaseHttpRequest implements HttpRequest {

View file

@ -1,5 +1,10 @@
package org.xbib.net.http.server; package org.xbib.net.http.server;
import java.net.InetSocketAddress;
import java.nio.ByteBuffer;
import java.nio.CharBuffer;
import java.nio.charset.Charset;
import java.util.Objects;
import org.xbib.net.Parameter; import org.xbib.net.Parameter;
import org.xbib.net.URL; import org.xbib.net.URL;
import org.xbib.net.URLBuilder; import org.xbib.net.URLBuilder;
@ -8,12 +13,6 @@ import org.xbib.net.http.HttpHeaders;
import org.xbib.net.http.HttpMethod; import org.xbib.net.http.HttpMethod;
import org.xbib.net.http.HttpVersion; import org.xbib.net.http.HttpVersion;
import java.net.InetSocketAddress;
import java.nio.ByteBuffer;
import java.nio.CharBuffer;
import java.nio.charset.Charset;
import java.util.Objects;
public abstract class BaseHttpRequestBuilder implements HttpRequestBuilder { public abstract class BaseHttpRequestBuilder implements HttpRequestBuilder {
protected HttpServerContext httpServerContext; protected HttpServerContext httpServerContext;

View file

@ -1,18 +1,5 @@
package org.xbib.net.http.server; package org.xbib.net.http.server;
import org.xbib.datastructures.common.Pair;
import org.xbib.net.Attributes;
import org.xbib.net.buffer.DataBuffer;
import org.xbib.net.buffer.DataBufferFactory;
import org.xbib.net.buffer.DefaultDataBufferFactory;
import org.xbib.net.http.server.cookie.CookieEncoder;
import org.xbib.net.http.HttpHeaderNames;
import org.xbib.net.http.HttpHeaderValues;
import org.xbib.net.http.HttpHeaders;
import org.xbib.net.http.HttpResponseStatus;
import org.xbib.net.http.HttpVersion;
import org.xbib.net.http.cookie.Cookie;
import java.io.InputStream; import java.io.InputStream;
import java.nio.CharBuffer; import java.nio.CharBuffer;
import java.nio.channels.FileChannel; import java.nio.channels.FileChannel;
@ -24,6 +11,19 @@ import java.util.Locale;
import java.util.Objects; import java.util.Objects;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import org.xbib.datastructures.common.Pair;
import org.xbib.net.Attributes;
import org.xbib.net.buffer.DataBuffer;
import org.xbib.net.buffer.DataBufferFactory;
import org.xbib.net.buffer.DefaultDataBufferFactory;
import org.xbib.net.http.HttpHeaderNames;
import org.xbib.net.http.HttpHeaderValues;
import org.xbib.net.http.HttpHeaders;
import org.xbib.net.http.HttpResponseStatus;
import org.xbib.net.http.HttpVersion;
import org.xbib.net.http.cookie.Cookie;
import org.xbib.net.http.server.auth.BaseAttributes;
import org.xbib.net.http.server.cookie.CookieEncoder;
public abstract class BaseHttpResponseBuilder implements HttpResponseBuilder { public abstract class BaseHttpResponseBuilder implements HttpResponseBuilder {
@ -344,6 +344,14 @@ public abstract class BaseHttpResponseBuilder implements HttpResponseBuilder {
logger.log(Level.FINER, "done"); logger.log(Level.FINER, "done");
} }
@Override
public void release() {
if (dataBuffer != null) {
logger.log(Level.FINER, "databuffer release " + dataBuffer);
dataBuffer.release();
}
}
public void buildHeaders(long contentLength) { public void buildHeaders(long contentLength) {
this.length = contentLength; this.length = contentLength;
if (!headers.containsHeader(HttpHeaderNames.CONTENT_TYPE)) { if (!headers.containsHeader(HttpHeaderNames.CONTENT_TYPE)) {
@ -373,7 +381,7 @@ public abstract class BaseHttpResponseBuilder implements HttpResponseBuilder {
if (httpServerConfig != null && httpServerConfig.getServerName() != null) { if (httpServerConfig != null && httpServerConfig.getServerName() != null) {
headers.add(HttpHeaderNames.SERVER, httpServerConfig.getServerName()); headers.add(HttpHeaderNames.SERVER, httpServerConfig.getServerName());
} }
logger.log(Level.FINER, "done: status = " + status + " headers = " + headers); logger.log(Level.FINER, "build headers: status = " + status + " headers = " + headers);
} }
public CharBuffer wrapHeaders() { public CharBuffer wrapHeaders() {

View file

@ -1,19 +1,5 @@
package org.xbib.net.http.server; package org.xbib.net.http.server;
import java.util.Map;
import org.xbib.datastructures.json.tiny.Json;
import org.xbib.net.Attributes;
import org.xbib.net.Parameter;
import org.xbib.net.ParameterBuilder;
import org.xbib.net.URL;
import org.xbib.net.buffer.DataBuffer;
import org.xbib.net.http.HttpHeaderNames;
import org.xbib.net.http.HttpHeaderValues;
import org.xbib.net.http.HttpHeaders;
import org.xbib.net.http.HttpMethod;
import org.xbib.net.http.cookie.CookieBox;
import org.xbib.net.http.server.route.HttpRouteResolver;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.nio.CharBuffer; import java.nio.CharBuffer;
@ -24,10 +10,26 @@ import java.nio.charset.IllegalCharsetNameException;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.nio.charset.UnsupportedCharsetException; import java.nio.charset.UnsupportedCharsetException;
import java.nio.file.Path; import java.nio.file.Path;
import java.util.Map;
import java.util.Objects; import java.util.Objects;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import org.xbib.datastructures.json.tiny.Json;
import org.xbib.net.Attributes;
import org.xbib.net.Parameter;
import org.xbib.net.ParameterBuilder;
import org.xbib.net.URL;
import org.xbib.net.buffer.DataBuffer;
import org.xbib.net.http.HttpHeaderNames;
import org.xbib.net.http.HttpHeaderValues;
import org.xbib.net.http.HttpHeaders;
import org.xbib.net.http.HttpMethod;
import org.xbib.net.http.cookie.CookieBox;
import org.xbib.net.http.server.application.Application;
import org.xbib.net.http.server.auth.BaseAttributes;
import org.xbib.net.http.server.domain.HttpDomain;
import org.xbib.net.http.server.route.HttpRouteResolver;
import org.xbib.net.http.server.service.HttpService;
import static org.xbib.net.http.HttpHeaderNames.CONTENT_TYPE; import static org.xbib.net.http.HttpHeaderNames.CONTENT_TYPE;
public class BaseHttpServerContext implements HttpServerContext { public class BaseHttpServerContext implements HttpServerContext {

View file

@ -1,7 +1,7 @@
package org.xbib.net.http.server; package org.xbib.net.http.server;
import org.xbib.net.http.HttpResponseStatus;
import java.io.IOException; import java.io.IOException;
import org.xbib.net.http.HttpResponseStatus;
@SuppressWarnings("serial") @SuppressWarnings("serial")
public class HttpException extends IOException { public class HttpException extends IOException {

View file

@ -1,5 +1,7 @@
package org.xbib.net.http.server; package org.xbib.net.http.server;
import java.io.InputStream;
import java.nio.ByteBuffer;
import org.xbib.net.Attributes; import org.xbib.net.Attributes;
import org.xbib.net.Parameter; import org.xbib.net.Parameter;
import org.xbib.net.Request; import org.xbib.net.Request;
@ -8,9 +10,6 @@ import org.xbib.net.http.HttpHeaders;
import org.xbib.net.http.HttpMethod; import org.xbib.net.http.HttpMethod;
import org.xbib.net.http.HttpVersion; import org.xbib.net.http.HttpVersion;
import java.io.InputStream;
import java.nio.ByteBuffer;
public interface HttpRequest extends Request { public interface HttpRequest extends Request {
URL getServerURL(); URL getServerURL();

View file

@ -1,5 +1,7 @@
package org.xbib.net.http.server; package org.xbib.net.http.server;
import java.nio.CharBuffer;
import java.nio.charset.Charset;
import org.xbib.net.Parameter; import org.xbib.net.Parameter;
import org.xbib.net.URL; import org.xbib.net.URL;
import org.xbib.net.http.HttpAddress; import org.xbib.net.http.HttpAddress;
@ -7,11 +9,7 @@ import org.xbib.net.http.HttpHeaders;
import org.xbib.net.http.HttpMethod; import org.xbib.net.http.HttpMethod;
import org.xbib.net.http.HttpVersion; import org.xbib.net.http.HttpVersion;
import java.io.Closeable; public interface HttpRequestBuilder {
import java.nio.CharBuffer;
import java.nio.charset.Charset;
public interface HttpRequestBuilder extends Closeable {
HttpRequestBuilder setAddress(HttpAddress httpAddress); HttpRequestBuilder setAddress(HttpAddress httpAddress);
@ -49,4 +47,6 @@ public interface HttpRequestBuilder extends Closeable {
void done(); void done();
void release();
} }

View file

@ -1,8 +1,7 @@
package org.xbib.net.http.server; package org.xbib.net.http.server;
import org.xbib.net.Response;
import java.io.IOException; import java.io.IOException;
import org.xbib.net.Response;
public interface HttpResponse extends Response { public interface HttpResponse extends Response {

View file

@ -1,5 +1,9 @@
package org.xbib.net.http.server; package org.xbib.net.http.server;
import java.io.InputStream;
import java.nio.CharBuffer;
import java.nio.channels.FileChannel;
import java.nio.charset.Charset;
import org.xbib.net.Attributes; import org.xbib.net.Attributes;
import org.xbib.net.buffer.DataBuffer; import org.xbib.net.buffer.DataBuffer;
import org.xbib.net.buffer.DataBufferFactory; import org.xbib.net.buffer.DataBufferFactory;
@ -8,13 +12,7 @@ import org.xbib.net.http.HttpResponseStatus;
import org.xbib.net.http.HttpVersion; import org.xbib.net.http.HttpVersion;
import org.xbib.net.http.cookie.Cookie; import org.xbib.net.http.cookie.Cookie;
import java.io.Closeable; public interface HttpResponseBuilder {
import java.io.InputStream;
import java.nio.CharBuffer;
import java.nio.channels.FileChannel;
import java.nio.charset.Charset;
public interface HttpResponseBuilder extends Closeable {
HttpResponseBuilder setDataBufferFactory(DataBufferFactory dataBufferFactory); HttpResponseBuilder setDataBufferFactory(DataBufferFactory dataBufferFactory);
@ -74,4 +72,6 @@ public interface HttpResponseBuilder extends Closeable {
void done(); void done();
void release();
} }

View file

@ -3,6 +3,7 @@ package org.xbib.net.http.server;
import java.io.Closeable; import java.io.Closeable;
import java.io.IOException; import java.io.IOException;
import java.net.BindException; import java.net.BindException;
import org.xbib.net.http.server.application.Application;
public interface HttpServer extends Closeable { public interface HttpServer extends Closeable {

View file

@ -1,8 +1,7 @@
package org.xbib.net.http.server; package org.xbib.net.http.server;
import org.xbib.net.NetworkClass;
import java.util.Optional; import java.util.Optional;
import org.xbib.net.NetworkClass;
public class HttpServerConfig { public class HttpServerConfig {

View file

@ -1,16 +1,16 @@
package org.xbib.net.http.server; package org.xbib.net.http.server;
import org.xbib.net.Attributes;
import org.xbib.net.URL;
import org.xbib.net.buffer.DataBuffer;
import org.xbib.net.http.server.route.HttpRouteResolver;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.nio.CharBuffer; import java.nio.CharBuffer;
import java.nio.channels.FileChannel; import java.nio.channels.FileChannel;
import java.nio.charset.Charset; import java.nio.charset.Charset;
import java.nio.file.Path; import java.nio.file.Path;
import org.xbib.net.Attributes;
import org.xbib.net.URL;
import org.xbib.net.buffer.DataBuffer;
import org.xbib.net.http.server.route.HttpRouteResolver;
import org.xbib.net.http.server.service.HttpService;
public interface HttpServerContext { public interface HttpServerContext {

View file

@ -2,6 +2,8 @@ package org.xbib.net.http.server;
import org.xbib.net.ParameterDefinition; import org.xbib.net.ParameterDefinition;
import org.xbib.net.http.HttpMethod; import org.xbib.net.http.HttpMethod;
import org.xbib.net.http.server.domain.HttpSecurityDomain;
import org.xbib.net.http.server.service.HttpService;
public interface HttpServiceBuilder { public interface HttpServiceBuilder {

View file

@ -1,9 +1,4 @@
package org.xbib.net.http.server; package org.xbib.net.http.server.application;
import org.xbib.net.http.HttpAddress;
import org.xbib.net.http.HttpResponseStatus;
import org.xbib.net.http.server.session.SessionListener;
import org.xbib.settings.Settings;
import java.io.Closeable; import java.io.Closeable;
import java.io.IOException; import java.io.IOException;
@ -12,6 +7,14 @@ import java.time.ZoneId;
import java.util.Collection; import java.util.Collection;
import java.util.Locale; import java.util.Locale;
import java.util.Set; import java.util.Set;
import org.xbib.net.http.HttpAddress;
import org.xbib.net.http.HttpResponseStatus;
import org.xbib.net.http.server.HttpRequestBuilder;
import org.xbib.net.http.server.HttpResponseBuilder;
import org.xbib.net.http.server.HttpServerContext;
import org.xbib.net.http.server.domain.HttpDomain;
import org.xbib.net.http.server.session.SessionListener;
import org.xbib.settings.Settings;
public interface Application extends SessionListener, Resolver<Path>, Closeable { public interface Application extends SessionListener, Resolver<Path>, Closeable {

View file

@ -1,11 +1,10 @@
package org.xbib.net.http.server; package org.xbib.net.http.server.application;
import org.xbib.net.http.server.route.HttpRouter;
import java.nio.file.Path; import java.nio.file.Path;
import java.time.ZoneId; import java.time.ZoneId;
import java.util.Locale; import java.util.Locale;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import org.xbib.net.http.server.route.HttpRouter;
public interface ApplicationBuilder { public interface ApplicationBuilder {

View file

@ -1,5 +1,8 @@
package org.xbib.net.http.server; package org.xbib.net.http.server.application;
import org.xbib.net.http.server.HttpRequest;
import org.xbib.net.http.server.HttpServerContext;
import org.xbib.net.http.server.service.HttpService;
import org.xbib.net.http.server.session.Session; import org.xbib.net.http.server.session.Session;
import org.xbib.settings.Settings; import org.xbib.settings.Settings;

View file

@ -0,0 +1,52 @@
package org.xbib.net.http.server.application;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.Callable;
import java.util.concurrent.RunnableFuture;
import java.util.concurrent.SynchronousQueue;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import java.util.logging.Level;
import java.util.logging.Logger;
public class ApplicationThreadPoolExecutor extends ThreadPoolExecutor {
private final Logger logger = Logger.getLogger(ApplicationThreadPoolExecutor.class.getName());
public ApplicationThreadPoolExecutor(int nThreads, int maxQueue,
long keepAliveTime, TimeUnit timeUnit,
ThreadFactory threadFactory) {
super(nThreads, nThreads, keepAliveTime, timeUnit, createBlockingQueue(maxQueue), threadFactory);
logger.log(Level.FINE, "threadpool executor up with nThreads = " + nThreads +
" keepAliveTime = " + keepAliveTime +
" time unit = " + timeUnit +
" maxQueue = " + maxQueue +
" threadFactory = " + threadFactory);
}
private static BlockingQueue<Runnable> createBlockingQueue(int max) {
return max == Integer.MAX_VALUE ? new SynchronousQueue<>(true) : new ArrayBlockingQueue<>(max);
}
@Override
protected <T> RunnableFuture<T> newTaskFor(Callable<T> callable) {
return new RouterTask<>(callable);
}
@Override
protected void afterExecute(Runnable runnable, Throwable terminationCause) {
super.afterExecute(runnable, terminationCause);
logger.log(Level.FINEST, "after execute of " + runnable);
if (terminationCause != null) {
logger.log(Level.SEVERE, terminationCause.getMessage(), terminationCause);
return;
}
if (runnable instanceof RouterTask<?> routerTask) {
RouterCallable routerCallable = (RouterCallable) routerTask.getCallable();
logger.log(Level.FINEST, "release " + routerCallable);
routerCallable.release();
}
}
}

View file

@ -1,22 +1,4 @@
package org.xbib.net.http.server; package org.xbib.net.http.server.application;
import org.xbib.net.http.cookie.SameSite;
import org.xbib.net.http.server.route.HttpRouter;
import org.xbib.net.http.HttpAddress;
import org.xbib.net.http.HttpResponseStatus;
import org.xbib.net.http.server.cookie.IncomingCookieHandler;
import org.xbib.net.http.server.cookie.OutgoingCookieHandler;
import org.xbib.net.http.server.persist.Codec;
import org.xbib.net.http.server.session.memory.MemoryPropertiesSessionCodec;
import org.xbib.net.http.server.render.HttpResponseRenderer;
import org.xbib.net.http.server.session.IncomingSessionHandler;
import org.xbib.net.http.server.session.OutgoingSessionHandler;
import org.xbib.net.http.server.session.Session;
import org.xbib.net.http.server.util.BlockingThreadPoolExecutor;
import org.xbib.net.http.server.validate.HttpRequestValidator;
import org.xbib.net.util.NamedThreadFactory;
import org.xbib.net.util.RandomUtil;
import org.xbib.settings.Settings;
import java.io.Closeable; import java.io.Closeable;
import java.io.IOException; import java.io.IOException;
@ -32,6 +14,29 @@ import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import org.xbib.net.http.HttpAddress;
import org.xbib.net.http.HttpResponseStatus;
import org.xbib.net.http.cookie.SameSite;
import org.xbib.net.http.server.BaseHttpServerContext;
import org.xbib.net.http.server.HttpException;
import org.xbib.net.http.server.HttpHandler;
import org.xbib.net.http.server.HttpRequestBuilder;
import org.xbib.net.http.server.HttpResponseBuilder;
import org.xbib.net.http.server.HttpServerContext;
import org.xbib.net.http.server.cookie.IncomingCookieHandler;
import org.xbib.net.http.server.cookie.OutgoingCookieHandler;
import org.xbib.net.http.server.domain.HttpDomain;
import org.xbib.net.http.server.persist.Codec;
import org.xbib.net.http.server.render.HttpResponseRenderer;
import org.xbib.net.http.server.route.HttpRouter;
import org.xbib.net.http.server.session.IncomingSessionHandler;
import org.xbib.net.http.server.session.OutgoingSessionHandler;
import org.xbib.net.http.server.session.Session;
import org.xbib.net.http.server.session.memory.MemoryPropertiesSessionCodec;
import org.xbib.net.http.server.validate.HttpRequestValidator;
import org.xbib.net.util.NamedThreadFactory;
import org.xbib.net.util.RandomUtil;
import org.xbib.settings.Settings;
public class BaseApplication implements Application { public class BaseApplication implements Application {
@ -39,7 +44,7 @@ public class BaseApplication implements Application {
protected BaseApplicationBuilder builder; protected BaseApplicationBuilder builder;
private final BlockingThreadPoolExecutor executor; private final ApplicationThreadPoolExecutor executor;
private final HttpRequestValidator httpRequestValidator; private final HttpRequestValidator httpRequestValidator;
@ -59,7 +64,7 @@ public class BaseApplication implements Application {
protected BaseApplication(BaseApplicationBuilder builder) { protected BaseApplication(BaseApplicationBuilder builder) {
this.builder = builder; this.builder = builder;
this.executor = new BlockingThreadPoolExecutor(builder.blockingThreadCount, builder.blockingThreadQueueCount, this.executor = new ApplicationThreadPoolExecutor(builder.blockingThreadCount, builder.blockingThreadQueueCount,
builder.blockingThreadKeepAliveTime, builder.blockingThreadKeepAliveTimeUnit, builder.blockingThreadKeepAliveTime, builder.blockingThreadKeepAliveTimeUnit,
new NamedThreadFactory("org-xbib-net-http-server-application")); new NamedThreadFactory("org-xbib-net-http-server-application"));
this.executor.setRejectedExecutionHandler((runnable, threadPoolExecutor) -> this.executor.setRejectedExecutionHandler((runnable, threadPoolExecutor) ->
@ -128,9 +133,21 @@ public class BaseApplication implements Application {
@Override @Override
public void dispatch(HttpRequestBuilder httpRequestBuilder, public void dispatch(HttpRequestBuilder httpRequestBuilder,
HttpResponseBuilder httpResponseBuilder) { HttpResponseBuilder httpResponseBuilder) {
Submittable submittable = new Submittable(httpRequestBuilder, httpResponseBuilder); RouterCallable routerCallable = new RouterCallable() {
Future<?> future = executor.submit(submittable); @Override
logger.log(Level.FINE, "dispatching " + future); public Boolean call() {
getRouter().route(httpRequestBuilder, httpResponseBuilder);
return true;
}
@Override
public void release() {
httpRequestBuilder.release();
httpResponseBuilder.release();
}
};
Future<?> future = executor.submit(routerCallable);
logger.log(Level.FINE, "dispatched " + future);
} }
@Override @Override
@ -139,10 +156,21 @@ public class BaseApplication implements Application {
HttpResponseStatus httpResponseStatus) { HttpResponseStatus httpResponseStatus) {
HttpServerContext httpServerContext = createContext(null, httpRequestBuilder, httpResponseBuilder); HttpServerContext httpServerContext = createContext(null, httpRequestBuilder, httpResponseBuilder);
httpServerContext.getAttributes().put("responsebuilder", httpResponseBuilder); httpServerContext.getAttributes().put("responsebuilder", httpResponseBuilder);
StatusSubmittable submittable = new StatusSubmittable(httpRequestBuilder, httpResponseBuilder, RouterCallable routerCallable = new RouterCallable() {
httpResponseStatus, httpServerContext); @Override
Future<?> future = executor.submit(submittable); public Boolean call() {
logger.log(Level.FINE, "dispatching status " + future); getRouter().routeStatus(httpResponseStatus, httpServerContext);
return true;
}
@Override
public void release() {
httpRequestBuilder.release();
httpResponseBuilder.release();
}
};
Future<?> future = executor.submit(routerCallable);
logger.log(Level.FINE, "dispatched status " + future);
} }
@Override @Override
@ -331,68 +359,4 @@ public class BaseApplication implements Application {
logger.log(Level.INFO, "application closed"); logger.log(Level.INFO, "application closed");
} }
private class Submittable implements Runnable, Closeable {
private final HttpRequestBuilder httpRequestBuilder;
private final HttpResponseBuilder httpResponseBuilder;
private Submittable(HttpRequestBuilder httpRequestBuilder,
HttpResponseBuilder httpResponseBuilder) {
this.httpRequestBuilder = httpRequestBuilder;
this.httpResponseBuilder = httpResponseBuilder;
}
@Override
public void run() {
try {
getRouter().route(httpRequestBuilder, httpResponseBuilder);
} catch (Throwable t) {
logger.log(Level.SEVERE, t.getMessage(), t);
throw t;
}
}
@Override
public void close() throws IOException {
httpRequestBuilder.close();
httpResponseBuilder.close();
}
}
private class StatusSubmittable implements Runnable, Closeable {
private final HttpRequestBuilder httpRequestBuilder;
private final HttpResponseBuilder httpResponseBuilder;
private final HttpResponseStatus httpResponseStatus;
private final HttpServerContext httpServerContext;
private StatusSubmittable(HttpRequestBuilder httpRequestBuilder,
HttpResponseBuilder httpResponseBuilder,
HttpResponseStatus httpResponseStatus,
HttpServerContext httpServerContext) {
this.httpRequestBuilder = httpRequestBuilder;
this.httpResponseBuilder = httpResponseBuilder;
this.httpResponseStatus = httpResponseStatus;
this.httpServerContext = httpServerContext;
}
@Override
public void run() {
try {
getRouter().routeStatus(httpResponseStatus, httpServerContext);
} catch (Throwable t) {
logger.log(Level.SEVERE, t.getMessage(), t);
throw t;
}
}
@Override
public void close() throws IOException {
httpRequestBuilder.close();
httpResponseBuilder.close();
}
}
} }

View file

@ -1,11 +1,4 @@
package org.xbib.net.http.server; package org.xbib.net.http.server.application;
import org.xbib.config.ConfigLoader;
import org.xbib.config.ConfigLogger;
import org.xbib.config.ConfigParams;
import org.xbib.config.SystemConfigLogger;
import org.xbib.net.http.server.route.HttpRouter;
import org.xbib.settings.Settings;
import java.nio.file.Path; import java.nio.file.Path;
import java.nio.file.Paths; import java.nio.file.Paths;
@ -20,6 +13,12 @@ import java.util.Set;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import org.xbib.config.ConfigLoader;
import org.xbib.config.ConfigLogger;
import org.xbib.config.ConfigParams;
import org.xbib.config.SystemConfigLogger;
import org.xbib.net.http.server.route.HttpRouter;
import org.xbib.settings.Settings;
public class BaseApplicationBuilder implements ApplicationBuilder { public class BaseApplicationBuilder implements ApplicationBuilder {

View file

@ -1,5 +1,8 @@
package org.xbib.net.http.server; package org.xbib.net.http.server.application;
import org.xbib.net.http.server.HttpRequest;
import org.xbib.net.http.server.HttpServerContext;
import org.xbib.net.http.server.service.HttpService;
import org.xbib.net.http.server.session.Session; import org.xbib.net.http.server.session.Session;
import org.xbib.settings.Settings; import org.xbib.settings.Settings;

View file

@ -1,4 +1,4 @@
package org.xbib.net.http.server; package org.xbib.net.http.server.application;
public interface Resolver<R> { public interface Resolver<R> {

View file

@ -0,0 +1,7 @@
package org.xbib.net.http.server.application;
import java.util.concurrent.Callable;
import org.xbib.net.buffer.Releasable;
public interface RouterCallable extends Callable<Boolean>, Releasable {
}

View file

@ -0,0 +1,18 @@
package org.xbib.net.http.server.application;
import java.util.concurrent.Callable;
import java.util.concurrent.FutureTask;
public class RouterTask<T> extends FutureTask<T> {
private final Callable<T> callable;
public RouterTask(Callable<T> callable) {
super(callable);
this.callable = callable;
}
public Callable<T> getCallable() {
return callable;
}
}

View file

@ -1,8 +1,7 @@
package org.xbib.net.http.server; package org.xbib.net.http.server.auth;
import org.xbib.net.Attributes;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import org.xbib.net.Attributes;
@SuppressWarnings("serial") @SuppressWarnings("serial")
public class BaseAttributes extends LinkedHashMap<String, Object> implements Attributes { public class BaseAttributes extends LinkedHashMap<String, Object> implements Attributes {

View file

@ -1,11 +1,9 @@
package org.xbib.net.http.server.auth; package org.xbib.net.http.server.auth;
import org.xbib.net.Attributes;
import org.xbib.net.UserProfile;
import org.xbib.net.http.server.BaseAttributes;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import org.xbib.net.Attributes;
import org.xbib.net.UserProfile;
public class BaseUserProfile implements UserProfile { public class BaseUserProfile implements UserProfile {

View file

@ -1,5 +1,9 @@
package org.xbib.net.http.server.auth; package org.xbib.net.http.server.auth;
import java.io.IOException;
import java.util.Base64;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.xbib.net.SecurityRealm; import org.xbib.net.SecurityRealm;
import org.xbib.net.UserProfile; import org.xbib.net.UserProfile;
import org.xbib.net.http.HttpHeaderNames; import org.xbib.net.http.HttpHeaderNames;
@ -8,11 +12,6 @@ import org.xbib.net.http.server.HttpHandler;
import org.xbib.net.http.server.HttpRequest; import org.xbib.net.http.server.HttpRequest;
import org.xbib.net.http.server.HttpServerContext; import org.xbib.net.http.server.HttpServerContext;
import java.io.IOException;
import java.util.Base64;
import java.util.logging.Level;
import java.util.logging.Logger;
public class BasicAuthenticationHandler extends LoginAuthenticationHandler implements HttpHandler { public class BasicAuthenticationHandler extends LoginAuthenticationHandler implements HttpHandler {
private static final Logger logger = Logger.getLogger(BasicAuthenticationHandler.class.getName()); private static final Logger logger = Logger.getLogger(BasicAuthenticationHandler.class.getName());

View file

@ -1,6 +1,9 @@
package org.xbib.net.http.server.auth; package org.xbib.net.http.server.auth;
import java.io.IOException;
import java.util.Collection; import java.util.Collection;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.xbib.net.Authenticator; import org.xbib.net.Authenticator;
import org.xbib.net.GroupsProvider; import org.xbib.net.GroupsProvider;
import org.xbib.net.Parameter; import org.xbib.net.Parameter;
@ -12,10 +15,6 @@ import org.xbib.net.UsersProvider;
import org.xbib.net.http.server.HttpHandler; import org.xbib.net.http.server.HttpHandler;
import org.xbib.net.http.server.HttpServerContext; import org.xbib.net.http.server.HttpServerContext;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
public class LoginAuthenticationHandler implements HttpHandler { public class LoginAuthenticationHandler implements HttpHandler {
private static final Logger logger = Logger.getLogger(LoginAuthenticationHandler.class.getName()); private static final Logger logger = Logger.getLogger(LoginAuthenticationHandler.class.getName());

View file

@ -1,13 +1,12 @@
package org.xbib.net.http.server.cookie; package org.xbib.net.http.server.cookie;
import org.xbib.net.http.cookie.Cookie;
import org.xbib.net.http.cookie.CookieHeaderNames;
import org.xbib.net.http.cookie.DefaultCookie;
import java.util.Collections; import java.util.Collections;
import java.util.LinkedHashSet; import java.util.LinkedHashSet;
import java.util.Objects; import java.util.Objects;
import java.util.Set; import java.util.Set;
import org.xbib.net.http.cookie.Cookie;
import org.xbib.net.http.cookie.CookieHeaderNames;
import org.xbib.net.http.cookie.DefaultCookie;
/** /**
* A <a href="http://tools.ietf.org/html/rfc6265">RFC6265</a> compliant cookie decoder to be used server side. * A <a href="http://tools.ietf.org/html/rfc6265">RFC6265</a> compliant cookie decoder to be used server side.

View file

@ -1,13 +1,12 @@
package org.xbib.net.http.server.cookie; package org.xbib.net.http.server.cookie;
import org.xbib.net.http.cookie.Cookie;
import org.xbib.net.http.cookie.CookieHeaderNames;
import org.xbib.net.http.cookie.CookieUtil;
import org.xbib.net.util.DateTimeUtil;
import java.time.Instant; import java.time.Instant;
import java.util.Locale; import java.util.Locale;
import java.util.Objects; import java.util.Objects;
import org.xbib.net.http.cookie.Cookie;
import org.xbib.net.http.cookie.CookieHeaderNames;
import org.xbib.net.http.cookie.CookieUtil;
import org.xbib.net.util.DateTimeUtil;
/** /**
* A <a href="http://tools.ietf.org/html/rfc6265">RFC6265</a> compliant cookie encoder to be used server side, * A <a href="http://tools.ietf.org/html/rfc6265">RFC6265</a> compliant cookie encoder to be used server side,

View file

@ -1,15 +1,14 @@
package org.xbib.net.http.server.cookie; package org.xbib.net.http.server.cookie;
import org.xbib.net.util.JsonUtil;
import javax.crypto.Mac;
import javax.crypto.spec.SecretKeySpec;
import java.io.IOException; import java.io.IOException;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.security.InvalidKeyException; import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException; import java.security.NoSuchAlgorithmException;
import java.util.Base64; import java.util.Base64;
import java.util.Map; import java.util.Map;
import javax.crypto.Mac;
import javax.crypto.spec.SecretKeySpec;
import org.xbib.net.util.JsonUtil;
public class CookieSignatureUtil { public class CookieSignatureUtil {

View file

@ -1,5 +1,6 @@
package org.xbib.net.http.server.cookie; package org.xbib.net.http.server.cookie;
import java.util.Collection;
import java.util.logging.Logger; import java.util.logging.Logger;
import org.xbib.net.http.HttpHeaderNames; import org.xbib.net.http.HttpHeaderNames;
import org.xbib.net.http.cookie.CookieBox; import org.xbib.net.http.cookie.CookieBox;
@ -7,8 +8,6 @@ import org.xbib.net.http.server.HttpException;
import org.xbib.net.http.server.HttpHandler; import org.xbib.net.http.server.HttpHandler;
import org.xbib.net.http.server.HttpServerContext; import org.xbib.net.http.server.HttpServerContext;
import java.util.Collection;
public class IncomingCookieHandler implements HttpHandler { public class IncomingCookieHandler implements HttpHandler {
private static final Logger logger = Logger.getLogger(IncomingCookieHandler.class.getName()); private static final Logger logger = Logger.getLogger(IncomingCookieHandler.class.getName());

View file

@ -1,14 +1,13 @@
package org.xbib.net.http.server.cookie; package org.xbib.net.http.server.cookie;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.xbib.net.http.cookie.Cookie; import org.xbib.net.http.cookie.Cookie;
import org.xbib.net.http.cookie.CookieBox; import org.xbib.net.http.cookie.CookieBox;
import org.xbib.net.http.server.HttpException; import org.xbib.net.http.server.HttpException;
import org.xbib.net.http.server.HttpHandler; import org.xbib.net.http.server.HttpHandler;
import org.xbib.net.http.server.HttpServerContext; import org.xbib.net.http.server.HttpServerContext;
import java.util.logging.Level;
import java.util.logging.Logger;
public class OutgoingCookieHandler implements HttpHandler { public class OutgoingCookieHandler implements HttpHandler {
private static final Logger logger = Logger.getLogger(OutgoingCookieHandler.class.getName()); private static final Logger logger = Logger.getLogger(OutgoingCookieHandler.class.getName());

View file

@ -1,16 +1,14 @@
package org.xbib.net.http.server.decorate; package org.xbib.net.http.server.decorate;
import java.io.IOException;
import java.util.Collection; import java.util.Collection;
import java.util.Objects;
import org.xbib.net.ParameterDefinition; import org.xbib.net.ParameterDefinition;
import org.xbib.net.http.HttpMethod; import org.xbib.net.http.HttpMethod;
import org.xbib.net.http.server.HttpHandler; import org.xbib.net.http.server.HttpHandler;
import org.xbib.net.http.server.HttpSecurityDomain;
import org.xbib.net.http.server.HttpServerContext; import org.xbib.net.http.server.HttpServerContext;
import org.xbib.net.http.server.HttpService; import org.xbib.net.http.server.domain.HttpSecurityDomain;
import org.xbib.net.http.server.service.HttpService;
import java.io.IOException;
import java.util.Objects;
public class DecoratingHttpService implements HttpService { public class DecoratingHttpService implements HttpService {

View file

@ -1,7 +1,7 @@
package org.xbib.net.http.server.decorate; package org.xbib.net.http.server.decorate;
import org.xbib.net.http.server.HttpServerConfig; import org.xbib.net.http.server.HttpServerConfig;
import org.xbib.net.http.server.Service; import org.xbib.net.http.server.service.Service;
public abstract class DecoratingService extends AbstractUnwrappable<Service> implements Service { public abstract class DecoratingService extends AbstractUnwrappable<Service> implements Service {

View file

@ -1,9 +1,10 @@
package org.xbib.net.http.server; package org.xbib.net.http.server.domain;
import java.util.Collection; import java.util.Collection;
import java.util.Objects; import java.util.Objects;
import java.util.Set; import java.util.Set;
import org.xbib.net.http.HttpAddress; import org.xbib.net.http.HttpAddress;
import org.xbib.net.http.server.service.HttpService;
public class BaseHttpDomain implements HttpDomain { public class BaseHttpDomain implements HttpDomain {

View file

@ -1,4 +1,4 @@
package org.xbib.net.http.server; package org.xbib.net.http.server.domain;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
@ -7,6 +7,7 @@ import java.util.LinkedHashSet;
import java.util.Objects; import java.util.Objects;
import java.util.Set; import java.util.Set;
import org.xbib.net.http.HttpAddress; import org.xbib.net.http.HttpAddress;
import org.xbib.net.http.server.service.HttpService;
public class BaseHttpDomainBuilder implements HttpDomainBuilder { public class BaseHttpDomainBuilder implements HttpDomainBuilder {

View file

@ -1,7 +1,8 @@
package org.xbib.net.http.server; package org.xbib.net.http.server.domain;
import java.util.List; import java.util.List;
import org.xbib.net.SecurityRealm; import org.xbib.net.SecurityRealm;
import org.xbib.net.http.server.HttpHandler;
public class BaseHttpSecurityDomain implements HttpSecurityDomain { public class BaseHttpSecurityDomain implements HttpSecurityDomain {

View file

@ -1,8 +1,9 @@
package org.xbib.net.http.server; package org.xbib.net.http.server.domain;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import org.xbib.net.SecurityRealm; import org.xbib.net.SecurityRealm;
import org.xbib.net.http.server.HttpHandler;
public class BaseHttpSecurityDomainBuilder { public class BaseHttpSecurityDomainBuilder {

View file

@ -1,9 +1,9 @@
package org.xbib.net.http.server; package org.xbib.net.http.server.domain;
import org.xbib.net.http.HttpAddress;
import java.util.Collection; import java.util.Collection;
import java.util.Set; import java.util.Set;
import org.xbib.net.http.HttpAddress;
import org.xbib.net.http.server.service.HttpService;
/** /**
* The {@code HttpDomain} interface represents a set of domain names attached to an HTTP address. * The {@code HttpDomain} interface represents a set of domain names attached to an HTTP address.

View file

@ -1,8 +1,8 @@
package org.xbib.net.http.server; package org.xbib.net.http.server.domain;
import org.xbib.net.http.HttpAddress;
import java.io.IOException; import java.io.IOException;
import org.xbib.net.http.HttpAddress;
import org.xbib.net.http.server.service.HttpService;
public interface HttpDomainBuilder { public interface HttpDomainBuilder {

View file

@ -1,7 +1,8 @@
package org.xbib.net.http.server; package org.xbib.net.http.server.domain;
import java.util.List; import java.util.List;
import org.xbib.net.SecurityDomain; import org.xbib.net.SecurityDomain;
import org.xbib.net.http.server.HttpHandler;
public interface HttpSecurityDomain extends SecurityDomain { public interface HttpSecurityDomain extends SecurityDomain {

View file

@ -1,13 +1,12 @@
package org.xbib.net.http.server.handler; package org.xbib.net.http.server.handler;
import org.xbib.net.http.server.HttpErrorHandler;
import org.xbib.net.http.server.HttpException;
import org.xbib.net.http.HttpResponseStatus;
import org.xbib.net.http.server.HttpServerContext;
import java.io.IOException; import java.io.IOException;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import org.xbib.net.http.HttpResponseStatus;
import org.xbib.net.http.server.HttpErrorHandler;
import org.xbib.net.http.server.HttpException;
import org.xbib.net.http.server.HttpServerContext;
public class InternalServerErrorHandler implements HttpErrorHandler { public class InternalServerErrorHandler implements HttpErrorHandler {

View file

@ -1,11 +1,10 @@
package org.xbib.net.http.server.handler; package org.xbib.net.http.server.handler;
import java.io.IOException;
import org.xbib.net.http.HttpResponseStatus; import org.xbib.net.http.HttpResponseStatus;
import org.xbib.net.http.server.HttpErrorHandler; import org.xbib.net.http.server.HttpErrorHandler;
import org.xbib.net.http.server.HttpServerContext; import org.xbib.net.http.server.HttpServerContext;
import java.io.IOException;
public class NotFoundHandler implements HttpErrorHandler { public class NotFoundHandler implements HttpErrorHandler {
public NotFoundHandler() { public NotFoundHandler() {

View file

@ -1,11 +1,10 @@
package org.xbib.net.http.server.handler; package org.xbib.net.http.server.handler;
import java.io.IOException;
import org.xbib.net.http.HttpResponseStatus; import org.xbib.net.http.HttpResponseStatus;
import org.xbib.net.http.server.HttpErrorHandler; import org.xbib.net.http.server.HttpErrorHandler;
import org.xbib.net.http.server.HttpServerContext; import org.xbib.net.http.server.HttpServerContext;
import java.io.IOException;
public class NotImplementedHandler implements HttpErrorHandler { public class NotImplementedHandler implements HttpErrorHandler {
public NotImplementedHandler() { public NotImplementedHandler() {

View file

@ -3,8 +3,8 @@ package org.xbib.net.http.server.ldap;
import java.util.Map; import java.util.Map;
import org.xbib.net.Authenticator; import org.xbib.net.Authenticator;
import org.xbib.net.GroupsProvider; import org.xbib.net.GroupsProvider;
import org.xbib.net.UsersProvider;
import org.xbib.net.SecurityRealm; import org.xbib.net.SecurityRealm;
import org.xbib.net.UsersProvider;
public class LdapRealm extends SecurityRealm { public class LdapRealm extends SecurityRealm {

View file

@ -7,9 +7,8 @@ import javax.naming.NamingException;
import javax.naming.directory.Attribute; import javax.naming.directory.Attribute;
import javax.naming.directory.Attributes; import javax.naming.directory.Attributes;
import javax.naming.directory.SearchResult; import javax.naming.directory.SearchResult;
import org.xbib.net.UsersProvider;
import org.xbib.net.UserDetails; import org.xbib.net.UserDetails;
import org.xbib.net.UsersProvider;
import static java.lang.String.format; import static java.lang.String.format;
public class LdapUsersProvider extends UsersProvider { public class LdapUsersProvider extends UsersProvider {

View file

@ -1,7 +1,5 @@
package org.xbib.net.http.server.persist.file; package org.xbib.net.http.server.persist.file;
import org.xbib.net.http.server.persist.Codec;
import java.io.IOException; import java.io.IOException;
import java.io.Reader; import java.io.Reader;
import java.io.Writer; import java.io.Writer;
@ -12,6 +10,7 @@ import java.util.LinkedHashMap;
import java.util.Map; import java.util.Map;
import java.util.Properties; import java.util.Properties;
import java.util.concurrent.locks.ReentrantReadWriteLock; import java.util.concurrent.locks.ReentrantReadWriteLock;
import org.xbib.net.http.server.persist.Codec;
public class FilePropertiesCodec implements Codec<Map<String, Object>> { public class FilePropertiesCodec implements Codec<Map<String, Object>> {

View file

@ -1,14 +1,12 @@
package org.xbib.net.http.server.persist.memory; package org.xbib.net.http.server.persist.memory;
import org.xbib.net.http.server.persist.Codec;
import java.io.IOException; import java.io.IOException;
import java.util.HashMap; import java.util.HashMap;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.Map; import java.util.Map;
import java.util.Properties; import java.util.Properties;
import java.util.concurrent.locks.ReentrantReadWriteLock; import java.util.concurrent.locks.ReentrantReadWriteLock;
import org.xbib.net.http.server.persist.Codec;
public class MemoryPropertiesCodec implements Codec<Map<String, Object>> { public class MemoryPropertiesCodec implements Codec<Map<String, Object>> {

View file

@ -1,12 +1,11 @@
package org.xbib.net.http.server.render; package org.xbib.net.http.server.render;
import java.io.IOException;
import org.xbib.net.http.server.HttpHandler; import org.xbib.net.http.server.HttpHandler;
import org.xbib.net.http.server.HttpResponse; import org.xbib.net.http.server.HttpResponse;
import org.xbib.net.http.server.HttpResponseBuilder; import org.xbib.net.http.server.HttpResponseBuilder;
import org.xbib.net.http.server.HttpServerContext; import org.xbib.net.http.server.HttpServerContext;
import java.io.IOException;
public class HttpResponseRenderer implements HttpHandler { public class HttpResponseRenderer implements HttpHandler {
public HttpResponseRenderer() { public HttpResponseRenderer() {

View file

@ -1,20 +1,5 @@
package org.xbib.net.http.server.resource; package org.xbib.net.http.server.resource;
import org.xbib.net.Resource;
import org.xbib.net.URL;
import org.xbib.net.buffer.DataBuffer;
import org.xbib.net.buffer.DataBufferUtil;
import org.xbib.net.http.HttpHeaderNames;
import org.xbib.net.http.HttpHeaders;
import org.xbib.net.http.HttpMethod;
import org.xbib.net.http.HttpResponseStatus;
import org.xbib.net.http.server.HttpException;
import org.xbib.net.http.server.HttpHandler;
import org.xbib.net.http.server.HttpResponseBuilder;
import org.xbib.net.http.server.HttpServerContext;
import org.xbib.net.util.DateTimeUtil;
import org.xbib.net.mime.MimeTypeService;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.net.URISyntaxException; import java.net.URISyntaxException;
@ -33,6 +18,20 @@ import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import org.xbib.net.Resource;
import org.xbib.net.URL;
import org.xbib.net.buffer.DataBuffer;
import org.xbib.net.buffer.DataBufferUtil;
import org.xbib.net.http.HttpHeaderNames;
import org.xbib.net.http.HttpHeaders;
import org.xbib.net.http.HttpMethod;
import org.xbib.net.http.HttpResponseStatus;
import org.xbib.net.http.server.HttpException;
import org.xbib.net.http.server.HttpHandler;
import org.xbib.net.http.server.HttpResponseBuilder;
import org.xbib.net.http.server.HttpServerContext;
import org.xbib.net.mime.MimeTypeService;
import org.xbib.net.util.DateTimeUtil;
public abstract class AbstractResourceHandler implements HttpHandler { public abstract class AbstractResourceHandler implements HttpHandler {
@ -267,6 +266,7 @@ public abstract class AbstractResourceHandler implements HttpHandler {
.append(StandardCharsets.ISO_8859_1.decode(dataBuffer.asByteBuffer())) .append(StandardCharsets.ISO_8859_1.decode(dataBuffer.asByteBuffer()))
.append('\n') .append('\n')
.append("--MULTIPART_BOUNDARY--").append('\n'); .append("--MULTIPART_BOUNDARY--").append('\n');
dataBuffer.release();
} catch (URISyntaxException | IOException e) { } catch (URISyntaxException | IOException e) {
logger.log(Level.FINEST, e.getMessage(), e); logger.log(Level.FINEST, e.getMessage(), e);
} }
@ -345,9 +345,10 @@ public abstract class AbstractResourceHandler implements HttpHandler {
} else { } else {
fileChannel = fileChannel.position(offset); fileChannel = fileChannel.position(offset);
try (ReadableByteChannel channel = fileChannel) { try (ReadableByteChannel channel = fileChannel) {
DataBuffer dataBuffer = DataBufferUtil.readBuffer(responseBuilder.getDataBufferFactory(), channel, size);
responseBuilder.setResponseStatus(httpResponseStatus) responseBuilder.setResponseStatus(httpResponseStatus)
.setContentType(contentType) .setContentType(contentType)
.write(DataBufferUtil.readBuffer(responseBuilder.getDataBufferFactory(), channel, size)); .write(dataBuffer);
} }
} }
} }
@ -363,10 +364,11 @@ public abstract class AbstractResourceHandler implements HttpHandler {
} else { } else {
long n = inputStream.skip(offset); long n = inputStream.skip(offset);
try (ReadableByteChannel channel = Channels.newChannel(inputStream)) { try (ReadableByteChannel channel = Channels.newChannel(inputStream)) {
DataBuffer dataBuffer = DataBufferUtil.readBuffer(responseBuilder.getDataBufferFactory(), channel, size);
responseBuilder responseBuilder
.setResponseStatus(httpResponseStatus) .setResponseStatus(httpResponseStatus)
.setContentType(contentType) .setContentType(contentType)
.write(DataBufferUtil.readBuffer(responseBuilder.getDataBufferFactory(), channel, size)); .write(dataBuffer);
} }
} }
} }

View file

@ -1,10 +1,9 @@
package org.xbib.net.http.server.resource; package org.xbib.net.http.server.resource;
import org.xbib.net.Resource;
import org.xbib.net.URL;
import java.nio.file.Path; import java.nio.file.Path;
import java.time.Instant; import java.time.Instant;
import org.xbib.net.Resource;
import org.xbib.net.URL;
public class BaseResource implements Resource { public class BaseResource implements Resource {

View file

@ -1,16 +1,15 @@
package org.xbib.net.http.server.resource; package org.xbib.net.http.server.resource;
import org.xbib.net.PathNormalizer;
import org.xbib.net.Resource;
import org.xbib.net.URL;
import org.xbib.net.http.server.HttpServerContext;
import java.io.IOException; import java.io.IOException;
import java.net.URLConnection; import java.net.URLConnection;
import java.nio.file.Path; import java.nio.file.Path;
import java.time.Instant; import java.time.Instant;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import org.xbib.net.PathNormalizer;
import org.xbib.net.Resource;
import org.xbib.net.URL;
import org.xbib.net.http.server.HttpServerContext;
public class ClassLoaderResourceHandler extends AbstractResourceHandler { public class ClassLoaderResourceHandler extends AbstractResourceHandler {

View file

@ -1,19 +1,18 @@
package org.xbib.net.http.server.resource; package org.xbib.net.http.server.resource;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.xbib.net.PathNormalizer;
import org.xbib.net.Resource;
import org.xbib.net.URL;
import org.xbib.net.http.server.Application;
import org.xbib.net.http.server.HttpServerContext;
import java.io.IOException; import java.io.IOException;
import java.net.URI; import java.net.URI;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
import java.nio.file.Paths; import java.nio.file.Paths;
import java.time.Instant; import java.time.Instant;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.xbib.net.PathNormalizer;
import org.xbib.net.Resource;
import org.xbib.net.URL;
import org.xbib.net.http.server.HttpServerContext;
import org.xbib.net.http.server.application.Application;
public class FileResourceHandler extends AbstractResourceHandler { public class FileResourceHandler extends AbstractResourceHandler {

View file

@ -1,15 +1,14 @@
package org.xbib.net.http.server.resource; package org.xbib.net.http.server.resource;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.xbib.net.URL;
import org.xbib.net.http.server.Application;
import org.xbib.net.http.server.HttpServerContext;
import java.io.IOException; import java.io.IOException;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
import java.time.Instant; import java.time.Instant;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.xbib.net.URL;
import org.xbib.net.http.server.HttpServerContext;
import org.xbib.net.http.server.application.Application;
public class HtmlTemplateResource implements HttpServerResource { public class HtmlTemplateResource implements HttpServerResource {

View file

@ -1,10 +1,9 @@
package org.xbib.net.http.server.resource; package org.xbib.net.http.server.resource;
import org.xbib.net.Resource;
import org.xbib.net.http.server.HttpServerContext;
import java.io.IOException; import java.io.IOException;
import java.nio.file.Path; import java.nio.file.Path;
import org.xbib.net.Resource;
import org.xbib.net.http.server.HttpServerContext;
public class HtmlTemplateResourceHandler extends AbstractResourceHandler { public class HtmlTemplateResourceHandler extends AbstractResourceHandler {

View file

@ -1,10 +1,9 @@
package org.xbib.net.http.server.resource; package org.xbib.net.http.server.resource;
import java.io.IOException;
import org.xbib.net.Resource; import org.xbib.net.Resource;
import org.xbib.net.http.server.HttpServerContext; import org.xbib.net.http.server.HttpServerContext;
import java.io.IOException;
public interface HttpServerResource extends Resource { public interface HttpServerResource extends Resource {
void render(HttpServerContext httpServerContext) throws IOException; void render(HttpServerContext httpServerContext) throws IOException;

View file

@ -1,11 +1,10 @@
package org.xbib.net.http.server.resource; package org.xbib.net.http.server.resource;
import java.lang.reflect.Method;
import org.xbib.net.http.server.HttpHandler; import org.xbib.net.http.server.HttpHandler;
import org.xbib.net.http.server.HttpRequest; import org.xbib.net.http.server.HttpRequest;
import org.xbib.net.http.server.HttpServerContext; import org.xbib.net.http.server.HttpServerContext;
import java.lang.reflect.Method;
public class MethodHandler implements HttpHandler { public class MethodHandler implements HttpHandler {
private final Method m; private final Method m;

View file

@ -1,10 +1,9 @@
package org.xbib.net.http.server.resource; package org.xbib.net.http.server.resource;
import org.xbib.net.Resource;
import org.xbib.net.http.server.HttpServerContext;
import java.io.IOException; import java.io.IOException;
import java.util.List; import java.util.List;
import org.xbib.net.Resource;
import org.xbib.net.http.server.HttpServerContext;
public interface ResourceResolver { public interface ResourceResolver {

View file

@ -1,18 +1,17 @@
package org.xbib.net.http.server.resource; package org.xbib.net.http.server.resource;
import org.xbib.net.PathNormalizer;
import org.xbib.net.Resource;
import org.xbib.net.URL;
import org.xbib.net.http.HttpResponseStatus;
import org.xbib.net.http.server.HttpRequest;
import org.xbib.net.http.server.HttpServerContext;
import java.io.IOException; import java.io.IOException;
import java.net.URI; import java.net.URI;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
import java.nio.file.Paths; import java.nio.file.Paths;
import java.util.List; import java.util.List;
import org.xbib.net.PathNormalizer;
import org.xbib.net.Resource;
import org.xbib.net.URL;
import org.xbib.net.http.HttpResponseStatus;
import org.xbib.net.http.server.HttpRequest;
import org.xbib.net.http.server.HttpServerContext;
public class WebRootResourceResolver implements ResourceResolver { public class WebRootResourceResolver implements ResourceResolver {

View file

@ -1,14 +1,13 @@
package org.xbib.net.http.server.resource.negotiate; package org.xbib.net.http.server.resource.negotiate;
import org.xbib.net.http.HttpHeaderNames;
import org.xbib.net.http.server.HttpRequest;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Locale; import java.util.Locale;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import org.xbib.net.http.HttpHeaderNames;
import org.xbib.net.http.server.HttpRequest;
/** /**
* Taken from org.apache.any23.servlet.conneg.ContentTypeNegotiator * Taken from org.apache.any23.servlet.conneg.ContentTypeNegotiator

View file

@ -2,7 +2,7 @@ package org.xbib.net.http.server.route;
import org.xbib.datastructures.common.LinkedHashSetMultiMap; import org.xbib.datastructures.common.LinkedHashSetMultiMap;
import org.xbib.net.http.HttpAddress; import org.xbib.net.http.HttpAddress;
import org.xbib.net.http.server.HttpDomain; import org.xbib.net.http.server.domain.HttpDomain;
public class BaseDomainsByAddress extends LinkedHashSetMultiMap<HttpAddress, HttpDomain> implements DomainsByAddress { public class BaseDomainsByAddress extends LinkedHashSetMultiMap<HttpAddress, HttpDomain> implements DomainsByAddress {

View file

@ -1,19 +1,18 @@
package org.xbib.net.http.server.route; package org.xbib.net.http.server.route;
import java.util.Collection;
import java.util.Set;
import org.xbib.net.ParameterBuilder;
import org.xbib.net.http.HttpAddress;
import org.xbib.net.http.HttpMethod;
import java.nio.file.FileSystems; import java.nio.file.FileSystems;
import java.nio.file.Path; import java.nio.file.Path;
import java.nio.file.PathMatcher; import java.nio.file.PathMatcher;
import java.nio.file.Paths; import java.nio.file.Paths;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection;
import java.util.List; import java.util.List;
import java.util.Objects; import java.util.Objects;
import java.util.Set;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import org.xbib.net.ParameterBuilder;
import org.xbib.net.http.HttpAddress;
import org.xbib.net.http.HttpMethod;
public class BaseHttpRoute implements HttpRoute { public class BaseHttpRoute implements HttpRoute {

View file

@ -1,20 +1,17 @@
package org.xbib.net.http.server.route; package org.xbib.net.http.server.route;
import java.util.Set;
import org.xbib.net.Parameter;
import org.xbib.net.ParameterBuilder;
import org.xbib.net.http.HttpAddress;
import org.xbib.net.http.HttpMethod;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Comparator; import java.util.Comparator;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.logging.Level; import java.util.Set;
import java.util.logging.Logger; import java.util.logging.Logger;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import org.xbib.net.Parameter;
import org.xbib.net.ParameterBuilder;
import org.xbib.net.http.HttpAddress;
import org.xbib.net.http.HttpMethod;
import static org.xbib.net.Parameter.Domain.PATH; import static org.xbib.net.Parameter.Domain.PATH;
public class BaseHttpRouteResolver<T> implements HttpRouteResolver<T> { public class BaseHttpRouteResolver<T> implements HttpRouteResolver<T> {

Some files were not shown because too many files have changed in this diff Show more