Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[jetty-users] Binding a WebAppContext to a specific connector?

Hello :)

https://stackoverflow.com/questions/26148418/jetty-9-setting-up-handlers-and-connectors talks about setting up a handler that is only used to respond to requests on a specific connector:

 

    ServerConnector httpConnector = new ServerConnector(server);

    httpConnector.setName("unsecured"); // named connector

    httpConnector.setPort(80);

 

    ContextHandler helloHandler = new ContextHandler();

    helloHandler.setContextPath("/hello");

    helloHandler.setHandler(new HelloHandler("Hello World"));

    helloHandler.setVirtualHosts(new String[]{"@unsecured"});

 

Does this work out of the box for web app contexts? Part of my code follows:

 

ServerConnector sslConnector = new ServerConnector(s,
     
new SslConnectionFactory(sslContextFactory, HttpVersion.HTTP_1_1.asString()),
     
new HttpConnectionFactory(sslHttpConfig));
sslConnector.setName(
"https");
sslConnector.setHost("0.0.0.0");
sslConnector.setPort(
443);

 

ServerConnector nonSslConnector = new ServerConnector(s,
     
new HttpConnectionFactory(),
     
new HttpConnectionFactory(nonSslHttpConfig));
nonSslConnector.setName(
"http");
nonSslConnector.setHost(
"0.0.0.0");
nonSslConnector.setPort(
80);

 

WebAppContext t1 = new WebAppContext();
t1.setContextPath(
"/");
t1.setDisplayName(
"abc");
t1.setWar(
"c:/TempWebapp-1.0.war");
t1.setVirtualHosts(
new String[] {"@https","admin.bamidbarconnect.com","test2.local"});
WebAppContext t2 =
new WebAppContext();
t2.setContextPath(
"/");
t2.setResourceBase(
"c:/TempWebapp2/");
t2.setParentLoaderPriority(
true);
t2.setVirtualHosts(
new String[] {"@http","test1.local"});

s.setConnectors(
new Connector[]{nonSslConnector, sslConnector});

HandlerList list =
new HandlerList();
list.addHandler(t1);
list.addHandler(t2);

s.setHandler(list);

 

If it’s supposed to work, it doesn’t seem to be working for me. T1 is only supposed to be served via the SSL connector on port 443 and T2 is only supposed to be served on the non-SSL connector on port 80.

 

Thanks

--Steve

 

--

Lobos Studios | Phone: 877.919.4WEB | LobosStudios.com | Facebook.com/LobosStudios | @LobosStudios

Web Development - Mobile Development - Helpdesk/Tech Support - Computer Sales & Service

Acer Authorized Reseller - Computers, Windows and Android Tablets, Accessories

 

Steve Sobol - CEO, Senior Developer and Server Jockey

steve@xxxxxxxxxxxxxxxx

 


Back to the top