Skip to content

Startup and shutdown

peacekeeper edited this page Aug 22, 2012 · 30 revisions

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 it 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.

Command line

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 jetty-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-jetty-applicationContext.xml>

Embedded

The XDI2 server can be launched in embedded mode from within your 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</artifactId>
	<version>0.1-SNAPSHOT</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 Throwable {

		// create the XDI2 server
		EndpointServer endpointServer = EndpointServer.newServer();

		// configure the XDI2 server, e.g. mount a messaging target, add interceptors, etc.
		endpointServer.getEndpointServlet().getEndpointRegistry().mountMessagingTarget("/", messagingTarget);

		// start the server
		endpointServer.start();
	}
}

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 jetty-applicationContext.xml configuration file for the embedded Jetty server.

public class ConfiguredEndpointServerSample {

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

		// read configuration files
		Resource applicationContextResource = new UrlResource(ConfiguredEndpointServerSample.class.getResource("applicationContext.xml"));
		Resource jettyApplicationContextResource = new UrlResource(ConfiguredEndpointServerSample.class.getResource("jetty-applicationContext.xml"));

		// create the XDI2 server
		EndpointServer endpointServer = EndpointServer.newServer(applicationContextResource, jettyApplicationContextResource);

		// start the server
		endpointServer.start();
	}
}

Startup and shutdown process

This diagram shows the steps when the xdi2-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

Clone this wiki locally