2 * Copyright (c) 2017 Cisco and/or its affiliates.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at:
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package io.fd.honeycomb.northbound.restconf;
19 import static io.fd.honeycomb.northbound.restconf.RestconfModule.RESTCONF_HTTP;
20 import static io.fd.honeycomb.northbound.restconf.RestconfModule.RESTCONF_HTTPS;
22 import com.google.inject.Inject;
23 import com.google.inject.name.Named;
24 import io.fd.honeycomb.binding.init.ProviderTrait;
26 import javax.annotation.Nullable;
28 import org.eclipse.jetty.server.Server;
29 import org.eclipse.jetty.server.ServerConnector;
30 import org.opendaylight.netconf.sal.rest.api.RestConnector;
31 import org.slf4j.Logger;
32 import org.slf4j.LoggerFactory;
34 class JettyServerStarter extends ProviderTrait<JettyServerStarter.ServerInit> {
36 private static final Logger LOG = LoggerFactory.getLogger(JettyServerStarter.class);
39 private Server server;
41 // injecting all connectors to make sure that server is started after they are added
43 private RestConnector connector;
45 // if HTTP is disabled, null will be injected
47 @Inject(optional = true)
49 private ServerConnector httpConnectorInit;
51 // if HTTPS is disabled, null will be injected
53 @Inject(optional = true)
54 @Named(RESTCONF_HTTPS)
55 private ServerConnector httpsConnectorInit;
58 protected ServerInit create() {
60 LOG.info("Starting RESTCONF Jetty server");
62 LOG.info("RESTCONF Jetty server successfully started");
63 } catch (Exception e) {
64 LOG.error("Unable to start RESTCONF Jetty server", e);
65 throw new IllegalStateException("Unable to start RESTCONF Jetty server", e);
68 return new ServerInit() {
72 interface ServerInit {