0

Good Day,

I have been struggling to find documentation for "Setting up SSL With Jetty" but there is nothing. I basically have a Jetty Server set up in my Java Program as such. My Java program is compiled into a .jar file, and it can be run instantly on my AMAZON EC2 instance. All Jetty libraries are inside the .jar itself.

It works great on EC2. But I need these Jetty URL's to be secure and on SSL.

import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.Connector;
import org.eclipse.jetty.server.Request;
import org.eclipse.jetty.server.handler.AbstractHandler;
import org.eclipse.jetty.server.nio.SelectChannelConnector;
import org.eclipse.jetty.servlet.ServletContextHandler;
import org.eclipse.jetty.servlet.ServletHolder;

private static Server server;

public static void main(String[] args) throws Exception {
    System.out.println("Servers!");

    server = new Server();
    Connector connector = new SelectChannelConnector();
    connector.setPort(8081);
    server.addConnector(connector);

    ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
    context.setContextPath("/");
    server.setHandler(context);
    context.addServlet(new ServletHolder(new HelloServlet()),"/*");
    context.addServlet(new ServletHolder(new PostServlet()),"/post/*");

    Thread monitor = new CommandThread();
    monitor.start();

    server.start();
    server.join();

}

Can I know what can be done to enable SSL on these links/servlets?

4

1 回答 1

0

可能最容易让您参考一些代码:

http://git.eclipse.org/c/jetty/org.eclipse.jetty.project.git/tree/jetty-server/src/test/java/org/eclipse/jetty/server/ssl/SSLSelectChannelConnectorLoadTest.java? h=jetty-8

您最感兴趣的是 startServer() 方法,因为这是为 ssl 配置测试用例的码头服务器的地方。我为您链接了测试的 jetty-8 版本,因为您使用的是 SelectChannelConnector,您使用的是 7 或 8。Jetty 9 的服务器连接器配置略有不同。我们必须为此 ssl 配置添加一个嵌入式示例,并在某个时候将其记录在我们的 jetty 9 文档中。我将在此处链接,以便人们在添加该示例时可以看到它。

http://www.eclipse.org/jetty/documentation/current/embedded-examples.html

于 2013-06-19T11:24:52.730 回答