Reputation: 6656
I can use Netty with Resteasy or as a Fileserver:
public void file()
{
ServerBootstrap bootstrap = new ServerBootstrap(
new NioServerSocketChannelFactory(
Executors.newCachedThreadPool(),Executors.newCachedThreadPool()));
bootstrap.setPipelineFactory(new HttpStaticFileServerPipelineFactory());
bootstrap.bind(new InetSocketAddress(8080));
}
public void rest()
{
ResteasyDeployment deployment = new ResteasyDeployment();
deployment.getActualResourceClasses().add(RestClass.class);
NettyJaxrsServer netty = new NettyJaxrsServer();
netty.setDeployment(deployment);
netty.setPort(8080);
netty.setRootResourcePath("");
netty.setSecurityDomain(null);
netty.start();
}
Both together are possible with different ports, but how can I integrate both approaches running one Netty server on a single port?
Update Currently I use this setup:
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-netty</artifactId>
<version>3.0.1.Final</version>
</dependency>
Upvotes: 3
Views: 909
Reputation: 12817
You would basically have to combine the different handlers into a new ServerPipelineFactory
. One approach would be to create a pipeline that has the common handlers already in place, plus a "dispatcher" handler that inspects the request and depending on the URL path dynamically adds handlers for static file serving or for resteasy processing.
Upvotes: 1