From ef0c59d3f55ceab12b81b7c2221bae19e0f4bf78 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=CC=88rg=20Prante?= Date: Tue, 30 Apr 2019 16:35:45 +0200 Subject: [PATCH] SslHandler factory, switch to JUnit 5 --- build.gradle | 29 +- gradle.properties | 14 +- gradle/ext.gradle | 0 gradle/publish.gradle | 0 gradle/sonarqube.gradle | 0 netty-http-client/build.gradle | 15 +- .../org/xbib/netty/http/client/Client.java | 37 +- .../handler/http/HttpChannelInitializer.java | 14 +- .../http2/Http2ChannelInitializer.java | 10 +- .../http/client/transport/HttpTransport.java | 8 +- .../client/test/CompletableFutureTest.java | 6 +- .../netty/http/client/test/ConscryptTest.java | 12 +- .../client/test/CookieSetterHttpBinTest.java | 11 +- .../http/client/test/ElasticsearchTest.java | 30 +- .../netty/http/client/test/Http1Test.java | 54 +- .../netty/http/client/test/Http2Test.java | 22 +- .../http/client/test/NettyHttpExtension.java | 11 +- .../http/client/test/RequestBuilderTest.java | 6 +- ...cureHttp1Test.java => SecureHttpTest.java} | 80 +- .../http/client/test/ThreadLeakTest.java | 17 +- .../xbib/netty/http/client/test/URITest.java | 12 +- .../xbib/netty/http/client/test/XbibTest.java | 17 +- .../test}/hacks/Http2FramesTest.java | 11 +- .../test}/hacks/SimpleHttp1Test.java | 17 +- .../test}/hacks/SimpleHttp2Test.java | 11 +- .../test/pool/DisableTestCondition.java | 17 + .../pool/DisabledIfEpolllNotAvailable.java | 14 + .../http/client/test/pool/EpollTest.java | 31 +- .../netty/http/client/test/pool/NioTest.java | 26 +- .../netty/http/client/test/pool/PoolTest.java | 65 +- .../client/test/pool/PooledClientTest.java | 12 +- .../http/client/test/rest/RestClientTest.java | 6 +- .../test/retry/ExponentialBackOffTest.java | 25 +- .../client/test/retry/MockBackOffTest.java | 8 +- netty-http-common/build.gradle | 4 +- netty-http-server-rest/build.gradle | 6 + .../org/xbib/netty/http/server/rest/Rest.java | 4 + .../netty/http/server/rest/RestBuilder.java | 4 + .../netty/http/server/rest/RestConfig.java | 4 + .../xbib/netty/http/server/rest/RestName.java | 44 + .../http/server/rest/util/MediaType.java | 1259 +++++++++++++++++ netty-http-server/build.gradle | 16 +- .../org/xbib/netty/http/server/Server.java | 22 +- .../xbib/netty/http/server/ServerBuilder.java | 15 +- .../xbib/netty/http/server/ServerConfig.java | 20 +- .../xbib/netty/http/server/ServerName.java | 2 +- .../http/server/context/ContextHandler.java | 24 - .../http/server/context/ContextInfo.java | 46 - .../ClasspathHandler.java} | 8 +- .../server/{context => endpoint}/Context.java | 8 +- .../DirectoryHandler.java} | 8 +- .../netty/http/server/endpoint/Endpoint.java | 46 + .../netty/http/server/endpoint/Handler.java | 24 + .../MethodHandler.java} | 15 +- .../http/server/endpoint/NamedEndpoint.java | 21 + .../NamedServer.java} | 66 +- .../NioHandler.java} | 8 +- .../server/transport/BaseServerTransport.java | 21 +- .../transport/Http2ServerTransport.java | 10 +- .../server/transport/HttpServerTransport.java | 10 +- .../http/server/transport/ServerRequest.java | 12 +- .../http/server/test/CleartextHttp1Test.java | 26 +- .../http/server/test/CleartextHttp2Test.java | 36 +- .../http/server/test/NettyHttpExtension.java | 15 +- .../http/server/test/SecureHttp1Test.java | 34 +- .../http/server/test/SecureHttp2Test.java | 39 +- .../test/SelfSignedCertificateTest.java | 6 +- .../netty/http/server/test/ServerTest.java | 12 +- .../server/test/StaticFileServerTest.java | 17 +- .../http/server/test/ThreadLeakTest.java | 18 +- .../server/test/hacks/CleartextHttp2Test.java | 19 +- .../test/hacks/HttpPipeliningHandlerTest.java | 81 +- .../MultiplexCodecCleartextHttp2Test.java | 16 +- .../MultithreadedCleartextHttp2Test.java | 12 +- ...eadedMultiplexCodecCleartextHttp2Test.java | 12 +- settings.gradle | 1 + 76 files changed, 2041 insertions(+), 678 deletions(-) delete mode 100644 gradle/ext.gradle delete mode 100644 gradle/publish.gradle delete mode 100644 gradle/sonarqube.gradle rename netty-http-server/src/test/java/org/xbib/netty/http/server/test/TestBase.java => netty-http-client/src/test/java/org/xbib/netty/http/client/test/NettyHttpExtension.java (79%) rename netty-http-client/src/test/java/org/xbib/netty/http/client/test/{SecureHttp1Test.java => SecureHttpTest.java} (78%) rename netty-http-client/src/test/java/org/xbib/netty/http/{ => client/test}/hacks/Http2FramesTest.java (96%) rename netty-http-client/src/test/java/org/xbib/netty/http/{ => client/test}/hacks/SimpleHttp1Test.java (96%) rename netty-http-client/src/test/java/org/xbib/netty/http/{ => client/test}/hacks/SimpleHttp2Test.java (98%) create mode 100644 netty-http-client/src/test/java/org/xbib/netty/http/client/test/pool/DisableTestCondition.java create mode 100644 netty-http-client/src/test/java/org/xbib/netty/http/client/test/pool/DisabledIfEpolllNotAvailable.java create mode 100644 netty-http-server-rest/build.gradle create mode 100644 netty-http-server-rest/src/main/java/org/xbib/netty/http/server/rest/Rest.java create mode 100644 netty-http-server-rest/src/main/java/org/xbib/netty/http/server/rest/RestBuilder.java create mode 100644 netty-http-server-rest/src/main/java/org/xbib/netty/http/server/rest/RestConfig.java create mode 100644 netty-http-server-rest/src/main/java/org/xbib/netty/http/server/rest/RestName.java create mode 100644 netty-http-server-rest/src/main/java/org/xbib/netty/http/server/rest/util/MediaType.java delete mode 100644 netty-http-server/src/main/java/org/xbib/netty/http/server/context/ContextHandler.java delete mode 100644 netty-http-server/src/main/java/org/xbib/netty/http/server/context/ContextInfo.java rename netty-http-server/src/main/java/org/xbib/netty/http/server/{context/ClasspathContextHandler.java => endpoint/ClasspathHandler.java} (85%) rename netty-http-server/src/main/java/org/xbib/netty/http/server/{context => endpoint}/Context.java (78%) rename netty-http-server/src/main/java/org/xbib/netty/http/server/{context/DirectoryContextHandler.java => endpoint/DirectoryHandler.java} (81%) create mode 100644 netty-http-server/src/main/java/org/xbib/netty/http/server/endpoint/Endpoint.java create mode 100644 netty-http-server/src/main/java/org/xbib/netty/http/server/endpoint/Handler.java rename netty-http-server/src/main/java/org/xbib/netty/http/server/{context/MethodContextHandler.java => endpoint/MethodHandler.java} (68%) create mode 100644 netty-http-server/src/main/java/org/xbib/netty/http/server/endpoint/NamedEndpoint.java rename netty-http-server/src/main/java/org/xbib/netty/http/server/{context/VirtualServer.java => endpoint/NamedServer.java} (74%) rename netty-http-server/src/main/java/org/xbib/netty/http/server/{context/NioContextHandler.java => endpoint/NioHandler.java} (85%) rename netty-http-client/src/test/java/org/xbib/TestBase.java => netty-http-server/src/test/java/org/xbib/netty/http/server/test/NettyHttpExtension.java (69%) diff --git a/build.gradle b/build.gradle index 1573f59..503831c 100644 --- a/build.gradle +++ b/build.gradle @@ -37,6 +37,9 @@ subprojects { } dependencies { + testImplementation "org.junit.jupiter:junit-jupiter-api:${project.property('junit.version')}" + testImplementation "org.junit.jupiter:junit-jupiter-params:${project.property('junit.version')}" + testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:${project.property('junit.version')}" alpnagent "org.mortbay.jetty.alpn:jetty-alpn-agent:${project.property('alpnagent.version')}" asciidoclet "org.asciidoctor:asciidoclet:${project.property('asciidoclet.version')}" wagon "org.apache.maven.wagon:wagon-ssh:${project.property('wagon.version')}" @@ -52,9 +55,11 @@ subprojects { targetCompatibility = JavaVersion.VERSION_1_8 } - [compileJava, compileTestJava]*.options*.encoding = 'UTF-8' tasks.withType(JavaCompile) { - options.compilerArgs << "-Xlint:all,-serial" + options.compilerArgs << "-Xlint:all,-fallthrough" + if (!options.compilerArgs.contains("-processor")) { + options.compilerArgs << '-proc:none' + } } jar { @@ -64,10 +69,20 @@ subprojects { } test { + useJUnitPlatform() systemProperty 'java.util.logging.config.file', 'src/test/resources/logging.properties' + failFast = false testLogging { - showStandardStreams = false - exceptionFormat = 'full' + events 'PASSED', 'FAILED', 'SKIPPED' + } + afterSuite { desc, result -> + if (!desc.parent) { + println "\nTest result: ${result.resultType}" + println "Test summary: ${result.testCount} tests, " + + "${result.successfulTestCount} succeeded, " + + "${result.failedTestCount} failed, " + + "${result.skippedTestCount} skipped" + } } if (JavaVersion.current() == JavaVersion.VERSION_1_8) { jvmArgs "-javaagent:" + configurations.alpnagent.asPath @@ -105,13 +120,13 @@ subprojects { task javadocJar(type: Jar, dependsOn: classes) { from javadoc into "build/tmp" - classifier 'javadoc' + archiveClassifier.set('javadoc') } task sourcesJar(type: Jar, dependsOn: classes) { from sourceSets.main.allSource into "build/tmp" - classifier 'sources' + archiveClassifier.set('sources') } artifacts { @@ -202,7 +217,7 @@ subprojects { } spotbugs { - toolVersion = '3.1.3' + toolVersion = '3.1.12' sourceSets = [sourceSets.main] ignoreFailures = true effort = "max" diff --git a/gradle.properties b/gradle.properties index efe7b45..b58aa65 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,16 +1,24 @@ group = org.xbib name = netty-http -version = 4.1.35.0 +version = 4.1.35.1 # main packages netty.version = 4.1.35.Final tcnative.version = 2.0.22.Final -bouncycastle.version = 1.61 alpnagent.version = 2.0.9 + +# common xbib-net-url.version = 1.2.2 +# server +bouncycastle.version = 1.61 + +# server-rest +xbib-guice.version = 4.0.4 + + # test packages -junit.version = 4.12 +junit.version = 5.4.2 conscrypt.version = 2.0.0 jackson.version = 2.8.11.1 wagon.version = 3.0.0 diff --git a/gradle/ext.gradle b/gradle/ext.gradle deleted file mode 100644 index e69de29..0000000 diff --git a/gradle/publish.gradle b/gradle/publish.gradle deleted file mode 100644 index e69de29..0000000 diff --git a/gradle/sonarqube.gradle b/gradle/sonarqube.gradle deleted file mode 100644 index e69de29..0000000 diff --git a/netty-http-client/build.gradle b/netty-http-client/build.gradle index 2851f2d..1e669ae 100644 --- a/netty-http-client/build.gradle +++ b/netty-http-client/build.gradle @@ -1,11 +1,12 @@ dependencies { - compile project(":netty-http-common") - compile "io.netty:netty-handler-proxy:${project.property('netty.version')}" - compile "io.netty:netty-transport-native-epoll:${project.property('netty.version')}" + implementation project(":netty-http-common") + implementation "io.netty:netty-handler-proxy:${project.property('netty.version')}" + implementation "io.netty:netty-transport-native-epoll:${project.property('netty.version')}" + implementation "io.netty:netty-codec-http2:${project.property('netty.version')}" + implementation "org.xbib:net-url:${project.property('xbib-net-url.version')}" - testCompile "io.netty:netty-tcnative-boringssl-static:${project.property('tcnative.version')}" - testCompile "org.conscrypt:conscrypt-openjdk-uber:${project.property('conscrypt.version')}" - testCompile "junit:junit:${project.property('junit.version')}" - testCompile "com.fasterxml.jackson.core:jackson-databind:${project.property('jackson.version')}" + testImplementation "io.netty:netty-tcnative-boringssl-static:${project.property('tcnative.version')}" + testImplementation "org.conscrypt:conscrypt-openjdk-uber:${project.property('conscrypt.version')}" + testImplementation "com.fasterxml.jackson.core:jackson-databind:${project.property('jackson.version')}" } diff --git a/netty-http-client/src/main/java/org/xbib/netty/http/client/Client.java b/netty-http-client/src/main/java/org/xbib/netty/http/client/Client.java index b506794..aa6a386 100644 --- a/netty-http-client/src/main/java/org/xbib/netty/http/client/Client.java +++ b/netty-http-client/src/main/java/org/xbib/netty/http/client/Client.java @@ -199,13 +199,13 @@ public final class Client { Channel channel; if (httpAddress != null) { HttpVersion httpVersion = httpAddress.getVersion(); + SslHandlerFactory sslHandlerFactory = new SslHandlerFactory(clientConfig, httpAddress, byteBufAllocator); ChannelInitializer initializer; - SslHandler sslHandler = newSslHandler(clientConfig, byteBufAllocator, httpAddress); if (httpVersion.majorVersion() == 1) { - initializer = new HttpChannelInitializer(clientConfig, httpAddress, sslHandler, - new Http2ChannelInitializer(clientConfig, httpAddress, sslHandler)); + initializer = new HttpChannelInitializer(clientConfig, httpAddress, sslHandlerFactory, + new Http2ChannelInitializer(clientConfig, httpAddress, sslHandlerFactory)); } else { - initializer = new Http2ChannelInitializer(clientConfig, httpAddress, sslHandler); + initializer = new Http2ChannelInitializer(clientConfig, httpAddress, sslHandlerFactory); } try { channel = bootstrap.handler(initializer) @@ -412,15 +412,34 @@ public final class Client { public void channelCreated(Channel channel) { HttpAddress httpAddress = channel.attr(pool.getAttributeKey()).get(); HttpVersion httpVersion = httpAddress.getVersion(); - SslHandler sslHandler = newSslHandler(clientConfig, byteBufAllocator, httpAddress); + SslHandlerFactory sslHandlerFactory = new SslHandlerFactory(clientConfig, httpAddress, byteBufAllocator); + Http2ChannelInitializer http2ChannelInitializer = new Http2ChannelInitializer(clientConfig, httpAddress, sslHandlerFactory); if (httpVersion.majorVersion() == 1) { - HttpChannelInitializer initializer = new HttpChannelInitializer(clientConfig, httpAddress, sslHandler, - new Http2ChannelInitializer(clientConfig, httpAddress, sslHandler)); + HttpChannelInitializer initializer = new HttpChannelInitializer(clientConfig, httpAddress, sslHandlerFactory, + http2ChannelInitializer); initializer.initChannel(channel); } else { - Http2ChannelInitializer initializer = new Http2ChannelInitializer(clientConfig, httpAddress, sslHandler); - initializer.initChannel(channel); + http2ChannelInitializer.initChannel(channel); } } } + + public class SslHandlerFactory { + + private final ClientConfig clientConfig; + + private final HttpAddress httpAddress; + + private final ByteBufAllocator allocator; + + SslHandlerFactory(ClientConfig clientConfig, HttpAddress httpAddress, ByteBufAllocator allocator) { + this.clientConfig = clientConfig; + this.httpAddress = httpAddress; + this.allocator = allocator; + } + + public SslHandler create() { + return newSslHandler(clientConfig, allocator, httpAddress); + } + } } diff --git a/netty-http-client/src/main/java/org/xbib/netty/http/client/handler/http/HttpChannelInitializer.java b/netty-http-client/src/main/java/org/xbib/netty/http/client/handler/http/HttpChannelInitializer.java index 81f3d91..7ef4248 100644 --- a/netty-http-client/src/main/java/org/xbib/netty/http/client/handler/http/HttpChannelInitializer.java +++ b/netty-http-client/src/main/java/org/xbib/netty/http/client/handler/http/HttpChannelInitializer.java @@ -10,7 +10,7 @@ import io.netty.handler.codec.http.HttpObjectAggregator; import io.netty.handler.logging.LogLevel; import io.netty.handler.ssl.ApplicationProtocolNames; import io.netty.handler.ssl.ApplicationProtocolNegotiationHandler; -import io.netty.handler.ssl.SslHandler; +import org.xbib.netty.http.client.Client; import org.xbib.netty.http.client.ClientConfig; import org.xbib.netty.http.client.handler.http2.Http2ChannelInitializer; import org.xbib.netty.http.common.HttpAddress; @@ -26,7 +26,7 @@ public class HttpChannelInitializer extends ChannelInitializer { private final HttpAddress httpAddress; - private final SslHandler sslHandler; + private final Client.SslHandlerFactory sslHandlerFactory; private final HttpResponseHandler httpResponseHandler; @@ -34,11 +34,11 @@ public class HttpChannelInitializer extends ChannelInitializer { public HttpChannelInitializer(ClientConfig clientConfig, HttpAddress httpAddress, - SslHandler sslHandler, + Client.SslHandlerFactory sslHandlerFactory, Http2ChannelInitializer http2ChannelInitializer) { this.clientConfig = clientConfig; this.httpAddress = httpAddress; - this.sslHandler = sslHandler; + this.sslHandlerFactory = sslHandlerFactory; this.http2ChannelInitializer = http2ChannelInitializer; this.httpResponseHandler = new HttpResponseHandler(); } @@ -60,7 +60,7 @@ public class HttpChannelInitializer extends ChannelInitializer { private void configureEncrypted(Channel channel) { ChannelPipeline pipeline = channel.pipeline(); - pipeline.addLast(sslHandler); + pipeline.addLast(sslHandlerFactory.create()); if (clientConfig.isEnableNegotiation()) { ApplicationProtocolNegotiationHandler negotiationHandler = new ApplicationProtocolNegotiationHandler(ApplicationProtocolNames.HTTP_1_1) { @@ -101,10 +101,6 @@ public class HttpChannelInitializer extends ChannelInitializer { false); httpObjectAggregator.setMaxCumulationBufferComponents(clientConfig.getMaxCompositeBufferComponents()); pipeline.addLast(httpObjectAggregator); - /*if (clientConfig.isEnableGzip()) { - pipeline.addLast(new HttpChunkContentCompressor(6)); - } - pipeline.addLast(new ChunkedWriteHandler());*/ pipeline.addLast(httpResponseHandler); } } diff --git a/netty-http-client/src/main/java/org/xbib/netty/http/client/handler/http2/Http2ChannelInitializer.java b/netty-http-client/src/main/java/org/xbib/netty/http/client/handler/http2/Http2ChannelInitializer.java index 2ac3cd7..42b1a07 100644 --- a/netty-http-client/src/main/java/org/xbib/netty/http/client/handler/http2/Http2ChannelInitializer.java +++ b/netty-http-client/src/main/java/org/xbib/netty/http/client/handler/http2/Http2ChannelInitializer.java @@ -12,7 +12,7 @@ import io.netty.handler.codec.http2.Http2Headers; import io.netty.handler.codec.http2.Http2MultiplexCodec; import io.netty.handler.codec.http2.Http2MultiplexCodecBuilder; import io.netty.handler.logging.LogLevel; -import io.netty.handler.ssl.SslHandler; +import org.xbib.netty.http.client.Client; import org.xbib.netty.http.client.ClientConfig; import org.xbib.netty.http.client.handler.http.TrafficLoggingHandler; import org.xbib.netty.http.client.transport.Transport; @@ -29,14 +29,14 @@ public class Http2ChannelInitializer extends ChannelInitializer { private final HttpAddress httpAddress; - private final SslHandler sslHandler; + private final Client.SslHandlerFactory sslHandlerFactory; public Http2ChannelInitializer(ClientConfig clientConfig, HttpAddress httpAddress, - SslHandler sslHandler) { + Client.SslHandlerFactory sslHandlerFactory) { this.clientConfig = clientConfig; this.httpAddress = httpAddress; - this.sslHandler = sslHandler; + this.sslHandlerFactory = sslHandlerFactory; } @Override @@ -55,7 +55,7 @@ public class Http2ChannelInitializer extends ChannelInitializer { } private void configureEncrypted(Channel channel) { - channel.pipeline().addLast(sslHandler); + channel.pipeline().addLast(sslHandlerFactory.create()); configureCleartext(channel); } diff --git a/netty-http-client/src/main/java/org/xbib/netty/http/client/transport/HttpTransport.java b/netty-http-client/src/main/java/org/xbib/netty/http/client/transport/HttpTransport.java index be8237d..a1cbb8c 100644 --- a/netty-http-client/src/main/java/org/xbib/netty/http/client/transport/HttpTransport.java +++ b/netty-http-client/src/main/java/org/xbib/netty/http/client/transport/HttpTransport.java @@ -80,12 +80,8 @@ public class HttpTransport extends BaseTransport { logger.log(Level.WARNING, "throwable not null for response " + fullHttpResponse, throwable); return; } - if (requests.isEmpty()) { - logger.log(Level.WARNING, "no request present, can not handle response " + fullHttpResponse); - return; - } // streamID is expected to be null, last request on memory is expected to be current, remove request from memory - Request request = requests.remove(requests.lastKey()); + Request request = requests.remove(requests.isEmpty() ? null : requests.lastKey()); if (request != null) { for (String cookieString : fullHttpResponse.headers().getAll(HttpHeaderNames.SET_COOKIE)) { Cookie cookie = ClientCookieDecoder.STRICT.decode(cookieString); @@ -140,6 +136,6 @@ public class HttpTransport extends BaseTransport { @Override protected String getRequestKey(String channelId, Integer streamId) { - return requests.lastKey(); + return requests.isEmpty() ? null : requests.lastKey(); } } diff --git a/netty-http-client/src/test/java/org/xbib/netty/http/client/test/CompletableFutureTest.java b/netty-http-client/src/test/java/org/xbib/netty/http/client/test/CompletableFutureTest.java index 253e122..ae50f04 100644 --- a/netty-http-client/src/test/java/org/xbib/netty/http/client/test/CompletableFutureTest.java +++ b/netty-http-client/src/test/java/org/xbib/netty/http/client/test/CompletableFutureTest.java @@ -1,7 +1,7 @@ package org.xbib.netty.http.client.test; import io.netty.handler.codec.http.FullHttpResponse; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.xbib.netty.http.client.Client; import org.xbib.netty.http.client.Request; @@ -12,7 +12,7 @@ import java.util.function.Function; import java.util.logging.Level; import java.util.logging.Logger; -public class CompletableFutureTest { +class CompletableFutureTest { private static final Logger logger = Logger.getLogger(CompletableFutureTest.class.getName()); @@ -20,7 +20,7 @@ public class CompletableFutureTest { * Get some weird content from one URL and post it to another URL, by composing completable futures. */ @Test - public void testComposeCompletableFutures() throws IOException { + void testComposeCompletableFutures() throws IOException { Client client = Client.builder().build(); try { final Function httpResponseStringFunction = response -> diff --git a/netty-http-client/src/test/java/org/xbib/netty/http/client/test/ConscryptTest.java b/netty-http-client/src/test/java/org/xbib/netty/http/client/test/ConscryptTest.java index 92f4c7a..1b0a474 100644 --- a/netty-http-client/src/test/java/org/xbib/netty/http/client/test/ConscryptTest.java +++ b/netty-http-client/src/test/java/org/xbib/netty/http/client/test/ConscryptTest.java @@ -1,8 +1,8 @@ package org.xbib.netty.http.client.test; import org.conscrypt.Conscrypt; -import org.junit.Test; -import org.xbib.TestBase; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.xbib.netty.http.client.Client; import org.xbib.netty.http.client.Request; @@ -11,14 +11,14 @@ import java.nio.charset.StandardCharsets; import java.util.logging.Level; import java.util.logging.Logger; -public class ConscryptTest extends TestBase { +@ExtendWith(NettyHttpExtension.class) +class ConscryptTest { - private static final Logger logger = Logger.getLogger(""); + private static final Logger logger = Logger.getLogger(ConscryptTest.class.getName()); @Test - public void testConscrypt() throws IOException { + void testConscrypt() throws IOException { Client client = Client.builder() - .enableDebug() .setJdkSslProvider() .setSslContextProvider(Conscrypt.newProvider()) .build(); diff --git a/netty-http-client/src/test/java/org/xbib/netty/http/client/test/CookieSetterHttpBinTest.java b/netty-http-client/src/test/java/org/xbib/netty/http/client/test/CookieSetterHttpBinTest.java index 1065076..6c78fe9 100644 --- a/netty-http-client/src/test/java/org/xbib/netty/http/client/test/CookieSetterHttpBinTest.java +++ b/netty-http-client/src/test/java/org/xbib/netty/http/client/test/CookieSetterHttpBinTest.java @@ -1,7 +1,7 @@ package org.xbib.netty.http.client.test; -import org.junit.Test; -import org.xbib.TestBase; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.xbib.netty.http.client.Client; import org.xbib.netty.http.client.Request; @@ -10,9 +10,8 @@ import java.nio.charset.StandardCharsets; import java.util.logging.Level; import java.util.logging.Logger; -/** - */ -public class CookieSetterHttpBinTest extends TestBase { +@ExtendWith(NettyHttpExtension.class) +class CookieSetterHttpBinTest { private static final Logger logger = Logger.getLogger(CookieSetterHttpBinTest.class.getName()); @@ -30,7 +29,7 @@ public class CookieSetterHttpBinTest extends TestBase { * @throws IOException if test fails */ @Test - public void testHttpBinCookies() throws IOException { + void testHttpBinCookies() throws IOException { Client client = new Client(); try { Request request = Request.get() diff --git a/netty-http-client/src/test/java/org/xbib/netty/http/client/test/ElasticsearchTest.java b/netty-http-client/src/test/java/org/xbib/netty/http/client/test/ElasticsearchTest.java index 5570e23..c32c04e 100644 --- a/netty-http-client/src/test/java/org/xbib/netty/http/client/test/ElasticsearchTest.java +++ b/netty-http-client/src/test/java/org/xbib/netty/http/client/test/ElasticsearchTest.java @@ -1,8 +1,8 @@ package org.xbib.netty.http.client.test; -import org.junit.Ignore; -import org.junit.Test; -import org.xbib.TestBase; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.xbib.netty.http.client.Client; import org.xbib.netty.http.common.HttpAddress; import org.xbib.netty.http.client.Request; @@ -18,17 +18,18 @@ import java.util.concurrent.atomic.AtomicInteger; import java.util.logging.Level; import java.util.logging.Logger; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; -@Ignore -public class ElasticsearchTest extends TestBase { +@Disabled +@ExtendWith(NettyHttpExtension.class) +class ElasticsearchTest { private static final Logger logger = Logger.getLogger(ElasticsearchTest.class.getName()); @Test - @Ignore - public void testElasticsearch() throws IOException { - Client client = Client.builder().enableDebug().build(); + void testElasticsearch() throws IOException { + Client client = Client.builder() + .build(); try { Request request = Request.get().url("http://localhost:9200") .build() @@ -44,9 +45,9 @@ public class ElasticsearchTest extends TestBase { } @Test - @Ignore - public void testElasticsearchCreateDocument() throws IOException { - Client client = Client.builder().enableDebug().build(); + void testElasticsearchCreateDocument() throws IOException { + Client client = Client.builder() + .build(); try { Request request = Request.put().url("http://localhost:9200/test/test/1") .json("{\"text\":\"Hello World\"}") @@ -63,8 +64,7 @@ public class ElasticsearchTest extends TestBase { } @Test - @Ignore - public void testElasticsearchMatchQuery() throws IOException { + void testElasticsearchMatchQuery() throws IOException { Client client = new Client(); try { Request request = Request.post().url("http://localhost:9200/test/_search") @@ -85,7 +85,7 @@ public class ElasticsearchTest extends TestBase { * @throws IOException if test fails */ @Test - public void testElasticsearchPooled() throws IOException { + void testElasticsearchPooled() throws IOException { HttpAddress httpAddress = HttpAddress.http1("localhost", 9200); int limit = 4; Client client = Client.builder() diff --git a/netty-http-client/src/test/java/org/xbib/netty/http/client/test/Http1Test.java b/netty-http-client/src/test/java/org/xbib/netty/http/client/test/Http1Test.java index 09a9eeb..57d42e2 100644 --- a/netty-http-client/src/test/java/org/xbib/netty/http/client/test/Http1Test.java +++ b/netty-http-client/src/test/java/org/xbib/netty/http/client/test/Http1Test.java @@ -1,8 +1,8 @@ package org.xbib.netty.http.client.test; import io.netty.handler.codec.http.HttpMethod; -import org.junit.Test; -import org.xbib.TestBase; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.xbib.netty.http.client.Client; import org.xbib.netty.http.client.Request; @@ -11,13 +11,15 @@ import java.nio.charset.StandardCharsets; import java.util.logging.Level; import java.util.logging.Logger; -public class Http1Test extends TestBase { +@ExtendWith(NettyHttpExtension.class) +class Http1Test { private static final Logger logger = Logger.getLogger(Http1Test.class.getName()); @Test - public void testHttp1() throws Exception { - Client client = Client.builder().enableDebug().build(); + void testHttp1() throws Exception { + Client client = Client.builder() + .build(); try { Request request = Request.get().url("http://xbib.org").build() .setResponseListener(msg -> logger.log(Level.INFO, "got response: " + @@ -31,8 +33,28 @@ public class Http1Test extends TestBase { } @Test - public void testParallelRequests() throws IOException { - Client client = Client.builder().enableDebug().build(); + void testSequentialRequests() throws Exception { + Client client = Client.builder() + .build(); + try { + Request request1 = Request.get().url("http://xbib.org").build() + .setResponseListener(msg -> logger.log(Level.INFO, "got response: " + + msg.content().toString(StandardCharsets.UTF_8))); + client.execute(request1).get(); + + Request request2 = Request.get().url("http://google.com").setVersion("HTTP/1.1").build() + .setResponseListener(msg -> logger.log(Level.INFO, "got response: " + + msg.content().toString(StandardCharsets.UTF_8))); + client.execute(request2).get(); + } finally { + client.shutdown(); + } + } + + @Test + void testParallelRequests() throws IOException { + Client client = Client.builder() + .build(); try { Request request1 = Request.builder(HttpMethod.GET) .url("http://xbib.org").setVersion("HTTP/1.1") @@ -58,22 +80,4 @@ public class Http1Test extends TestBase { client.shutdownGracefully(); } } - - @Test - public void testSequentialRequests() throws Exception { - Client client = Client.builder().enableDebug().build(); - try { - Request request1 = Request.get().url("http://xbib.org").build() - .setResponseListener(msg -> logger.log(Level.INFO, "got response: " + - msg.content().toString(StandardCharsets.UTF_8))); - client.execute(request1).get(); - - Request request2 = Request.get().url("http://google.com").setVersion("HTTP/1.1").build() - .setResponseListener(msg -> logger.log(Level.INFO, "got response: " + - msg.content().toString(StandardCharsets.UTF_8))); - client.execute(request2).get(); - } finally { - client.shutdown(); - } - } } diff --git a/netty-http-client/src/test/java/org/xbib/netty/http/client/test/Http2Test.java b/netty-http-client/src/test/java/org/xbib/netty/http/client/test/Http2Test.java index 3569ebf..7b3e67c 100644 --- a/netty-http-client/src/test/java/org/xbib/netty/http/client/test/Http2Test.java +++ b/netty-http-client/src/test/java/org/xbib/netty/http/client/test/Http2Test.java @@ -1,9 +1,8 @@ package org.xbib.netty.http.client.test; import io.netty.handler.codec.http.HttpMethod; -import org.junit.Ignore; -import org.junit.Test; -import org.xbib.TestBase; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.xbib.netty.http.client.Client; import org.xbib.netty.http.client.Request; @@ -12,7 +11,8 @@ import java.nio.charset.StandardCharsets; import java.util.logging.Level; import java.util.logging.Logger; -public class Http2Test extends TestBase { +@ExtendWith(NettyHttpExtension.class) +class Http2Test { private static final Logger logger = Logger.getLogger(Http2Test.class.getName()); @@ -29,10 +29,8 @@ public class Http2Test extends TestBase { * @throws IOException if test fails */ @Test - @Ignore - public void testAkamai() throws IOException { + void testAkamai() throws IOException { Client client = Client.builder() - .enableDebug() .addServerNameForIdentification("http2.akamai.com") .build(); try { @@ -53,8 +51,9 @@ public class Http2Test extends TestBase { } @Test - public void testWebtide() throws Exception { - Client client = Client.builder().enableDebug().build(); + void testWebtide() throws Exception { + Client client = Client.builder() + .build(); client.logDiagnostics(Level.INFO); try { Request request = Request.get().url("https://webtide.com").setVersion("HTTP/2.0").build() @@ -69,10 +68,9 @@ public class Http2Test extends TestBase { } @Test - public void testHttp2PushIO() throws IOException { + void testHttp2PushIO() throws IOException { String url = "https://http2-push.io"; Client client = Client.builder() - .enableDebug() .addServerNameForIdentification("http2-push.io") .build(); try { @@ -91,7 +89,7 @@ public class Http2Test extends TestBase { } @Test - public void testWebtideTwoRequestsOnSameConnection() throws IOException { + void testWebtideTwoRequestsOnSameConnection() throws IOException { Client client = new Client(); try { Request request1 = Request.builder(HttpMethod.GET) diff --git a/netty-http-server/src/test/java/org/xbib/netty/http/server/test/TestBase.java b/netty-http-client/src/test/java/org/xbib/netty/http/client/test/NettyHttpExtension.java similarity index 79% rename from netty-http-server/src/test/java/org/xbib/netty/http/server/test/TestBase.java rename to netty-http-client/src/test/java/org/xbib/netty/http/client/test/NettyHttpExtension.java index 126e379..4c01125 100644 --- a/netty-http-server/src/test/java/org/xbib/netty/http/server/test/TestBase.java +++ b/netty-http-client/src/test/java/org/xbib/netty/http/client/test/NettyHttpExtension.java @@ -1,4 +1,7 @@ -package org.xbib.netty.http.server.test; +package org.xbib.netty.http.client.test; + +import org.junit.jupiter.api.extension.BeforeAllCallback; +import org.junit.jupiter.api.extension.ExtensionContext; import java.util.logging.ConsoleHandler; import java.util.logging.Handler; @@ -7,10 +10,10 @@ import java.util.logging.LogManager; import java.util.logging.Logger; import java.util.logging.SimpleFormatter; -public class TestBase { - - static { +public class NettyHttpExtension implements BeforeAllCallback { + @Override + public void beforeAll(ExtensionContext context) throws Exception { System.setProperty("io.netty.noUnsafe", Boolean.toString(true)); System.setProperty("io.netty.noKeySetOptimization", Boolean.toString(true)); //System.setProperty("io.netty.recycler.maxCapacity", Integer.toString(0)); diff --git a/netty-http-client/src/test/java/org/xbib/netty/http/client/test/RequestBuilderTest.java b/netty-http-client/src/test/java/org/xbib/netty/http/client/test/RequestBuilderTest.java index 6faa6e5..c6a99c5 100644 --- a/netty-http-client/src/test/java/org/xbib/netty/http/client/test/RequestBuilderTest.java +++ b/netty-http-client/src/test/java/org/xbib/netty/http/client/test/RequestBuilderTest.java @@ -1,18 +1,18 @@ package org.xbib.netty.http.client.test; import io.netty.handler.codec.http.HttpMethod; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.xbib.netty.http.client.Request; import java.util.logging.Level; import java.util.logging.Logger; -public class RequestBuilderTest { +class RequestBuilderTest { private static final Logger logger = Logger.getLogger(RequestBuilderTest.class.getName()); @Test - public void testSimpleRequest() { + void testSimpleRequest() { Request request = Request.builder(HttpMethod.GET).content("Hello", "text/plain").build(); logger.log(Level.INFO, request.toString()); } diff --git a/netty-http-client/src/test/java/org/xbib/netty/http/client/test/SecureHttp1Test.java b/netty-http-client/src/test/java/org/xbib/netty/http/client/test/SecureHttpTest.java similarity index 78% rename from netty-http-client/src/test/java/org/xbib/netty/http/client/test/SecureHttp1Test.java rename to netty-http-client/src/test/java/org/xbib/netty/http/client/test/SecureHttpTest.java index a31b560..3e1a09e 100644 --- a/netty-http-client/src/test/java/org/xbib/netty/http/client/test/SecureHttp1Test.java +++ b/netty-http-client/src/test/java/org/xbib/netty/http/client/test/SecureHttpTest.java @@ -1,9 +1,8 @@ package org.xbib.netty.http.client.test; import io.netty.handler.codec.http.HttpMethod; -import org.junit.Ignore; -import org.junit.Test; -import org.xbib.TestBase; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.xbib.netty.http.client.Client; import org.xbib.netty.http.client.Request; @@ -12,13 +11,15 @@ import java.nio.charset.StandardCharsets; import java.util.logging.Level; import java.util.logging.Logger; -public class SecureHttp1Test extends TestBase { +@ExtendWith(NettyHttpExtension.class) +class SecureHttpTest { - private static final Logger logger = Logger.getLogger(SecureHttp1Test.class.getName()); + private static final Logger logger = Logger.getLogger(SecureHttpTest.class.getName()); @Test - public void testHttp1() throws Exception { - Client client = Client.builder().enableDebug().build(); + void testHttp1() throws Exception { + Client client = Client.builder() + .build(); try { Request request = Request.get().url("https://www.google.com/").build() .setResponseListener(msg -> logger.log(Level.INFO, "got response: " + @@ -32,39 +33,9 @@ public class SecureHttp1Test extends TestBase { } @Test - @Ignore - public void testParallelRequests() throws IOException { - Client client = Client.builder().enableDebug().build(); - try { - Request request1 = Request.builder(HttpMethod.GET) - .url("https://google.com").setVersion("HTTP/1.1") - .build() - .setResponseListener(msg -> logger.log(Level.INFO, "got response: " + - msg.headers().entries() + - //msg.content().toString(StandardCharsets.UTF_8) + - " status=" + msg.status().code())); - Request request2 = Request.builder(HttpMethod.GET) - .url("https://google.com").setVersion("HTTP/1.1") - .build() - .setResponseListener(msg -> logger.log(Level.INFO, "got response: " + - msg.headers().entries() + - //msg.content().toString(StandardCharsets.UTF_8) + - " status=" + msg.status().code())); - - for (int i = 0; i < 10; i++) { - client.execute(request1); - client.execute(request2); - } - - } finally { - client.shutdownGracefully(); - } - } - - @Test - @Ignore - public void testSequentialRequests() throws Exception { - Client client = Client.builder().enableDebug().build(); + void testSequentialRequests() throws Exception { + Client client = Client.builder() + .build(); try { Request request1 = Request.get().url("https://google.com").build() .setResponseListener(msg -> logger.log(Level.INFO, "got response: " + @@ -79,4 +50,33 @@ public class SecureHttp1Test extends TestBase { client.shutdown(); } } + + @Test + void testParallelRequests() throws IOException { + Client client = Client.builder() + .build(); + try { + Request request1 = Request.builder(HttpMethod.GET) + .url("https://google.com").setVersion("HTTP/1.1") + .build() + .setResponseListener(msg -> logger.log(Level.INFO, "got response: " + + msg.headers().entries() + + " status=" + msg.status().code())); + Request request2 = Request.builder(HttpMethod.GET) + .url("https://google.com").setVersion("HTTP/1.1") + .build() + .setResponseListener(msg -> logger.log(Level.INFO, "got response: " + + msg.headers().entries() + + " status=" + msg.status().code())); + + for (int i = 0; i < 10; i++) { + client.execute(request1); + client.execute(request2); + } + + } finally { + client.shutdownGracefully(); + } + } + } diff --git a/netty-http-client/src/test/java/org/xbib/netty/http/client/test/ThreadLeakTest.java b/netty-http-client/src/test/java/org/xbib/netty/http/client/test/ThreadLeakTest.java index 0e70876..1a93049 100644 --- a/netty-http-client/src/test/java/org/xbib/netty/http/client/test/ThreadLeakTest.java +++ b/netty-http-client/src/test/java/org/xbib/netty/http/client/test/ThreadLeakTest.java @@ -1,8 +1,9 @@ package org.xbib.netty.http.client.test; -import org.junit.After; -import org.junit.Test; -import org.xbib.TestBase; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.extension.ExtendWith; import org.xbib.netty.http.client.Client; import java.io.IOException; @@ -10,18 +11,20 @@ import java.util.Set; import java.util.logging.Level; import java.util.logging.Logger; -public class ThreadLeakTest extends TestBase { +@ExtendWith(NettyHttpExtension.class) +@TestInstance(TestInstance.Lifecycle.PER_CLASS) +class ThreadLeakTest { private static final Logger logger = Logger.getLogger(ThreadLeakTest.class.getName()); @Test - public void testForLeaks() throws IOException { + void testForLeaks() throws IOException { Client client = new Client(); client.shutdownGracefully(); } - @After - public void checkThreads() { + @AfterAll + void checkThreads() { Set threadSet = Thread.getAllStackTraces().keySet(); logger.log(Level.INFO, "threads = " + threadSet.size() ); threadSet.forEach( thread -> logger.log(Level.INFO, thread.toString())); diff --git a/netty-http-client/src/test/java/org/xbib/netty/http/client/test/URITest.java b/netty-http-client/src/test/java/org/xbib/netty/http/client/test/URITest.java index a5a8cdb..f4dc03a 100644 --- a/netty-http-client/src/test/java/org/xbib/netty/http/client/test/URITest.java +++ b/netty-http-client/src/test/java/org/xbib/netty/http/client/test/URITest.java @@ -1,19 +1,17 @@ package org.xbib.netty.http.client.test; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.xbib.netty.http.client.Request; import org.xbib.netty.http.client.RequestBuilder; import java.net.URI; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; -/** - */ -public class URITest { +class URITest { @Test - public void testURIResolve() { + void testURIResolve() { URI uri = URI.create("http://localhost"); URI uri2 = uri.resolve("/path"); assertEquals("http://localhost/path", uri2.toString()); @@ -23,7 +21,7 @@ public class URITest { } @Test - public void testRequestURIs() { + void testRequestURIs() { RequestBuilder httpRequestBuilder = Request.get(); httpRequestBuilder.url("https://localhost").uri("/path"); assertEquals("/path", httpRequestBuilder.build().relativeUri()); diff --git a/netty-http-client/src/test/java/org/xbib/netty/http/client/test/XbibTest.java b/netty-http-client/src/test/java/org/xbib/netty/http/client/test/XbibTest.java index 88c76ff..e824a56 100644 --- a/netty-http-client/src/test/java/org/xbib/netty/http/client/test/XbibTest.java +++ b/netty-http-client/src/test/java/org/xbib/netty/http/client/test/XbibTest.java @@ -2,8 +2,7 @@ package org.xbib.netty.http.client.test; import io.netty.handler.codec.http.FullHttpResponse; import io.netty.handler.proxy.HttpProxyHandler; -import org.junit.Test; -import org.xbib.TestBase; +import org.junit.jupiter.api.Test; import org.xbib.netty.http.client.Client; import org.xbib.netty.http.client.Request; @@ -15,12 +14,12 @@ import java.util.function.Function; import java.util.logging.Level; import java.util.logging.Logger; -public class XbibTest extends TestBase { +class XbibTest { - private static final Logger logger = Logger.getLogger(""); + private static final Logger logger = Logger.getLogger(XbibTest.class.getName()); @Test - public void testXbibOrgWithDefaults() throws IOException { + void testXbibOrgWithDefaults() throws IOException { Client client = new Client(); try { Request request = Request.get().url("http://xbib.org") @@ -36,7 +35,7 @@ public class XbibTest extends TestBase { } @Test - public void testXbibOrgWithCompletableFuture() throws IOException { + void testXbibOrgWithCompletableFuture() throws IOException { Client httpClient = Client.builder() .setTcpNodelay(true) .build(); @@ -66,7 +65,7 @@ public class XbibTest extends TestBase { } @Test - public void testXbibOrgWithProxy() throws IOException { + void testXbibOrgWithProxy() throws IOException { Client httpClient = Client.builder() .setHttpProxyHandler(new HttpProxyHandler(new InetSocketAddress("80.241.223.251", 8080))) .setConnectTimeoutMillis(30000) @@ -87,7 +86,7 @@ public class XbibTest extends TestBase { } @Test - public void testXbibOrgWithVeryShortReadTimeout() throws IOException { + void testXbibOrgWithVeryShortReadTimeout() throws IOException { Client httpClient = Client.builder() .build(); try { @@ -106,7 +105,7 @@ public class XbibTest extends TestBase { } @Test - public void testXbibTwoSequentialRequests() throws IOException { + void testXbibTwoSequentialRequests() throws IOException { Client httpClient = new Client(); try { httpClient.execute(Request.get() diff --git a/netty-http-client/src/test/java/org/xbib/netty/http/hacks/Http2FramesTest.java b/netty-http-client/src/test/java/org/xbib/netty/http/client/test/hacks/Http2FramesTest.java similarity index 96% rename from netty-http-client/src/test/java/org/xbib/netty/http/hacks/Http2FramesTest.java rename to netty-http-client/src/test/java/org/xbib/netty/http/client/test/hacks/Http2FramesTest.java index 0cba6a2..410ef32 100644 --- a/netty-http-client/src/test/java/org/xbib/netty/http/hacks/Http2FramesTest.java +++ b/netty-http-client/src/test/java/org/xbib/netty/http/client/test/hacks/Http2FramesTest.java @@ -1,4 +1,4 @@ -package org.xbib.netty.http.hacks; +package org.xbib.netty.http.client.test.hacks; import io.netty.bootstrap.Bootstrap; import io.netty.buffer.ByteBuf; @@ -26,9 +26,7 @@ import io.netty.handler.ssl.SslHandler; import io.netty.handler.ssl.SslProvider; import io.netty.handler.ssl.SupportedCipherSuiteFilter; import io.netty.handler.ssl.util.InsecureTrustManagerFactory; -import org.junit.Ignore; -import org.junit.Test; -import org.xbib.TestBase; +import org.junit.jupiter.api.Test; import javax.net.ssl.SNIHostName; import javax.net.ssl.SNIServerName; @@ -40,13 +38,12 @@ import java.util.concurrent.CompletableFuture; import java.util.logging.Level; import java.util.logging.Logger; -@Ignore -public class Http2FramesTest extends TestBase { +class Http2FramesTest { private static final Logger logger = Logger.getLogger(Http2FramesTest.class.getName()); @Test - public void testHttp2Frames() throws Exception { + void testHttp2Frames() throws Exception { final InetSocketAddress inetSocketAddress = new InetSocketAddress("webtide.com", 443); CompletableFuture completableFuture = new CompletableFuture<>(); EventLoopGroup eventLoopGroup = new NioEventLoopGroup(); diff --git a/netty-http-client/src/test/java/org/xbib/netty/http/hacks/SimpleHttp1Test.java b/netty-http-client/src/test/java/org/xbib/netty/http/client/test/hacks/SimpleHttp1Test.java similarity index 96% rename from netty-http-client/src/test/java/org/xbib/netty/http/hacks/SimpleHttp1Test.java rename to netty-http-client/src/test/java/org/xbib/netty/http/client/test/hacks/SimpleHttp1Test.java index 6368175..9d8a88b 100644 --- a/netty-http-client/src/test/java/org/xbib/netty/http/hacks/SimpleHttp1Test.java +++ b/netty-http-client/src/test/java/org/xbib/netty/http/client/test/hacks/SimpleHttp1Test.java @@ -1,4 +1,4 @@ -package org.xbib.netty.http.hacks; +package org.xbib.netty.http.client.test.hacks; import io.netty.bootstrap.Bootstrap; import io.netty.channel.Channel; @@ -19,10 +19,9 @@ import io.netty.handler.codec.http.HttpMethod; import io.netty.handler.codec.http.HttpObjectAggregator; import io.netty.handler.codec.http.HttpVersion; import io.netty.util.AttributeKey; -import org.junit.After; -import org.junit.Ignore; -import org.junit.Test; -import org.xbib.TestBase; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInstance; import java.io.IOException; import java.net.InetSocketAddress; @@ -40,8 +39,8 @@ import java.util.logging.LogManager; import java.util.logging.Logger; import java.util.logging.SimpleFormatter; -@Ignore -public class SimpleHttp1Test extends TestBase { +@TestInstance(TestInstance.Lifecycle.PER_CLASS) +public class SimpleHttp1Test { private static final Logger logger = Logger.getLogger(SimpleHttp1Test.class.getName()); @@ -62,7 +61,7 @@ public class SimpleHttp1Test extends TestBase { } } - @After + @AfterAll public void checkThreads() { Set threadSet = Thread.getAllStackTraces().keySet(); logger.log(Level.INFO, "threads = " + threadSet.size() ); @@ -74,7 +73,7 @@ public class SimpleHttp1Test extends TestBase { } @Test - public void testHttp1() throws Exception { + void testHttp1() throws Exception { Client client = new Client(); try { HttpTransport transport = client.newTransport("xbib.org", 80); diff --git a/netty-http-client/src/test/java/org/xbib/netty/http/hacks/SimpleHttp2Test.java b/netty-http-client/src/test/java/org/xbib/netty/http/client/test/hacks/SimpleHttp2Test.java similarity index 98% rename from netty-http-client/src/test/java/org/xbib/netty/http/hacks/SimpleHttp2Test.java rename to netty-http-client/src/test/java/org/xbib/netty/http/client/test/hacks/SimpleHttp2Test.java index 759d067..6663a4d 100644 --- a/netty-http-client/src/test/java/org/xbib/netty/http/hacks/SimpleHttp2Test.java +++ b/netty-http-client/src/test/java/org/xbib/netty/http/client/test/hacks/SimpleHttp2Test.java @@ -1,4 +1,4 @@ -package org.xbib.netty.http.hacks; +package org.xbib.netty.http.client.test.hacks; import io.netty.bootstrap.Bootstrap; import io.netty.channel.Channel; @@ -35,9 +35,7 @@ import io.netty.handler.ssl.SslProvider; import io.netty.handler.ssl.SupportedCipherSuiteFilter; import io.netty.handler.ssl.util.InsecureTrustManagerFactory; import io.netty.util.AttributeKey; -import org.junit.Ignore; -import org.junit.Test; -import org.xbib.TestBase; +import org.junit.jupiter.api.Test; import javax.net.ssl.SSLException; import java.io.IOException; @@ -53,13 +51,12 @@ import java.util.concurrent.atomic.AtomicInteger; import java.util.logging.Level; import java.util.logging.Logger; -@Ignore -public class SimpleHttp2Test extends TestBase { +class SimpleHttp2Test { private static final Logger logger = Logger.getLogger(SimpleHttp2Test.class.getName()); @Test - public void testHttp2WithUpgrade() throws Exception { + void testHttp2WithUpgrade() throws Exception { Client client = new Client(); try { Http2Transport transport = client.newTransport("webtide.com", 443); diff --git a/netty-http-client/src/test/java/org/xbib/netty/http/client/test/pool/DisableTestCondition.java b/netty-http-client/src/test/java/org/xbib/netty/http/client/test/pool/DisableTestCondition.java new file mode 100644 index 0000000..9ea45f8 --- /dev/null +++ b/netty-http-client/src/test/java/org/xbib/netty/http/client/test/pool/DisableTestCondition.java @@ -0,0 +1,17 @@ +package org.xbib.netty.http.client.test.pool; + +import io.netty.channel.epoll.Epoll; +import org.junit.jupiter.api.extension.ConditionEvaluationResult; +import org.junit.jupiter.api.extension.ExecutionCondition; +import org.junit.jupiter.api.extension.ExtensionContext; + +public class DisableTestCondition implements ExecutionCondition { + @Override + public ConditionEvaluationResult evaluateExecutionCondition(ExtensionContext context) { + if (Epoll.isAvailable()) { + return ConditionEvaluationResult.enabled("Test enabled"); + } else { + return ConditionEvaluationResult.disabled("Test disabled"); + } + } +} diff --git a/netty-http-client/src/test/java/org/xbib/netty/http/client/test/pool/DisabledIfEpolllNotAvailable.java b/netty-http-client/src/test/java/org/xbib/netty/http/client/test/pool/DisabledIfEpolllNotAvailable.java new file mode 100644 index 0000000..b9b6d74 --- /dev/null +++ b/netty-http-client/src/test/java/org/xbib/netty/http/client/test/pool/DisabledIfEpolllNotAvailable.java @@ -0,0 +1,14 @@ +package org.xbib.netty.http.client.test.pool; + +import org.junit.jupiter.api.extension.ExtendWith; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Target({ElementType.TYPE, ElementType.METHOD}) +@Retention(RetentionPolicy.RUNTIME) +@ExtendWith(DisableTestCondition.class) +public @interface DisabledIfEpolllNotAvailable { +} diff --git a/netty-http-client/src/test/java/org/xbib/netty/http/client/test/pool/EpollTest.java b/netty-http-client/src/test/java/org/xbib/netty/http/client/test/pool/EpollTest.java index 72fc753..2cf9ba2 100644 --- a/netty-http-client/src/test/java/org/xbib/netty/http/client/test/pool/EpollTest.java +++ b/netty-http-client/src/test/java/org/xbib/netty/http/client/test/pool/EpollTest.java @@ -17,17 +17,14 @@ import io.netty.channel.epoll.EpollSocketChannel; import io.netty.channel.socket.SocketChannel; import io.netty.handler.codec.http.HttpVersion; -import org.junit.After; -import org.junit.Before; -import org.junit.Ignore; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInstance; import org.xbib.netty.http.common.HttpAddress; import org.xbib.netty.http.client.pool.Pool; import org.xbib.netty.http.client.pool.BoundedChannelPool; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; - import java.io.Closeable; import java.util.Collections; import java.util.List; @@ -40,8 +37,12 @@ import java.util.concurrent.atomic.LongAdder; import java.util.logging.Level; import java.util.logging.Logger; -@Ignore -public class EpollTest { +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; + +@TestInstance(TestInstance.Lifecycle.PER_CLASS) +@DisabledIfEpolllNotAvailable +class EpollTest { private static final Logger logger = Logger.getLogger(EpollTest.class.getName()); @@ -64,8 +65,8 @@ public class EpollTest { private EventLoopGroup eventLoopGroup; - @Before - public void setUp() throws Exception { + @BeforeAll + void setUp() throws Exception { mockEpollServer = new MockEpollServer(12345, FAIL_EVERY_ATTEMPT); Semaphore semaphore = new Semaphore(CONCURRENCY); eventLoopGroup = new EpollEventLoopGroup(); @@ -86,15 +87,15 @@ public class EpollTest { channelPool.prepare(CONCURRENCY); } - @After - public void tearDown() throws Exception { + @AfterAll + void tearDown() throws Exception { channelPool.close(); eventLoopGroup.shutdownGracefully(); mockEpollServer.close(); } @Test - public void testPoolEpoll() throws Exception { + void testPoolEpoll() throws Exception { LongAdder longAdder = new LongAdder(); ExecutorService executor = Executors.newFixedThreadPool(CONCURRENCY); for(int i = 0; i < CONCURRENCY; i ++) { @@ -146,7 +147,7 @@ public class EpollTest { private final AtomicLong reqCounter; - public MockEpollServer(int port, int dropEveryRequest) throws InterruptedException { + MockEpollServer(int port, int dropEveryRequest) throws InterruptedException { dispatchGroup = new EpollEventLoopGroup(); workerGroup = new EpollEventLoopGroup(); reqCounter = new AtomicLong(0); diff --git a/netty-http-client/src/test/java/org/xbib/netty/http/client/test/pool/NioTest.java b/netty-http-client/src/test/java/org/xbib/netty/http/client/test/pool/NioTest.java index 5b1b1b0..4adb343 100644 --- a/netty-http-client/src/test/java/org/xbib/netty/http/client/test/pool/NioTest.java +++ b/netty-http-client/src/test/java/org/xbib/netty/http/client/test/pool/NioTest.java @@ -16,9 +16,10 @@ import io.netty.channel.socket.SocketChannel; import io.netty.channel.socket.nio.NioServerSocketChannel; import io.netty.channel.socket.nio.NioSocketChannel; import io.netty.handler.codec.http.HttpVersion; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInstance; import org.xbib.netty.http.common.HttpAddress; import org.xbib.netty.http.client.pool.Pool; import org.xbib.netty.http.client.pool.BoundedChannelPool; @@ -35,10 +36,11 @@ import java.util.concurrent.atomic.LongAdder; import java.util.logging.Level; import java.util.logging.Logger; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; -public class NioTest { +@TestInstance(TestInstance.Lifecycle.PER_CLASS) +class NioTest { private static final Logger logger = Logger.getLogger(NioTest.class.getName()); @@ -61,8 +63,8 @@ public class NioTest { private EventLoopGroup eventLoopGroup; - @Before - public void setUp() throws Exception { + @BeforeAll + void setUp() throws Exception { mockNioServer = new MockNioServer(12345, FAIL_EVERY_ATTEMPT); Semaphore semaphore = new Semaphore(CONCURRENCY); eventLoopGroup = new NioEventLoopGroup(); @@ -83,15 +85,15 @@ public class NioTest { channelPool.prepare(CONCURRENCY); } - @After - public void tearDown() throws Exception { + @AfterAll + void tearDown() throws Exception { channelPool.close(); eventLoopGroup.shutdownGracefully(); mockNioServer.close(); } @Test - public void testPoolNio() throws Exception { + void testPoolNio() throws Exception { LongAdder longAdder = new LongAdder(); ExecutorService executor = Executors.newFixedThreadPool(CONCURRENCY); for(int i = 0; i < CONCURRENCY; i ++) { @@ -142,7 +144,7 @@ public class NioTest { private final AtomicLong reqCounter; - public MockNioServer(int port, int dropEveryRequest) throws InterruptedException { + MockNioServer(int port, int dropEveryRequest) throws InterruptedException { dispatchGroup = new NioEventLoopGroup(); workerGroup = new NioEventLoopGroup(); reqCounter = new AtomicLong(0); diff --git a/netty-http-client/src/test/java/org/xbib/netty/http/client/test/pool/PoolTest.java b/netty-http-client/src/test/java/org/xbib/netty/http/client/test/pool/PoolTest.java index 7478802..78f01fc 100644 --- a/netty-http-client/src/test/java/org/xbib/netty/http/client/test/pool/PoolTest.java +++ b/netty-http-client/src/test/java/org/xbib/netty/http/client/test/pool/PoolTest.java @@ -9,16 +9,13 @@ import io.netty.channel.socket.nio.NioServerSocketChannel; import io.netty.channel.socket.nio.NioSocketChannel; import io.netty.handler.codec.http.HttpVersion; import io.netty.util.AttributeKey; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ValueSource; import org.xbib.netty.http.common.HttpAddress; import org.xbib.netty.http.client.pool.BoundedChannelPool; import org.xbib.netty.http.client.pool.Pool; import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; import java.util.List; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; @@ -30,11 +27,10 @@ import java.util.concurrent.atomic.LongAdder; import java.util.logging.Level; import java.util.logging.Logger; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; -@RunWith(Parameterized.class) -public class PoolTest { +class PoolTest { private static final Logger logger = Logger.getLogger(PoolTest.class.getName()); @@ -42,30 +38,11 @@ public class PoolTest { private static final int BATCH_SIZE = 0x1000; - private int nodeCount; - - private ConcurrentMap nodeFreq = new ConcurrentHashMap<>(); - - @Parameterized.Parameters - public static Collection generateData() { - return Arrays.asList(new Object[][] { - {1, 1}, - {10, 1}, - {10, 2}, - //{10, 5}, - //{10, 10}, - {100, 1}, - {100, 2}, - //{100, 5}, - //{100, 10}, - //{1000, 1}, - //{1000, 2}, - //{1000, 5}, - //{1000, 10} - }); - } - - public PoolTest(int concurrencyLevel, int nodeCount) throws InterruptedException { + @ParameterizedTest + @ValueSource(ints = {1,10,100}) + void testPool(int concurrencyLevel) throws InterruptedException { + ConcurrentMap nodeFreq = new ConcurrentHashMap<>(); + int nodecount = 2; ServerBootstrap serverBootstrap = new ServerBootstrap() .group(new NioEventLoopGroup()) @@ -77,9 +54,8 @@ public class PoolTest { }); Channel serverChannel = serverBootstrap.bind("localhost", 8008).sync().channel(); - this.nodeCount = nodeCount; List nodes = new ArrayList<>(); - for (int i = 0; i < nodeCount; i ++) { + for (int i = 0; i < nodecount; i ++) { nodes.add(HttpAddress.http1("localhost", 8008)); } try (Pool pool = new BoundedChannelPool<>(new Semaphore(concurrencyLevel), HttpVersion.HTTP_1_1, @@ -127,25 +103,16 @@ public class PoolTest { } finally { serverChannel.close(); long connCountSum = nodeFreq.values().stream().mapToLong(LongAdder::sum).sum(); - logger.log(Level.INFO, "concurrency = " + concurrencyLevel + ", nodes = " + nodeCount + " -> rate: " + + logger.log(Level.INFO, "concurrency = " + concurrencyLevel + ", nodes = " + nodecount + " -> rate: " + connCountSum / TEST_STEP_TIME_SECONDS); - } - } - - @Test - public void testNodeFrequency() { - if (nodeCount > 1) { - long connCountSum = nodeFreq.values().stream().mapToLong(LongAdder::sum).sum(); - long avgConnCountPerNode = connCountSum / nodeCount; + long avgConnCountPerNode = connCountSum / 2; for (HttpAddress nodeAddr: nodeFreq.keySet()) { assertTrue(nodeFreq.get(nodeAddr).sum() > 0); - assertEquals("Node count: " + nodeCount + ", node: " + nodeAddr - + ", expected connection count: " + avgConnCountPerNode + ", actual: " - + nodeFreq.get(nodeAddr).sum(), + assertEquals(/*"Node count: " + nodeCount + ", node: " + nodeAddr + + ", expected connection count: " + avgConnCountPerNode + ", actual: " + + nodeFreq.get(nodeAddr).sum(),*/ avgConnCountPerNode, nodeFreq.get(nodeAddr).sum(), 1.5 * avgConnCountPerNode); } - } else { - assertTrue(true); } } } diff --git a/netty-http-client/src/test/java/org/xbib/netty/http/client/test/pool/PooledClientTest.java b/netty-http-client/src/test/java/org/xbib/netty/http/client/test/pool/PooledClientTest.java index 42563a7..93ffcb3 100644 --- a/netty-http-client/src/test/java/org/xbib/netty/http/client/test/pool/PooledClientTest.java +++ b/netty-http-client/src/test/java/org/xbib/netty/http/client/test/pool/PooledClientTest.java @@ -1,11 +1,12 @@ package org.xbib.netty.http.client.test.pool; import io.netty.handler.codec.http.HttpVersion; -import org.junit.Test; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.xbib.net.URL; import org.xbib.netty.http.client.Client; -import org.xbib.TestBase; import org.xbib.netty.http.client.listener.ResponseListener; +import org.xbib.netty.http.client.test.NettyHttpExtension; import org.xbib.netty.http.common.HttpAddress; import org.xbib.netty.http.client.Request; @@ -18,12 +19,13 @@ import java.util.concurrent.atomic.AtomicInteger; import java.util.logging.Level; import java.util.logging.Logger; -public class PooledClientTest extends TestBase { +@ExtendWith(NettyHttpExtension.class) +class PooledClientTest { - private static final Logger logger = Logger.getLogger(""); + private static final Logger logger = Logger.getLogger(PooledClientTest.class.getName()); @Test - public void testPooledClientWithSingleNode() throws IOException { + void testPooledClientWithSingleNode() throws IOException { int loop = 10; int threads = Runtime.getRuntime().availableProcessors(); URL url = URL.from("https://fl-test.hbz-nrw.de/app/fl"); diff --git a/netty-http-client/src/test/java/org/xbib/netty/http/client/test/rest/RestClientTest.java b/netty-http-client/src/test/java/org/xbib/netty/http/client/test/rest/RestClientTest.java index e7fcbc2..0ef8145 100644 --- a/netty-http-client/src/test/java/org/xbib/netty/http/client/test/rest/RestClientTest.java +++ b/netty-http-client/src/test/java/org/xbib/netty/http/client/test/rest/RestClientTest.java @@ -1,17 +1,17 @@ package org.xbib.netty.http.client.test.rest; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.xbib.netty.http.client.rest.RestClient; import java.io.IOException; import java.util.logging.Logger; -public class RestClientTest { +class RestClientTest { private static final Logger logger = Logger.getLogger(RestClientTest.class.getName()); @Test - public void testSimpleGet() throws IOException { + void testSimpleGet() throws IOException { String result = RestClient.get("http://xbib.org").asString(); logger.info(result); } diff --git a/netty-http-client/src/test/java/org/xbib/netty/http/client/test/retry/ExponentialBackOffTest.java b/netty-http-client/src/test/java/org/xbib/netty/http/client/test/retry/ExponentialBackOffTest.java index 17621d8..168f312 100644 --- a/netty-http-client/src/test/java/org/xbib/netty/http/client/test/retry/ExponentialBackOffTest.java +++ b/netty-http-client/src/test/java/org/xbib/netty/http/client/test/retry/ExponentialBackOffTest.java @@ -1,19 +1,20 @@ package org.xbib.netty.http.client.test.retry; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.xbib.netty.http.client.retry.BackOff; import org.xbib.netty.http.client.retry.ExponentialBackOff; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; + /** * Tests {@link ExponentialBackOff}. */ -public class ExponentialBackOffTest { +class ExponentialBackOffTest { @Test - public void testConstructor() { + void testConstructor() { ExponentialBackOff backOffPolicy = new ExponentialBackOff(); assertEquals(ExponentialBackOff.DEFAULT_INITIAL_INTERVAL_MILLIS, backOffPolicy.getInitialIntervalMillis()); @@ -29,7 +30,7 @@ public class ExponentialBackOffTest { } @Test - public void testBuilder() { + void testBuilder() { ExponentialBackOff backOffPolicy = new ExponentialBackOff.Builder().build(); assertEquals(ExponentialBackOff.DEFAULT_INITIAL_INTERVAL_MILLIS, backOffPolicy.getInitialIntervalMillis()); @@ -64,7 +65,7 @@ public class ExponentialBackOffTest { } @Test - public void testBackOff() { + void testBackOff() { int testInitialInterval = 500; double testRandomizationFactor = 0.1; double testMultiplier = 2.0; @@ -90,7 +91,7 @@ public class ExponentialBackOffTest { } @Test - public void testGetRandomizedInterval() { + void testGetRandomizedInterval() { // 33% chance of being 1. assertEquals(1, ExponentialBackOff.getRandomValueFromInterval(0.5, 0, 2)); assertEquals(1, ExponentialBackOff.getRandomValueFromInterval(0.5, 0.33, 2)); @@ -103,14 +104,14 @@ public class ExponentialBackOffTest { } @Test - public void testGetElapsedTimeMillis() { + void testGetElapsedTimeMillis() { ExponentialBackOff backOffPolicy = new ExponentialBackOff.Builder().setNanoClock(new MyNanoClock()).build(); long elapsedTimeMillis = backOffPolicy.getElapsedTimeMillis(); - assertEquals("elapsedTimeMillis=" + elapsedTimeMillis, 1000, elapsedTimeMillis); + assertEquals(1000, elapsedTimeMillis); } @Test - public void testMaxElapsedTime() { + void testMaxElapsedTime() { ExponentialBackOff backOffPolicy = new ExponentialBackOff.Builder().setNanoClock(new MyNanoClock(10000)).build(); assertTrue(backOffPolicy.nextBackOffMillis() != BackOff.STOP); @@ -121,7 +122,7 @@ public class ExponentialBackOffTest { } @Test - public void testBackOffOverflow() { + void testBackOffOverflow() { int testInitialInterval = Integer.MAX_VALUE / 2; double testMultiplier = 2.1; int testMaxInterval = Integer.MAX_VALUE; diff --git a/netty-http-client/src/test/java/org/xbib/netty/http/client/test/retry/MockBackOffTest.java b/netty-http-client/src/test/java/org/xbib/netty/http/client/test/retry/MockBackOffTest.java index 1e79dc8..8989c60 100644 --- a/netty-http-client/src/test/java/org/xbib/netty/http/client/test/retry/MockBackOffTest.java +++ b/netty-http-client/src/test/java/org/xbib/netty/http/client/test/retry/MockBackOffTest.java @@ -1,19 +1,19 @@ package org.xbib.netty.http.client.test.retry; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.xbib.netty.http.client.retry.BackOff; import java.io.IOException; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; /** * Tests {@link MockBackOff}. */ -public class MockBackOffTest { +class MockBackOffTest { @Test - public void testNextBackOffMillis() throws IOException { + void testNextBackOffMillis() throws IOException { subtestNextBackOffMillis(0, new MockBackOff()); subtestNextBackOffMillis(BackOff.STOP, new MockBackOff().setBackOffMillis(BackOff.STOP)); subtestNextBackOffMillis(42, new MockBackOff().setBackOffMillis(42)); diff --git a/netty-http-common/build.gradle b/netty-http-common/build.gradle index 99d739f..c6c6bbf 100644 --- a/netty-http-common/build.gradle +++ b/netty-http-common/build.gradle @@ -1,5 +1,5 @@ dependencies { - compile "org.xbib:net-url:${project.property('xbib-net-url.version')}" - compile "io.netty:netty-codec-http2:${project.property('netty.version')}" + implementation "org.xbib:net-url:${project.property('xbib-net-url.version')}" + implementation "io.netty:netty-codec-http2:${project.property('netty.version')}" } diff --git a/netty-http-server-rest/build.gradle b/netty-http-server-rest/build.gradle new file mode 100644 index 0000000..ac8651f --- /dev/null +++ b/netty-http-server-rest/build.gradle @@ -0,0 +1,6 @@ +dependencies { + implementation project(":netty-http-server") + implementation "io.netty:netty-codec-http2:${project.property('netty.version')}" + implementation "org.xbib:net-url:${project.property('xbib-net-url.version')}" + implementation "org.xbib:guice:${project.property('xbib-guice.version')}" +} diff --git a/netty-http-server-rest/src/main/java/org/xbib/netty/http/server/rest/Rest.java b/netty-http-server-rest/src/main/java/org/xbib/netty/http/server/rest/Rest.java new file mode 100644 index 0000000..74d2dc7 --- /dev/null +++ b/netty-http-server-rest/src/main/java/org/xbib/netty/http/server/rest/Rest.java @@ -0,0 +1,4 @@ +package org.xbib.netty.http.server.rest; + +public class Rest { +} diff --git a/netty-http-server-rest/src/main/java/org/xbib/netty/http/server/rest/RestBuilder.java b/netty-http-server-rest/src/main/java/org/xbib/netty/http/server/rest/RestBuilder.java new file mode 100644 index 0000000..f75b12a --- /dev/null +++ b/netty-http-server-rest/src/main/java/org/xbib/netty/http/server/rest/RestBuilder.java @@ -0,0 +1,4 @@ +package org.xbib.netty.http.server.rest; + +public class RestBuilder { +} diff --git a/netty-http-server-rest/src/main/java/org/xbib/netty/http/server/rest/RestConfig.java b/netty-http-server-rest/src/main/java/org/xbib/netty/http/server/rest/RestConfig.java new file mode 100644 index 0000000..572287b --- /dev/null +++ b/netty-http-server-rest/src/main/java/org/xbib/netty/http/server/rest/RestConfig.java @@ -0,0 +1,4 @@ +package org.xbib.netty.http.server.rest; + +public class RestConfig { +} diff --git a/netty-http-server-rest/src/main/java/org/xbib/netty/http/server/rest/RestName.java b/netty-http-server-rest/src/main/java/org/xbib/netty/http/server/rest/RestName.java new file mode 100644 index 0000000..d7db68e --- /dev/null +++ b/netty-http-server-rest/src/main/java/org/xbib/netty/http/server/rest/RestName.java @@ -0,0 +1,44 @@ +package org.xbib.netty.http.server.rest; + +import io.netty.bootstrap.Bootstrap; + +import java.util.Optional; + +/** + * Server name. + */ +public final class RestName { + + /** + * The default value for {@code Server} header. + */ + private static final String SERVER_NAME = String.format("RestServer/%s (Java/%s/%s) (Netty/%s)", + httpServerVersion(), javaVendor(), javaVersion(), nettyVersion()); + + private RestName() { + } + + public static String getServerName() { + return SERVER_NAME; + } + + private static String httpServerVersion() { + return Optional.ofNullable(Rest.class.getPackage().getImplementationVersion()) + .orElse("unknown"); + } + + private static String javaVendor() { + return Optional.ofNullable(System.getProperty("java.vendor")) + .orElse("unknown"); + } + + private static String javaVersion() { + return Optional.ofNullable(System.getProperty("java.version")) + .orElse("unknown"); + } + + private static String nettyVersion() { + return Optional.ofNullable(Bootstrap.class.getPackage().getImplementationVersion()) + .orElse("unknown"); + } +} diff --git a/netty-http-server-rest/src/main/java/org/xbib/netty/http/server/rest/util/MediaType.java b/netty-http-server-rest/src/main/java/org/xbib/netty/http/server/rest/util/MediaType.java new file mode 100644 index 0000000..80d3720 --- /dev/null +++ b/netty-http-server-rest/src/main/java/org/xbib/netty/http/server/rest/util/MediaType.java @@ -0,0 +1,1259 @@ +package org.xbib.netty.http.server.rest.util; + +import java.util.Arrays; +import java.util.LinkedHashMap; +import java.util.Map; + +public class MediaType { + + public static final MediaType DEFAULT = MediaType.BINARY; + private static final Map FILE_EXTENSIONS = new LinkedHashMap<>(); + private static final String[] NO_ATTR = new String[0]; + public static final MediaType ANY = create("*/*"); + public static final MediaType TEXT_ANY = create("text/*"); + public static final MediaType APPLICATION_ANY = create("application/*"); + public static final MediaType IMAGE_ANY = create("image/*"); + public static final MediaType VIDEO_ANY = create("video/*"); + public static final MediaType AUDIO_ANY = create("audio/*"); + public static final MediaType TEXT_YAML = create("text/yaml", "yaml"); + public static final MediaType APPLICATION_ANDREW_INSET = create("application/andrew-inset", "ez"); + public static final MediaType APPLICATION_ANNODEX = create("application/annodex", "anx"); + public static final MediaType APPLICATION_APPLIXWARE = create("application/applixware", "aw"); + public static final MediaType APPLICATION_BBOLIN = create("application/bbolin", "lin"); + public static final MediaType APPLICATION_CAP = create("application/cap", "cap", "pcap"); + public static final MediaType APPLICATION_CCXML_XML = create("application/ccxml+xml", "ccxml"); + public static final MediaType APPLICATION_CDMI_CAPABILITY = create("application/cdmi-capability", "cdmia"); + public static final MediaType APPLICATION_CDMI_CONTAINER = create("application/cdmi-container", "cdmic"); + public static final MediaType APPLICATION_CDMI_DOMAIN = create("application/cdmi-domain", "cdmid"); + public static final MediaType APPLICATION_CDMI_OBJECT = create("application/cdmi-object", "cdmio"); + public static final MediaType APPLICATION_CDMI_QUEUE = create("application/cdmi-queue", "cdmiq"); + public static final MediaType APPLICATION_CU_SEEME = create("application/cu-seeme", "cu"); + public static final MediaType APPLICATION_DAVMOUNT_XML = create("application/davmount+xml", "davmount"); + public static final MediaType APPLICATION_DOCBOOK_XML = create("application/docbook+xml", "dbk"); + public static final MediaType APPLICATION_DSPTYPE = create("application/dsptype", "tsp"); + public static final MediaType APPLICATION_DSSC_DER = create("application/dssc+der", "dssc"); + public static final MediaType APPLICATION_DSSC_XML = create("application/dssc+xml", "xdssc"); + public static final MediaType APPLICATION_EMMA_XML = create("application/emma+xml", "emma"); + public static final MediaType APPLICATION_EPUB_ZIP = create("application/epub+zip", "epub"); + public static final MediaType APPLICATION_EXI = create("application/exi", "exi"); + public static final MediaType APPLICATION_FONT_TDPFR = create("application/font-tdpfr", "pfr"); + public static final MediaType APPLICATION_FUTURESPLASH = create("application/futuresplash", "spl"); + public static final MediaType APPLICATION_GML_XML = create("application/gml+xml", "gml"); + public static final MediaType APPLICATION_GPX_XML = create("application/gpx+xml", "gpx"); + public static final MediaType APPLICATION_GXF = create("application/gxf", "gxf"); + public static final MediaType APPLICATION_HTA = create("application/hta", "hta"); + public static final MediaType APPLICATION_HYPERSTUDIO = create("application/hyperstudio", "stk"); + public static final MediaType APPLICATION_INKML_XML = create("application/inkml+xml", "ink", "inkml"); + public static final MediaType APPLICATION_IPFIX = create("application/ipfix", "ipfix"); + public static final MediaType APPLICATION_JAVA_ARCHIVE = create("application/java-archive", "jar"); + public static final MediaType APPLICATION_JAVA_SERIALIZED_OBJECT = create("application/java-serialized-object", + "ser"); + public static final MediaType APPLICATION_JAVA_VM = create("application/java-vm", "class"); + public static final MediaType APPLICATION_JSON = create("application/json", "json", "map"); + public static final MediaType APPLICATION_JSONML_JSON = create("application/jsonml+json", "jsonml"); + public static final MediaType APPLICATION_LOST_XML = create("application/lost+xml", "lostxml"); + public static final MediaType APPLICATION_M3G = create("application/m3g", "m3g"); + public static final MediaType APPLICATION_MAC_BINHEX40 = create("application/mac-binhex40", "hqx"); + public static final MediaType APPLICATION_MAC_COMPACTPRO = create("application/mac-compactpro", "cpt"); + public static final MediaType APPLICATION_MADS_XML = create("application/mads+xml", "mads"); + public static final MediaType APPLICATION_MARC = create("application/marc", "mrc"); + public static final MediaType APPLICATION_MARCXML_XML = create("application/marcxml+xml", "mrcx"); + public static final MediaType APPLICATION_MATHEMATICA = create("application/mathematica", "ma", "mb", "nb", "nbp"); + public static final MediaType APPLICATION_MATHML_XML = create("application/mathml+xml", "mathml"); + public static final MediaType APPLICATION_MBOX = create("application/mbox", "mbox"); + public static final MediaType APPLICATION_MEDIASERVERCONTROL_XML = create("application/mediaservercontrol+xml", + "MSCML"); + public static final MediaType APPLICATION_METALINK4_XML = create("application/metalink4+xml", "meta4"); + public static final MediaType APPLICATION_METALINK_XML = create("application/metalink+xml", "metalink"); + public static final MediaType APPLICATION_METS_XML = create("application/mets+xml", "mets"); + public static final MediaType APPLICATION_MODS_XML = create("application/mods+xml", "mods"); + public static final MediaType APPLICATION_MP21 = create("application/mp21", "m21", "mp21"); + public static final MediaType APPLICATION_MP4 = create("application/mp4", "mp4s"); + public static final MediaType APPLICATION_MSACCESS = create("application/msaccess", "mdb"); + public static final MediaType APPLICATION_MSWORD = create("application/msword", "doc", "dot"); + public static final MediaType APPLICATION_MXF = create("application/mxf", "mxf"); + public static final MediaType APPLICATION_OCTET_STREAM = create("application/octet-stream", "bin", "dms", "lrf", + "MAR", "SO", "DIST", "DISTZ", "PKG", "BPK", "DUMP", "ELC", "DEPLOY"); + public static final MediaType APPLICATION_ODA = create("application/oda", "oda"); + public static final MediaType APPLICATION_OEBPS_PACKAGE_XML = create("application/oebps-package+xml", "opf"); + public static final MediaType APPLICATION_OGG = create("application/ogg", "ogx"); + public static final MediaType APPLICATION_OMDOC_XML = create("application/omdoc+xml", "omdoc"); + public static final MediaType APPLICATION_ONENOTE = create("application/onenote", "one", "onetoc", "onetoc2", + "ONETMP", "ONEPKG"); + public static final MediaType APPLICATION_OXPS = create("application/oxps", "oxps"); + public static final MediaType APPLICATION_PATCH_OPS_ERROR_XML = create("application/patch-ops-error+xml", "xer"); + public static final MediaType APPLICATION_PDF = create("application/pdf", "pdf"); + public static final MediaType APPLICATION_PGP_ENCRYPTED = create("application/pgp-encrypted", "pgp"); + public static final MediaType APPLICATION_PGP_KEYS = create("application/pgp-keys", "key"); + public static final MediaType APPLICATION_PGP_SIGNATURE = create("application/pgp-signature", "asc", "pgp", "sig"); + public static final MediaType APPLICATION_PICS_RULES = create("application/pics-rules", "prf"); + public static final MediaType APPLICATION_PKCS10 = create("application/pkcs10", "p10"); + public static final MediaType APPLICATION_PKCS7_MIME = create("application/pkcs7-mime", "p7m", "p7c"); + public static final MediaType APPLICATION_PKCS7_SIGNATURE = create("application/pkcs7-signature", "p7s"); + public static final MediaType APPLICATION_PKCS8 = create("application/pkcs8", "p8"); + public static final MediaType APPLICATION_PKIX_ATTR_CERT = create("application/pkix-attr-cert", "ac"); + public static final MediaType APPLICATION_PKIX_CERT = create("application/pkix-cert", "cer"); + public static final MediaType APPLICATION_PKIXCMP = create("application/pkixcmp", "pki"); + public static final MediaType APPLICATION_PKIX_CRL = create("application/pkix-crl", "crl"); + public static final MediaType APPLICATION_PKIX_PKIPATH = create("application/pkix-pkipath", "pkipath"); + public static final MediaType APPLICATION_PLS_XML = create("application/pls+xml", "pls"); + public static final MediaType APPLICATION_POSTSCRIPT = create("application/postscript", "ps", "ai", "eps", "epsi", + "EPSF", "EPS2", "EPS3"); + public static final MediaType APPLICATION_PRS_CWW = create("application/prs.cww", "cww"); + public static final MediaType APPLICATION_PSKC_XML = create("application/pskc+xml", "pskcxml"); + public static final MediaType APPLICATION_RAR = create("application/rar", "rar"); + public static final MediaType APPLICATION_RDF_XML = create("application/rdf+xml", "rdf"); + public static final MediaType APPLICATION_REGINFO_XML = create("application/reginfo+xml", "rif"); + public static final MediaType APPLICATION_RELAX_NG_COMPACT_SYNTAX = create("application/relax-ng-compact-syntax", + "RNC"); + public static final MediaType APPLICATION_RESOURCE_LISTS_DIFF_XML = create("application/resource-lists-diff+xml", + "RLD"); + public static final MediaType APPLICATION_RESOURCE_LISTS_XML = create("application/resource-lists+xml", "rl"); + public static final MediaType APPLICATION_RLS_SERVICES_XML = create("application/rls-services+xml", "rs"); + public static final MediaType APPLICATION_RPKI_GHOSTBUSTERS = create("application/rpki-ghostbusters", "gbr"); + public static final MediaType APPLICATION_RPKI_MANIFEST = create("application/rpki-manifest", "mft"); + public static final MediaType APPLICATION_RPKI_ROA = create("application/rpki-roa", "roa"); + public static final MediaType APPLICATION_RTF = create("application/rtf", "rtf"); + public static final MediaType APPLICATION_SBML_XML = create("application/sbml+xml", "sbml"); + public static final MediaType APPLICATION_SCVP_CV_REQUEST = create("application/scvp-cv-request", "scq"); + public static final MediaType APPLICATION_SCVP_CV_RESPONSE = create("application/scvp-cv-response", "scs"); + public static final MediaType APPLICATION_SCVP_VP_REQUEST = create("application/scvp-vp-request", "spq"); + public static final MediaType APPLICATION_SCVP_VP_RESPONSE = create("application/scvp-vp-response", "spp"); + public static final MediaType APPLICATION_SDP = create("application/sdp", "sdp"); + public static final MediaType APPLICATION_SET_PAYMENT_INITIATION = create("application/set-payment-initiation", + "SETPAY"); + public static final MediaType APPLICATION_SET_REGISTRATION_INITIATION = create( + "APPLICATION/SET-REGISTRATION-INITIATION", "SETREG"); + public static final MediaType APPLICATION_SHF_XML = create("application/shf+xml", "shf"); + public static final MediaType APPLICATION_SLA = create("application/sla", "stl"); + public static final MediaType APPLICATION_SMIL = create("application/smil", "smi", "smil"); + public static final MediaType APPLICATION_SMIL_XML = create("application/smil+xml", "smi", "smil"); + public static final MediaType APPLICATION_SPARQL_QUERY = create("application/sparql-query", "rq"); + public static final MediaType APPLICATION_SPARQL_RESULTS_XML = create("application/sparql-results+xml", "srx"); + public static final MediaType APPLICATION_SRGS = create("application/srgs", "gram"); + public static final MediaType APPLICATION_SRGS_XML = create("application/srgs+xml", "grxml"); + public static final MediaType APPLICATION_SRU_XML = create("application/sru+xml", "sru"); + public static final MediaType APPLICATION_SSDL_XML = create("application/ssdl+xml", "ssdl"); + public static final MediaType APPLICATION_SSML_XML = create("application/ssml+xml", "ssml"); + public static final MediaType APPLICATION_TEI_XML = create("application/tei+xml", "tei", "teicorpus"); + public static final MediaType APPLICATION_THRAUD_XML = create("application/thraud+xml", "tfi"); + public static final MediaType APPLICATION_TIMESTAMPED_DATA = create("application/timestamped-data", "tsd"); + public static final MediaType APPLICATION_VND_3GPP2_TCAP = create("application/vnd.3gpp2.tcap", "tcap"); + public static final MediaType APPLICATION_VND_3GPP_PIC_BW_LARGE = create("application/vnd.3gpp.pic-bw-large", "plb"); + public static final MediaType APPLICATION_VND_3GPP_PIC_BW_SMALL = create("application/vnd.3gpp.pic-bw-small", "psb"); + public static final MediaType APPLICATION_VND_3GPP_PIC_BW_VAR = create("application/vnd.3gpp.pic-bw-var", "pvb"); + public static final MediaType APPLICATION_VND_3M_POST_IT_NOTES = create("application/vnd.3m.post-it-notes", "pwn"); + public static final MediaType APPLICATION_VND_ACCPAC_SIMPLY_ASO = create("application/vnd.accpac.simply.aso", "aso"); + public static final MediaType APPLICATION_VND_ACCPAC_SIMPLY_IMP = create("application/vnd.accpac.simply.imp", "imp"); + public static final MediaType APPLICATION_VND_ACUCOBOL = create("application/vnd.acucobol", "acu"); + public static final MediaType APPLICATION_VND_ACUCORP = create("application/vnd.acucorp", "atc", "acutc"); + public static final MediaType APPLICATION_VND_ADOBE_AIR_APPLICATION_INSTALLER_PACKAGE_ZIP = create( + "APPLICATION/VND.ADOBE.AIR-APPLICATION-INSTALLER-PACKAGE+ZIP", "AIR"); + public static final MediaType APPLICATION_VND_ADOBE_FORMSCENTRAL_FCDT = create( + "APPLICATION/VND.ADOBE.FORMSCENTRAL.FCDT", "FCDT"); + public static final MediaType APPLICATION_VND_ADOBE_FXP = create("application/vnd.adobe.fxp", "fxp", "fxpl"); + public static final MediaType APPLICATION_VND_ADOBE_XDP_XML = create("application/vnd.adobe.xdp+xml", "xdp"); + public static final MediaType APPLICATION_VND_ADOBE_XFDF = create("application/vnd.adobe.xfdf", "xfdf"); + public static final MediaType APPLICATION_VND_AHEAD_SPACE = create("application/vnd.ahead.space", "ahead"); + public static final MediaType APPLICATION_VND_AIRZIP_FILESECURE_AZF = create( + "application/vnd.airzip.filesecure.azf", "AZF"); + public static final MediaType APPLICATION_VND_AIRZIP_FILESECURE_AZS = create( + "application/vnd.airzip.filesecure.azs", "AZS"); + public static final MediaType APPLICATION_VND_AMAZON_EBOOK = create("application/vnd.amazon.ebook", "azw"); + public static final MediaType APPLICATION_VND_AMERICANDYNAMICS_ACC = create("application/vnd.americandynamics.acc", + "ACC"); + public static final MediaType APPLICATION_VND_AMIGA_AMI = create("application/vnd.amiga.ami", "ami"); + public static final MediaType APPLICATION_VND_ANDROID_PACKAGE_ARCHIVE = create( + "APPLICATION/VND.ANDROID.PACKAGE-ARCHIVE", "APK"); + public static final MediaType APPLICATION_VND_ANSER_WEB_CERTIFICATE_ISSUE_INITIATION = create( + "APPLICATION/VND.ANSER-WEB-CERTIFICATE-ISSUE-INITIATION", "CII"); + public static final MediaType APPLICATION_VND_ANSER_WEB_FUNDS_TRANSFER_INITIATION = create( + "APPLICATION/VND.ANSER-WEB-FUNDS-TRANSFER-INITIATION", "FTI"); + public static final MediaType APPLICATION_VND_ANTIX_GAME_COMPONENT = create("application/vnd.antix.game-component", + "ATX"); + public static final MediaType APPLICATION_VND_APPLE_INSTALLER_XML = create("application/vnd.apple.installer+xml", + "MPKG"); + public static final MediaType APPLICATION_VND_APPLE_MPEGURL = create("application/vnd.apple.mpegurl", "m3u8"); + public static final MediaType APPLICATION_VND_ARISTANETWORKS_SWI = create("application/vnd.aristanetworks.swi", + "swi"); + public static final MediaType APPLICATION_VND_ASTRAEA_SOFTWARE_IOTA = create( + "application/vnd.astraea-software.iota", "IOTA"); + public static final MediaType APPLICATION_VND_AUDIOGRAPH = create("application/vnd.audiograph", "aep"); + public static final MediaType APPLICATION_VND_BLUEICE_MULTIPASS = create("application/vnd.blueice.multipass", "mpm"); + public static final MediaType APPLICATION_VND_BMI = create("application/vnd.bmi", "bmi"); + public static final MediaType APPLICATION_VND_BUSINESSOBJECTS = create("application/vnd.businessobjects", "rep"); + public static final MediaType APPLICATION_VND_CHEMDRAW_XML = create("application/vnd.chemdraw+xml", "cdxml"); + public static final MediaType APPLICATION_VND_CHIPNUTS_KARAOKE_MMD = create("application/vnd.chipnuts.karaoke-mmd", + "MMD"); + public static final MediaType APPLICATION_VND_CINDERELLA = create("application/vnd.cinderella", "cdy"); + public static final MediaType APPLICATION_VND_CLAYMORE = create("application/vnd.claymore", "cla"); + public static final MediaType APPLICATION_VND_CLOANTO_RP9 = create("application/vnd.cloanto.rp9", "rp9"); + public static final MediaType APPLICATION_VND_CLONK_C4GROUP = create("application/vnd.clonk.c4group", "c4g", "c4d", + "C4F", "C4P", "C4U"); + public static final MediaType APPLICATION_VND_CLUETRUST_CARTOMOBILE_CONFIG = create( + "APPLICATION/VND.CLUETRUST.CARTOMOBILE-CONFIG", "C11AMC"); + public static final MediaType APPLICATION_VND_CLUETRUST_CARTOMOBILE_CONFIG_PKG = create( + "APPLICATION/VND.CLUETRUST.CARTOMOBILE-CONFIG-PKG", "C11AMZ"); + public static final MediaType APPLICATION_VND_COMMONSPACE = create("application/vnd.commonspace", "csp"); + public static final MediaType APPLICATION_VND_CONTACT_CMSG = create("application/vnd.contact.cmsg", "cdbcmsg"); + public static final MediaType APPLICATION_VND_COSMOCALLER = create("application/vnd.cosmocaller", "cmc"); + public static final MediaType APPLICATION_VND_CRICK_CLICKER = create("application/vnd.crick.clicker", "clkx"); + public static final MediaType APPLICATION_VND_CRICK_CLICKER_KEYBOARD = create( + "APPLICATION/VND.CRICK.CLICKER.KEYBOARD", "CLKK"); + public static final MediaType APPLICATION_VND_CRICK_CLICKER_PALETTE = create( + "application/vnd.crick.clicker.palette", "CLKP"); + public static final MediaType APPLICATION_VND_CRICK_CLICKER_TEMPLATE = create( + "APPLICATION/VND.CRICK.CLICKER.TEMPLATE", "CLKT"); + public static final MediaType APPLICATION_VND_CRICK_CLICKER_WORDBANK = create( + "APPLICATION/VND.CRICK.CLICKER.WORDBANK", "CLKW"); + public static final MediaType APPLICATION_VND_CRITICALTOOLS_WBS_XML = create( + "application/vnd.criticaltools.wbs+xml", "WBS"); + public static final MediaType APPLICATION_VND_CTC_POSML = create("application/vnd.ctc-posml", "pml"); + public static final MediaType APPLICATION_VND_CUPS_PPD = create("application/vnd.cups-ppd", "ppd"); + public static final MediaType APPLICATION_VND_CURL_CAR = create("application/vnd.curl.car", "car"); + public static final MediaType APPLICATION_VND_CURL_PCURL = create("application/vnd.curl.pcurl", "pcurl"); + public static final MediaType APPLICATION_VND_DART = create("application/vnd.dart", "dart"); + public static final MediaType APPLICATION_VND_DATA_VISION_RDZ = create("application/vnd.data-vision.rdz", "rdz"); + public static final MediaType APPLICATION_VND_DECE_DATA = create("application/vnd.dece.data", "uvf", "uvvf", "uvd", + "UVVD"); + public static final MediaType APPLICATION_VND_DECE_TTML_XML = create("application/vnd.dece.ttml+xml", "uvt", "uvvt"); + public static final MediaType APPLICATION_VND_DECE_UNSPECIFIED = create("application/vnd.dece.unspecified", "uvx", + "UVVX"); + public static final MediaType APPLICATION_VND_DECE_ZIP = create("application/vnd.dece.zip", "uvz", "uvvz"); + public static final MediaType APPLICATION_VND_DENOVO_FCSELAYOUT_LINK = create( + "APPLICATION/VND.DENOVO.FCSELAYOUT-LINK", "FE_LAUNCH"); + public static final MediaType APPLICATION_VND_DNA = create("application/vnd.dna", "dna"); + public static final MediaType APPLICATION_VND_DOLBY_MLP = create("application/vnd.dolby.mlp", "mlp"); + public static final MediaType APPLICATION_VND_DPGRAPH = create("application/vnd.dpgraph", "dpg"); + public static final MediaType APPLICATION_VND_DREAMFACTORY = create("application/vnd.dreamfactory", "dfac"); + public static final MediaType APPLICATION_VND_DS_KEYPOINT = create("application/vnd.ds-keypoint", "kpxx"); + public static final MediaType APPLICATION_VND_DVB_AIT = create("application/vnd.dvb.ait", "ait"); + public static final MediaType APPLICATION_VND_DVB_SERVICE = create("application/vnd.dvb.service", "svc"); + public static final MediaType APPLICATION_VND_DYNAGEO = create("application/vnd.dynageo", "geo"); + public static final MediaType APPLICATION_VND_ECOWIN_CHART = create("application/vnd.ecowin.chart", "mag"); + public static final MediaType APPLICATION_VND_ENLIVEN = create("application/vnd.enliven", "nml"); + public static final MediaType APPLICATION_VND_EPSON_ESF = create("application/vnd.epson.esf", "esf"); + public static final MediaType APPLICATION_VND_EPSON_MSF = create("application/vnd.epson.msf", "msf"); + public static final MediaType APPLICATION_VND_EPSON_QUICKANIME = create("application/vnd.epson.quickanime", "qam"); + public static final MediaType APPLICATION_VND_EPSON_SALT = create("application/vnd.epson.salt", "slt"); + public static final MediaType APPLICATION_VND_EPSON_SSF = create("application/vnd.epson.ssf", "ssf"); + public static final MediaType APPLICATION_VND_ESZIGNO3_XML = create("application/vnd.eszigno3+xml", "es3", "et3"); + public static final MediaType APPLICATION_VND_EZPIX_ALBUM = create("application/vnd.ezpix-album", "ez2"); + public static final MediaType APPLICATION_VND_EZPIX_PACKAGE = create("application/vnd.ezpix-package", "ez3"); + public static final MediaType APPLICATION_VND_FDF = create("application/vnd.fdf", "fdf"); + public static final MediaType APPLICATION_VND_FDSN_MSEED = create("application/vnd.fdsn.mseed", "mseed"); + public static final MediaType APPLICATION_VND_FDSN_SEED = create("application/vnd.fdsn.seed", "seed", "dataless"); + public static final MediaType APPLICATION_VND_FLOGRAPHIT = create("application/vnd.flographit", "gph"); + public static final MediaType APPLICATION_VND_FLUXTIME_CLIP = create("application/vnd.fluxtime.clip", "ftc"); + public static final MediaType APPLICATION_VND_FRAMEMAKER = create("application/vnd.framemaker", "fm", "frame", + "MAKER", "BOOK"); + public static final MediaType APPLICATION_VND_FROGANS_FNC = create("application/vnd.frogans.fnc", "fnc"); + public static final MediaType APPLICATION_VND_FROGANS_LTF = create("application/vnd.frogans.ltf", "ltf"); + public static final MediaType APPLICATION_VND_FSC_WEBLAUNCH = create("application/vnd.fsc.weblaunch", "fsc"); + public static final MediaType APPLICATION_VND_FUJITSU_OASYS2 = create("application/vnd.fujitsu.oasys2", "oa2"); + public static final MediaType APPLICATION_VND_FUJITSU_OASYS3 = create("application/vnd.fujitsu.oasys3", "oa3"); + public static final MediaType APPLICATION_VND_FUJITSU_OASYSGP = create("application/vnd.fujitsu.oasysgp", "fg5"); + public static final MediaType APPLICATION_VND_FUJITSU_OASYS = create("application/vnd.fujitsu.oasys", "oas"); + public static final MediaType APPLICATION_VND_FUJITSU_OASYSPRS = create("application/vnd.fujitsu.oasysprs", "bh2"); + public static final MediaType APPLICATION_VND_FUJIXEROX_DDD = create("application/vnd.fujixerox.ddd", "ddd"); + public static final MediaType APPLICATION_VND_FUJIXEROX_DOCUWORKS_BINDER = create( + "APPLICATION/VND.FUJIXEROX.DOCUWORKS.BINDER", "XBD"); + public static final MediaType APPLICATION_VND_FUJIXEROX_DOCUWORKS = create("application/vnd.fujixerox.docuworks", + "XDW"); + public static final MediaType APPLICATION_VND_FUZZYSHEET = create("application/vnd.fuzzysheet", "fzs"); + public static final MediaType APPLICATION_VND_GENOMATIX_TUXEDO = create("application/vnd.genomatix.tuxedo", "txd"); + public static final MediaType APPLICATION_VND_GEOGEBRA_FILE = create("application/vnd.geogebra.file", "ggb"); + public static final MediaType APPLICATION_VND_GEOGEBRA_TOOL = create("application/vnd.geogebra.tool", "ggt"); + public static final MediaType APPLICATION_VND_GEOMETRY_EXPLORER = create("application/vnd.geometry-explorer", + "gex", "GRE"); + public static final MediaType APPLICATION_VND_GEONEXT = create("application/vnd.geonext", "gxt"); + public static final MediaType APPLICATION_VND_GEOPLAN = create("application/vnd.geoplan", "g2w"); + public static final MediaType APPLICATION_VND_GEOSPACE = create("application/vnd.geospace", "g3w"); + public static final MediaType APPLICATION_VND_GMX = create("application/vnd.gmx", "gmx"); + public static final MediaType APPLICATION_VND_GOOGLE_EARTH_KML_XML = create("application/vnd.google-earth.kml+xml", + "KML"); + public static final MediaType APPLICATION_VND_GOOGLE_EARTH_KMZ = create("application/vnd.google-earth.kmz", "kmz"); + public static final MediaType APPLICATION_VND_GRAFEQ = create("application/vnd.grafeq", "gqf", "gqs"); + public static final MediaType APPLICATION_VND_GROOVE_ACCOUNT = create("application/vnd.groove-account", "gac"); + public static final MediaType APPLICATION_VND_GROOVE_HELP = create("application/vnd.groove-help", "ghf"); + public static final MediaType APPLICATION_VND_GROOVE_IDENTITY_MESSAGE = create( + "APPLICATION/VND.GROOVE-IDENTITY-MESSAGE", "GIM"); + public static final MediaType APPLICATION_VND_GROOVE_INJECTOR = create("application/vnd.groove-injector", "grv"); + public static final MediaType APPLICATION_VND_GROOVE_TOOL_MESSAGE = create("application/vnd.groove-tool-message", + "GTM"); + public static final MediaType APPLICATION_VND_GROOVE_TOOL_TEMPLATE = create("application/vnd.groove-tool-template", + "TPL"); + public static final MediaType APPLICATION_VND_GROOVE_VCARD = create("application/vnd.groove-vcard", "vcg"); + public static final MediaType APPLICATION_VND_HAL_XML = create("application/vnd.hal+xml", "hal"); + public static final MediaType APPLICATION_VND_HANDHELD_ENTERTAINMENT_XML = create( + "APPLICATION/VND.HANDHELD-ENTERTAINMENT+XML", "ZMM"); + public static final MediaType APPLICATION_VND_HBCI = create("application/vnd.hbci", "hbci"); + public static final MediaType APPLICATION_VND_HHE_LESSON_PLAYER = create("application/vnd.hhe.lesson-player", "les"); + public static final MediaType APPLICATION_VND_HP_HPGL = create("application/vnd.hp-hpgl", "hpgl"); + public static final MediaType APPLICATION_VND_HP_HPID = create("application/vnd.hp-hpid", "hpid"); + public static final MediaType APPLICATION_VND_HP_HPS = create("application/vnd.hp-hps", "hps"); + public static final MediaType APPLICATION_VND_HP_JLYT = create("application/vnd.hp-jlyt", "jlt"); + public static final MediaType APPLICATION_VND_HP_PCL = create("application/vnd.hp-pcl", "pcl"); + public static final MediaType APPLICATION_VND_HP_PCLXL = create("application/vnd.hp-pclxl", "pclxl"); + public static final MediaType APPLICATION_VND_HYDROSTATIX_SOF_DATA = create("application/vnd.hydrostatix.sof-data", + "SFD-HDSTX"); + public static final MediaType APPLICATION_VND_IBM_MINIPAY = create("application/vnd.ibm.minipay", "mpy"); + public static final MediaType APPLICATION_VND_IBM_MODCAP = create("application/vnd.ibm.modcap", "afp", "listafp", + "LIST3820"); + public static final MediaType APPLICATION_VND_IBM_RIGHTS_MANAGEMENT = create( + "application/vnd.ibm.rights-management", "IRM"); + public static final MediaType APPLICATION_VND_IBM_SECURE_CONTAINER = create("application/vnd.ibm.secure-container", + "SC"); + public static final MediaType APPLICATION_VND_ICCPROFILE = create("application/vnd.iccprofile", "icc", "icm"); + public static final MediaType APPLICATION_VND_IGLOADER = create("application/vnd.igloader", "igl"); + public static final MediaType APPLICATION_VND_IMMERVISION_IVP = create("application/vnd.immervision-ivp", "ivp"); + public static final MediaType APPLICATION_VND_IMMERVISION_IVU = create("application/vnd.immervision-ivu", "ivu"); + public static final MediaType APPLICATION_VND_INSORS_IGM = create("application/vnd.insors.igm", "igm"); + public static final MediaType APPLICATION_VND_INTERCON_FORMNET = create("application/vnd.intercon.formnet", "xpw", + "XPX"); + public static final MediaType APPLICATION_VND_INTERGEO = create("application/vnd.intergeo", "i2g"); + public static final MediaType APPLICATION_VND_INTU_QBO = create("application/vnd.intu.qbo", "qbo"); + public static final MediaType APPLICATION_VND_INTU_QFX = create("application/vnd.intu.qfx", "qfx"); + public static final MediaType APPLICATION_VND_IPUNPLUGGED_RCPROFILE = create( + "application/vnd.ipunplugged.rcprofile", "RCPROFILE"); + public static final MediaType APPLICATION_VND_IREPOSITORY_PACKAGE_XML = create( + "APPLICATION/VND.IREPOSITORY.PACKAGE+XML", "IRP"); + public static final MediaType APPLICATION_VND_ISAC_FCS = create("application/vnd.isac.fcs", "fcs"); + public static final MediaType APPLICATION_VND_IS_XPR = create("application/vnd.is-xpr", "xpr"); + public static final MediaType APPLICATION_VND_JAM = create("application/vnd.jam", "jam"); + public static final MediaType APPLICATION_VND_JCP_JAVAME_MIDLET_RMS = create( + "application/vnd.jcp.javame.midlet-rms", "RMS"); + public static final MediaType APPLICATION_VND_JISP = create("application/vnd.jisp", "jisp"); + public static final MediaType APPLICATION_VND_JOOST_JODA_ARCHIVE = create("application/vnd.joost.joda-archive", + "joda"); + public static final MediaType APPLICATION_VND_KAHOOTZ = create("application/vnd.kahootz", "ktz", "ktr"); + public static final MediaType APPLICATION_VND_KDE_KARBON = create("application/vnd.kde.karbon", "karbon"); + public static final MediaType APPLICATION_VND_KDE_KCHART = create("application/vnd.kde.kchart", "chrt"); + public static final MediaType APPLICATION_VND_KDE_KFORMULA = create("application/vnd.kde.kformula", "kfo"); + public static final MediaType APPLICATION_VND_KDE_KIVIO = create("application/vnd.kde.kivio", "flw"); + public static final MediaType APPLICATION_VND_KDE_KONTOUR = create("application/vnd.kde.kontour", "kon"); + public static final MediaType APPLICATION_VND_KDE_KPRESENTER = create("application/vnd.kde.kpresenter", "kpr", + "kpt"); + public static final MediaType APPLICATION_VND_KDE_KSPREAD = create("application/vnd.kde.kspread", "ksp"); + public static final MediaType APPLICATION_VND_KDE_KWORD = create("application/vnd.kde.kword", "kwd", "kwt"); + public static final MediaType APPLICATION_VND_KENAMEAAPP = create("application/vnd.kenameaapp", "htke"); + public static final MediaType APPLICATION_VND_KIDSPIRATION = create("application/vnd.kidspiration", "kia"); + public static final MediaType APPLICATION_VND_KINAR = create("application/vnd.kinar", "kne", "knp"); + public static final MediaType APPLICATION_VND_KOAN = create("application/vnd.koan", "skp", "skd", "skt", "skm"); + public static final MediaType APPLICATION_VND_KODAK_DESCRIPTOR = create("application/vnd.kodak-descriptor", "sse"); + public static final MediaType APPLICATION_VND_LAS_LAS_XML = create("application/vnd.las.las+xml", "lasxml"); + public static final MediaType APPLICATION_VND_LLAMAGRAPHICS_LIFE_BALANCE_DESKTOP = create( + "APPLICATION/VND.LLAMAGRAPHICS.LIFE-BALANCE.DESKTOP", "LBD"); + public static final MediaType APPLICATION_VND_LLAMAGRAPHICS_LIFE_BALANCE_EXCHANGE_XML = create( + "APPLICATION/VND.LLAMAGRAPHICS.LIFE-BALANCE.EXCHANGE+XML", "LBE"); + public static final MediaType APPLICATION_VND_LOTUS_1_2_3 = create("application/vnd.lotus-1-2-3", "123"); + public static final MediaType APPLICATION_VND_LOTUS_APPROACH = create("application/vnd.lotus-approach", "apr"); + public static final MediaType APPLICATION_VND_LOTUS_FREELANCE = create("application/vnd.lotus-freelance", "pre"); + public static final MediaType APPLICATION_VND_LOTUS_NOTES = create("application/vnd.lotus-notes", "nsf"); + public static final MediaType APPLICATION_VND_LOTUS_ORGANIZER = create("application/vnd.lotus-organizer", "org"); + public static final MediaType APPLICATION_VND_LOTUS_SCREENCAM = create("application/vnd.lotus-screencam", "scm"); + public static final MediaType APPLICATION_VND_LOTUS_WORDPRO = create("application/vnd.lotus-wordpro", "lwp"); + public static final MediaType APPLICATION_VND_MACPORTS_PORTPKG = create("application/vnd.macports.portpkg", + "portpkg"); + public static final MediaType APPLICATION_VND_MCD = create("application/vnd.mcd", "mcd"); + public static final MediaType APPLICATION_VND_MEDCALCDATA = create("application/vnd.medcalcdata", "mc1"); + public static final MediaType APPLICATION_VND_MEDIASTATION_CDKEY = create("application/vnd.mediastation.cdkey", + "CDKEY"); + public static final MediaType APPLICATION_VND_MFER = create("application/vnd.mfer", "mwf"); + public static final MediaType APPLICATION_VND_MFMP = create("application/vnd.mfmp", "mfm"); + public static final MediaType APPLICATION_VND_MICROGRAFX_FLO = create("application/vnd.micrografx.flo", "flo"); + public static final MediaType APPLICATION_VND_MICROGRAFX_IGX = create("application/vnd.micrografx.igx", "igx"); + public static final MediaType APPLICATION_VND_MIF = create("application/vnd.mif", "mif"); + public static final MediaType APPLICATION_VND_MOBIUS_DAF = create("application/vnd.mobius.daf", "daf"); + public static final MediaType APPLICATION_VND_MOBIUS_DIS = create("application/vnd.mobius.dis", "dis"); + public static final MediaType APPLICATION_VND_MOBIUS_MBK = create("application/vnd.mobius.mbk", "mbk"); + public static final MediaType APPLICATION_VND_MOBIUS_MQY = create("application/vnd.mobius.mqy", "mqy"); + public static final MediaType APPLICATION_VND_MOBIUS_MSL = create("application/vnd.mobius.msl", "msl"); + public static final MediaType APPLICATION_VND_MOBIUS_PLC = create("application/vnd.mobius.plc", "plc"); + public static final MediaType APPLICATION_VND_MOBIUS_TXF = create("application/vnd.mobius.txf", "txf"); + public static final MediaType APPLICATION_VND_MOPHUN_APPLICATION = create("application/vnd.mophun.application", + "mpn"); + public static final MediaType APPLICATION_VND_MOPHUN_CERTIFICATE = create("application/vnd.mophun.certificate", + "mpc"); + public static final MediaType APPLICATION_VND_MOZILLA_XUL_XML = create("application/vnd.mozilla.xul+xml", "xul"); + public static final MediaType APPLICATION_VND_MS_ARTGALRY = create("application/vnd.ms-artgalry", "cil"); + public static final MediaType APPLICATION_VND_MS_CAB_COMPRESSED = create("application/vnd.ms-cab-compressed", "cab"); + public static final MediaType APPLICATION_VND_MSEQ = create("application/vnd.mseq", "mseq"); + public static final MediaType APPLICATION_VND_MS_EXCEL_ADDIN_MACROENABLED_12 = create( + "APPLICATION/VND.MS-EXCEL.ADDIN.MACROENABLED.12", "XLAM"); + public static final MediaType APPLICATION_VND_MS_EXCEL_SHEET_BINARY_MACROENABLED_12 = create( + "APPLICATION/VND.MS-EXCEL.SHEET.BINARY.MACROENABLED.12", "XLSB"); + public static final MediaType APPLICATION_VND_MS_EXCEL_SHEET_MACROENABLED_12 = create( + "APPLICATION/VND.MS-EXCEL.SHEET.MACROENABLED.12", "XLSM"); + public static final MediaType APPLICATION_VND_MS_EXCEL_TEMPLATE_MACROENABLED_12 = create( + "APPLICATION/VND.MS-EXCEL.TEMPLATE.MACROENABLED.12", "XLTM"); + public static final MediaType APPLICATION_VND_MS_EXCEL = create("application/vnd.ms-excel", "xls", "xlm", "xla", + "XLB", "XLC", "XLT", "XLW"); + public static final MediaType APPLICATION_VND_MS_FONTOBJECT = create("application/vnd.ms-fontobject", "eot"); + public static final MediaType APPLICATION_VND_MS_HTMLHELP = create("application/vnd.ms-htmlhelp", "chm"); + public static final MediaType APPLICATION_VND_MS_IMS = create("application/vnd.ms-ims", "ims"); + public static final MediaType APPLICATION_VND_MS_LRM = create("application/vnd.ms-lrm", "lrm"); + public static final MediaType APPLICATION_VND_MS_OFFICETHEME = create("application/vnd.ms-officetheme", "thmx"); + public static final MediaType APPLICATION_VND_MS_PKI_SECCAT = create("application/vnd.ms-pki.seccat", "cat"); + public static final MediaType APPLICATION_VND_MS_PKI_STL = create("application/vnd.ms-pki.stl", "stl"); + public static final MediaType APPLICATION_VND_MS_POWERPOINT_ADDIN_MACROENABLED_12 = create( + "APPLICATION/VND.MS-POWERPOINT.ADDIN.MACROENABLED.12", "PPAM"); + public static final MediaType APPLICATION_VND_MS_POWERPOINT = create("application/vnd.ms-powerpoint", "ppt", "pps", + "POT"); + public static final MediaType APPLICATION_VND_MS_POWERPOINT_PRESENTATION_MACROENABLED_12 = create( + "APPLICATION/VND.MS-POWERPOINT.PRESENTATION.MACROENABLED.12", "PPTM"); + public static final MediaType APPLICATION_VND_MS_POWERPOINT_SLIDE_MACROENABLED_12 = create( + "APPLICATION/VND.MS-POWERPOINT.SLIDE.MACROENABLED.12", "SLDM"); + public static final MediaType APPLICATION_VND_MS_POWERPOINT_SLIDESHOW_MACROENABLED_12 = create( + "APPLICATION/VND.MS-POWERPOINT.SLIDESHOW.MACROENABLED.12", "PPSM"); + public static final MediaType APPLICATION_VND_MS_POWERPOINT_TEMPLATE_MACROENABLED_12 = create( + "APPLICATION/VND.MS-POWERPOINT.TEMPLATE.MACROENABLED.12", "POTM"); + public static final MediaType APPLICATION_VND_MS_PROJECT = create("application/vnd.ms-project", "mpp", "mpt"); + public static final MediaType APPLICATION_VND_MS_WORD_DOCUMENT_MACROENABLED_12 = create( + "APPLICATION/VND.MS-WORD.DOCUMENT.MACROENABLED.12", "DOCM"); + public static final MediaType APPLICATION_VND_MS_WORD_TEMPLATE_MACROENABLED_12 = create( + "APPLICATION/VND.MS-WORD.TEMPLATE.MACROENABLED.12", "DOTM"); + public static final MediaType APPLICATION_VND_MS_WORKS = create("application/vnd.ms-works", "wps", "wks", "wcm", + "wdb"); + public static final MediaType APPLICATION_VND_MS_WPL = create("application/vnd.ms-wpl", "wpl"); + public static final MediaType APPLICATION_VND_MS_XPSDOCUMENT = create("application/vnd.ms-xpsdocument", "xps"); + public static final MediaType APPLICATION_VND_MUSICIAN = create("application/vnd.musician", "mus"); + public static final MediaType APPLICATION_VND_MUVEE_STYLE = create("application/vnd.muvee.style", "msty"); + public static final MediaType APPLICATION_VND_MYNFC = create("application/vnd.mynfc", "taglet"); + public static final MediaType APPLICATION_VND_NEUROLANGUAGE_NLU = create("application/vnd.neurolanguage.nlu", "nlu"); + public static final MediaType APPLICATION_VND_NITF = create("application/vnd.nitf", "ntf", "nitf"); + public static final MediaType APPLICATION_VND_NOBLENET_DIRECTORY = create("application/vnd.noblenet-directory", + "nnd"); + public static final MediaType APPLICATION_VND_NOBLENET_SEALER = create("application/vnd.noblenet-sealer", "nns"); + public static final MediaType APPLICATION_VND_NOBLENET_WEB = create("application/vnd.noblenet-web", "nnw"); + public static final MediaType APPLICATION_VND_NOKIA_N_GAGE_DATA = create("application/vnd.nokia.n-gage.data", + "ngdat"); + public static final MediaType APPLICATION_VND_NOKIA_N_GAGE_SYMBIAN_INSTALL = create( + "APPLICATION/VND.NOKIA.N-GAGE.SYMBIAN.INSTALL", "N-GAGE"); + public static final MediaType APPLICATION_VND_NOKIA_RADIO_PRESET = create("application/vnd.nokia.radio-preset", + "rpst"); + public static final MediaType APPLICATION_VND_NOKIA_RADIO_PRESETS = create("application/vnd.nokia.radio-presets", + "RPSS"); + public static final MediaType APPLICATION_VND_NOVADIGM_EDM = create("application/vnd.novadigm.edm", "edm"); + public static final MediaType APPLICATION_VND_NOVADIGM_EDX = create("application/vnd.novadigm.edx", "edx"); + public static final MediaType APPLICATION_VND_NOVADIGM_EXT = create("application/vnd.novadigm.ext", "ext"); + public static final MediaType APPLICATION_VND_OASIS_OPENDOCUMENT_CHART = create( + "APPLICATION/VND.OASIS.OPENDOCUMENT.CHART", "ODC"); + public static final MediaType APPLICATION_VND_OASIS_OPENDOCUMENT_CHART_TEMPLATE = create( + "APPLICATION/VND.OASIS.OPENDOCUMENT.CHART-TEMPLATE", "OTC"); + public static final MediaType APPLICATION_VND_OASIS_OPENDOCUMENT_DATABASE = create( + "APPLICATION/VND.OASIS.OPENDOCUMENT.DATABASE", "ODB"); + public static final MediaType APPLICATION_VND_OASIS_OPENDOCUMENT_FORMULA = create( + "APPLICATION/VND.OASIS.OPENDOCUMENT.FORMULA", "ODF"); + public static final MediaType APPLICATION_VND_OASIS_OPENDOCUMENT_FORMULA_TEMPLATE = create( + "APPLICATION/VND.OASIS.OPENDOCUMENT.FORMULA-TEMPLATE", "ODFT"); + public static final MediaType APPLICATION_VND_OASIS_OPENDOCUMENT_GRAPHICS = create( + "APPLICATION/VND.OASIS.OPENDOCUMENT.GRAPHICS", "ODG"); + public static final MediaType APPLICATION_VND_OASIS_OPENDOCUMENT_GRAPHICS_TEMPLATE = create( + "APPLICATION/VND.OASIS.OPENDOCUMENT.GRAPHICS-TEMPLATE", "OTG"); + public static final MediaType APPLICATION_VND_OASIS_OPENDOCUMENT_IMAGE = create( + "APPLICATION/VND.OASIS.OPENDOCUMENT.IMAGE", "ODI"); + public static final MediaType APPLICATION_VND_OASIS_OPENDOCUMENT_IMAGE_TEMPLATE = create( + "APPLICATION/VND.OASIS.OPENDOCUMENT.IMAGE-TEMPLATE", "OTI"); + public static final MediaType APPLICATION_VND_OASIS_OPENDOCUMENT_PRESENTATION = create( + "APPLICATION/VND.OASIS.OPENDOCUMENT.PRESENTATION", "ODP"); + public static final MediaType APPLICATION_VND_OASIS_OPENDOCUMENT_PRESENTATION_TEMPLATE = create( + "APPLICATION/VND.OASIS.OPENDOCUMENT.PRESENTATION-TEMPLATE", "OTP"); + public static final MediaType APPLICATION_VND_OASIS_OPENDOCUMENT_SPREADSHEET = create( + "APPLICATION/VND.OASIS.OPENDOCUMENT.SPREADSHEET", "ODS"); + public static final MediaType APPLICATION_VND_OASIS_OPENDOCUMENT_SPREADSHEET_TEMPLATE = create( + "APPLICATION/VND.OASIS.OPENDOCUMENT.SPREADSHEET-TEMPLATE", "OTS"); + public static final MediaType APPLICATION_VND_OASIS_OPENDOCUMENT_TEXT_MASTER = create( + "APPLICATION/VND.OASIS.OPENDOCUMENT.TEXT-MASTER", "ODM"); + public static final MediaType APPLICATION_VND_OASIS_OPENDOCUMENT_TEXT = create( + "APPLICATION/VND.OASIS.OPENDOCUMENT.TEXT", "ODT"); + public static final MediaType APPLICATION_VND_OASIS_OPENDOCUMENT_TEXT_TEMPLATE = create( + "APPLICATION/VND.OASIS.OPENDOCUMENT.TEXT-TEMPLATE", "OTT"); + public static final MediaType APPLICATION_VND_OASIS_OPENDOCUMENT_TEXT_WEB = create( + "APPLICATION/VND.OASIS.OPENDOCUMENT.TEXT-WEB", "OTH"); + public static final MediaType APPLICATION_VND_OLPC_SUGAR = create("application/vnd.olpc-sugar", "xo"); + public static final MediaType APPLICATION_VND_OMA_DD2_XML = create("application/vnd.oma.dd2+xml", "dd2"); + public static final MediaType APPLICATION_VND_OPENOFFICEORG_EXTENSION = create( + "APPLICATION/VND.OPENOFFICEORG.EXTENSION", "OXT"); + public static final MediaType APPLICATION_VND_OPENXMLFORMATS_OFFICEDOCUMENT_PRESENTATIONML_PRESENTATION = create( + "APPLICATION/VND.OPENXMLFORMATS-OFFICEDOCUMENT.PRESENTATIONML.PRESENTATION", "PPTX"); + public static final MediaType APPLICATION_VND_OPENXMLFORMATS_OFFICEDOCUMENT_PRESENTATIONML_SLIDESHOW = create( + "APPLICATION/VND.OPENXMLFORMATS-OFFICEDOCUMENT.PRESENTATIONML.SLIDESHOW", "PPSX"); + public static final MediaType APPLICATION_VND_OPENXMLFORMATS_OFFICEDOCUMENT_PRESENTATIONML_SLIDE = create( + "APPLICATION/VND.OPENXMLFORMATS-OFFICEDOCUMENT.PRESENTATIONML.SLIDE", "SLDX"); + public static final MediaType APPLICATION_VND_OPENXMLFORMATS_OFFICEDOCUMENT_PRESENTATIONML_TEMPLATE = create( + "APPLICATION/VND.OPENXMLFORMATS-OFFICEDOCUMENT.PRESENTATIONML.TEMPLATE", "POTX"); + public static final MediaType APPLICATION_VND_OPENXMLFORMATS_OFFICEDOCUMENT_SPREADSHEETML_SHEET = create( + "APPLICATION/VND.OPENXMLFORMATS-OFFICEDOCUMENT.SPREADSHEETML.SHEET", "XLSX"); + public static final MediaType APPLICATION_VND_OPENXMLFORMATS_OFFICEDOCUMENT_SPREADSHEETML_TEMPLATE = create( + "APPLICATION/VND.OPENXMLFORMATS-OFFICEDOCUMENT.SPREADSHEETML.TEMPLATE", "XLTX"); + public static final MediaType APPLICATION_VND_OPENXMLFORMATS_OFFICEDOCUMENT_WORDPROCESSINGML_DOCUMENT = create( + "APPLICATION/VND.OPENXMLFORMATS-OFFICEDOCUMENT.WORDPROCESSINGML.DOCUMENT", "DOCX"); + public static final MediaType APPLICATION_VND_OPENXMLFORMATS_OFFICEDOCUMENT_WORDPROCESSINGML_TEMPLATE = create( + "APPLICATION/VND.OPENXMLFORMATS-OFFICEDOCUMENT.WORDPROCESSINGML.TEMPLATE", "DOTX"); + public static final MediaType APPLICATION_VND_OSGEO_MAPGUIDE_PACKAGE = create( + "APPLICATION/VND.OSGEO.MAPGUIDE.PACKAGE", "MGP"); + public static final MediaType APPLICATION_VND_OSGI_DP = create("application/vnd.osgi.dp", "dp"); + public static final MediaType APPLICATION_VND_OSGI_SUBSYSTEM = create("application/vnd.osgi.subsystem", "esa"); + public static final MediaType APPLICATION_VND_PALM = create("application/vnd.palm", "pdb", "pqa", "oprc"); + public static final MediaType APPLICATION_VND_PAWAAFILE = create("application/vnd.pawaafile", "paw"); + public static final MediaType APPLICATION_VND_PG_FORMAT = create("application/vnd.pg.format", "str"); + public static final MediaType APPLICATION_VND_PG_OSASLI = create("application/vnd.pg.osasli", "ei6"); + public static final MediaType APPLICATION_VND_PICSEL = create("application/vnd.picsel", "efif"); + public static final MediaType APPLICATION_VND_PMI_WIDGET = create("application/vnd.pmi.widget", "wg"); + public static final MediaType APPLICATION_VND_POCKETLEARN = create("application/vnd.pocketlearn", "plf"); + public static final MediaType APPLICATION_VND_POWERBUILDER6 = create("application/vnd.powerbuilder6", "pbd"); + public static final MediaType APPLICATION_VND_PREVIEWSYSTEMS_BOX = create("application/vnd.previewsystems.box", + "box"); + public static final MediaType APPLICATION_VND_PROTEUS_MAGAZINE = create("application/vnd.proteus.magazine", "mgz"); + public static final MediaType APPLICATION_VND_PUBLISHARE_DELTA_TREE = create( + "application/vnd.publishare-delta-tree", "QPS"); + public static final MediaType APPLICATION_VND_PVI_PTID1 = create("application/vnd.pvi.ptid1", "ptid"); + public static final MediaType APPLICATION_VND_QUARK_QUARKXPRESS = create("application/vnd.quark.quarkxpress", + "qxd", "QXT", "QWD", "QWT", "QXL", "QXB"); + public static final MediaType APPLICATION_VND_REALVNC_BED = create("application/vnd.realvnc.bed", "bed"); + public static final MediaType APPLICATION_VND_RECORDARE_MUSICXML = create("application/vnd.recordare.musicxml", + "mxl"); + public static final MediaType APPLICATION_VND_RECORDARE_MUSICXML_XML = create( + "APPLICATION/VND.RECORDARE.MUSICXML+XML", "MUSICXML"); + public static final MediaType APPLICATION_VND_RIG_CRYPTONOTE = create("application/vnd.rig.cryptonote", + "cryptonote"); + public static final MediaType APPLICATION_VND_RIM_COD = create("application/vnd.rim.cod", "cod"); + public static final MediaType APPLICATION_VND_RN_REALMEDIA = create("application/vnd.rn-realmedia", "rm"); + public static final MediaType APPLICATION_VND_RN_REALMEDIA_VBR = create("application/vnd.rn-realmedia-vbr", "rmvb"); + public static final MediaType APPLICATION_VND_ROUTE66_LINK66_XML = create("application/vnd.route66.link66+xml", + "LINK66"); + public static final MediaType APPLICATION_VND_SAILINGTRACKER_TRACK = create("application/vnd.sailingtracker.track", + "ST"); + public static final MediaType APPLICATION_VND_SEEMAIL = create("application/vnd.seemail", "see"); + public static final MediaType APPLICATION_VND_SEMA = create("application/vnd.sema", "sema"); + public static final MediaType APPLICATION_VND_SEMD = create("application/vnd.semd", "semd"); + public static final MediaType APPLICATION_VND_SEMF = create("application/vnd.semf", "semf"); + public static final MediaType APPLICATION_VND_SHANA_INFORMED_FORMDATA = create( + "APPLICATION/VND.SHANA.INFORMED.FORMDATA", "IFM"); + public static final MediaType APPLICATION_VND_SHANA_INFORMED_FORMTEMPLATE = create( + "APPLICATION/VND.SHANA.INFORMED.FORMTEMPLATE", "ITP"); + public static final MediaType APPLICATION_VND_SHANA_INFORMED_INTERCHANGE = create( + "APPLICATION/VND.SHANA.INFORMED.INTERCHANGE", "IIF"); + public static final MediaType APPLICATION_VND_SHANA_INFORMED_PACKAGE = create( + "APPLICATION/VND.SHANA.INFORMED.PACKAGE", "IPK"); + public static final MediaType APPLICATION_VND_SIMTECH_MINDMAPPER = create("application/vnd.simtech-mindmapper", + "twd", "TWDS"); + public static final MediaType APPLICATION_VND_SMAF = create("application/vnd.smaf", "mmf"); + public static final MediaType APPLICATION_VND_SMART_TEACHER = create("application/vnd.smart.teacher", "teacher"); + public static final MediaType APPLICATION_VND_SOLENT_SDKM_XML = create("application/vnd.solent.sdkm+xml", "sdkm", + "SDKD"); + public static final MediaType APPLICATION_VND_SPOTFIRE_DXP = create("application/vnd.spotfire.dxp", "dxp"); + public static final MediaType APPLICATION_VND_SPOTFIRE_SFS = create("application/vnd.spotfire.sfs", "sfs"); + public static final MediaType APPLICATION_VND_STARDIVISION_CALC = create("application/vnd.stardivision.calc", "sdc"); + public static final MediaType APPLICATION_VND_STARDIVISION_CHART = create("application/vnd.stardivision.chart", + "sds"); + public static final MediaType APPLICATION_VND_STARDIVISION_DRAW = create("application/vnd.stardivision.draw", "sda"); + public static final MediaType APPLICATION_VND_STARDIVISION_IMPRESS = create("application/vnd.stardivision.impress", + "SDD"); + public static final MediaType APPLICATION_VND_STARDIVISION_MATH = create("application/vnd.stardivision.math", + "smf", "SDF"); + public static final MediaType APPLICATION_VND_STARDIVISION_WRITER_GLOBAL = create( + "APPLICATION/VND.STARDIVISION.WRITER-GLOBAL", "SGL"); + public static final MediaType APPLICATION_VND_STARDIVISION_WRITER = create("application/vnd.stardivision.writer", + "SDW", "VOR"); + public static final MediaType APPLICATION_VND_STEPMANIA_PACKAGE = create("application/vnd.stepmania.package", + "smzip"); + public static final MediaType APPLICATION_VND_STEPMANIA_STEPCHART = create("application/vnd.stepmania.stepchart", + "sm"); + public static final MediaType APPLICATION_VND_SUN_XML_CALC = create("application/vnd.sun.xml.calc", "sxc"); + public static final MediaType APPLICATION_VND_SUN_XML_CALC_TEMPLATE = create( + "application/vnd.sun.xml.calc.template", "STC"); + public static final MediaType APPLICATION_VND_SUN_XML_DRAW = create("application/vnd.sun.xml.draw", "sxd"); + public static final MediaType APPLICATION_VND_SUN_XML_DRAW_TEMPLATE = create( + "application/vnd.sun.xml.draw.template", "STD"); + public static final MediaType APPLICATION_VND_SUN_XML_IMPRESS = create("application/vnd.sun.xml.impress", "sxi"); + public static final MediaType APPLICATION_VND_SUN_XML_IMPRESS_TEMPLATE = create( + "APPLICATION/VND.SUN.XML.IMPRESS.TEMPLATE", "STI"); + public static final MediaType APPLICATION_VND_SUN_XML_MATH = create("application/vnd.sun.xml.math", "sxm"); + public static final MediaType APPLICATION_VND_SUN_XML_WRITER_GLOBAL = create( + "application/vnd.sun.xml.writer.global", "SXG"); + public static final MediaType APPLICATION_VND_SUN_XML_WRITER = create("application/vnd.sun.xml.writer", "sxw"); + public static final MediaType APPLICATION_VND_SUN_XML_WRITER_TEMPLATE = create( + "APPLICATION/VND.SUN.XML.WRITER.TEMPLATE", "STW"); + public static final MediaType APPLICATION_VND_SUS_CALENDAR = create("application/vnd.sus-calendar", "sus", "susp"); + public static final MediaType APPLICATION_VND_SVD = create("application/vnd.svd", "svd"); + public static final MediaType APPLICATION_VND_SYMBIAN_INSTALL = create("application/vnd.symbian.install", "sis", + "SISX"); + public static final MediaType APPLICATION_VND_SYNCML_DM_WBXML = create("application/vnd.syncml.dm+wbxml", "bdm"); + public static final MediaType APPLICATION_VND_SYNCML_DM_XML = create("application/vnd.syncml.dm+xml", "xdm"); + public static final MediaType APPLICATION_VND_SYNCML_XML = create("application/vnd.syncml+xml", "xsm"); + public static final MediaType APPLICATION_VND_TAO_INTENT_MODULE_ARCHIVE = create( + "APPLICATION/VND.TAO.INTENT-MODULE-ARCHIVE", "TAO"); + public static final MediaType APPLICATION_VND_TCPDUMP_PCAP = create("application/vnd.tcpdump.pcap", "pcap", "cap", + "DMP"); + public static final MediaType APPLICATION_VND_TMOBILE_LIVETV = create("application/vnd.tmobile-livetv", "tmo"); + public static final MediaType APPLICATION_VND_TRID_TPT = create("application/vnd.trid.tpt", "tpt"); + public static final MediaType APPLICATION_VND_TRISCAPE_MXS = create("application/vnd.triscape.mxs", "mxs"); + public static final MediaType APPLICATION_VND_TRUEAPP = create("application/vnd.trueapp", "tra"); + public static final MediaType APPLICATION_VND_UFDL = create("application/vnd.ufdl", "ufd", "ufdl"); + public static final MediaType APPLICATION_VND_UIQ_THEME = create("application/vnd.uiq.theme", "utz"); + public static final MediaType APPLICATION_VND_UMAJIN = create("application/vnd.umajin", "umj"); + public static final MediaType APPLICATION_VND_UNITY = create("application/vnd.unity", "unityweb"); + public static final MediaType APPLICATION_VND_UOML_XML = create("application/vnd.uoml+xml", "uoml"); + public static final MediaType APPLICATION_VND_VCX = create("application/vnd.vcx", "vcx"); + public static final MediaType APPLICATION_VND_VISIONARY = create("application/vnd.visionary", "vis"); + public static final MediaType APPLICATION_VND_VISIO = create("application/vnd.visio", "vsd", "vst", "vss", "vsw"); + public static final MediaType APPLICATION_VND_VSF = create("application/vnd.vsf", "vsf"); + public static final MediaType APPLICATION_VND_WAP_WBXML = create("application/vnd.wap.wbxml", "wbxml"); + public static final MediaType APPLICATION_VND_WAP_WMLC = create("application/vnd.wap.wmlc", "wmlc"); + public static final MediaType APPLICATION_VND_WAP_WMLSCRIPTC = create("application/vnd.wap.wmlscriptc", "wmlsc"); + public static final MediaType APPLICATION_VND_WEBTURBO = create("application/vnd.webturbo", "wtb"); + public static final MediaType APPLICATION_VND_WOLFRAM_PLAYER = create("application/vnd.wolfram.player", "nbp"); + public static final MediaType APPLICATION_VND_WORDPERFECT5_1 = create("application/vnd.wordperfect5.1", "wp5"); + public static final MediaType APPLICATION_VND_WORDPERFECT = create("application/vnd.wordperfect", "wpd"); + public static final MediaType APPLICATION_VND_WQD = create("application/vnd.wqd", "wqd"); + public static final MediaType APPLICATION_VND_WT_STF = create("application/vnd.wt.stf", "stf"); + public static final MediaType APPLICATION_VND_XARA = create("application/vnd.xara", "xar"); + public static final MediaType APPLICATION_VND_XFDL = create("application/vnd.xfdl", "xfdl"); + public static final MediaType APPLICATION_VND_YAMAHA_HV_DIC = create("application/vnd.yamaha.hv-dic", "hvd"); + public static final MediaType APPLICATION_VND_YAMAHA_HV_SCRIPT = create("application/vnd.yamaha.hv-script", "hvs"); + public static final MediaType APPLICATION_VND_YAMAHA_HV_VOICE = create("application/vnd.yamaha.hv-voice", "hvp"); + public static final MediaType APPLICATION_VND_YAMAHA_OPENSCOREFORMAT = create( + "APPLICATION/VND.YAMAHA.OPENSCOREFORMAT", "OSF"); + public static final MediaType APPLICATION_VND_YAMAHA_OPENSCOREFORMAT_OSFPVG_XML = create( + "APPLICATION/VND.YAMAHA.OPENSCOREFORMAT.OSFPVG+XML", "OSFPVG"); + public static final MediaType APPLICATION_VND_YAMAHA_SMAF_AUDIO = create("application/vnd.yamaha.smaf-audio", "saf"); + public static final MediaType APPLICATION_VND_YAMAHA_SMAF_PHRASE = create("application/vnd.yamaha.smaf-phrase", + "spf"); + public static final MediaType APPLICATION_VND_YELLOWRIVER_CUSTOM_MENU = create( + "APPLICATION/VND.YELLOWRIVER-CUSTOM-MENU", "CMP"); + public static final MediaType APPLICATION_VND_ZUL = create("application/vnd.zul", "zir", "zirz"); + public static final MediaType APPLICATION_VND_ZZAZZ_DECK_XML = create("application/vnd.zzazz.deck+xml", "zaz"); + public static final MediaType APPLICATION_VOICEXML_XML = create("application/voicexml+xml", "vxml"); + public static final MediaType APPLICATION_WIDGET = create("application/widget", "wgt"); + public static final MediaType APPLICATION_WINHLP = create("application/winhlp", "hlp"); + public static final MediaType APPLICATION_WSDL_XML = create("application/wsdl+xml", "wsdl"); + public static final MediaType APPLICATION_WSPOLICY_XML = create("application/wspolicy+xml", "wspolicy"); + public static final MediaType APPLICATION_X_123 = create("application/x-123", "wk"); + public static final MediaType APPLICATION_X_7Z_COMPRESSED = create("application/x-7z-compressed", "7z"); + public static final MediaType APPLICATION_X_ABIWORD = create("application/x-abiword", "abw"); + public static final MediaType APPLICATION_X_ACE_COMPRESSED = create("application/x-ace-compressed", "ace"); + public static final MediaType APPLICATION_XAML_XML = create("application/xaml+xml", "xaml"); + public static final MediaType APPLICATION_X_APPLE_DISKIMAGE = create("application/x-apple-diskimage", "dmg"); + public static final MediaType APPLICATION_X_AUTHORWARE_BIN = create("application/x-authorware-bin", "aab", "x32", + "U32", "VOX"); + public static final MediaType APPLICATION_X_AUTHORWARE_MAP = create("application/x-authorware-map", "aam"); + public static final MediaType APPLICATION_X_AUTHORWARE_SEG = create("application/x-authorware-seg", "aas"); + public static final MediaType APPLICATION_X_BCPIO = create("application/x-bcpio", "bcpio"); + public static final MediaType APPLICATION_X_BITTORRENT = create("application/x-bittorrent", "torrent"); + public static final MediaType APPLICATION_X_BLORB = create("application/x-blorb", "blb", "blorb"); + public static final MediaType APPLICATION_X_BZIP2 = create("application/x-bzip2", "bz2", "boz"); + public static final MediaType APPLICATION_X_BZIP = create("application/x-bzip", "bz"); + public static final MediaType APPLICATION_X_CAB = create("application/x-cab", "cab"); + public static final MediaType APPLICATION_XCAP_DIFF_XML = create("application/xcap-diff+xml", "xdf"); + public static final MediaType APPLICATION_X_CBR = create("application/x-cbr", "cbr", "cba", "cbt", "cbz", "cb7"); + public static final MediaType APPLICATION_X_CBZ = create("application/x-cbz", "cbz"); + public static final MediaType APPLICATION_X_CDF = create("application/x-cdf", "cdf", "cda"); + public static final MediaType APPLICATION_X_CDLINK = create("application/x-cdlink", "vcd"); + public static final MediaType APPLICATION_X_CFS_COMPRESSED = create("application/x-cfs-compressed", "cfs"); + public static final MediaType APPLICATION_X_CHAT = create("application/x-chat", "chat"); + public static final MediaType APPLICATION_X_CHESS_PGN = create("application/x-chess-pgn", "pgn"); + public static final MediaType APPLICATION_X_COMSOL = create("application/x-comsol", "mph"); + public static final MediaType APPLICATION_X_CONFERENCE = create("application/x-conference", "nsc"); + public static final MediaType APPLICATION_X_CPIO = create("application/x-cpio", "cpio"); + public static final MediaType APPLICATION_X_CSH = create("application/x-csh", "csh"); + public static final MediaType APPLICATION_X_DEBIAN_PACKAGE = create("application/x-debian-package", "deb", "udeb"); + public static final MediaType APPLICATION_X_DGC_COMPRESSED = create("application/x-dgc-compressed", "dgc"); + public static final MediaType APPLICATION_X_DIRECTOR = create("application/x-director", "dir", "dcr", "dxr", "cst", + "CCT", "CXT", "W3D", "FGD", "SWA"); + public static final MediaType APPLICATION_X_DMS = create("application/x-dms", "dms"); + public static final MediaType APPLICATION_X_DOOM = create("application/x-doom", "wad"); + public static final MediaType APPLICATION_X_DTBNCX_XML = create("application/x-dtbncx+xml", "ncx"); + public static final MediaType APPLICATION_X_DTBOOK_XML = create("application/x-dtbook+xml", "dtb"); + public static final MediaType APPLICATION_X_DTBRESOURCE_XML = create("application/x-dtbresource+xml", "res"); + public static final MediaType APPLICATION_X_DVI = create("application/x-dvi", "dvi"); + public static final MediaType APPLICATION_XENC_XML = create("application/xenc+xml", "xenc"); + public static final MediaType APPLICATION_X_ENVOY = create("application/x-envoy", "evy"); + public static final MediaType APPLICATION_X_EVA = create("application/x-eva", "eva"); + public static final MediaType APPLICATION_X_FONT_BDF = create("application/x-font-bdf", "bdf"); + public static final MediaType APPLICATION_X_FONT_GHOSTSCRIPT = create("application/x-font-ghostscript", "gsf"); + public static final MediaType APPLICATION_X_FONT_LINUX_PSF = create("application/x-font-linux-psf", "psf"); + public static final MediaType APPLICATION_X_FONT_OTF = create("application/x-font-otf", "otf"); + public static final MediaType APPLICATION_X_FONT_PCF = create("application/x-font-pcf", "pcf"); + public static final MediaType APPLICATION_X_FONT = create("application/x-font", "pfa", "pfb", "gsf", "pcf", "pcf.z"); + public static final MediaType APPLICATION_X_FONT_SNF = create("application/x-font-snf", "snf"); + public static final MediaType APPLICATION_X_FONT_TTF = create("application/x-font-ttf", "ttf", "ttc"); + public static final MediaType APPLICATION_X_FONT_TYPE1 = create("application/x-font-type1", "pfa", "pfb", "pfm", + "afm"); + public static final MediaType APPLICATION_X_FONT_WOFF = create("application/x-font-woff", "woff", "woff2"); + public static final MediaType APPLICATION_X_FREEARC = create("application/x-freearc", "arc"); + public static final MediaType APPLICATION_X_FREEMIND = create("application/x-freemind", "mm"); + public static final MediaType APPLICATION_X_FUTURESPLASH = create("application/x-futuresplash", "spl"); + public static final MediaType APPLICATION_X_GANTTPROJECT = create("application/x-ganttproject", "gan"); + public static final MediaType APPLICATION_X_GCA_COMPRESSED = create("application/x-gca-compressed", "gca"); + public static final MediaType APPLICATION_X_GLULX = create("application/x-glulx", "ulx"); + public static final MediaType APPLICATION_X_GNUMERIC = create("application/x-gnumeric", "gnumeric"); + public static final MediaType APPLICATION_X_GO_SGF = create("application/x-go-sgf", "sgf"); + public static final MediaType APPLICATION_X_GRAMPS_XML = create("application/x-gramps-xml", "gramps"); + public static final MediaType APPLICATION_X_GRAPHING_CALCULATOR = create("application/x-graphing-calculator", "gcf"); + public static final MediaType APPLICATION_X_GTAR_COMPRESSED = create("application/x-gtar-compressed", "tgz", "taz"); + public static final MediaType APPLICATION_X_GTAR = create("application/x-gtar", "gtar"); + public static final MediaType APPLICATION_X_HDF = create("application/x-hdf", "hdf"); + public static final MediaType APPLICATION_X_HTTPD_ERUBY = create("application/x-httpd-eruby", "rhtml"); + public static final MediaType APPLICATION_X_HTTPD_PHP3 = create("application/x-httpd-php3", "php3"); + public static final MediaType APPLICATION_X_HTTPD_PHP3_PREPROCESSED = create( + "application/x-httpd-php3-preprocessed", "PHP3P"); + public static final MediaType APPLICATION_X_HTTPD_PHP4 = create("application/x-httpd-php4", "php4"); + public static final MediaType APPLICATION_X_HTTPD_PHP5 = create("application/x-httpd-php5", "php5"); + public static final MediaType APPLICATION_X_HTTPD_PHP = create("application/x-httpd-php", "phtml", "pht", "php"); + public static final MediaType APPLICATION_X_HTTPD_PHP_SOURCE = create("application/x-httpd-php-source", "phps"); + public static final MediaType APPLICATION_X_ICA = create("application/x-ica", "ica"); + public static final MediaType APPLICATION_X_INFO = create("application/x-info", "info"); + public static final MediaType APPLICATION_X_INSTALL_INSTRUCTIONS = create("application/x-install-instructions", + "INSTALL"); + public static final MediaType APPLICATION_X_INTERNET_SIGNUP = create("application/x-internet-signup", "ins", "isp"); + public static final MediaType APPLICATION_X_IPHONE = create("application/x-iphone", "iii"); + public static final MediaType APPLICATION_X_ISO9660_IMAGE = create("application/x-iso9660-image", "iso"); + public static final MediaType APPLICATION_X_JAM = create("application/x-jam", "jam"); + public static final MediaType APPLICATION_X_JAVA_JNLP_FILE = create("application/x-java-jnlp-file", "jnlp"); + public static final MediaType APPLICATION_X_JMOL = create("application/x-jmol", "jmz"); + public static final MediaType APPLICATION_X_KCHART = create("application/x-kchart", "chrt"); + public static final MediaType APPLICATION_X_KILLUSTRATOR = create("application/x-killustrator", "kil"); + public static final MediaType APPLICATION_X_KOAN = create("application/x-koan", "skp", "skd", "skt", "skm"); + public static final MediaType APPLICATION_X_KPRESENTER = create("application/x-kpresenter", "kpr", "kpt"); + public static final MediaType APPLICATION_X_KSPREAD = create("application/x-kspread", "ksp"); + public static final MediaType APPLICATION_X_KWORD = create("application/x-kword", "kwd", "kwt"); + public static final MediaType APPLICATION_X_LATEX = create("application/x-latex", "latex"); + public static final MediaType APPLICATION_X_LHA = create("application/x-lha", "lha"); + public static final MediaType APPLICATION_X_LYX = create("application/x-lyx", "lyx"); + public static final MediaType APPLICATION_X_LZH_COMPRESSED = create("application/x-lzh-compressed", "lzh", "lha"); + public static final MediaType APPLICATION_X_LZH = create("application/x-lzh", "lzh"); + public static final MediaType APPLICATION_X_LZX = create("application/x-lzx", "lzx"); + public static final MediaType APPLICATION_X_MAKER = create("application/x-maker", "frm", "maker", "frame", "fm", + "fb", "BOOK", "FBDOC"); + public static final MediaType APPLICATION_X_MIE = create("application/x-mie", "mie"); + public static final MediaType APPLICATION_X_MIF = create("application/x-mif", "mif"); + public static final MediaType APPLICATION_XML = create("application/xml", "xml", "xsl", "xsd"); + public static final MediaType APPLICATION_X_MOBIPOCKET_EBOOK = create("application/x-mobipocket-ebook", "prc", + "mobi"); + public static final MediaType APPLICATION_X_MPEGURL = create("application/x-mpegurl", "m3u8"); + public static final MediaType APPLICATION_X_MSACCESS = create("application/x-msaccess", "mdb"); + public static final MediaType APPLICATION_X_MS_APPLICATION = create("application/x-ms-application", "application"); + public static final MediaType APPLICATION_X_MSBINDER = create("application/x-msbinder", "obd"); + public static final MediaType APPLICATION_X_MSCARDFILE = create("application/x-mscardfile", "crd"); + public static final MediaType APPLICATION_X_MSCLIP = create("application/x-msclip", "clp"); + public static final MediaType APPLICATION_X_MSDOS_PROGRAM = create("application/x-msdos-program", "com", "exe", + "bat", "DLL"); + public static final MediaType APPLICATION_X_MSDOWNLOAD = create("application/x-msdownload", "exe", "dll", "com", + "BAT", "MSI"); + public static final MediaType APPLICATION_X_MSI = create("application/x-msi", "msi"); + public static final MediaType APPLICATION_X_MSMEDIAVIEW = create("application/x-msmediaview", "mvb", "m13", "m14"); + public static final MediaType APPLICATION_X_MSMETAFILE = create("application/x-msmetafile", "wmf", "wmz", "emf", + "emz"); + public static final MediaType APPLICATION_X_MSMONEY = create("application/x-msmoney", "mny"); + public static final MediaType APPLICATION_X_MSPUBLISHER = create("application/x-mspublisher", "pub"); + public static final MediaType APPLICATION_X_MSSCHEDULE = create("application/x-msschedule", "scd"); + public static final MediaType APPLICATION_X_MS_SHORTCUT = create("application/x-ms-shortcut", "lnk"); + public static final MediaType APPLICATION_X_MSTERMINAL = create("application/x-msterminal", "trm"); + public static final MediaType APPLICATION_X_MS_WMD = create("application/x-ms-wmd", "wmd"); + public static final MediaType APPLICATION_X_MS_WMZ = create("application/x-ms-wmz", "wmz"); + public static final MediaType APPLICATION_X_MSWRITE = create("application/x-mswrite", "wri"); + public static final MediaType APPLICATION_X_MS_XBAP = create("application/x-ms-xbap", "xbap"); + public static final MediaType APPLICATION_X_NETCDF = create("application/x-netcdf", "nc", "cdf"); + public static final MediaType APPLICATION_X_NS_PROXY_AUTOCONFIG = create("application/x-ns-proxy-autoconfig", + "pac", "DAT"); + public static final MediaType APPLICATION_X_NWC = create("application/x-nwc", "nwc"); + public static final MediaType APPLICATION_X_NZB = create("application/x-nzb", "nzb"); + public static final MediaType APPLICATION_X_OBJECT = create("application/x-object", "o"); + public static final MediaType APPLICATION_XOP_XML = create("application/xop+xml", "xop"); + public static final MediaType APPLICATION_X_OZ_APPLICATION = create("application/x-oz-application", "oza"); + public static final MediaType APPLICATION_X_PKCS12 = create("application/x-pkcs12", "p12", "pfx"); + public static final MediaType APPLICATION_X_PKCS7_CERTIFICATES = create("application/x-pkcs7-certificates", "p7b", + "SPC"); + public static final MediaType APPLICATION_X_PKCS7_CERTREQRESP = create("application/x-pkcs7-certreqresp", "p7r"); + public static final MediaType APPLICATION_X_PKCS7_CRL = create("application/x-pkcs7-crl", "crl"); + public static final MediaType APPLICATION_XPROC_XML = create("application/xproc+xml", "xpl"); + public static final MediaType APPLICATION_X_PYTHON_CODE = create("application/x-python-code", "pyc", "pyo"); + public static final MediaType APPLICATION_X_QGIS = create("application/x-qgis", "qgs", "shp", "shx"); + public static final MediaType APPLICATION_X_QUICKTIMEPLAYER = create("application/x-quicktimeplayer", "qtl"); + public static final MediaType APPLICATION_X_RAR_COMPRESSED = create("application/x-rar-compressed", "rar"); + public static final MediaType APPLICATION_X_RDP = create("application/x-rdp", "rdp"); + public static final MediaType APPLICATION_X_REDHAT_PACKAGE_MANAGER = create("application/x-redhat-package-manager", + "RPM"); + public static final MediaType APPLICATION_X_RESEARCH_INFO_SYSTEMS = create("application/x-research-info-systems", + "RIS"); + public static final MediaType APPLICATION_X_RUBY = create("application/x-ruby", "rb"); + public static final MediaType APPLICATION_X_SCILAB = create("application/x-scilab", "sci", "sce"); + public static final MediaType APPLICATION_X_SHAR = create("application/x-shar", "shar"); + public static final MediaType APPLICATION_X_SHOCKWAVE_FLASH = create("application/x-shockwave-flash", "swf", "swfl"); + public static final MediaType APPLICATION_X_SILVERLIGHT_APP = create("application/x-silverlight-app", "xap"); + public static final MediaType APPLICATION_X_SILVERLIGHT = create("application/x-silverlight", "scr"); + public static final MediaType APPLICATION_X_STUFFIT = create("application/x-stuffit", "sit", "sitx"); + public static final MediaType APPLICATION_X_STUFFITX = create("application/x-stuffitx", "sitx"); + public static final MediaType APPLICATION_X_SUBRIP = create("application/x-subrip", "srt"); + public static final MediaType APPLICATION_X_SV4CPIO = create("application/x-sv4cpio", "sv4cpio"); + public static final MediaType APPLICATION_X_SV4CRC = create("application/x-sv4crc", "sv4crc"); + public static final MediaType APPLICATION_X_T3VM_IMAGE = create("application/x-t3vm-image", "t3"); + public static final MediaType APPLICATION_X_TADS = create("application/x-tads", "gam"); + public static final MediaType APPLICATION_X_TAR = create("application/x-tar", "tar"); + public static final MediaType APPLICATION_X_TCL = create("application/x-tcl", "tcl"); + public static final MediaType APPLICATION_X_TEX_GF = create("application/x-tex-gf", "gf"); + public static final MediaType APPLICATION_X_TEXINFO = create("application/x-texinfo", "texinfo", "texi"); + public static final MediaType APPLICATION_X_TEX_PK = create("application/x-tex-pk", "pk"); + public static final MediaType APPLICATION_X_TEX = create("application/x-tex", "tex"); + public static final MediaType APPLICATION_X_TEX_TFM = create("application/x-tex-tfm", "tfm"); + public static final MediaType APPLICATION_X_TGIF = create("application/x-tgif", "obj"); + public static final MediaType APPLICATION_X_TRASH = create("application/x-trash", "~", "%", "bak", "old", "sik"); + public static final MediaType APPLICATION_X_TROFF_MAN = create("application/x-troff-man", "man"); + public static final MediaType APPLICATION_X_TROFF_ME = create("application/x-troff-me", "me"); + public static final MediaType APPLICATION_X_TROFF_MS = create("application/x-troff-ms", "ms"); + public static final MediaType APPLICATION_X_TROFF = create("application/x-troff", "t", "tr", "roff"); + public static final MediaType APPLICATION_X_USTAR = create("application/x-ustar", "ustar"); + public static final MediaType APPLICATION_XV_XML = create("application/xv+xml", "mxml", "xhvml", "xvml", "xvm"); + public static final MediaType APPLICATION_X_WAIS_SOURCE = create("application/x-wais-source", "src"); + public static final MediaType APPLICATION_X_WINGZ = create("application/x-wingz", "wz"); + public static final MediaType APPLICATION_X_X509_CA_CERT = create("application/x-x509-ca-cert", "der", "crt"); + public static final MediaType APPLICATION_X_XCF = create("application/x-xcf", "xcf"); + public static final MediaType APPLICATION_X_XFIG = create("application/x-xfig", "fig"); + public static final MediaType APPLICATION_X_XLIFF_XML = create("application/x-xliff+xml", "xlf"); + public static final MediaType APPLICATION_X_XPINSTALL = create("application/x-xpinstall", "xpi"); + public static final MediaType APPLICATION_X_XZ = create("application/x-xz", "xz"); + public static final MediaType APPLICATION_X_ZMACHINE = create("application/x-zmachine", "z1", "z2", "z3", "z4", + "z5", "Z6", "Z7", "Z8"); + public static final MediaType APPLICATION_YANG = create("application/yang", "yang"); + public static final MediaType APPLICATION_YIN_XML = create("application/yin+xml", "yin"); + public static final MediaType APPLICATION_ZIP = create("application/zip", "zip"); + public static final MediaType AUDIO_ADPCM = create("audio/adpcm", "adp"); + public static final MediaType AUDIO_AMR = create("audio/amr", "amr"); + public static final MediaType AUDIO_AMR_WB = create("audio/amr-wb", "awb"); + public static final MediaType AUDIO_ANNODEX = create("audio/annodex", "axa"); + public static final MediaType AUDIO_BASIC = create("audio/basic", "au", "snd"); + public static final MediaType AUDIO_CSOUND = create("audio/csound", "csd", "orc", "sco"); + public static final MediaType AUDIO_FLAC = create("audio/flac", "flac"); + public static final MediaType AUDIO_MIDI = create("audio/midi", "mid", "midi", "kar", "rmi"); + public static final MediaType AUDIO_MP4 = create("audio/mp4", "mp4a"); + public static final MediaType AUDIO_MPEG = create("audio/mpeg", "mpga", "mpega", "mp2", "mp2a", "mp3", "m2a", + "m3a", "MP3", "M4A"); + public static final MediaType AUDIO_MPEGURL = create("audio/mpegurl", "m3u"); + public static final MediaType AUDIO_OGG = create("audio/ogg", "oga", "ogg", "spx"); + public static final MediaType AUDIO_PRS_SID = create("audio/prs.sid", "sid"); + public static final MediaType AUDIO_S3M = create("audio/s3m", "s3m"); + public static final MediaType AUDIO_SILK = create("audio/silk", "sil"); + public static final MediaType AUDIO_VND_DECE_AUDIO = create("audio/vnd.dece.audio", "uva", "uvva"); + public static final MediaType AUDIO_VND_DIGITAL_WINDS = create("audio/vnd.digital-winds", "eol"); + public static final MediaType AUDIO_VND_DRA = create("audio/vnd.dra", "dra"); + public static final MediaType AUDIO_VND_DTS = create("audio/vnd.dts", "dts"); + public static final MediaType AUDIO_VND_DTS_HD = create("audio/vnd.dts.hd", "dtshd"); + public static final MediaType AUDIO_VND_LUCENT_VOICE = create("audio/vnd.lucent.voice", "lvp"); + public static final MediaType AUDIO_VND_MS_PLAYREADY_MEDIA_PYA = create("audio/vnd.ms-playready.media.pya", "pya"); + public static final MediaType AUDIO_VND_NUERA_ECELP4800 = create("audio/vnd.nuera.ecelp4800", "ecelp4800"); + public static final MediaType AUDIO_VND_NUERA_ECELP7470 = create("audio/vnd.nuera.ecelp7470", "ecelp7470"); + public static final MediaType AUDIO_VND_NUERA_ECELP9600 = create("audio/vnd.nuera.ecelp9600", "ecelp9600"); + public static final MediaType AUDIO_VND_RIP = create("audio/vnd.rip", "rip"); + public static final MediaType AUDIO_WEBM = create("audio/webm", "weba"); + public static final MediaType AUDIO_X_AAC = create("audio/x-aac", "aac"); + public static final MediaType AUDIO_X_AIFF = create("audio/x-aiff", "aif", "aiff", "aifc"); + public static final MediaType AUDIO_X_CAF = create("audio/x-caf", "caf"); + public static final MediaType AUDIO_X_FLAC = create("audio/x-flac", "flac"); + public static final MediaType AUDIO_X_GSM = create("audio/x-gsm", "gsm"); + public static final MediaType AUDIO_X_MATROSKA = create("audio/x-matroska", "mka"); + public static final MediaType AUDIO_X_MPEGURL = create("audio/x-mpegurl", "m3u"); + public static final MediaType AUDIO_X_MS_WAX = create("audio/x-ms-wax", "wax"); + public static final MediaType AUDIO_X_MS_WMA = create("audio/x-ms-wma", "wma"); + public static final MediaType AUDIO_XM = create("audio/xm", "xm"); + public static final MediaType AUDIO_X_PN_REALAUDIO_PLUGIN = create("audio/x-pn-realaudio-plugin", "rmp"); + public static final MediaType AUDIO_X_PN_REALAUDIO = create("audio/x-pn-realaudio", "ra", "rm", "ram"); + public static final MediaType AUDIO_X_REALAUDIO = create("audio/x-realaudio", "ra"); + public static final MediaType AUDIO_X_SCPLS = create("audio/x-scpls", "pls"); + public static final MediaType AUDIO_X_SD2 = create("audio/x-sd2", "sd2"); + public static final MediaType AUDIO_X_WAV = create("audio/x-wav", "wav"); + public static final MediaType CHEMICAL_X_ALCHEMY = create("chemical/x-alchemy", "alc"); + public static final MediaType CHEMICAL_X_CACHE = create("chemical/x-cache", "cac", "cache"); + public static final MediaType CHEMICAL_X_CACHE_CSF = create("chemical/x-cache-csf", "csf"); + public static final MediaType CHEMICAL_X_CACTVS_BINARY = create("chemical/x-cactvs-binary", "cbin", "cascii", + "ctab"); + public static final MediaType CHEMICAL_X_CDX = create("chemical/x-cdx", "cdx"); + public static final MediaType CHEMICAL_X_CERIUS = create("chemical/x-cerius", "cer"); + public static final MediaType CHEMICAL_X_CHEM3D = create("chemical/x-chem3d", "c3d"); + public static final MediaType CHEMICAL_X_CHEMDRAW = create("chemical/x-chemdraw", "chm"); + public static final MediaType CHEMICAL_X_CIF = create("chemical/x-cif", "cif"); + public static final MediaType CHEMICAL_X_CMDF = create("chemical/x-cmdf", "cmdf"); + public static final MediaType CHEMICAL_X_CML = create("chemical/x-cml", "cml"); + public static final MediaType CHEMICAL_X_COMPASS = create("chemical/x-compass", "cpa"); + public static final MediaType CHEMICAL_X_CROSSFIRE = create("chemical/x-crossfire", "bsd"); + public static final MediaType CHEMICAL_X_CSML = create("chemical/x-csml", "csml", "csm"); + public static final MediaType CHEMICAL_X_CTX = create("chemical/x-ctx", "ctx"); + public static final MediaType CHEMICAL_X_CXF = create("chemical/x-cxf", "cxf", "cef"); + public static final MediaType CHEMICAL_X_DAYLIGHT_SMILES = create("chemical/x-daylight-smiles", "smi"); + public static final MediaType CHEMICAL_X_EMBL_DL_NUCLEOTIDE = create("chemical/x-embl-dl-nucleotide", "emb", "embl"); + public static final MediaType CHEMICAL_X_GALACTIC_SPC = create("chemical/x-galactic-spc", "spc"); + public static final MediaType CHEMICAL_X_GAMESS_INPUT = create("chemical/x-gamess-input", "inp", "gam", "gamin"); + public static final MediaType CHEMICAL_X_GAUSSIAN_CHECKPOINT = create("chemical/x-gaussian-checkpoint", "fch", + "fchk"); + public static final MediaType CHEMICAL_X_GAUSSIAN_CUBE = create("chemical/x-gaussian-cube", "cub"); + public static final MediaType CHEMICAL_X_GAUSSIAN_INPUT = create("chemical/x-gaussian-input", "gau", "gjc", "gjf"); + public static final MediaType CHEMICAL_X_GAUSSIAN_LOG = create("chemical/x-gaussian-log", "gal"); + public static final MediaType CHEMICAL_X_GCG8_SEQUENCE = create("chemical/x-gcg8-sequence", "gcg"); + public static final MediaType CHEMICAL_X_GENBANK = create("chemical/x-genbank", "gen"); + public static final MediaType CHEMICAL_X_HIN = create("chemical/x-hin", "hin"); + public static final MediaType CHEMICAL_X_ISOSTAR = create("chemical/x-isostar", "istr", "ist"); + public static final MediaType CHEMICAL_X_JCAMP_DX = create("chemical/x-jcamp-dx", "jdx", "dx"); + public static final MediaType CHEMICAL_X_KINEMAGE = create("chemical/x-kinemage", "kin"); + public static final MediaType CHEMICAL_X_MACMOLECULE = create("chemical/x-macmolecule", "mcm"); + public static final MediaType CHEMICAL_X_MACROMODEL_INPUT = create("chemical/x-macromodel-input", "mmd", "mmod"); + public static final MediaType CHEMICAL_X_MDL_MOLFILE = create("chemical/x-mdl-molfile", "mol"); + public static final MediaType CHEMICAL_X_MDL_RDFILE = create("chemical/x-mdl-rdfile", "rd"); + public static final MediaType CHEMICAL_X_MDL_RXNFILE = create("chemical/x-mdl-rxnfile", "rxn"); + public static final MediaType CHEMICAL_X_MDL_SDFILE = create("chemical/x-mdl-sdfile", "sd", "sdf"); + public static final MediaType CHEMICAL_X_MDL_TGF = create("chemical/x-mdl-tgf", "tgf"); + public static final MediaType CHEMICAL_X_MIF = create("chemical/x-mif", "mif"); + public static final MediaType CHEMICAL_X_MMCIF = create("chemical/x-mmcif", "mcif"); + public static final MediaType CHEMICAL_X_MOL2 = create("chemical/x-mol2", "mol2"); + public static final MediaType CHEMICAL_X_MOLCONN_Z = create("chemical/x-molconn-z", "b"); + public static final MediaType CHEMICAL_X_MOPAC_GRAPH = create("chemical/x-mopac-graph", "gpt"); + public static final MediaType CHEMICAL_X_MOPAC_INPUT = create("chemical/x-mopac-input", "mop", "mopcrt", "mpc", + "zmt"); + public static final MediaType CHEMICAL_X_MOPAC_OUT = create("chemical/x-mopac-out", "moo"); + public static final MediaType CHEMICAL_X_MOPAC_VIB = create("chemical/x-mopac-vib", "mvb"); + public static final MediaType CHEMICAL_X_NCBI_ASN1_ASCII = create("chemical/x-ncbi-asn1-ascii", "prt", "ent"); + public static final MediaType CHEMICAL_X_NCBI_ASN1 = create("chemical/x-ncbi-asn1", "asn"); + public static final MediaType CHEMICAL_X_NCBI_ASN1_BINARY = create("chemical/x-ncbi-asn1-binary", "val", "aso"); + public static final MediaType CHEMICAL_X_NCBI_ASN1_SPEC = create("chemical/x-ncbi-asn1-spec", "asn"); + public static final MediaType CHEMICAL_X_PDB = create("chemical/x-pdb", "pdb", "ent"); + public static final MediaType CHEMICAL_X_ROSDAL = create("chemical/x-rosdal", "ros"); + public static final MediaType CHEMICAL_X_SWISSPROT = create("chemical/x-swissprot", "sw"); + public static final MediaType CHEMICAL_X_VAMAS_ISO14976 = create("chemical/x-vamas-iso14976", "vms"); + public static final MediaType CHEMICAL_X_VMD = create("chemical/x-vmd", "vmd"); + public static final MediaType CHEMICAL_X_XTEL = create("chemical/x-xtel", "xtel"); + public static final MediaType CHEMICAL_X_XYZ = create("chemical/x-xyz", "xyz"); + public static final MediaType IMAGE_BMP = create("image/bmp", "bmp"); + public static final MediaType IMAGE_CGM = create("image/cgm", "cgm"); + public static final MediaType IMAGE_G3FAX = create("image/g3fax", "g3"); + public static final MediaType IMAGE_GIF = create("image/gif", "gif"); + public static final MediaType IMAGE_IEF = create("image/ief", "ief"); + public static final MediaType IMAGE_JPEG = create("image/jpeg", "jpeg", "jpg", "jpe"); + public static final MediaType IMAGE_KTX = create("image/ktx", "ktx"); + public static final MediaType IMAGE_PCX = create("image/pcx", "pcx"); + public static final MediaType IMAGE_PNG = create("image/png", "png"); + public static final MediaType IMAGE_PRS_BTIF = create("image/prs.btif", "btif"); + public static final MediaType IMAGE_SGI = create("image/sgi", "sgi"); + public static final MediaType IMAGE_TIFF = create("image/tiff", "tiff", "tif"); + public static final MediaType IMAGE_VND_ADOBE_PHOTOSHOP = create("image/vnd.adobe.photoshop", "psd"); + public static final MediaType IMAGE_VND_DECE_GRAPHIC = create("image/vnd.dece.graphic", "uvi", "uvvi", "uvg", + "uvvg"); + public static final MediaType IMAGE_VND_DJVU = create("image/vnd.djvu", "djvu", "djv"); + public static final MediaType IMAGE_VND_DVB_SUBTITLE = create("image/vnd.dvb.subtitle", "sub"); + public static final MediaType IMAGE_VND_DWG = create("image/vnd.dwg", "dwg"); + public static final MediaType IMAGE_VND_DXF = create("image/vnd.dxf", "dxf"); + public static final MediaType IMAGE_VND_FASTBIDSHEET = create("image/vnd.fastbidsheet", "fbs"); + public static final MediaType IMAGE_VND_FPX = create("image/vnd.fpx", "fpx"); + public static final MediaType IMAGE_VND_FST = create("image/vnd.fst", "fst"); + public static final MediaType IMAGE_VND_FUJIXEROX_EDMICS_MMR = create("image/vnd.fujixerox.edmics-mmr", "mmr"); + public static final MediaType IMAGE_VND_FUJIXEROX_EDMICS_RLC = create("image/vnd.fujixerox.edmics-rlc", "rlc"); + public static final MediaType IMAGE_VND_MS_MODI = create("image/vnd.ms-modi", "mdi"); + public static final MediaType IMAGE_VND_MS_PHOTO = create("image/vnd.ms-photo", "wdp"); + public static final MediaType IMAGE_VND_NET_FPX = create("image/vnd.net-fpx", "npx"); + public static final MediaType IMAGE_VND_WAP_WBMP = create("image/vnd.wap.wbmp", "wbmp"); + public static final MediaType IMAGE_VND_XIFF = create("image/vnd.xiff", "xif"); + public static final MediaType IMAGE_WEBP = create("image/webp", "webp"); + public static final MediaType IMAGE_X_3DS = create("image/x-3ds", "3ds"); + public static final MediaType IMAGE_X_CANON_CR2 = create("image/x-canon-cr2", "cr2"); + public static final MediaType IMAGE_X_CANON_CRW = create("image/x-canon-crw", "crw"); + public static final MediaType IMAGE_X_CMU_RASTER = create("image/x-cmu-raster", "ras"); + public static final MediaType IMAGE_X_CMX = create("image/x-cmx", "cmx"); + public static final MediaType IMAGE_X_CORELDRAW = create("image/x-coreldraw", "cdr"); + public static final MediaType IMAGE_X_CORELDRAWPATTERN = create("image/x-coreldrawpattern", "pat"); + public static final MediaType IMAGE_X_CORELDRAWTEMPLATE = create("image/x-coreldrawtemplate", "cdt"); + public static final MediaType IMAGE_X_CORELPHOTOPAINT = create("image/x-corelphotopaint", "cpt"); + public static final MediaType IMAGE_X_EPSON_ERF = create("image/x-epson-erf", "erf"); + public static final MediaType IMAGE_X_FREEHAND = create("image/x-freehand", "fh", "fhc", "fh4", "fh5", "fh7"); + public static final MediaType IMAGE_X_ICON = create("image/x-icon", "ico"); + public static final MediaType IMAGE_X_JG = create("image/x-jg", "art"); + public static final MediaType IMAGE_X_JNG = create("image/x-jng", "jng"); + public static final MediaType IMAGE_X_MRSID_IMAGE = create("image/x-mrsid-image", "sid"); + public static final MediaType IMAGE_X_NIKON_NEF = create("image/x-nikon-nef", "nef"); + public static final MediaType IMAGE_X_OLYMPUS_ORF = create("image/x-olympus-orf", "orf"); + public static final MediaType IMAGE_X_PCX = create("image/x-pcx", "pcx"); + public static final MediaType IMAGE_X_PHOTOSHOP = create("image/x-photoshop", "psd"); + public static final MediaType IMAGE_X_PICT = create("image/x-pict", "pic", "pct"); + public static final MediaType IMAGE_X_PORTABLE_ANYMAP = create("image/x-portable-anymap", "pnm"); + public static final MediaType IMAGE_X_PORTABLE_BITMAP = create("image/x-portable-bitmap", "pbm"); + public static final MediaType IMAGE_X_PORTABLE_GRAYMAP = create("image/x-portable-graymap", "pgm"); + public static final MediaType IMAGE_X_PORTABLE_PIXMAP = create("image/x-portable-pixmap", "ppm"); + public static final MediaType IMAGE_X_RGB = create("image/x-rgb", "rgb"); + public static final MediaType IMAGE_X_TGA = create("image/x-tga", "tga"); + public static final MediaType IMAGE_X_XBITMAP = create("image/x-xbitmap", "xbm"); + public static final MediaType IMAGE_X_XPIXMAP = create("image/x-xpixmap", "xpm"); + public static final MediaType IMAGE_X_XWINDOWDUMP = create("image/x-xwindowdump", "xwd"); + public static final MediaType MESSAGE_RFC822 = create("message/rfc822", "eml", "mime"); + public static final MediaType MODEL_IGES = create("model/iges", "igs", "iges"); + public static final MediaType MODEL_MESH = create("model/mesh", "msh", "mesh", "silo"); + public static final MediaType MODEL_VND_COLLADA_XML = create("model/vnd.collada+xml", "dae"); + public static final MediaType MODEL_VND_DWF = create("model/vnd.dwf", "dwf"); + public static final MediaType MODEL_VND_GDL = create("model/vnd.gdl", "gdl"); + public static final MediaType MODEL_VND_GTW = create("model/vnd.gtw", "gtw"); + public static final MediaType MODEL_VND_MTS = create("model/vnd.mts", "mts"); + public static final MediaType MODEL_VND_VTU = create("model/vnd.vtu", "vtu"); + public static final MediaType MODEL_VRML = create("model/vrml", "wrl", "vrml"); + public static final MediaType MODEL_X3D_BINARY = create("model/x3d+binary", "x3db", "x3dbz"); + public static final MediaType MODEL_X3D_VRML = create("model/x3d+vrml", "x3dv", "x3dvz"); + public static final MediaType MODEL_X3D_XML = create("model/x3d+xml", "x3d", "x3dz"); + public static final MediaType TEXT_CACHE_MANIFEST = create("text/cache-manifest", "appcache", "manifest"); + public static final MediaType TEXT_CALENDAR = create("text/calendar", "ics", "icz", "ifb"); + public static final MediaType TEXT_H323 = create("text/h323", "323"); + public static final MediaType TEXT_IULS = create("text/iuls", "uls"); + public static final MediaType TEXT_MATHML = create("text/mathml", "mml"); + public static final MediaType TEXT_N3 = create("text/n3", "n3"); + public static final MediaType TEXT_PLAIN = create("text/plain"); + public static final MediaType TEXT_PRS_LINES_TAG = create("text/prs.lines.tag", "dsc"); + public static final MediaType TEXT_RICHTEXT = create("text/richtext", "rtx"); + public static final MediaType TEXT_SCRIPTLET = create("text/scriptlet", "sct", "wsc"); + public static final MediaType TEXT_SGML = create("text/sgml", "sgml", "sgm"); + public static final MediaType TEXT_TEXMACS = create("text/texmacs", "tm"); + public static final MediaType TEXT_TROFF = create("text/troff", "t", "tr", "roff", "man", "me", "ms"); + public static final MediaType TEXT_TURTLE = create("text/turtle", "ttl"); + public static final MediaType TEXT_URI_LIST = create("text/uri-list", "uri", "uris", "urls"); + public static final MediaType TEXT_VCARD = create("text/vcard", "vcard"); + public static final MediaType TEXT_VND_CURL = create("text/vnd.curl", "curl"); + public static final MediaType TEXT_VND_CURL_DCURL = create("text/vnd.curl.dcurl", "dcurl"); + public static final MediaType TEXT_VND_CURL_MCURL = create("text/vnd.curl.mcurl", "mcurl"); + public static final MediaType TEXT_VND_CURL_SCURL = create("text/vnd.curl.scurl", "scurl"); + public static final MediaType TEXT_VND_DVB_SUBTITLE = create("text/vnd.dvb.subtitle", "sub"); + public static final MediaType TEXT_VND_FLY = create("text/vnd.fly", "fly"); + public static final MediaType TEXT_VND_FMI_FLEXSTOR = create("text/vnd.fmi.flexstor", "flx"); + public static final MediaType TEXT_VND_GRAPHVIZ = create("text/vnd.graphviz", "gv"); + public static final MediaType TEXT_VND_IN3D_3DML = create("text/vnd.in3d.3dml", "3dml"); + public static final MediaType TEXT_VND_IN3D_SPOT = create("text/vnd.in3d.spot", "spot"); + public static final MediaType TEXT_VND_SUN_J2ME_APP_DESCRIPTOR = create("text/vnd.sun.j2me.app-descriptor", "jad"); + public static final MediaType TEXT_VND_WAP_WMLSCRIPT = create("text/vnd.wap.wmlscript", "wmls"); + public static final MediaType TEXT_VND_WAP_WML = create("text/vnd.wap.wml", "wml"); + public static final MediaType VIDEO_3GPP2 = create("video/3gpp2", "3g2"); + public static final MediaType VIDEO_3GPP = create("video/3gpp", "3gp"); + public static final MediaType VIDEO_ANNODEX = create("video/annodex", "axv"); + public static final MediaType VIDEO_DL = create("video/dl", "dl"); + public static final MediaType VIDEO_DV = create("video/dv", "dif", "dv"); + public static final MediaType VIDEO_FLI = create("video/fli", "fli"); + public static final MediaType VIDEO_GL = create("video/gl", "gl"); + public static final MediaType VIDEO_H261 = create("video/h261", "h261"); + public static final MediaType VIDEO_H263 = create("video/h263", "h263"); + public static final MediaType VIDEO_H264 = create("video/h264", "h264"); + public static final MediaType VIDEO_JPEG = create("video/jpeg", "jpgv"); + public static final MediaType VIDEO_JPM = create("video/jpm", "jpm", "jpgm"); + public static final MediaType VIDEO_MJ2 = create("video/mj2", "mj2", "mjp2"); + public static final MediaType VIDEO_MP2T = create("video/mp2t", "ts"); + public static final MediaType VIDEO_MP4 = create("video/mp4", "mp4", "mp4v", "mpg4"); + public static final MediaType VIDEO_MPEG = create("video/mpeg", "mpeg", "mpg", "mpe", "m1v", "m2v"); + public static final MediaType VIDEO_OGG = create("video/ogg", "ogv"); + public static final MediaType VIDEO_QUICKTIME = create("video/quicktime", "qt", "mov"); + public static final MediaType VIDEO_VND_DECE_HD = create("video/vnd.dece.hd", "uvh", "uvvh"); + public static final MediaType VIDEO_VND_DECE_MOBILE = create("video/vnd.dece.mobile", "uvm", "uvvm"); + public static final MediaType VIDEO_VND_DECE_PD = create("video/vnd.dece.pd", "uvp", "uvvp"); + public static final MediaType VIDEO_VND_DECE_SD = create("video/vnd.dece.sd", "uvs", "uvvs"); + public static final MediaType VIDEO_VND_DECE_VIDEO = create("video/vnd.dece.video", "uvv", "uvvv"); + public static final MediaType VIDEO_VND_DVB_FILE = create("video/vnd.dvb.file", "dvb"); + public static final MediaType VIDEO_VND_FVT = create("video/vnd.fvt", "fvt"); + public static final MediaType VIDEO_VND_MPEGURL = create("video/vnd.mpegurl", "mxu", "m4u"); + public static final MediaType VIDEO_VND_MS_PLAYREADY_MEDIA_PYV = create("video/vnd.ms-playready.media.pyv", "pyv"); + public static final MediaType VIDEO_VND_UVVU_MP4 = create("video/vnd.uvvu.mp4", "uvu", "uvvu"); + public static final MediaType VIDEO_VND_VIVO = create("video/vnd.vivo", "viv"); + public static final MediaType VIDEO_WEBM = create("video/webm", "webm"); + public static final MediaType VIDEO_X_F4V = create("video/x-f4v", "f4v"); + public static final MediaType VIDEO_X_FLI = create("video/x-fli", "fli"); + public static final MediaType VIDEO_X_FLV = create("video/x-flv", "flv"); + public static final MediaType VIDEO_X_LA_ASF = create("video/x-la-asf", "lsf", "lsx"); + public static final MediaType VIDEO_X_M4V = create("video/x-m4v", "m4v"); + public static final MediaType VIDEO_X_MATROSKA = create("video/x-matroska", "mpv", "mkv", "mk3d", "mks"); + public static final MediaType VIDEO_X_MNG = create("video/x-mng", "mng"); + public static final MediaType VIDEO_X_MS_ASF = create("video/x-ms-asf", "asf", "asx"); + public static final MediaType VIDEO_X_MSVIDEO = create("video/x-msvideo", "avi"); + public static final MediaType VIDEO_X_MS_VOB = create("video/x-ms-vob", "vob"); + public static final MediaType VIDEO_X_MS_WMV = create("video/x-ms-wmv", "wmv"); + public static final MediaType VIDEO_X_MS_WM = create("video/x-ms-wm", "wm"); + public static final MediaType VIDEO_X_MS_WMX = create("video/x-ms-wmx", "wmx"); + public static final MediaType VIDEO_X_MS_WVX = create("video/x-ms-wvx", "wvx"); + public static final MediaType VIDEO_X_SGI_MOVIE = create("video/x-sgi-movie", "movie"); + public static final MediaType VIDEO_X_SMV = create("video/x-smv", "smv"); + public static final MediaType X_CONFERENCE_X_COOLTALK = create("x-conference/x-cooltalk", "ice"); + public static final MediaType X_EPOC_X_SISX_APP = create("x-epoc/x-sisx-app", "sisx"); + public static final MediaType X_WORLD_X_VRML = create("x-world/x-vrml", "vrm", "vrml", "wrl"); + + private static final String[] UTF8_ATTR = {"charset=utf-8"}; + + public static final MediaType APPLICATION_ATOMCAT_XML_UTF8 = createUTF8("application/atomcat+xml", "atomcat"); + public static final MediaType APPLICATION_ATOMSERV_XML_UTF8 = createUTF8("application/atomserv+xml", "atomsrv"); + public static final MediaType APPLICATION_ATOMSVC_XML_UTF8 = createUTF8("application/atomsvc+xml", "atomsvc"); + public static final MediaType APPLICATION_ATOM_XML_UTF8 = createUTF8("application/atom+xml", "atom"); + public static final MediaType APPLICATION_ECMASCRIPT_UTF8 = createUTF8("application/ecmascript", "ecma", "es"); + public static final MediaType APPLICATION_JAVASCRIPT_UTF8 = createUTF8("application/javascript", "js"); + public static final MediaType APPLICATION_RSD_XML_UTF8 = createUTF8("application/rsd+xml", "rsd"); + public static final MediaType APPLICATION_RSS_XML_UTF8 = createUTF8("application/rss+xml", "rss"); + public static final MediaType APPLICATION_XHTML_XML_UTF8 = createUTF8("application/xhtml+xml", "xhtml", "xht"); + public static final MediaType APPLICATION_XML_DTD_UTF8 = createUTF8("application/xml-dtd", "dtd"); + public static final MediaType APPLICATION_XML_UTF8 = createUTF8("application/xml", "xml", "xsl", "xsd"); + public static final MediaType APPLICATION_X_SH_UTF8 = createUTF8("application/x-sh", "sh"); + public static final MediaType APPLICATION_XSLT_XML_UTF8 = createUTF8("application/xslt+xml", "xslt"); + public static final MediaType APPLICATION_XSPF_XML_UTF8 = createUTF8("application/xspf+xml", "xspf"); + public static final MediaType APPLICATION_X_SQL_UTF8 = createUTF8("application/x-sql", "sql"); + public static final MediaType IMAGE_SVG_XML = createUTF8("image/svg+xml", "svg", "svgz"); + public static final MediaType TEXT_CSS_UTF8 = createUTF8("text/css", "css"); + public static final MediaType TEXT_CSV_UTF8 = createUTF8("text/csv", "csv"); + public static final MediaType TEXT_HTML_UTF8 = createUTF8("text/html", "html", "htm", "shtml"); + public static final MediaType TEXT_PLAIN_UTF8 = createUTF8("text/plain", "asc", "txt", "text", "conf", "def", + "pot", "brf", "LIST", "LOG", "IN"); + public static final MediaType TEXT_TAB_SEPARATED_VALUES_UTF8 = createUTF8("text/tab-separated-values", "tsv"); + public static final MediaType TEXT_X_ASM_UTF8 = createUTF8("text/x-asm", "s", "asm"); + public static final MediaType TEXT_X_BIBTEX_UTF8 = createUTF8("text/x-bibtex", "bib"); + public static final MediaType TEXT_X_BOO_UTF8 = createUTF8("text/x-boo", "boo"); + public static final MediaType TEXT_X_C_UTF8 = createUTF8("text/x-c", "c", "cc", "cxx", "cpp", "h", "hh", "dic"); + public static final MediaType TEXT_X_CHDR_UTF8 = createUTF8("text/x-chdr", "h"); + public static final MediaType TEXT_X_C__HDR_UTF8 = createUTF8("text/x-c++hdr", "h++", "hpp", "hxx", "hh"); + public static final MediaType TEXT_X_COMPONENT_UTF8 = createUTF8("text/x-component", "htc"); + public static final MediaType TEXT_X_CSH_UTF8 = createUTF8("text/x-csh", "csh"); + public static final MediaType TEXT_X_CSRC_UTF8 = createUTF8("text/x-csrc", "c"); + public static final MediaType TEXT_X_C__SRC_UTF8 = createUTF8("text/x-c++src", "c++", "cpp", "cxx", "cc"); + public static final MediaType TEXT_X_DIFF_UTF8 = createUTF8("text/x-diff", "diff", "patch"); + public static final MediaType TEXT_X_DSRC_UTF8 = createUTF8("text/x-dsrc", "d"); + public static final MediaType TEXT_X_FORTRAN_UTF8 = createUTF8("text/x-fortran", "f", "for", "f77", "f90"); + public static final MediaType TEXT_X_HASKELL_UTF8 = createUTF8("text/x-haskell", "hs"); + public static final MediaType TEXT_X_JAVA_UTF8 = createUTF8("text/x-java", "java"); + public static final MediaType TEXT_X_JAVA_SOURCE_UTF8 = createUTF8("text/x-java-source", "java"); + public static final MediaType TEXT_X_LITERATE_HASKELL_UTF8 = createUTF8("text/x-literate-haskell", "lhs"); + public static final MediaType TEXT_X_MOC_UTF8 = createUTF8("text/x-moc", "moc"); + public static final MediaType TEXT_X_NFO_UTF8 = createUTF8("text/x-nfo", "nfo"); + public static final MediaType TEXT_X_OPML_UTF8 = createUTF8("text/x-opml", "opml"); + public static final MediaType TEXT_X_PASCAL_UTF8 = createUTF8("text/x-pascal", "p", "pas"); + public static final MediaType TEXT_X_PCS_GCD_UTF8 = createUTF8("text/x-pcs-gcd", "gcd"); + public static final MediaType TEXT_X_PERL_UTF8 = createUTF8("text/x-perl", "pl", "pm"); + public static final MediaType TEXT_X_PYTHON_UTF8 = createUTF8("text/x-python", "py"); + public static final MediaType TEXT_X_SCALA_UTF8 = createUTF8("text/x-scala", "scala"); + public static final MediaType TEXT_X_SETEXT_UTF8 = createUTF8("text/x-setext", "etx"); + public static final MediaType TEXT_X_SFV_UTF8 = createUTF8("text/x-sfv", "sfv"); + public static final MediaType TEXT_X_SH_UTF8 = createUTF8("text/x-sh", "sh"); + public static final MediaType TEXT_X_TCL_UTF8 = createUTF8("text/x-tcl", "tcl", "tk"); + public static final MediaType TEXT_X_TEX_UTF8 = createUTF8("text/x-tex", "tex", "ltx", "sty", "cls"); + public static final MediaType TEXT_X_UUENCODE_UTF8 = createUTF8("text/x-uuencode", "uu"); + public static final MediaType TEXT_X_VCALENDAR_UTF8 = createUTF8("text/x-vcalendar", "vcs"); + public static final MediaType TEXT_X_VCARD_UTF8 = createUTF8("text/x-vcard", "vcf"); + + public static final MediaType HTML_UTF_8 = TEXT_HTML_UTF8; + public static final MediaType CSS_UTF_8 = TEXT_CSS_UTF8; + public static final MediaType CSV_UTF_8 = TEXT_CSV_UTF8; + public static final MediaType PLAIN_TEXT_UTF_8 = TEXT_PLAIN_UTF8; + public static final MediaType XHTML_XML_UTF8 = APPLICATION_XHTML_XML_UTF8; + public static final MediaType JAVASCRIPT_UTF8 = APPLICATION_JAVASCRIPT_UTF8; + public static final MediaType JSON = APPLICATION_JSON; + public static final MediaType XML_UTF_8 = APPLICATION_XML_UTF8; + public static final MediaType BINARY = APPLICATION_OCTET_STREAM; + public static final MediaType ZIP = APPLICATION_ZIP; + public static final MediaType PDF = APPLICATION_PDF; + public static final MediaType SWF = APPLICATION_X_SHOCKWAVE_FLASH; + public static final MediaType JPEG = IMAGE_JPEG; + public static final MediaType PNG = IMAGE_PNG; + public static final MediaType BMP = IMAGE_BMP; + public static final MediaType GIF = IMAGE_GIF; + public static final MediaType SVG = IMAGE_SVG_XML; + + private final byte[] bytes; + private final String contentType; + + private MediaType(String contentType) { + this.bytes = contentType.getBytes(); + this.contentType = contentType; + } + + private MediaType(String name, String[] attributes) { + this.bytes = join(name, attributes).getBytes(); + this.contentType = new String(this.bytes); + } + + private static MediaType create(String type, String... fileExtensisons) { + return create(type, NO_ATTR, fileExtensisons); + } + + private static MediaType create(String type, String[] attributes, String... fileExtensisons) { + MediaType mt = new MediaType(type, attributes); + for (String ext : fileExtensisons) { + FILE_EXTENSIONS.put(ext, mt); + } + return mt; + } + + private static MediaType createUTF8(String type, String... fileExtensisons) { + return create(type, UTF8_ATTR, fileExtensisons); + } + + public static MediaType getByFileExtension(String fileExtension) { + return FILE_EXTENSIONS.get(fileExtension); + } + + public static MediaType getByFileName(String filename) { + int dotPos = filename.lastIndexOf('.'); + if (dotPos >= 0) { + String ext = filename.substring(dotPos + 1); + return getByFileExtension(ext); + } else { + return MediaType.DEFAULT; + } + } + + public static MediaType of(String contentType) { + return new MediaType(contentType); + } + + public String withCharset(String charset) { + return charset != null ? String.format("%s; charset=%s", this.contentType, charset.toUpperCase()) : this.contentType; + } + + private String join(String name, String[] attributes) { + String attrs = String.join(";", attributes); + return attrs.isEmpty() ? name : name + "; " + attrs; + } + + public byte[] getBytes() { + return bytes; + } + + public String contentType() { + return this.contentType; + } + + @Override + public String toString() { + return this.contentType; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + Arrays.hashCode(bytes); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + MediaType other = (MediaType) obj; + return Arrays.equals(bytes, other.bytes); + } + + public String info() { + if (this == HTML_UTF_8) { + return "html"; + } + if (this == JSON) { + return "json"; + } + if (this == PLAIN_TEXT_UTF_8) { + return "plain"; + } + if (this == BINARY) { + return "binary"; + } + return toString(); + } +} diff --git a/netty-http-server/build.gradle b/netty-http-server/build.gradle index f6bccee..2015e3a 100644 --- a/netty-http-server/build.gradle +++ b/netty-http-server/build.gradle @@ -1,10 +1,10 @@ dependencies { - compile project(":netty-http-common") - compile "io.netty:netty-handler:${project.property('netty.version')}" - compile "io.netty:netty-transport-native-epoll:${project.property('netty.version')}" - compile "io.netty:netty-tcnative-boringssl-static:${project.property('tcnative.version')}" - compile "org.bouncycastle:bcpkix-jdk15on:${project.property('bouncycastle.version')}" - - testCompile project(":netty-http-client") - testCompile "junit:junit:${project.property('junit.version')}" + implementation project(":netty-http-common") + implementation "io.netty:netty-handler:${project.property('netty.version')}" + implementation "io.netty:netty-transport-native-epoll:${project.property('netty.version')}" + implementation "io.netty:netty-tcnative-boringssl-static:${project.property('tcnative.version')}" + implementation "io.netty:netty-codec-http2:${project.property('netty.version')}" + implementation "org.xbib:net-url:${project.property('xbib-net-url.version')}" + implementation "org.bouncycastle:bcpkix-jdk15on:${project.property('bouncycastle.version')}" + testImplementation project(":netty-http-client") } diff --git a/netty-http-server/src/main/java/org/xbib/netty/http/server/Server.java b/netty-http-server/src/main/java/org/xbib/netty/http/server/Server.java index b348465..cf4c101 100644 --- a/netty-http-server/src/main/java/org/xbib/netty/http/server/Server.java +++ b/netty-http-server/src/main/java/org/xbib/netty/http/server/Server.java @@ -21,7 +21,7 @@ import io.netty.handler.ssl.SslContextBuilder; import io.netty.util.DomainNameMapping; import io.netty.util.DomainNameMappingBuilder; import org.xbib.netty.http.common.HttpAddress; -import org.xbib.netty.http.server.context.VirtualServer; +import org.xbib.netty.http.server.endpoint.NamedServer; import org.xbib.netty.http.server.handler.http.HttpChannelInitializer; import org.xbib.netty.http.server.handler.http2.Http2ChannelInitializer; import org.xbib.netty.http.server.transport.HttpServerTransport; @@ -73,7 +73,7 @@ public final class Server { private final ServerBootstrap bootstrap; - private final Map virtualServerMap; + private final Map virtualServerMap; private ChannelFuture channelFuture; @@ -118,11 +118,11 @@ public final class Server { bootstrap.handler(new LoggingHandler("bootstrap-server", serverConfig.getDebugLogLevel())); } this.virtualServerMap = new HashMap<>(); - for (VirtualServer virtualServer : serverConfig.getVirtualServers()) { - String name = virtualServer.getName(); - virtualServerMap.put(name, virtualServer); - for (String alias : virtualServer.getAliases()) { - virtualServerMap.put(alias, virtualServer); + for (NamedServer namedServer : serverConfig.getNamedServers()) { + String name = namedServer.getName(); + virtualServerMap.put(name, namedServer); + for (String alias : namedServer.getAliases()) { + virtualServerMap.put(alias, namedServer); } } DomainNameMapping domainNameMapping = null; @@ -136,8 +136,8 @@ public final class Server { } SslContext sslContext = sslContextBuilder.build(); DomainNameMappingBuilder mappingBuilder = new DomainNameMappingBuilder<>(sslContext); - for (VirtualServer virtualServer : serverConfig.getVirtualServers()) { - String name = virtualServer.getName(); + for (NamedServer namedServer : serverConfig.getNamedServers()) { + String name = namedServer.getName(); mappingBuilder.add(name == null ? "*" : name, sslContext); } domainNameMapping = mappingBuilder.build(); @@ -169,11 +169,11 @@ public final class Server { * the default virtual host * @return the virtual host with the given name, or null if it doesn't exist */ - public VirtualServer getVirtualServer(String name) { + public NamedServer getVirtualServer(String name) { return virtualServerMap.get(name); } - public VirtualServer getDefaultVirtualServer() { + public NamedServer getDefaultVirtualServer() { return virtualServerMap.get(null); } diff --git a/netty-http-server/src/main/java/org/xbib/netty/http/server/ServerBuilder.java b/netty-http-server/src/main/java/org/xbib/netty/http/server/ServerBuilder.java index a107e46..46ddf2f 100644 --- a/netty-http-server/src/main/java/org/xbib/netty/http/server/ServerBuilder.java +++ b/netty-http-server/src/main/java/org/xbib/netty/http/server/ServerBuilder.java @@ -8,7 +8,8 @@ import io.netty.handler.ssl.CipherSuiteFilter; import io.netty.handler.ssl.SslProvider; import io.netty.handler.ssl.util.InsecureTrustManagerFactory; import org.xbib.netty.http.common.HttpAddress; -import org.xbib.netty.http.server.context.VirtualServer; +import org.xbib.netty.http.server.endpoint.Handler; +import org.xbib.netty.http.server.endpoint.NamedServer; import org.xbib.netty.http.server.security.tls.SelfSignedCertificate; import javax.net.ssl.SSLException; @@ -224,8 +225,16 @@ public class ServerBuilder { return this; } - public ServerBuilder addVirtualServer(VirtualServer virtualServer) { - this.serverConfig.addVirtualServer(virtualServer); + public ServerBuilder addServer(NamedServer namedServer) { + this.serverConfig.add(namedServer); + return this; + } + + public ServerBuilder addHandler(String path, Handler handler, String... methods) { + if (serverConfig.getNamedServers().isEmpty()) { + serverConfig.add(new NamedServer()); + } + serverConfig.getNamedServers().getLast().addHandler(path, handler, methods); return this; } diff --git a/netty-http-server/src/main/java/org/xbib/netty/http/server/ServerConfig.java b/netty-http-server/src/main/java/org/xbib/netty/http/server/ServerConfig.java index d6fdbab..b796a6c 100644 --- a/netty-http-server/src/main/java/org/xbib/netty/http/server/ServerConfig.java +++ b/netty-http-server/src/main/java/org/xbib/netty/http/server/ServerConfig.java @@ -10,12 +10,14 @@ import io.netty.handler.ssl.OpenSsl; import io.netty.handler.ssl.SslProvider; import io.netty.handler.ssl.SupportedCipherSuiteFilter; import org.xbib.netty.http.common.HttpAddress; -import org.xbib.netty.http.server.context.VirtualServer; +import org.xbib.netty.http.server.endpoint.NamedServer; import javax.net.ssl.TrustManagerFactory; import java.io.InputStream; import java.security.KeyStore; import java.util.ArrayList; +import java.util.Deque; +import java.util.LinkedList; import java.util.List; public class ServerConfig { @@ -117,7 +119,7 @@ public class ServerConfig { /** * This is Netty's default. - * See {@link io.netty.handler.codec.MessageAggregator#DEFAULT_MAX_COMPOSITEBUFFER_COMPONENTS}. + * See {@link io.netty.handler.codec.MessageAggregator#maxCumulationBufferComponents()}. */ int MAX_COMPOSITE_BUFFER_COMPONENTS = 1024; @@ -225,15 +227,15 @@ public class ServerConfig { private String keyPassword; - private List virtualServers; + private Deque namedServers; private TrustManagerFactory trustManagerFactory = TRUST_MANAGER_FACTORY; private KeyStore trustManagerKeyStore = null; public ServerConfig() { - this.virtualServers = new ArrayList<>(); - addVirtualServer(new VirtualServer(null)); + this.namedServers = new LinkedList<>(); + add(new NamedServer(null)); } public ServerConfig enableDebug() { @@ -512,13 +514,13 @@ public class ServerConfig { return keyPassword; } - public ServerConfig addVirtualServer(VirtualServer virtualServer) { - this.virtualServers.add(virtualServer); + public ServerConfig add(NamedServer namedServer) { + this.namedServers.add(namedServer); return this; } - public List getVirtualServers() { - return virtualServers; + public Deque getNamedServers() { + return namedServers; } public ServerConfig setTrustManagerFactory(TrustManagerFactory trustManagerFactory) { diff --git a/netty-http-server/src/main/java/org/xbib/netty/http/server/ServerName.java b/netty-http-server/src/main/java/org/xbib/netty/http/server/ServerName.java index 623e6a4..70a800d 100644 --- a/netty-http-server/src/main/java/org/xbib/netty/http/server/ServerName.java +++ b/netty-http-server/src/main/java/org/xbib/netty/http/server/ServerName.java @@ -12,7 +12,7 @@ public final class ServerName { /** * The default value for {@code Server} header. */ - private static final String SERVER_NAME = String.format("XbibHttpServer/%s (Java/%s/%s) (Netty/%s)", + private static final String SERVER_NAME = String.format("NettyHttpServer/%s (Java/%s/%s) (Netty/%s)", httpServerVersion(), javaVendor(), javaVersion(), nettyVersion()); private ServerName() { diff --git a/netty-http-server/src/main/java/org/xbib/netty/http/server/context/ContextHandler.java b/netty-http-server/src/main/java/org/xbib/netty/http/server/context/ContextHandler.java deleted file mode 100644 index 3d43396..0000000 --- a/netty-http-server/src/main/java/org/xbib/netty/http/server/context/ContextHandler.java +++ /dev/null @@ -1,24 +0,0 @@ -package org.xbib.netty.http.server.context; - -import org.xbib.netty.http.server.transport.ServerRequest; -import org.xbib.netty.http.server.transport.ServerResponse; - -import java.io.IOException; - -/** - * A {@code ContextHandler} is capable of serving content for resources within its context. - * - * @see VirtualServer#addContext - */ -@FunctionalInterface -public interface ContextHandler { - - /** - * Serves the given request using the given response. - * - * @param serverRequest the request to be served - * @param serverResponse the response to be filled - * @throws IOException if an IO error occurs - */ - void serve(ServerRequest serverRequest, ServerResponse serverResponse) throws IOException; -} diff --git a/netty-http-server/src/main/java/org/xbib/netty/http/server/context/ContextInfo.java b/netty-http-server/src/main/java/org/xbib/netty/http/server/context/ContextInfo.java deleted file mode 100644 index 483cfc8..0000000 --- a/netty-http-server/src/main/java/org/xbib/netty/http/server/context/ContextInfo.java +++ /dev/null @@ -1,46 +0,0 @@ -package org.xbib.netty.http.server.context; - -import java.util.LinkedHashMap; -import java.util.Map; - -/** - * The {@code ContextInfo} class holds a single context's information. - */ -public class ContextInfo { - - private final VirtualServer virtualServer; - - private final Map methodHandlerMap; - - public ContextInfo(VirtualServer virtualServer) { - this.virtualServer = virtualServer; - this.methodHandlerMap = new LinkedHashMap<>(); - } - - /** - * Returns the map of supported HTTP methods and their corresponding handlers. - * - * @return the map of supported HTTP methods and their corresponding handlers - */ - public Map getMethodHandlerMap() { - return methodHandlerMap; - } - - /** - * Adds (or replaces) a context handler for the given HTTP methods. - * - * @param handler the context handler - * @param methods the HTTP methods supported by the handler (default is "GET") - */ - public void addHandler(ContextHandler handler, String... methods) { - if (methods.length == 0) { - methodHandlerMap.put("GET", handler); - virtualServer.getMethods().add("GET"); - } else { - for (String method : methods) { - methodHandlerMap.put(method, handler); - virtualServer.getMethods().add(method); - } - } - } -} diff --git a/netty-http-server/src/main/java/org/xbib/netty/http/server/context/ClasspathContextHandler.java b/netty-http-server/src/main/java/org/xbib/netty/http/server/endpoint/ClasspathHandler.java similarity index 85% rename from netty-http-server/src/main/java/org/xbib/netty/http/server/context/ClasspathContextHandler.java rename to netty-http-server/src/main/java/org/xbib/netty/http/server/endpoint/ClasspathHandler.java index dd58212..5679375 100644 --- a/netty-http-server/src/main/java/org/xbib/netty/http/server/context/ClasspathContextHandler.java +++ b/netty-http-server/src/main/java/org/xbib/netty/http/server/endpoint/ClasspathHandler.java @@ -1,4 +1,4 @@ -package org.xbib.netty.http.server.context; +package org.xbib.netty.http.server.endpoint; import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; @@ -16,19 +16,19 @@ import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; -public class ClasspathContextHandler implements ContextHandler { +public class ClasspathHandler implements Handler { private final ClassLoader classLoader; private final String prefix; - public ClasspathContextHandler(ClassLoader classLoader, String prefix) { + public ClasspathHandler(ClassLoader classLoader, String prefix) { this.classLoader = classLoader; this.prefix = prefix; } @Override - public void serve(ServerRequest serverRequest, ServerResponse serverResponse) throws IOException { + public void handle(ServerRequest serverRequest, ServerResponse serverResponse) throws IOException { String contextPath = serverRequest.getContextPath(); URL url = classLoader.getResource(prefix + contextPath); if (url != null) { diff --git a/netty-http-server/src/main/java/org/xbib/netty/http/server/context/Context.java b/netty-http-server/src/main/java/org/xbib/netty/http/server/endpoint/Context.java similarity index 78% rename from netty-http-server/src/main/java/org/xbib/netty/http/server/context/Context.java rename to netty-http-server/src/main/java/org/xbib/netty/http/server/endpoint/Context.java index 8112d27..0f7d9cd 100644 --- a/netty-http-server/src/main/java/org/xbib/netty/http/server/context/Context.java +++ b/netty-http-server/src/main/java/org/xbib/netty/http/server/endpoint/Context.java @@ -1,4 +1,4 @@ -package org.xbib.netty.http.server.context; +package org.xbib.netty.http.server.endpoint; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; @@ -7,11 +7,11 @@ import java.lang.annotation.Target; /** * The {@code Context} annotation decorates methods which are mapped - * to a context (path) within the server, and provide its contents. + * to a context path within the server, and provide its contents. * The annotated methods must have the same signature and contract - * as {@link ContextHandler#serve}, but can have arbitrary names. + * as {@link Handler#handle}, but can have arbitrary names. * - * @see VirtualServer#addContexts(Object) + * @see NamedServer#addHandlers(Object) */ @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.METHOD) diff --git a/netty-http-server/src/main/java/org/xbib/netty/http/server/context/DirectoryContextHandler.java b/netty-http-server/src/main/java/org/xbib/netty/http/server/endpoint/DirectoryHandler.java similarity index 81% rename from netty-http-server/src/main/java/org/xbib/netty/http/server/context/DirectoryContextHandler.java rename to netty-http-server/src/main/java/org/xbib/netty/http/server/endpoint/DirectoryHandler.java index 02b6e4d..a8b23d4 100644 --- a/netty-http-server/src/main/java/org/xbib/netty/http/server/context/DirectoryContextHandler.java +++ b/netty-http-server/src/main/java/org/xbib/netty/http/server/endpoint/DirectoryHandler.java @@ -1,4 +1,4 @@ -package org.xbib.netty.http.server.context; +package org.xbib.netty.http.server.endpoint; import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBufAllocator; @@ -13,19 +13,19 @@ import java.nio.channels.SeekableByteChannel; import java.nio.file.Files; import java.nio.file.Path; -public class DirectoryContextHandler implements ContextHandler { +public class DirectoryHandler implements Handler { private Path path; private ByteBufAllocator allocator; - public DirectoryContextHandler(Path path, ByteBufAllocator allocator) { + public DirectoryHandler(Path path, ByteBufAllocator allocator) { this.path = path; this.allocator = allocator; } @Override - public void serve(ServerRequest serverRequest, ServerResponse serverResponse) throws IOException { + public void handle(ServerRequest serverRequest, ServerResponse serverResponse) throws IOException { String uri = serverRequest.getRequest().uri(); Path p = path.resolve(uri); ByteBuf byteBuf = read(allocator, p); diff --git a/netty-http-server/src/main/java/org/xbib/netty/http/server/endpoint/Endpoint.java b/netty-http-server/src/main/java/org/xbib/netty/http/server/endpoint/Endpoint.java new file mode 100644 index 0000000..3929cda --- /dev/null +++ b/netty-http-server/src/main/java/org/xbib/netty/http/server/endpoint/Endpoint.java @@ -0,0 +1,46 @@ +package org.xbib.netty.http.server.endpoint; + +import java.util.LinkedHashMap; +import java.util.Map; + +/** + * The {@code Endpoint} class holds an endpoint information. + */ +public class Endpoint { + + private final NamedServer namedServer; + + private final Map handlerMap; + + public Endpoint(NamedServer namedServer) { + this.namedServer = namedServer; + this.handlerMap = new LinkedHashMap<>(); + } + + /** + * Returns the map of supported HTTP methods and their corresponding handlers. + * + * @return the map of supported HTTP methods and their corresponding handlers + */ + public Map getHandlerMap() { + return handlerMap; + } + + /** + * Adds (or replaces) a handler for the given HTTP methods. + * + * @param handler the handler + * @param methods the HTTP methods supported by the handler (default is "GET") + */ + public void addHandler(Handler handler, String... methods) { + if (methods.length == 0) { + handlerMap.put("GET", handler); + namedServer.getMethods().add("GET"); + } else { + for (String method : methods) { + handlerMap.put(method, handler); + namedServer.getMethods().add(method); + } + } + } +} diff --git a/netty-http-server/src/main/java/org/xbib/netty/http/server/endpoint/Handler.java b/netty-http-server/src/main/java/org/xbib/netty/http/server/endpoint/Handler.java new file mode 100644 index 0000000..56c4bb8 --- /dev/null +++ b/netty-http-server/src/main/java/org/xbib/netty/http/server/endpoint/Handler.java @@ -0,0 +1,24 @@ +package org.xbib.netty.http.server.endpoint; + +import org.xbib.netty.http.server.transport.ServerRequest; +import org.xbib.netty.http.server.transport.ServerResponse; + +import java.io.IOException; + +/** + * A {@code Handler} is capable of serving content for resources within its context. + * + * @see NamedServer#addHandler + */ +@FunctionalInterface +public interface Handler { + + /** + * Handles the given request by using the given response. + * + * @param serverRequest the request to be served + * @param serverResponse the response to be generated + * @throws IOException if an IO error occurs + */ + void handle(ServerRequest serverRequest, ServerResponse serverResponse) throws IOException; +} diff --git a/netty-http-server/src/main/java/org/xbib/netty/http/server/context/MethodContextHandler.java b/netty-http-server/src/main/java/org/xbib/netty/http/server/endpoint/MethodHandler.java similarity index 68% rename from netty-http-server/src/main/java/org/xbib/netty/http/server/context/MethodContextHandler.java rename to netty-http-server/src/main/java/org/xbib/netty/http/server/endpoint/MethodHandler.java index 24a83d5..c34bde1 100644 --- a/netty-http-server/src/main/java/org/xbib/netty/http/server/context/MethodContextHandler.java +++ b/netty-http-server/src/main/java/org/xbib/netty/http/server/endpoint/MethodHandler.java @@ -1,4 +1,4 @@ -package org.xbib.netty.http.server.context; +package org.xbib.netty.http.server.endpoint; import org.xbib.netty.http.server.transport.ServerRequest; import org.xbib.netty.http.server.transport.ServerResponse; @@ -8,20 +8,19 @@ import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; /** - * The {@code MethodContextHandler} services a context - * by invoking a handler method on a specified object. + * The {@code MethodHandler} invokes g a handler method on a specified object. * The method must have the same signature and contract as - * {@link ContextHandler#serve}, but can have an arbitrary name. + * {@link Handler#handle}, but can have an arbitrary name. * - * @see VirtualServer#addContexts(Object) + * @see NamedServer#addHandlers(Object) */ -public class MethodContextHandler implements ContextHandler { +public class MethodHandler implements Handler { private final Method m; private final Object obj; - public MethodContextHandler(Method m, Object obj) throws IllegalArgumentException { + public MethodHandler(Method m, Object obj) throws IllegalArgumentException { this.m = m; this.obj = obj; Class[] params = m.getParameterTypes(); @@ -34,7 +33,7 @@ public class MethodContextHandler implements ContextHandler { } @Override - public void serve(ServerRequest serverRequest, ServerResponse serverResponse) throws IOException { + public void handle(ServerRequest serverRequest, ServerResponse serverResponse) throws IOException { try { m.invoke(obj, serverRequest, serverResponse); } catch (InvocationTargetException ite) { diff --git a/netty-http-server/src/main/java/org/xbib/netty/http/server/endpoint/NamedEndpoint.java b/netty-http-server/src/main/java/org/xbib/netty/http/server/endpoint/NamedEndpoint.java new file mode 100644 index 0000000..0172937 --- /dev/null +++ b/netty-http-server/src/main/java/org/xbib/netty/http/server/endpoint/NamedEndpoint.java @@ -0,0 +1,21 @@ +package org.xbib.netty.http.server.endpoint; + +public class NamedEndpoint { + + private final String name; + + private final Endpoint endpoint; + + NamedEndpoint(String name, Endpoint endpoint) { + this.name = name; + this.endpoint = endpoint; + } + + public String getName() { + return name; + } + + public Endpoint getEndpoint() { + return endpoint; + } +} diff --git a/netty-http-server/src/main/java/org/xbib/netty/http/server/context/VirtualServer.java b/netty-http-server/src/main/java/org/xbib/netty/http/server/endpoint/NamedServer.java similarity index 74% rename from netty-http-server/src/main/java/org/xbib/netty/http/server/context/VirtualServer.java rename to netty-http-server/src/main/java/org/xbib/netty/http/server/endpoint/NamedServer.java index 9fb39ec..62d966b 100644 --- a/netty-http-server/src/main/java/org/xbib/netty/http/server/context/VirtualServer.java +++ b/netty-http-server/src/main/java/org/xbib/netty/http/server/endpoint/NamedServer.java @@ -1,4 +1,4 @@ -package org.xbib.netty.http.server.context; +package org.xbib.netty.http.server.endpoint; import java.lang.reflect.Method; import java.util.Collections; @@ -10,7 +10,7 @@ import java.util.Set; /** * The {@code VirtualServer} class represents a virtual server. */ -public class VirtualServer { +public class NamedServer { private final String name; @@ -18,28 +18,28 @@ public class VirtualServer { private final Set methods; - private final ContextInfo emptyContext; + private final Endpoint defaultEndpoint; - private final Map contexts; + private final Map endpointMap; private volatile boolean allowGeneratedIndex; - public VirtualServer() { + public NamedServer() { this(null); } /** - * Constructs a VirtualServer with the given name. + * Constructs a {@code NamedServer} with the given name. * * @param name the name, or null if it is the default server */ - public VirtualServer(String name) { + public NamedServer(String name) { this.name = name; this.aliases = new HashSet<>(); this.methods = new HashSet<>(); - this.contexts = new HashMap<>(); - this.emptyContext = new ContextInfo(this); - contexts.put("*", new ContextInfo(this)); // for "OPTIONS *" + this.endpointMap = new HashMap<>(); + this.defaultEndpoint = new Endpoint(this); + endpointMap.put("*", new Endpoint(this)); // for "OPTIONS *" } /** @@ -105,34 +105,36 @@ public class VirtualServer { * @param path the context's path (must start with '/') * @param handler the context handler for the given path * @param methods the HTTP methods supported by the context handler (default is "GET") + * @return this virtual server * @throws IllegalArgumentException if path is malformed */ - public VirtualServer addContext(String path, ContextHandler handler, String... methods) { + public NamedServer addHandler(String path, Handler handler, String... methods) { if (path == null || !path.startsWith("/") && !path.equals("*")) { throw new IllegalArgumentException("invalid path: " + path); } String s = trimRight(path, '/'); - ContextInfo info = new ContextInfo(this); - ContextInfo existing = contexts.putIfAbsent(s, info); + Endpoint info = new Endpoint(this); + Endpoint existing = endpointMap.putIfAbsent(s, info); info = existing != null ? existing : info; info.addHandler(handler, methods); return this; } /** - * Adds contexts for all methods of the given object that + * Adds handler for all methods of the given object that * are annotated with the {@link Context} annotation. * * @param o the object whose annotated methods are added + * @return this virtual server * @throws IllegalArgumentException if a Context-annotated * method has an {@link Context invalid signature} */ - public VirtualServer addContexts(Object o) throws IllegalArgumentException { + public NamedServer addHandlers(Object o) throws IllegalArgumentException { for (Class c = o.getClass(); c != null; c = c.getSuperclass()) { for (Method m : c.getDeclaredMethods()) { Context context = m.getAnnotation(Context.class); if (context != null) { - addContext(context.value(), new MethodContextHandler(m, o), context.methods()); + addHandler(context.value(), new MethodHandler(m, o), context.methods()); } } } @@ -140,24 +142,24 @@ public class VirtualServer { } /** - * Returns the context handler for the given path. - * If a context is not found for the given path, the search is repeated for + * Returns the endpoint for the given path. + * If an endpoint is not found for the given path, the search is repeated for * its parent path, and so on until a base context is found. If neither the * given path nor any of its parents has a context, an empty context is returned. * * @param path the context's path * @return the context info for the given path, or an empty context if none exists */ - public ContextPath getContextPath(String path) { + public NamedEndpoint getNamedEndpoint(String path) { String s = trimRight(path, '/'); - ContextInfo info = null; + Endpoint info = null; String hook = null; while (info == null && s != null) { hook = s; - info = contexts.get(s); + info = endpointMap.get(s); s = getParentPath(s); } - return new ContextPath(hook, info != null ? info : emptyContext); + return new NamedEndpoint(hook, info != null ? info : defaultEndpoint); } /** @@ -190,24 +192,4 @@ public class VirtualServer { return slash == -1 ? null : s.substring(0, slash); } - public class ContextPath { - - private final String hook; - - private final ContextInfo contextInfo; - - ContextPath(String hook, ContextInfo contextInfo) { - this.hook = hook; - this.contextInfo = contextInfo; - } - - public String getHook() { - return hook; - } - - public ContextInfo getContextInfo() { - return contextInfo; - } - } - } diff --git a/netty-http-server/src/main/java/org/xbib/netty/http/server/context/NioContextHandler.java b/netty-http-server/src/main/java/org/xbib/netty/http/server/endpoint/NioHandler.java similarity index 85% rename from netty-http-server/src/main/java/org/xbib/netty/http/server/context/NioContextHandler.java rename to netty-http-server/src/main/java/org/xbib/netty/http/server/endpoint/NioHandler.java index 3af4205..3365560 100644 --- a/netty-http-server/src/main/java/org/xbib/netty/http/server/context/NioContextHandler.java +++ b/netty-http-server/src/main/java/org/xbib/netty/http/server/endpoint/NioHandler.java @@ -1,4 +1,4 @@ -package org.xbib.netty.http.server.context; +package org.xbib.netty.http.server.endpoint; import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; @@ -13,11 +13,11 @@ import java.nio.channels.FileChannel; import java.nio.file.Files; import java.nio.file.Path; -public class NioContextHandler implements ContextHandler { +public class NioHandler implements Handler { private final Path prefix; - public NioContextHandler(Path prefix) { + public NioHandler(Path prefix) { this.prefix = prefix; if (!Files.exists(prefix) || !Files.isDirectory(prefix)) { throw new IllegalArgumentException("prefix: " + prefix + " (not a directory"); @@ -25,7 +25,7 @@ public class NioContextHandler implements ContextHandler { } @Override - public void serve(ServerRequest serverRequest, ServerResponse serverResponse) throws IOException { + public void handle(ServerRequest serverRequest, ServerResponse serverResponse) throws IOException { String requestPath = serverRequest.getRequestPath(); Path path = prefix.resolve(requestPath.substring(1)); // starts always with '/' if (Files.exists(path) && Files.isReadable(path)) { diff --git a/netty-http-server/src/main/java/org/xbib/netty/http/server/transport/BaseServerTransport.java b/netty-http-server/src/main/java/org/xbib/netty/http/server/transport/BaseServerTransport.java index cd17bc4..06dfbf2 100644 --- a/netty-http-server/src/main/java/org/xbib/netty/http/server/transport/BaseServerTransport.java +++ b/netty-http-server/src/main/java/org/xbib/netty/http/server/transport/BaseServerTransport.java @@ -6,8 +6,9 @@ import io.netty.handler.codec.http.HttpHeaders; import io.netty.handler.codec.http.HttpResponseStatus; import io.netty.handler.codec.http.HttpVersion; import org.xbib.netty.http.server.Server; -import org.xbib.netty.http.server.context.ContextHandler; -import org.xbib.netty.http.server.context.VirtualServer; +import org.xbib.netty.http.server.endpoint.Handler; +import org.xbib.netty.http.server.endpoint.NamedEndpoint; +import org.xbib.netty.http.server.endpoint.NamedServer; import java.io.IOException; import java.util.Arrays; @@ -88,28 +89,28 @@ abstract class BaseServerTransport implements ServerTransport { protected static void handle(ServerRequest serverRequest, ServerResponse serverResponse) throws IOException { String method = serverRequest.getRequest().method().name(); String path = serverRequest.getRequest().uri(); - VirtualServer virtualServer = serverRequest.getVirtualServer(); - VirtualServer.ContextPath contextPath = virtualServer.getContextPath(path); - serverRequest.setContextPath(contextPath.getHook()); - Map methodHandlerMap = contextPath.getContextInfo().getMethodHandlerMap(); + NamedServer namedServer = serverRequest.getNamedServer(); + NamedEndpoint namedEndpoint = namedServer.getNamedEndpoint(path); + serverRequest.setContextPath(namedEndpoint.getName()); + Map methodHandlerMap = namedEndpoint.getEndpoint().getHandlerMap(); // RFC 2616#5.1.1 - GET and HEAD must be supported if (method.equals("GET") || method.equals("HEAD") || methodHandlerMap.containsKey(method)) { - ContextHandler handler = methodHandlerMap.get(method); + Handler handler = methodHandlerMap.get(method); if (handler == null) { serverResponse.writeError(HttpResponseStatus.NOT_FOUND); } else { - handler.serve(serverRequest, serverResponse); + handler.handle(serverRequest, serverResponse); } } else { Set methods = new LinkedHashSet<>(METHODS); // "*" is a special server-wide (no-context) request supported by OPTIONS boolean isServerOptions = path.equals("*") && method.equals("OPTIONS"); - methods.addAll(isServerOptions ? virtualServer.getMethods() : methodHandlerMap.keySet()); + methods.addAll(isServerOptions ? namedServer.getMethods() : methodHandlerMap.keySet()); serverResponse.setHeader(HttpHeaderNames.ALLOW, String.join(", ", methods)); if (method.equals("OPTIONS")) { // default OPTIONS handler serverResponse.setHeader(HttpHeaderNames.CONTENT_LENGTH, "0"); // RFC2616#9.2 serverResponse.write(HttpResponseStatus.OK); - } else if (virtualServer.getMethods().contains(method)) { + } else if (namedServer.getMethods().contains(method)) { serverResponse.write(HttpResponseStatus.METHOD_NOT_ALLOWED); // supported by server, but not this context (nor built-in) } else { serverResponse.writeError(HttpResponseStatus.NOT_IMPLEMENTED); // unsupported method diff --git a/netty-http-server/src/main/java/org/xbib/netty/http/server/transport/Http2ServerTransport.java b/netty-http-server/src/main/java/org/xbib/netty/http/server/transport/Http2ServerTransport.java index 3280dfb..b3f42f6 100644 --- a/netty-http-server/src/main/java/org/xbib/netty/http/server/transport/Http2ServerTransport.java +++ b/netty-http-server/src/main/java/org/xbib/netty/http/server/transport/Http2ServerTransport.java @@ -8,7 +8,7 @@ import io.netty.handler.codec.http2.Http2Settings; import io.netty.handler.codec.http2.HttpConversionUtil; import org.xbib.netty.http.common.HttpAddress; import org.xbib.netty.http.server.Server; -import org.xbib.netty.http.server.context.VirtualServer; +import org.xbib.netty.http.server.endpoint.NamedServer; import java.io.IOException; @@ -26,13 +26,13 @@ public class Http2ServerTransport extends BaseServerTransport { @Override public void requestReceived(ChannelHandlerContext ctx, FullHttpRequest fullHttpRequest, Integer sequenceId) throws IOException { int requestId = requestCounter.incrementAndGet(); - VirtualServer virtualServer = server.getVirtualServer(fullHttpRequest.headers().get(HttpHeaderNames.HOST)); - if (virtualServer == null) { - virtualServer = server.getDefaultVirtualServer(); + NamedServer namedServer = server.getVirtualServer(fullHttpRequest.headers().get(HttpHeaderNames.HOST)); + if (namedServer == null) { + namedServer = server.getDefaultVirtualServer(); } HttpAddress httpAddress = server.getServerConfig().getAddress(); Integer streamId = fullHttpRequest.headers().getInt(HttpConversionUtil.ExtensionHeaderNames.STREAM_ID.text()); - ServerRequest serverRequest = new ServerRequest(virtualServer, httpAddress, fullHttpRequest, + ServerRequest serverRequest = new ServerRequest(namedServer, httpAddress, fullHttpRequest, sequenceId, streamId, requestId); ServerResponse serverResponse = new Http2ServerResponse(serverRequest, ctx); if (acceptRequest(serverRequest, serverResponse)) { diff --git a/netty-http-server/src/main/java/org/xbib/netty/http/server/transport/HttpServerTransport.java b/netty-http-server/src/main/java/org/xbib/netty/http/server/transport/HttpServerTransport.java index cfa2cba..9238c41 100644 --- a/netty-http-server/src/main/java/org/xbib/netty/http/server/transport/HttpServerTransport.java +++ b/netty-http-server/src/main/java/org/xbib/netty/http/server/transport/HttpServerTransport.java @@ -7,7 +7,7 @@ import io.netty.handler.codec.http.HttpResponseStatus; import io.netty.handler.codec.http2.Http2Settings; import org.xbib.netty.http.common.HttpAddress; import org.xbib.netty.http.server.Server; -import org.xbib.netty.http.server.context.VirtualServer; +import org.xbib.netty.http.server.endpoint.NamedServer; import java.io.IOException; @@ -26,12 +26,12 @@ public class HttpServerTransport extends BaseServerTransport { public void requestReceived(ChannelHandlerContext ctx, FullHttpRequest fullHttpRequest, Integer sequenceId) throws IOException { int requestId = requestCounter.incrementAndGet(); - VirtualServer virtualServer = server.getVirtualServer(fullHttpRequest.headers().get(HttpHeaderNames.HOST)); - if (virtualServer == null) { - virtualServer = server.getDefaultVirtualServer(); + NamedServer namedServer = server.getVirtualServer(fullHttpRequest.headers().get(HttpHeaderNames.HOST)); + if (namedServer == null) { + namedServer = server.getDefaultVirtualServer(); } HttpAddress httpAddress = server.getServerConfig().getAddress(); - ServerRequest serverRequest = new ServerRequest(virtualServer, httpAddress, fullHttpRequest, + ServerRequest serverRequest = new ServerRequest(namedServer, httpAddress, fullHttpRequest, sequenceId, null, requestId); ServerResponse serverResponse = new HttpServerResponse(serverRequest, ctx); if (acceptRequest(serverRequest, serverResponse)) { diff --git a/netty-http-server/src/main/java/org/xbib/netty/http/server/transport/ServerRequest.java b/netty-http-server/src/main/java/org/xbib/netty/http/server/transport/ServerRequest.java index 9b766cd..1903e93 100644 --- a/netty-http-server/src/main/java/org/xbib/netty/http/server/transport/ServerRequest.java +++ b/netty-http-server/src/main/java/org/xbib/netty/http/server/transport/ServerRequest.java @@ -2,14 +2,14 @@ package org.xbib.netty.http.server.transport; import io.netty.handler.codec.http.FullHttpRequest; import org.xbib.netty.http.common.HttpAddress; -import org.xbib.netty.http.server.context.VirtualServer; +import org.xbib.netty.http.server.endpoint.NamedServer; /** * The {@code ServerRequest} class encapsulates a single request. */ public class ServerRequest { - private final VirtualServer virtualServer; + private final NamedServer namedServer; private final HttpAddress httpAddress; @@ -23,9 +23,9 @@ public class ServerRequest { private String contextPath; - public ServerRequest(VirtualServer virtualServer, HttpAddress httpAddress, + public ServerRequest(NamedServer namedServer, HttpAddress httpAddress, FullHttpRequest httpRequest, Integer sequenceId, Integer streamId, Integer requestId) { - this.virtualServer = virtualServer; + this.namedServer = namedServer; this.httpAddress = httpAddress; this.httpRequest = httpRequest; this.sequenceId = sequenceId; @@ -33,8 +33,8 @@ public class ServerRequest { this.requestId = requestId; } - public VirtualServer getVirtualServer() { - return virtualServer; + public NamedServer getNamedServer() { + return namedServer; } public void setContextPath(String contextPath) { diff --git a/netty-http-server/src/test/java/org/xbib/netty/http/server/test/CleartextHttp1Test.java b/netty-http-server/src/test/java/org/xbib/netty/http/server/test/CleartextHttp1Test.java index b332bbb..6f5d43b 100644 --- a/netty-http-server/src/test/java/org/xbib/netty/http/server/test/CleartextHttp1Test.java +++ b/netty-http-server/src/test/java/org/xbib/netty/http/server/test/CleartextHttp1Test.java @@ -2,7 +2,8 @@ package org.xbib.netty.http.server.test; import io.netty.handler.codec.http.HttpResponseStatus; import io.netty.handler.codec.http.HttpVersion; -import org.junit.Test; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.xbib.netty.http.client.Client; import org.xbib.netty.http.client.Request; import org.xbib.netty.http.client.listener.ResponseListener; @@ -18,18 +19,19 @@ import java.util.concurrent.atomic.AtomicInteger; import java.util.logging.Level; import java.util.logging.Logger; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; -public class CleartextHttp1Test extends TestBase { +@ExtendWith(NettyHttpExtension.class) +class CleartextHttp1Test { private static final Logger logger = Logger.getLogger(CleartextHttp1Test.class.getName()); @Test - public void testSimpleClearTextHttp1() throws Exception { + void testSimpleClearTextHttp1() throws Exception { HttpAddress httpAddress = HttpAddress.http1("localhost", 8008); Server server = Server.builder() .bind(httpAddress).build(); - server.getDefaultVirtualServer().addContext("/", (request, response) -> + server.getDefaultVirtualServer().addHandler("/", (request, response) -> response.write(HttpResponseStatus.OK, "text/plain", request.getRequest().content().retain())); server.accept(); Client client = Client.builder() @@ -51,23 +53,20 @@ public class CleartextHttp1Test extends TestBase { client.shutdownGracefully(); server.shutdownGracefully(); } - logger.log(Level.INFO, "exepecting=1 counter=" + counter.get()); assertEquals(1, counter.get()); } @Test - public void testPooledClearTextHttp1() throws Exception { + void testPooledClearTextHttp1() throws Exception { int loop = 4096; HttpAddress httpAddress = HttpAddress.http1("localhost", 8008); Server server = Server.builder() - //.enableDebug() .bind(httpAddress).build(); - server.getDefaultVirtualServer().addContext("/", (request, response) -> { + server.getDefaultVirtualServer().addHandler("/", (request, response) -> { response.write(HttpResponseStatus.OK, "text/plain", request.getRequest().content().retain()); }); server.accept(); Client client = Client.builder() - //.enableDebug() .addPoolNode(httpAddress) .setPoolNodeConnectionLimit(2) .build(); @@ -96,19 +95,17 @@ public class CleartextHttp1Test extends TestBase { client.shutdownGracefully(); server.shutdownGracefully(); } - logger.log(Level.INFO, "expecting=" + loop + " counter=" + counter.get()); assertEquals(loop, counter.get()); } @Test - public void testMultithreadedPooledClearTextHttp1() throws Exception { + void testMultithreadedPooledClearTextHttp1() throws Exception { int threads = 4; int loop = 4 * 1024; HttpAddress httpAddress = HttpAddress.http1("localhost", 8008); Server server = Server.builder() - //.enableDebug() .bind(httpAddress).build(); - server.getDefaultVirtualServer().addContext("/", (request, response) -> { + server.getDefaultVirtualServer().addHandler("/", (request, response) -> { response.write(HttpResponseStatus.OK, "text/plain", request.getRequest().content().retain()); }); server.accept(); @@ -159,7 +156,6 @@ public class CleartextHttp1Test extends TestBase { client.shutdownGracefully(); server.shutdownGracefully(); } - logger.log(Level.INFO, "expecting=" + (threads * loop) + " counter=" + counter.get()); assertEquals(threads * loop, counter.get()); } } diff --git a/netty-http-server/src/test/java/org/xbib/netty/http/server/test/CleartextHttp2Test.java b/netty-http-server/src/test/java/org/xbib/netty/http/server/test/CleartextHttp2Test.java index ef4011d..66843db 100644 --- a/netty-http-server/src/test/java/org/xbib/netty/http/server/test/CleartextHttp2Test.java +++ b/netty-http-server/src/test/java/org/xbib/netty/http/server/test/CleartextHttp2Test.java @@ -1,7 +1,8 @@ package org.xbib.netty.http.server.test; import io.netty.handler.codec.http.HttpResponseStatus; -import org.junit.Test; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.xbib.netty.http.client.Client; import org.xbib.netty.http.client.Request; import org.xbib.netty.http.client.listener.ResponseListener; @@ -18,19 +19,20 @@ import java.util.concurrent.atomic.AtomicInteger; import java.util.logging.Level; import java.util.logging.Logger; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; -public class CleartextHttp2Test extends TestBase { +@ExtendWith(NettyHttpExtension.class) +class CleartextHttp2Test { private static final Logger logger = Logger.getLogger(CleartextHttp2Test.class.getName()); @Test - public void testSimpleCleartextHttp2() throws Exception { + void testSimpleCleartextHttp2() throws Exception { HttpAddress httpAddress = HttpAddress.http2("localhost", 8008); Server server = Server.builder() .bind(httpAddress) .build(); - server.getDefaultVirtualServer().addContext("/", (request, response) -> + server.getDefaultVirtualServer().addHandler("/", (request, response) -> response.write(HttpResponseStatus.OK, "text/plain", request.getRequest().content().retain())); server.accept(); Client client = Client.builder() @@ -60,23 +62,19 @@ public class CleartextHttp2Test extends TestBase { client.shutdownGracefully(); server.shutdownGracefully(); } - logger.log(Level.INFO, "counter = " + counter.get()); assertEquals(1, counter.get()); } @Test - public void testPooledClearTextHttp2() throws Exception { + void testPooledClearTextHttp2() throws Exception { int loop = 4096; HttpAddress httpAddress = HttpAddress.http2("localhost", 8008); Server server = Server.builder() .bind(httpAddress).build(); - server.getDefaultVirtualServer().addContext("/", (request, response) -> + server.getDefaultVirtualServer().addHandler("/", (request, response) -> response.write(HttpResponseStatus.OK, "text/plain", request.getRequest().content().retain())); - //server.getDefaultVirtualServer().addContext("/", (request, response) -> - // response.write(request.getRequest().content().toString(StandardCharsets.UTF_8))); server.accept(); Client client = Client.builder() - //.enableDebug() .addPoolNode(httpAddress) .setPoolNodeConnectionLimit(2) .build(); @@ -114,14 +112,14 @@ public class CleartextHttp2Test extends TestBase { } @Test - public void testMultithreadPooledClearTextHttp2() throws Exception { + void testMultithreadPooledClearTextHttp2() throws Exception { int threads = 2; int loop = 4 * 1024; HttpAddress httpAddress = HttpAddress.http2("localhost", 8008); Server server = Server.builder() .bind(httpAddress) .build(); - server.getDefaultVirtualServer().addContext("/", (request, response) -> + server.getDefaultVirtualServer().addHandler("/", (request, response) -> response.write(request.getRequest().content().toString(StandardCharsets.UTF_8)) ); server.accept(); @@ -176,7 +174,7 @@ public class CleartextHttp2Test extends TestBase { } @Test - public void testTwoPooledClearTextHttp2() throws Exception { + void testTwoPooledClearTextHttp2() throws Exception { int threads = 2; int loop = 4 * 1024; @@ -184,7 +182,7 @@ public class CleartextHttp2Test extends TestBase { AtomicInteger counter1 = new AtomicInteger(); Server server1 = Server.builder() .bind(httpAddress1).build(); - server1.getDefaultVirtualServer().addContext("/", (request, response) -> { + server1.getDefaultVirtualServer().addHandler("/", (request, response) -> { response.write(request.getRequest().content().toString(StandardCharsets.UTF_8)); counter1.incrementAndGet(); }); @@ -194,7 +192,7 @@ public class CleartextHttp2Test extends TestBase { AtomicInteger counter2 = new AtomicInteger(); Server server2 = Server.builder() .bind(httpAddress2).build(); - server2.getDefaultVirtualServer().addContext("/", (request, response) -> { + server2.getDefaultVirtualServer().addHandler("/", (request, response) -> { response.write(request.getRequest().content().toString(StandardCharsets.UTF_8)); counter2.incrementAndGet(); }); @@ -240,9 +238,9 @@ public class CleartextHttp2Test extends TestBase { }); } executorService.shutdown(); - boolean terminated = executorService.awaitTermination(30, TimeUnit.SECONDS); + boolean terminated = executorService.awaitTermination(60, TimeUnit.SECONDS); logger.log(Level.INFO, "terminated = " + terminated + ", now waiting for transport to complete"); - transport.get(30, TimeUnit.SECONDS); + transport.get(60, TimeUnit.SECONDS); } finally { client.shutdownGracefully(); server1.shutdownGracefully(); @@ -250,6 +248,6 @@ public class CleartextHttp2Test extends TestBase { } logger.log(Level.INFO, "counter1=" + counter1.get() + " counter2=" + counter2.get()); logger.log(Level.INFO, "expecting=" + threads * loop + " counter=" + counter.get()); - //assertEquals(threads * loop, counter.get()); + assertEquals(threads * loop, counter.get()); } } diff --git a/netty-http-client/src/test/java/org/xbib/TestBase.java b/netty-http-server/src/test/java/org/xbib/netty/http/server/test/NettyHttpExtension.java similarity index 69% rename from netty-http-client/src/test/java/org/xbib/TestBase.java rename to netty-http-server/src/test/java/org/xbib/netty/http/server/test/NettyHttpExtension.java index 1449c1e..ef96f3d 100644 --- a/netty-http-client/src/test/java/org/xbib/TestBase.java +++ b/netty-http-server/src/test/java/org/xbib/netty/http/server/test/NettyHttpExtension.java @@ -1,5 +1,10 @@ -package org.xbib; +package org.xbib.netty.http.server.test; +import org.bouncycastle.jce.provider.BouncyCastleProvider; +import org.junit.jupiter.api.extension.BeforeAllCallback; +import org.junit.jupiter.api.extension.ExtensionContext; + +import java.security.Security; import java.util.logging.ConsoleHandler; import java.util.logging.Handler; import java.util.logging.Level; @@ -7,9 +12,13 @@ import java.util.logging.LogManager; import java.util.logging.Logger; import java.util.logging.SimpleFormatter; -public class TestBase { +public class NettyHttpExtension implements BeforeAllCallback { - static { + @Override + public void beforeAll(ExtensionContext context) { + if (Security.getProvider("BC") == null) { + Security.addProvider(new BouncyCastleProvider()); + } System.setProperty("io.netty.noUnsafe", Boolean.toString(true)); System.setProperty("io.netty.noKeySetOptimization", Boolean.toString(true)); //System.setProperty("io.netty.recycler.maxCapacity", Integer.toString(0)); diff --git a/netty-http-server/src/test/java/org/xbib/netty/http/server/test/SecureHttp1Test.java b/netty-http-server/src/test/java/org/xbib/netty/http/server/test/SecureHttp1Test.java index 322eaa2..3859cc4 100644 --- a/netty-http-server/src/test/java/org/xbib/netty/http/server/test/SecureHttp1Test.java +++ b/netty-http-server/src/test/java/org/xbib/netty/http/server/test/SecureHttp1Test.java @@ -2,8 +2,8 @@ package org.xbib.netty.http.server.test; import io.netty.handler.codec.http.HttpResponseStatus; import io.netty.handler.codec.http.HttpVersion; -import org.bouncycastle.jce.provider.BouncyCastleProvider; -import org.junit.Test; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.xbib.netty.http.client.Client; import org.xbib.netty.http.client.Request; import org.xbib.netty.http.client.listener.ResponseListener; @@ -13,7 +13,6 @@ import org.xbib.netty.http.server.Server; import java.io.IOException; import java.nio.charset.StandardCharsets; -import java.security.Security; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.TimeUnit; @@ -21,20 +20,15 @@ import java.util.concurrent.atomic.AtomicInteger; import java.util.logging.Level; import java.util.logging.Logger; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; -public class SecureHttp1Test extends TestBase { +@ExtendWith(NettyHttpExtension.class) +class SecureHttp1Test { private static final Logger logger = Logger.getLogger(SecureHttp1Test.class.getName()); - static { - if (Security.getProvider("BC") == null) { - Security.addProvider(new BouncyCastleProvider()); - } - } - @Test - public void testSimpleSecureHttp1() throws Exception { + void testSimpleSecureHttp1() throws Exception { Server server = Server.builder() .setJdkSslProvider() .setSelfCert() @@ -51,7 +45,7 @@ public class SecureHttp1Test extends TestBase { counter.getAndIncrement(); }; try { - server.getDefaultVirtualServer().addContext("/", (request, response) -> + server.getDefaultVirtualServer().addHandler("/", (request, response) -> response.write(HttpResponseStatus.OK, "text/plain", request.getRequest().content().retain())); server.accept(); Request request = Request.get().setVersion(HttpVersion.HTTP_1_1) @@ -63,19 +57,18 @@ public class SecureHttp1Test extends TestBase { client.shutdownGracefully(); server.shutdownGracefully(); } - logger.log(Level.INFO, "counter=" + counter.get()); assertEquals(1, counter.get()); } @Test - public void testPooledSecureHttp1() throws Exception { + void testPooledSecureHttp1() throws Exception { int loop = 4096; HttpAddress httpAddress = HttpAddress.secureHttp1("localhost", 8143); Server server = Server.builder() .setJdkSslProvider() .setSelfCert() .bind(httpAddress).build(); - server.getDefaultVirtualServer().addContext("/", (request, response) -> + server.getDefaultVirtualServer().addHandler("/", (request, response) -> response.write(HttpResponseStatus.OK, "text/plain", request.getRequest().content().retain())); server.accept(); Client client = Client.builder() @@ -114,7 +107,7 @@ public class SecureHttp1Test extends TestBase { } @Test - public void testMultithreadPooledSecureHttp1() throws Exception { + void testMultithreadPooledSecureHttp1() throws Exception { int threads = 4; int loop = 4 * 1024; HttpAddress httpAddress = HttpAddress.secureHttp1("localhost", 8143); @@ -123,7 +116,7 @@ public class SecureHttp1Test extends TestBase { .setSelfCert() .bind(httpAddress) .build(); - server.getDefaultVirtualServer().addContext("/", (request, response) -> + server.getDefaultVirtualServer().addHandler("/", (request, response) -> response.write(HttpResponseStatus.OK, "text/plain", request.getRequest().content().retain()) ); server.accept(); @@ -147,7 +140,7 @@ public class SecureHttp1Test extends TestBase { executorService.submit(() -> { try { for (int i = 0; i < loop; i++) { - String payload = Integer.toString(t) + "/" + Integer.toString(i); + String payload = t + "/" + i; Request request = Request.get().setVersion(HttpVersion.HTTP_1_1) .url(server.getServerConfig().getAddress().base()) .content(payload, "text/plain") @@ -168,13 +161,12 @@ public class SecureHttp1Test extends TestBase { }); } executorService.shutdown(); - boolean terminated = executorService.awaitTermination(30, TimeUnit.SECONDS); + boolean terminated = executorService.awaitTermination(60, TimeUnit.SECONDS); logger.log(Level.INFO, "terminated = " + terminated); } finally { client.shutdownGracefully(); server.shutdownGracefully(); } - logger.log(Level.INFO, "expecting=" + (threads * loop) + " counter=" + counter.get()); assertEquals(threads * loop , counter.get()); } } diff --git a/netty-http-server/src/test/java/org/xbib/netty/http/server/test/SecureHttp2Test.java b/netty-http-server/src/test/java/org/xbib/netty/http/server/test/SecureHttp2Test.java index 805bd31..05ef17b 100644 --- a/netty-http-server/src/test/java/org/xbib/netty/http/server/test/SecureHttp2Test.java +++ b/netty-http-server/src/test/java/org/xbib/netty/http/server/test/SecureHttp2Test.java @@ -1,8 +1,8 @@ package org.xbib.netty.http.server.test; import io.netty.handler.codec.http.HttpResponseStatus; -import org.bouncycastle.jce.provider.BouncyCastleProvider; -import org.junit.Test; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.xbib.netty.http.client.Client; import org.xbib.netty.http.client.Request; import org.xbib.netty.http.client.listener.ResponseListener; @@ -12,7 +12,6 @@ import org.xbib.netty.http.server.Server; import java.io.IOException; import java.nio.charset.StandardCharsets; -import java.security.Security; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.TimeUnit; @@ -20,27 +19,22 @@ import java.util.concurrent.atomic.AtomicInteger; import java.util.logging.Level; import java.util.logging.Logger; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; -public class SecureHttp2Test extends TestBase { +@ExtendWith(NettyHttpExtension.class) +class SecureHttp2Test { private static final Logger logger = Logger.getLogger(SecureHttp2Test.class.getName()); - static { - if (Security.getProvider("BC") == null) { - Security.addProvider(new BouncyCastleProvider()); - } - } - @Test - public void testSimpleSecureHttp2() throws Exception { + void testSimpleSecureHttp2() throws Exception { HttpAddress httpAddress = HttpAddress.secureHttp2("localhost", 8143); Server server = Server.builder() .setJdkSslProvider() .setSelfCert() .bind(httpAddress) .build(); - server.getDefaultVirtualServer().addContext("/", (request, response) -> + server.getDefaultVirtualServer().addHandler("/", (request, response) -> response.write(HttpResponseStatus.OK, "text/plain", request.getRequest().content().retain())); server.accept(); Client client = Client.builder() @@ -57,7 +51,7 @@ public class SecureHttp2Test extends TestBase { }; try { Transport transport = client.newTransport(httpAddress); - String payload = Integer.toString(0) + "/" + Integer.toString(0); + String payload = 0 + "/" + 0; Request request = Request.get() .setVersion("HTTP/2.0") .uri("/") @@ -71,12 +65,11 @@ public class SecureHttp2Test extends TestBase { client.shutdownGracefully(); server.shutdownGracefully(); } - logger.log(Level.INFO, "counter = " + counter.get()); assertEquals(1, counter.get()); } @Test - public void testPooledSecureHttp2() throws Exception { + void testPooledSecureHttp2() throws Exception { int loop = 4096; HttpAddress httpAddress = HttpAddress.secureHttp2("localhost", 8143); Server server = Server.builder() @@ -84,7 +77,7 @@ public class SecureHttp2Test extends TestBase { .setSelfCert() .bind(httpAddress) .build(); - server.getDefaultVirtualServer().addContext("/", (request, response) -> + server.getDefaultVirtualServer().addHandler("/", (request, response) -> response.write(HttpResponseStatus.OK, "text/plain", request.getRequest().content().retain())); server.accept(); Client client = Client.builder() @@ -122,12 +115,11 @@ public class SecureHttp2Test extends TestBase { client.shutdownGracefully(); server.shutdownGracefully(); } - logger.log(Level.INFO, "counter=" + counter.get()); assertEquals(loop, counter.get()); } @Test - public void testMultithreadPooledSecureHttp2() throws Exception { + void testMultithreadPooledSecureHttp2() throws Exception { int threads = 4; int loop = 4 * 1024; HttpAddress httpAddress = HttpAddress.secureHttp2("localhost", 8143); @@ -136,7 +128,7 @@ public class SecureHttp2Test extends TestBase { .setSelfCert() .bind(httpAddress) .build(); - server.getDefaultVirtualServer().addContext("/", (request, response) -> + server.getDefaultVirtualServer().addHandler("/", (request, response) -> response.write(HttpResponseStatus.OK, "text/plain", request.getRequest().content().retain()) ); server.accept(); @@ -163,7 +155,7 @@ public class SecureHttp2Test extends TestBase { executorService.submit(() -> { try { for (int i = 0; i < loop; i++) { - String payload = Integer.toString(t) + "/" + Integer.toString(i); + String payload = t + "/" + i; Request request = Request.get().setVersion("HTTP/2.0") .url(server.getServerConfig().getAddress().base()) .content(payload, "text/plain") @@ -181,14 +173,13 @@ public class SecureHttp2Test extends TestBase { }); } executorService.shutdown(); - boolean terminated = executorService.awaitTermination(30, TimeUnit.SECONDS); + boolean terminated = executorService.awaitTermination(60, TimeUnit.SECONDS); logger.log(Level.INFO, "terminated = " + terminated + ", now waiting for transport to complete"); - transport.get(30, TimeUnit.SECONDS); + transport.get(60, TimeUnit.SECONDS); } finally { client.shutdownGracefully(); server.shutdownGracefully(); } - logger.log(Level.INFO, "expected=" + (threads * loop) + " counter=" + counter.get()); assertEquals(threads * loop , counter.get()); } } diff --git a/netty-http-server/src/test/java/org/xbib/netty/http/server/test/SelfSignedCertificateTest.java b/netty-http-server/src/test/java/org/xbib/netty/http/server/test/SelfSignedCertificateTest.java index ecea3b2..64e1e15 100644 --- a/netty-http-server/src/test/java/org/xbib/netty/http/server/test/SelfSignedCertificateTest.java +++ b/netty-http-server/src/test/java/org/xbib/netty/http/server/test/SelfSignedCertificateTest.java @@ -1,16 +1,16 @@ package org.xbib.netty.http.server.test; import org.bouncycastle.jce.provider.BouncyCastleProvider; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.xbib.netty.http.server.security.tls.SelfSignedCertificate; import java.security.Security; import java.util.logging.Logger; -public class SelfSignedCertificateTest { +class SelfSignedCertificateTest { @Test - public void testSelfSignedCertificate() throws Exception { + void testSelfSignedCertificate() throws Exception { Security.addProvider(new BouncyCastleProvider()); SelfSignedCertificate selfSignedCertificate = new SelfSignedCertificate("localhost"); selfSignedCertificate.exportPEM(Logger.getLogger("test")); diff --git a/netty-http-server/src/test/java/org/xbib/netty/http/server/test/ServerTest.java b/netty-http-server/src/test/java/org/xbib/netty/http/server/test/ServerTest.java index cc8db3c..b25766c 100644 --- a/netty-http-server/src/test/java/org/xbib/netty/http/server/test/ServerTest.java +++ b/netty-http-server/src/test/java/org/xbib/netty/http/server/test/ServerTest.java @@ -1,17 +1,17 @@ package org.xbib.netty.http.server.test; -import org.junit.Ignore; -import org.junit.Test; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; import org.xbib.netty.http.server.Server; -@Ignore -public class ServerTest { +@Disabled +class ServerTest { @Test - public void testServer() throws Exception { + void testServer() throws Exception { Server server = Server.builder() .build(); - server.getDefaultVirtualServer().addContext("/", (request, response) -> + server.getDefaultVirtualServer().addHandler("/", (request, response) -> response.write("Hello World")); try { server.accept().channel().closeFuture().sync(); diff --git a/netty-http-server/src/test/java/org/xbib/netty/http/server/test/StaticFileServerTest.java b/netty-http-server/src/test/java/org/xbib/netty/http/server/test/StaticFileServerTest.java index 346dec1..df09000 100644 --- a/netty-http-server/src/test/java/org/xbib/netty/http/server/test/StaticFileServerTest.java +++ b/netty-http-server/src/test/java/org/xbib/netty/http/server/test/StaticFileServerTest.java @@ -1,12 +1,12 @@ package org.xbib.netty.http.server.test; import io.netty.handler.codec.http.HttpVersion; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.xbib.netty.http.client.Client; import org.xbib.netty.http.client.Request; +import org.xbib.netty.http.common.HttpAddress; import org.xbib.netty.http.server.Server; -import org.xbib.netty.http.server.context.NioContextHandler; -import org.xbib.netty.http.server.context.VirtualServer; +import org.xbib.netty.http.server.endpoint.NioHandler; import java.nio.charset.StandardCharsets; import java.nio.file.Files; @@ -16,18 +16,19 @@ import java.util.concurrent.atomic.AtomicBoolean; import java.util.logging.Level; import java.util.logging.Logger; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; -public class StaticFileServerTest { +class StaticFileServerTest { private static final Logger logger = Logger.getLogger(StaticFileServerTest.class.getName()); @Test - public void testStaticFileServer() throws Exception { + void testStaticFileServer() throws Exception { Path vartmp = Paths.get("/var/tmp/"); Server server = Server.builder() - .addVirtualServer(new VirtualServer().addContext("/static", new NioContextHandler(vartmp))) + .bind(HttpAddress.http1("localhost", 8008)) + .addHandler("/static", new NioHandler(vartmp)) .build(); Client client = Client.builder() .build(); diff --git a/netty-http-server/src/test/java/org/xbib/netty/http/server/test/ThreadLeakTest.java b/netty-http-server/src/test/java/org/xbib/netty/http/server/test/ThreadLeakTest.java index ecbe611..04037e9 100644 --- a/netty-http-server/src/test/java/org/xbib/netty/http/server/test/ThreadLeakTest.java +++ b/netty-http-server/src/test/java/org/xbib/netty/http/server/test/ThreadLeakTest.java @@ -1,8 +1,10 @@ package org.xbib.netty.http.server.test; import io.netty.buffer.UnpooledByteBufAllocator; -import org.junit.After; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.extension.ExtendWith; import org.xbib.netty.http.server.Server; import java.io.IOException; @@ -10,16 +12,18 @@ import java.util.Set; import java.util.logging.Level; import java.util.logging.Logger; -public class ThreadLeakTest extends TestBase { +@TestInstance(TestInstance.Lifecycle.PER_CLASS) +@ExtendWith(NettyHttpExtension.class) +class ThreadLeakTest { private static final Logger logger = Logger.getLogger(ThreadLeakTest.class.getName()); @Test - public void testForLeaks() throws IOException { + void testForLeaks() throws IOException { Server server = Server.builder() .setByteBufAllocator(UnpooledByteBufAllocator.DEFAULT) .build(); - server.getDefaultVirtualServer().addContext("/", (request, response) -> + server.getDefaultVirtualServer().addHandler("/", (request, response) -> response.write("Hello World")); try { server.accept(); @@ -28,8 +32,8 @@ public class ThreadLeakTest extends TestBase { } } - @After - public void checkThreads() throws Exception { + @AfterAll + void checkThreads() throws Exception { Thread.sleep(1000L); System.gc(); Thread.sleep(3000L); diff --git a/netty-http-server/src/test/java/org/xbib/netty/http/server/test/hacks/CleartextHttp2Test.java b/netty-http-server/src/test/java/org/xbib/netty/http/server/test/hacks/CleartextHttp2Test.java index 44b1fe3..cea7c1b 100644 --- a/netty-http-server/src/test/java/org/xbib/netty/http/server/test/hacks/CleartextHttp2Test.java +++ b/netty-http-server/src/test/java/org/xbib/netty/http/server/test/hacks/CleartextHttp2Test.java @@ -29,9 +29,9 @@ import io.netty.handler.codec.http2.HttpToHttp2ConnectionHandlerBuilder; import io.netty.handler.codec.http2.InboundHttp2ToHttpAdapterBuilder; import io.netty.handler.logging.LogLevel; import io.netty.handler.logging.LoggingHandler; -import org.junit.Ignore; -import org.junit.Test; -import org.xbib.netty.http.server.test.TestBase; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.xbib.netty.http.server.test.NettyHttpExtension; import java.net.InetSocketAddress; import java.util.concurrent.CompletableFuture; @@ -39,8 +39,8 @@ import java.util.concurrent.TimeUnit; import java.util.logging.Level; import java.util.logging.Logger; -@Ignore -public class CleartextHttp2Test extends TestBase { +@ExtendWith(NettyHttpExtension.class) +class CleartextHttp2Test { private static final Logger clientLogger = Logger.getLogger("client"); private static final Logger serverLogger = Logger.getLogger("server"); @@ -56,17 +56,12 @@ public class CleartextHttp2Test extends TestBase { private CompletableFuture completableFuture; @Test - public void testHttp2() throws Exception { - + void testHttp2() throws Exception { final InetSocketAddress inetSocketAddress = new InetSocketAddress("localhost", 8008); - settingsPrefaceFuture = new CompletableFuture<>(); - completableFuture = new CompletableFuture<>(); - EventLoopGroup serverEventLoopGroup = new NioEventLoopGroup(); EventLoopGroup clientEventLoopGroup = new NioEventLoopGroup(); - try { Http2Connection http2ServerConnection = new DefaultHttp2Connection(true); ServerBootstrap serverBootstrap = new ServerBootstrap() @@ -132,7 +127,7 @@ public class CleartextHttp2Test extends TestBase { clientChannel.writeAndFlush(request); clientLogger.log(level, "waiting"); - completableFuture.get(10, TimeUnit.SECONDS); + completableFuture.get(30, TimeUnit.SECONDS); if (completableFuture.isDone()) { clientLogger.log(Level.INFO, "done"); } diff --git a/netty-http-server/src/test/java/org/xbib/netty/http/server/test/hacks/HttpPipeliningHandlerTest.java b/netty-http-server/src/test/java/org/xbib/netty/http/server/test/hacks/HttpPipeliningHandlerTest.java index 3005170..9eee791 100644 --- a/netty-http-server/src/test/java/org/xbib/netty/http/server/test/hacks/HttpPipeliningHandlerTest.java +++ b/netty-http-server/src/test/java/org/xbib/netty/http/server/test/hacks/HttpPipeliningHandlerTest.java @@ -18,13 +18,15 @@ import io.netty.handler.codec.http.HttpResponseStatus; import io.netty.handler.codec.http.HttpVersion; import io.netty.handler.codec.http.LastHttpContent; import io.netty.handler.codec.http.QueryStringDecoder; -import org.junit.After; -import org.junit.Ignore; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.extension.ExtendWith; import org.xbib.netty.http.server.handler.http.HttpPipelinedRequest; import org.xbib.netty.http.server.handler.http.HttpPipelinedResponse; import org.xbib.netty.http.server.handler.http.HttpPipeliningHandler; -import org.xbib.netty.http.server.test.TestBase; +import org.xbib.netty.http.server.test.NettyHttpExtension; import java.nio.channels.ClosedChannelException; import java.nio.charset.StandardCharsets; @@ -42,26 +44,30 @@ import java.util.concurrent.TimeUnit; import java.util.logging.Level; import java.util.logging.Logger; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.core.Is.is; -import static org.junit.Assert.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; -@Ignore -public class HttpPipeliningHandlerTest extends TestBase { +/** flaky */ +@Disabled +@TestInstance(TestInstance.Lifecycle.PER_CLASS) +@ExtendWith(NettyHttpExtension.class) +class HttpPipeliningHandlerTest { private static final Logger logger = Logger.getLogger(HttpPipeliningHandlerTest.class.getName()); private static Map waitingRequests = new ConcurrentHashMap<>(); - @After - public void closeResources() { + @AfterAll + void closeResources() { for (String url : waitingRequests.keySet()) { finishRequest(url); } } @Test - public void testThatPipeliningWorksWithFastSerializedRequests() { + void testThatPipeliningWorksWithFastSerializedRequests() { WorkEmulatorHandler handler = new WorkEmulatorHandler(); EmbeddedChannel embeddedChannel = new EmbeddedChannel(new HttpPipeliningHandler(10000), handler); @@ -75,11 +81,11 @@ public class HttpPipeliningHandlerTest extends TestBase { for (int i = 0; i < 5; i++) { assertReadHttpMessageHasContent(embeddedChannel, String.valueOf(i)); } - assertThat(embeddedChannel.isOpen(), is(true)); + assertTrue(embeddedChannel.isOpen()); } @Test - public void testThatPipeliningWorksWhenSlowRequestsInDifferentOrder() { + void testThatPipeliningWorksWhenSlowRequestsInDifferentOrder() { WorkEmulatorHandler handler = new WorkEmulatorHandler(); EmbeddedChannel embeddedChannel = new EmbeddedChannel(new HttpPipeliningHandler(10000), handler); @@ -95,11 +101,11 @@ public class HttpPipeliningHandlerTest extends TestBase { for (int i = 0; i < 5; i++) { assertReadHttpMessageHasContent(embeddedChannel, String.valueOf(i)); } - assertThat(embeddedChannel.isOpen(), is(true)); + assertTrue(embeddedChannel.isOpen()); } @Test - public void testThatPipeliningWorksWithChunkedRequests() { + void testThatPipeliningWorksWithChunkedRequests() { WorkEmulatorHandler handler = new WorkEmulatorHandler(); EmbeddedChannel embeddedChannel = new EmbeddedChannel(new AggregateUrisAndHeadersHandler(), new HttpPipeliningHandler(10000), handler); @@ -115,32 +121,34 @@ public class HttpPipeliningHandlerTest extends TestBase { for (int i = 0; i < 2; i++) { assertReadHttpMessageHasContent(embeddedChannel, String.valueOf(i)); } - assertThat(embeddedChannel.isOpen(), is(true)); + assertTrue(embeddedChannel.isOpen()); } - @Test(expected = ClosedChannelException.class) - public void testThatPipeliningClosesConnectionWithTooManyEvents() { - WorkEmulatorHandler handler = new WorkEmulatorHandler(); - EmbeddedChannel embeddedChannel = new EmbeddedChannel(new HttpPipeliningHandler(2), - handler); - embeddedChannel.writeInbound(createHttpRequest("/0")); - embeddedChannel.writeInbound(createHttpRequest("/1")); - embeddedChannel.writeInbound(createHttpRequest("/2")); - embeddedChannel.writeInbound(createHttpRequest("/3")); - finishRequest("1"); - finishRequest("2"); - finishRequest("3"); - finishRequest("0"); - handler.shutdownExecutorService(); - embeddedChannel.writeInbound(createHttpRequest("/")); + @Test + void testThatPipeliningClosesConnectionWithTooManyEvents() { + assertThrows(ClosedChannelException.class, () -> { + WorkEmulatorHandler handler = new WorkEmulatorHandler(); + EmbeddedChannel embeddedChannel = new EmbeddedChannel(new HttpPipeliningHandler(2), + handler); + embeddedChannel.writeInbound(createHttpRequest("/0")); + embeddedChannel.writeInbound(createHttpRequest("/1")); + embeddedChannel.writeInbound(createHttpRequest("/2")); + embeddedChannel.writeInbound(createHttpRequest("/3")); + finishRequest("1"); + finishRequest("2"); + finishRequest("3"); + finishRequest("0"); + handler.shutdownExecutorService(); + embeddedChannel.writeInbound(createHttpRequest("/")); + }); } private void assertReadHttpMessageHasContent(EmbeddedChannel embeddedChannel, String expectedContent) { FullHttpResponse response = (FullHttpResponse) embeddedChannel.outboundMessages().poll(); - assertNotNull("Expected response to exist, maybe you did not wait long enough?", response); - assertNotNull("Expected response to have content " + expectedContent, response.content()); + assertNotNull(response); + assertNotNull(response.content()); String data = new String(ByteBufUtil.getBytes(response.content()), StandardCharsets.UTF_8); - assertThat(data, is(expectedContent)); + assertEquals(expectedContent, data); } private void finishRequest(String url) { @@ -163,7 +171,7 @@ public class HttpPipeliningHandlerTest extends TestBase { private class WorkEmulatorHandler extends SimpleChannelInboundHandler { - private final ExecutorService executorService = Executors.newFixedThreadPool(5); + private final ExecutorService executorService = Executors.newFixedThreadPool(8); @Override protected void channelRead0(ChannelHandlerContext ctx, HttpPipelinedRequest pipelinedRequest) { @@ -181,6 +189,7 @@ public class HttpPipeliningHandlerTest extends TestBase { httpResponse.headers().add(HttpHeaderNames.CONTENT_LENGTH, content.readableBytes()); CountDownLatch latch = new CountDownLatch(1); waitingRequests.put(uri, latch); + // can cause RejectedExecutionException if executorService is too small executorService.submit(() -> { try { latch.await(2, TimeUnit.SECONDS); diff --git a/netty-http-server/src/test/java/org/xbib/netty/http/server/test/hacks/MultiplexCodecCleartextHttp2Test.java b/netty-http-server/src/test/java/org/xbib/netty/http/server/test/hacks/MultiplexCodecCleartextHttp2Test.java index eb0a8e8..723669c 100644 --- a/netty-http-server/src/test/java/org/xbib/netty/http/server/test/hacks/MultiplexCodecCleartextHttp2Test.java +++ b/netty-http-server/src/test/java/org/xbib/netty/http/server/test/hacks/MultiplexCodecCleartextHttp2Test.java @@ -25,7 +25,6 @@ import io.netty.handler.codec.http.HttpServerUpgradeHandler; import io.netty.handler.codec.http.HttpVersion; import io.netty.handler.codec.http2.CleartextHttp2ServerUpgradeHandler; import io.netty.handler.codec.http2.DefaultHttp2Headers; -//import io.netty.handler.codec.http2.DefaultHttp2PushPromiseFrame; import io.netty.handler.codec.http2.DefaultHttp2HeadersFrame; import io.netty.handler.codec.http2.Http2CodecUtil; import io.netty.handler.codec.http2.Http2ConnectionPrefaceAndSettingsFrameWrittenEvent; @@ -41,9 +40,9 @@ import io.netty.handler.codec.http2.Http2StreamFrameToHttpObjectCodec; import io.netty.handler.logging.LogLevel; import io.netty.handler.logging.LoggingHandler; import io.netty.util.AsciiString; -import org.junit.Ignore; -import org.junit.Test; -import org.xbib.netty.http.server.test.TestBase; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.xbib.netty.http.server.test.NettyHttpExtension; import java.net.InetSocketAddress; import java.util.concurrent.CompletableFuture; @@ -69,8 +68,8 @@ import java.util.logging.Logger; * * */ -@Ignore -public class MultiplexCodecCleartextHttp2Test extends TestBase { +@ExtendWith(NettyHttpExtension.class) +class MultiplexCodecCleartextHttp2Test { private static final Logger clientLogger = Logger.getLogger("client"); private static final Logger serverLogger = Logger.getLogger("server"); @@ -82,14 +81,11 @@ public class MultiplexCodecCleartextHttp2Test extends TestBase { private final CompletableFuture responseFuture = new CompletableFuture<>(); @Test - public void testMultiplexHttp2() throws Exception { - + void testMultiplexHttp2() throws Exception { Http2FrameLogger serverFrameLogger = new Http2FrameLogger(LogLevel.INFO, "server"); Http2FrameLogger clientFrameLogger = new Http2FrameLogger(LogLevel.INFO, "client"); - EventLoopGroup serverEventLoopGroup = new NioEventLoopGroup(); EventLoopGroup clientEventLoopGroup = new NioEventLoopGroup(); - try { ServerBootstrap serverBootstrap = new ServerBootstrap() .group(serverEventLoopGroup) diff --git a/netty-http-server/src/test/java/org/xbib/netty/http/server/test/hacks/MultithreadedCleartextHttp2Test.java b/netty-http-server/src/test/java/org/xbib/netty/http/server/test/hacks/MultithreadedCleartextHttp2Test.java index a527983..efaba6a 100644 --- a/netty-http-server/src/test/java/org/xbib/netty/http/server/test/hacks/MultithreadedCleartextHttp2Test.java +++ b/netty-http-server/src/test/java/org/xbib/netty/http/server/test/hacks/MultithreadedCleartextHttp2Test.java @@ -27,9 +27,9 @@ import io.netty.handler.codec.http2.Http2ConnectionPrefaceAndSettingsFrameWritte import io.netty.handler.codec.http2.Http2Settings; import io.netty.handler.codec.http2.HttpToHttp2ConnectionHandlerBuilder; import io.netty.handler.codec.http2.InboundHttp2ToHttpAdapterBuilder; -import org.junit.Ignore; -import org.junit.Test; -import org.xbib.netty.http.server.test.TestBase; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.xbib.netty.http.server.test.NettyHttpExtension; import java.net.InetSocketAddress; import java.util.concurrent.CompletableFuture; @@ -40,8 +40,8 @@ import java.util.concurrent.atomic.AtomicInteger; import java.util.logging.Level; import java.util.logging.Logger; -@Ignore -public class MultithreadedCleartextHttp2Test extends TestBase { +@ExtendWith(NettyHttpExtension.class) +class MultithreadedCleartextHttp2Test { private static final Logger clientLogger = Logger.getLogger("client"); private static final Logger serverLogger = Logger.getLogger("server"); @@ -61,7 +61,7 @@ public class MultithreadedCleartextHttp2Test extends TestBase { private final AtomicInteger responseCounter = new AtomicInteger(); @Test - public void testMultiThreadedHttp2() throws Exception { + void testMultiThreadedHttp2() throws Exception { inetSocketAddress = new InetSocketAddress("localhost", 8008); settingsPrefaceFuture = new CompletableFuture<>(); diff --git a/netty-http-server/src/test/java/org/xbib/netty/http/server/test/hacks/MultithreadedMultiplexCodecCleartextHttp2Test.java b/netty-http-server/src/test/java/org/xbib/netty/http/server/test/hacks/MultithreadedMultiplexCodecCleartextHttp2Test.java index 94b61cc..0bf00c0 100644 --- a/netty-http-server/src/test/java/org/xbib/netty/http/server/test/hacks/MultithreadedMultiplexCodecCleartextHttp2Test.java +++ b/netty-http-server/src/test/java/org/xbib/netty/http/server/test/hacks/MultithreadedMultiplexCodecCleartextHttp2Test.java @@ -35,9 +35,9 @@ import io.netty.handler.codec.http2.Http2StreamChannel; import io.netty.handler.codec.http2.Http2StreamChannelBootstrap; import io.netty.handler.codec.http2.Http2StreamFrameToHttpObjectCodec; import io.netty.util.AsciiString; -import org.junit.Ignore; -import org.junit.Test; -import org.xbib.netty.http.server.test.TestBase; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.xbib.netty.http.server.test.NettyHttpExtension; import java.net.InetSocketAddress; import java.util.concurrent.CompletableFuture; @@ -53,8 +53,8 @@ import java.util.logging.Logger; * Multithreaded Http2MultiplexCodec demo for cleartext HTTP/2 between a server and a client. * */ -@Ignore -public class MultithreadedMultiplexCodecCleartextHttp2Test extends TestBase { +@ExtendWith(NettyHttpExtension.class) +class MultithreadedMultiplexCodecCleartextHttp2Test { private static final Logger clientLogger = Logger.getLogger("client"); private static final Logger serverLogger = Logger.getLogger("server"); @@ -74,7 +74,7 @@ public class MultithreadedMultiplexCodecCleartextHttp2Test extends TestBase { private final AtomicInteger responseCounter = new AtomicInteger(); @Test - public void testMultithreadedMultiplexHttp2() throws Exception { + void testMultithreadedMultiplexHttp2() throws Exception { inetSocketAddress = new InetSocketAddress("localhost", 8008); settingsPrefaceFuture = new CompletableFuture<>(); diff --git a/settings.gradle b/settings.gradle index 586e261..e188a01 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,3 +1,4 @@ include 'netty-http-common' include 'netty-http-client' include 'netty-http-server' +include 'netty-http-server-rest' \ No newline at end of file