Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 11 Next »

Introduction

This page describes how the OpenNCP Protocol Terminator common component can be integrated with the National Connector (NC).

Background

Each country has their own implementation of the National Connector and therefore the way that OpenNCP connects with the NC will be different for each country. Therefore it is necessary to “inject” country-specific functionality into the Protocol Terminator.

Implementation

The following diagram shows the relevant OpenNCP classes and the classes that are country-specific.

Injection of the National implementation classes is handled by a ServiceLoader.  The ServiceLoader will locate and load a specific implementation (called a Service Provider) of an interface.  The ServiceLoader is included in Java SE6 and is already utilized in OpenNCP.

Here is an example that shows the ServiceLoader in action.  Here you can see how an implementation of the PatientSearchInterface is loaded.

 

public class XCPDServiceImpl implements XCPDServiceInterface {
    private ServiceLoader<PatientSearchInterface> serviceLoader;
    private PatientSearchInterface patientSearchService;
    
    public XCPDServiceImpl() {
        serviceLoader = ServiceLoader.load(PatientSearchInterface.class);
    	try {
    		logger.info("Loading National implementation of PatientSearchInterface...");
    		patientSearchService = serviceLoader.iterator().next();
    		logger.info("Successfully loaded PatientSearchService");
    	} catch (ServiceConfigurationError e) {
    		logger.fatal("Exception loading PatientSearchService: ", e);
    	}
    }
}

Note that the loader is initialized with an interface type.  The loader will search for a provider-configuration file in the resource directory META-INF/services.  The file's name is the same as the interface name.  The file contains the fully-qualified name of the concrete provider class.

Example of provider-configuration file containing Swedish configuration:

eu.epsos.protocolterminators.ws.server.xcpd.PatientSearchInterface

se.sb.epsos.shelob.ws.server.xcpd.impl.PatientSearchImpl

Mock implementations

Mock implementations of the DocumentSubmitImpl, DocumentSearchImpl and PatientSearchImpl are provided in the project epsos-ws-server-mock-impl.  These classes simply return dummy responses (not implemented yet).  The mock implementations are packaged as a jar file epsos-ws-server-mock-impl-0.1.0.jar.

Packaging

Each country must build their own jar file containing their own implementations, dependencies and supporting files. This jar file is bundled into the epsos-ws-server.war.  The pom.xml for the epsos-ws-server project uses profiles to achieve this goal.  Maven profiles enable portable build scripts that can be run with with different configurations.

	<profiles>
		<profile>
			<!-- This profile bundles a mock National Connector interface -->
			<id>national-connector-mock-impl</id>
			<activation>
				<activeByDefault>true</activeByDefault>
			</activation>
			<dependencies>
				<dependency>
					<groupId>eu.epsos.protocolterminators.ws.server</groupId>
					<artifactId>epsos-ws-server-mock-impl</artifactId>
					<version>0.1.0</version>
					<scope>runtime</scope>
				</dependency>
			</dependencies>
		</profile>
		<profile>
			<!-- This profile bundles the country-specifig National Connector interface -->
			<id>national-connector-impl</id>
			<dependencies>
				<dependency>
					<groupId>${national-connector-interface.groupid}</groupId>
					<artifactId>${national-connector-interface.artifactid}</artifactId>
					<version>${national-connector-interface.version}</version>
					<scope>runtime</scope>
				</dependency>
			</dependencies>
		</profile>
	</profiles>

The first profile (activated by default) bundles the mock implementations into the war file.  The second profile will bundle the National implementation.  

For the National build to work it is necessary to configure the build environment with properties.  These properties are defined in local configuration files:

Per User

- Defined in the Maven-settings (%USER_HOME%/.m2/settings.xml).

Global

- Defined in the global Maven-settings (%M2_HOME%/conf/settings.xml).

Profile descriptor

- a descriptor located in project basedir (profiles.xml) (unsupported in Maven 3.x)

Here are the Maven commands

# build server with mock implementation
mvn clean install
 
# build server with real implementation
mvn clean install -P national-connector-impl
 

References

Java SE6 ServiceLoader

ServiceLoader tutorial at java.net

Introduction to profiles

 

  • No labels