Startup and shutdown

Markus Sabadello edited this page Aug 16, 2015 · 30 revisions

XDI2

Clone this wiki locally

This page describes different ways of starting the XDI2 server, as well as what happens during the startup process.

Ways of starting the XDI2 server

The XDI2 server is at its core simply a Java web application that can be started in a number of different ways.

All of these ways use the main XDI2 applicationContext.xml configuration file, which always stays the same independently of how the server is started (See Configuration files for a description of this and other files)

mvn jetty:run

The simplest way to start the XDI2 server for testing purposes is to use the Maven Jetty plugin:

cd server-war
mvn jetty:run

The main XDI2 applicationContext.xml configuration file is expected to be in the WEB-INF/ directory of the web application, i.e. at src/main/webapp/WEB-INF/ in the source tree. The web.xml configuration file in that directory is also used.

Deployed .war file

In production mode, the typical way of starting the XDI2 server is to deploy a .war file in a servlet container such as Apache Tomcat or Jetty. The .war file can be built as follows.

cd server-war
mvn package

The process of deploying the .war file varies depending on your servlet container.

The main XDI2 applicationContext.xml configuration file is expected to be in the WEB-INF/ directory of the web application. The web.xml configuration file in that directory is also used.

Standalone mode

The XDI2 server can be launched from the command line by executing a single .jar file (built with One-JAR). To do so, run the following command:

cd server-standalone
java -jar target/xdi2-server-standalone-XXX.one-jar.jar

This requires 2 configuration files: The main XDI2 applicationContext.xml configuration file, and a server-applicationContext.xml configuration file for the embedded Jetty server. Both files are expected to be in the current working directory, but their paths can also be passed on the command line, e.g.

java -jar target/xdi2-server-standalone-XXX.one-jar.jar <path-to-applicationContext.xml> <path-to-server-applicationContext.xml>

Embedded mode

The XDI2 server can be launched in embedded mode from within your own Java application. To do so, it must be on your classpath, e.g. by adding a Maven dependency like the following to your project:

<dependency>
	<groupId>xdi2</groupId>
	<artifactId>xdi2-server-standalone</artifactId>
	<version>XXX</version>
	<scope>compile</scope>
</dependency>

You can then start and configure the XDI2 server as follows:

public class BasicEndpointServerSample {

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

		// create the XDI2 server

		XDIStandaloneServer endpointServer = XDIStandaloneServer.newServer();

		// set up graph messaging target

		Graph graph = MemoryGraphFactory.getInstance().openGraph();
		GraphMessagingTarget messagingTarget = new GraphMessagingTarget();
		messagingTarget.setGraph(graph);

		// add interceptors

		BootstrapInterceptor bi = new BootstrapInterceptor();
		bi.setBootstrapOwner(XDIAddress.create("=!:uuid:1111"));
		bi.setBootstrapRootLinkContract(true);

		AuthenticationSecretTokenInterceptor asti = new AuthenticationSecretTokenInterceptor();
		asti.setSecretTokenAuthenticator(
				new StaticSecretTokenAuthenticator(
						"00000000-0000-0000-0000-000000000000", 
						Collections.singletonMap(
								XDIAddress.create("=!:uuid:1111"), 
								SecretTokens.localSaltAndDigestSecretToken(
										"s3cr3t",
										"00000000-0000-0000-0000-000000000000"))));

		LinkContractInterceptor li = new LinkContractInterceptor();

		messagingTarget.getInterceptors().addInterceptor(bi);
		messagingTarget.getInterceptors().addInterceptor(asti);
		messagingTarget.getInterceptors().addInterceptor(li);

		// mount messaging target

		endpointServer.getEndpointServlet().getHttpTransport().getUriMessagingTargetRegistry().mountMessagingTarget("/", messagingTarget);

		// start the server

		endpointServer.startServer();
	}
}

Instead of configuring the embedded XDI2 server programmatically, you can also use the same 2 configuration files that are used in the command line mode: The main XDI2 applicationContext.xml configuration file, and a server-applicationContext.xml configuration file for the embedded Jetty server.

public class ConfiguredEndpointServerSample {

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

		// read configuration files

		Resource applicationContextResource = new UrlResource(ConfiguredEndpointServerSample.class.getResource("applicationContext.xml"));
		Resource serverApplicationContextResource = new UrlResource(ConfiguredEndpointServerSample.class.getResource("server-applicationContext.xml"));

		// create the XDI2 server

		XDIStandaloneServer endpointServer = XDIStandaloneServer.newServer(applicationContextResource, serverApplicationContextResource);

		// start the server

		endpointServer.startServer();
	}
}

Startup and shutdown process

This diagram shows the steps when the server is started and shut down.

Messaging targets and messaging target factories are initialized and mounted at their configured paths. Certain interceptors are also called to perform various other initialization work.

XDI2-STARTUP-SHUTDOWN.png

Source: XDI2.vsd