Initial JAX-RS test facilities
commit
594cf0af56
@ -0,0 +1,5 @@
|
|||||||
|
.project
|
||||||
|
dependency-reduced-pom.xml
|
||||||
|
.classpath
|
||||||
|
.settings
|
||||||
|
target
|
||||||
@ -0,0 +1,51 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<parent>
|
||||||
|
<groupId>twopm.tech</groupId>
|
||||||
|
<artifactId>jax-rs-bench</artifactId>
|
||||||
|
<version>1.0-SNAPSHOT</version>
|
||||||
|
<relativePath>../../pom.xml</relativePath>
|
||||||
|
</parent>
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
<artifactId>rawnetty</artifactId>
|
||||||
|
<properties>
|
||||||
|
<app.main.class>com.colobu.rest.nativenetty.Main</app.main.class>
|
||||||
|
</properties>
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>io.netty</groupId>
|
||||||
|
<artifactId>netty-all</artifactId>
|
||||||
|
<version>${netty.version}</version>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-shade-plugin</artifactId>
|
||||||
|
<version>3.2.4</version>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<phase>package</phase>
|
||||||
|
<goals>
|
||||||
|
<goal>shade</goal>
|
||||||
|
</goals>
|
||||||
|
<configuration>
|
||||||
|
<transformers>
|
||||||
|
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
|
||||||
|
<manifestEntries>
|
||||||
|
<Main-Class>${app.main.class}</Main-Class>
|
||||||
|
<X-Compile-Source-JDK>${maven.compile.source}</X-Compile-Source-JDK>
|
||||||
|
<X-Compile-Target-JDK>${maven.compile.target}</X-Compile-Target-JDK>
|
||||||
|
</manifestEntries>
|
||||||
|
</transformer>
|
||||||
|
</transformers>
|
||||||
|
</configuration>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
</project>
|
||||||
@ -0,0 +1,45 @@
|
|||||||
|
package twopm.tech.bench.jaxrs;
|
||||||
|
|
||||||
|
import io.netty.bootstrap.ServerBootstrap;
|
||||||
|
import io.netty.channel.*;
|
||||||
|
import io.netty.channel.nio.NioEventLoopGroup;
|
||||||
|
import io.netty.channel.socket.SocketChannel;
|
||||||
|
import io.netty.channel.socket.nio.NioServerSocketChannel;
|
||||||
|
import io.netty.handler.codec.http.HttpServerCodec;
|
||||||
|
|
||||||
|
public class Bench {
|
||||||
|
public static void main(String[] args) throws Exception {
|
||||||
|
String host = "0.0.0.0";
|
||||||
|
int port = 8080;
|
||||||
|
if (args.length > 0) {
|
||||||
|
host = args[0];
|
||||||
|
}
|
||||||
|
if (args.length > 1) {
|
||||||
|
port = Integer.parseInt(args[1]);
|
||||||
|
}
|
||||||
|
|
||||||
|
EventLoopGroup bossGroup = new NioEventLoopGroup(1);
|
||||||
|
EventLoopGroup workerGroup = new NioEventLoopGroup();
|
||||||
|
try {
|
||||||
|
ServerBootstrap b = new ServerBootstrap();
|
||||||
|
b.option(ChannelOption.SO_BACKLOG, 1024);
|
||||||
|
b.group(bossGroup, workerGroup)
|
||||||
|
.channel(NioServerSocketChannel.class)
|
||||||
|
.childHandler(new ChannelInitializer<SocketChannel>(){
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void initChannel(SocketChannel ch) throws Exception {
|
||||||
|
ChannelPipeline p = ch.pipeline();
|
||||||
|
p.addLast(new HttpServerCodec());
|
||||||
|
p.addLast(new HelloWorldHandler());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
Channel ch = b.bind(host,port).sync().channel();
|
||||||
|
ch.closeFuture().sync();
|
||||||
|
} finally {
|
||||||
|
bossGroup.shutdownGracefully();
|
||||||
|
workerGroup.shutdownGracefully();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,55 @@
|
|||||||
|
package twopm.tech.bench.jaxrs;
|
||||||
|
|
||||||
|
import io.netty.buffer.Unpooled;
|
||||||
|
import io.netty.channel.ChannelFutureListener;
|
||||||
|
import io.netty.channel.ChannelHandlerContext;
|
||||||
|
import io.netty.channel.ChannelInboundHandlerAdapter;
|
||||||
|
import io.netty.handler.codec.http.*;
|
||||||
|
import io.netty.util.AsciiString;
|
||||||
|
import static io.netty.handler.codec.http.HttpResponseStatus.*;
|
||||||
|
import static io.netty.handler.codec.http.HttpVersion.*;
|
||||||
|
|
||||||
|
|
||||||
|
public class HelloWorldHandler extends ChannelInboundHandlerAdapter {
|
||||||
|
private static final byte[] CONTENT = { 'H', 'e', 'l', 'l', 'o', ' ', 'W', 'o', 'r', 'l', 'd' };
|
||||||
|
|
||||||
|
private static final AsciiString CONTENT_TYPE = new AsciiString("Content-Type");
|
||||||
|
private static final AsciiString CONTENT_LENGTH = new AsciiString("Content-Length");
|
||||||
|
private static final AsciiString CONNECTION = new AsciiString("Connection");
|
||||||
|
private static final AsciiString KEEP_ALIVE = new AsciiString("keep-alive");
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void channelReadComplete(ChannelHandlerContext ctx) {
|
||||||
|
ctx.flush();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void channelRead(ChannelHandlerContext ctx, Object msg) {
|
||||||
|
if (msg instanceof HttpRequest) {
|
||||||
|
HttpRequest req = (HttpRequest) msg;
|
||||||
|
|
||||||
|
if (HttpUtil.is100ContinueExpected(req)) {
|
||||||
|
ctx.write(new DefaultFullHttpResponse(HTTP_1_1, CONTINUE));
|
||||||
|
}
|
||||||
|
boolean keepAlive = HttpUtil.isKeepAlive(req);
|
||||||
|
FullHttpResponse response = new DefaultFullHttpResponse(HTTP_1_1, OK, Unpooled.wrappedBuffer(CONTENT));
|
||||||
|
if (req.method() == HttpMethod.GET) {
|
||||||
|
response.headers().set(CONTENT_TYPE, "text/plain");
|
||||||
|
response.headers().setInt(CONTENT_LENGTH, response.content().readableBytes());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!keepAlive) {
|
||||||
|
ctx.write(response).addListener(ChannelFutureListener.CLOSE);
|
||||||
|
} else {
|
||||||
|
response.headers().set(CONNECTION, KEEP_ALIVE);
|
||||||
|
ctx.write(response);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
|
||||||
|
cause.printStackTrace();
|
||||||
|
ctx.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,19 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
<groupId>twopm.tech</groupId>
|
||||||
|
<artifactId>jax-rs-bench</artifactId>
|
||||||
|
<packaging>pom</packaging>
|
||||||
|
<version>1.0-SNAPSHOT</version>
|
||||||
|
<properties>
|
||||||
|
<netty.version>4.1.69.Final</netty.version>
|
||||||
|
|
||||||
|
<java.version>11</java.version>
|
||||||
|
<maven.compiler.source>11</maven.compiler.source>
|
||||||
|
<maven.compiler.target>11</maven.compiler.target>
|
||||||
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
</properties>
|
||||||
|
<modules>
|
||||||
|
<module>modules/rawnetty</module>
|
||||||
|
</modules>
|
||||||
|
</project>
|
||||||
@ -0,0 +1,21 @@
|
|||||||
|
{
|
||||||
|
"folders": [
|
||||||
|
{
|
||||||
|
"name": "modules",
|
||||||
|
"path": "modules"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "jax-rs-bench",
|
||||||
|
"path": ".",
|
||||||
|
"files.exclude": ["", ""]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"settings": {
|
||||||
|
"java.configuration.updateBuildConfiguration": "automatic",
|
||||||
|
"java.dependency.packagePresentation": "hierarchical",
|
||||||
|
"java.dependency.syncWithFolderExplorer": true,
|
||||||
|
"files.exclude": {
|
||||||
|
"modules": true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue