1

I am new user of jetty and developing a jetty server which redirect all http request to ssl port. I found the concept of Confidential port in jetty tutorial but its not working. I am adding code snapshot plz correct me where i am going wrong.

public class ServerMain {

    public static void main(String[] args) throws Exception {

        Server server = new Server();
        SslContextFactory con = new SslContextFactory();
        con.setKeyStorePath("D:/.keystore");
        con.setKeyStorePassword("password");
        con.setTrustStore("D:/jssecacerts");
        con.setTrustStorePassword("changeit");

        SslSelectChannelConnector connector = new SslSelectChannelConnector(con);
        connector.setHost("10.10.10.10");
        connector.setPort(8443);
        connector.setMaxIdleTime(30000);

        SelectChannelConnector connector1 = new SelectChannelConnector();
        connector1.setHost("10.10.10.10");
        connector1.setPort(8080);


        //connector1.setConfidentialPort(443);
        connector1.setConfidentialPort(8443);

        server.setConnectors(new Connector[] {connector, connector1});

        QueuedThreadPool threadPool = new QueuedThreadPool();

        threadPool.setMaxThreads(24);
        threadPool.setMinThreads(12);

        server.setThreadPool(threadPool);       

        ContextHandlerCollection contexts = new ContextHandlerCollection();

        ContextHandler mycontext = new ContextHandler();
        mycontext.setContextPath("/test");

        Handler handler = new MyHandler();
        mycontext.setHandler(handler);

        contexts.addHandler(mycontext);

        HandlerCollection handlers = new HandlerCollection();
        handlers.setHandlers(new Handler[] { contexts, new DefaultHandler() });

        server.setHandler(handlers);

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

    }   
}

MyHandler is also added where i am handling request and sending 200 ok.

Please Help me.

Colin Dumitru
  • 3,327
  • 6
  • 30
  • 47
Nandan
  • 203
  • 1
  • 2
  • 7
  • What error are you getting, what is going wrong exactly? – emecas Mar 14 '13 at 07:53
  • I am not getting any error. But the requests are not redirecting on ssl port. Case 1: When i am hitting a url (http://10.10.10.10:8080/test) then its not showing any ssl exception on my browser and simply connected with server. In this case it should throw an exception on browser. case 2: when i m hitting (https://10.10.10.10:8443/test) its showing ssl exception. – Nandan Mar 14 '13 at 09:07

2 Answers2

0

Why should jetty redirect to the https connector with your current setup? To achieve something like this you have to for example add a security-constraint to your webapp as described here (first link I found in google. Just search for webapp security-constraint confidential to find more examples): http://docs.oracle.com/javaee/6/tutorial/doc/gkbaa.html

Or add a handler that redirects from the http connector to the https connector or something similar.

Thomas Becker
  • 934
  • 8
  • 16
  • i am using embedded Jetty but here i found all example and setting with web.xml and annotation form. So if u have any example in embedded jetty kindly provide me coz i am not getting how to set Security constraint in Embedded jetty. Thanks in Advance. – Nandan Mar 15 '13 at 08:00
0

You might need to configure the transport-guarantee element in web.xml in order for it to work.

See: http://docs.oracle.com/cd/E19226-01/820-7627/bncbk/index.html

Jiri Tousek
  • 12,211
  • 5
  • 29
  • 43