MCPcopy Create free account
hub / github.com/BaseXdb/basex / BaseXHTTP

Method BaseXHTTP

basex-api/src/main/java/org/basex/BaseXHTTP.java:70–181  ·  view source on GitHub ↗

Constructor. @param args command-line arguments @throws Exception exception

(final String... args)

Source from the content-addressed store, hash-verified

68 * @throws Exception exception
69 */
70 public BaseXHTTP(final String... args) throws Exception {
71 super(null, args);
72
73 // context must be initialized after parsing of arguments
74 soptions = new StaticOptions(true);
75
76 if(!quiet) Util.println(header());
77
78 // initialize configuration files and initialize HTTP context
79 final String webapp = soptions.get(StaticOptions.WEBPATH);
80 final WebAppContext wac = new WebAppContext(webapp, "/");
81 final IOFile webXml = locate(WEBCONF, webapp), jettyXml = locate(JETTYCONF, webapp);
82
83 hc = HTTPContext.get();
84 hc.init(soptions, webXml);
85
86 // create jetty instance
87 final URI jettyUri = Paths.get(jettyXml.toString()).toUri();
88 final Resource resource = new PathResourceFactory().newResource(jettyUri);
89 jetty = (Server) new XmlConfiguration(resource).configure();
90
91 // try to use GZIP compression (changed with Jetty 12.1)
92 Supplier<Handler> supplier = wac;
93 if(soptions.get(StaticOptions.GZIP)) {
94 final String clzz = "org.eclipse.jetty.compression.server.CompressionHandler";
95 if(Reflect.available(clzz)) {
96 // create anonymous class, as a lambda expression would yield a ClassNotFoundException
97 // if the compression handler is not included in the classpath
98 supplier = gzip(wac);
99 } else if(Reflect.available("org.eclipse.jetty.server.handler.gzip.GzipHandler")) {
100 Util.errln("Please add " + clzz + " to the classpath to enable GZIP compression");
101 }
102 }
103 jetty.setHandler(supplier);
104 JettyWebSocketServletContainerInitializer.configure(wac, null);
105
106 ServerConnector sc = null;
107 for(final Connector conn : jetty.getConnectors()) {
108 if(conn instanceof final ServerConnector s) sc = s;
109 }
110 if(sc == null) throw new BaseXException("No Jetty connector defined in " + JETTYCONF + '.');
111 if(port != 0) sc.setPort(port);
112 else port = sc.getPort();
113
114 // info strings
115 final Function<Boolean, String> msg1 = start -> start ? SRV_STARTED_PORT_X : SRV_STOPPED_PORT_X;
116 final Function<Boolean, String> msg2 = start -> Util.info(HTTP + ' ' + msg1.apply(start), port);
117 // output user info, keep message visible for a while
118 final Consumer<Boolean> info = start -> {
119 Util.println(msg2.apply(start));
120 if(!soptions.get(StaticOptions.HTTPLOCAL)) {
121 final int serverPort = soptions.get(StaticOptions.SERVERPORT);
122 Util.println(msg1.apply(start), serverPort);
123 }
124 Performance.sleep(1000);
125 };
126
127 // stop web server

Callers

nothing calls this directly

Calls 15

printlnMethod · 0.95
headerMethod · 0.95
locateMethod · 0.95
getMethod · 0.95
availableMethod · 0.95
gzipMethod · 0.95
errlnMethod · 0.95
infoMethod · 0.95
sleepMethod · 0.95
stopMethod · 0.95
startMethod · 0.95
debugMethod · 0.95

Tested by

no test coverage detected