Auxiliary Files Service

You can use auxiliary files to pass a file to a custom filter or communication point using the Auxiliary Files Service.

Auxiliary files can either be attached to a filter or communication point via the Auxiliary tab in the Configuration dialog, or they can be embedded into the custom module JAR file. The technique for fetching the files is the same for both methods:

  1. Starting with the BlockingCommPoint you created earlier, modify the properties bean to hold the contents of a file passed as a property from Rhapsody IDE.

    package com.orionhealth.EMEA.rhapsody.module.BlockingCommPoint;
    
    public class PropertiesBean {
    	int port;
        String fileContents;
    
        public String getFileContents() {
        	return fileContents;
        }
                    
    	public void setFileContents(String fileContents) {
            this.fileContents = fileContents;
        }
                    
    	public int getPort() {
        	return port;
        }
        public void setPort(int port) {
        	this.port = port;
        }
    }
    
  2. Edit your BlockingCommPoint class.
  3. Add the file type property. 

    private static final String PROPSFILE= "FILE|*f||configuration file||Set this to any file";
    private static final String[] props = { PORT, PROPSFILE };
  4. Now modify the configure() method to read the file.  Use Eclipse to automatically add all the try/catch blocks.

    ...
    property = config.getConfiguratedProperties().get("FILE");
    if (null==property || 0==property.length()) {
    	throw new CommunicationPointConfigurationException("Required field 'file' missing.");
    } else {
    	InputStream fileStream = null;
    	try {
        	fileStream = Activator.getAuxiliaryFilesService().openAuxiliaryFile(getCommunicationPointInfo(), property);
            BufferedReader reader = new BufferedReader(new InputStreamReader(fileStream));
            StringBuilder sb = new StringBuilder();
            String line = null;
            while ((line = reader.readLine()) != null) {
            	sb.append(line + "\n");
            }
            fileStream.close();
            String fileString = sb.toString();
            this.properties.setFileContents(fileString);
        } catch (FileNotFoundException e) {
            throw new CommunicationPointConfigurationException("",e);
        } catch (SecurityException e) {
            throw new CommunicationPointConfigurationException("",e);
        } catch (IOException e){
            throw new CommunicationPointConfigurationException("",e);
        } finally {
    		if (fileStream != null) {
    			try {
    				fileStream.close();
    			} catch (IOException ignore) { }
    		}
    	}
    }

    Closing streams

    It is best practice to close streams when you are finished with them (as in the example above), to release the resources. This should be done in the finally block, so that the stream will still get closed even if an exception is thrown in the try block.

  5. Now you can use the file in the Connection class – use it as the contents for the input message:

    protected String read() {
                                                   
    	readThread = new Thread() {
    		@Override
        	public void run() {
            	try {
                	Thread.sleep(10000); // sleep for 10 seconds
                } catch (InterruptedException e) {
    			} 
            }
        };
        readThread.start();
        try {
        	readThread.join();
            return config.getFileContents();
        } catch (InterruptedException e) {
            return "";
        } finally {
            readThread = null;
        }
    }
  6. Modify the Activator so it can receive the Auxiliary File Service from Rhapsody:

    public class Activator {
                   
    	private static AuxiliaryFilesService auxiliaryFilesService;
                   
        protected void setAuxiliaryFilesService(final AuxiliaryFilesService auxiliaryFilesService) {
        	Activator.auxiliaryFilesService = auxiliaryFilesService;
        }
    
        protected void unsetAuxiliaryFilesService(final AuxiliaryFilesService auxiliaryFilesService) {
        	Activator.auxiliaryFilesService = null;
        }
                   
        public static AuxiliaryFilesService getAuxiliaryFilesService() {
            return Activator.auxiliaryFilesService;
        }
  7. Finally modify the Service.xml to specify how the service should be injected into the module:

    <?xml version="1.0" encoding="UTF-8"?>
    <component name="com.orionhealth.EMEA.rhapsody.module.BlockingCommPoint" immediate="true">
    	<implementation class="com.orionhealth.EMEA.rhapsody.module.BlockingCommPoint.Activator"/>
        <reference name="AUXILIARY_FILE" interface="com.orchestral.rhapsody.configuration.auxiliaryfiles.AuxiliaryFilesService"
     		bind="setAuxiliaryFilesService" unbind="unsetAuxiliaryFilesService"/>
    </component>
  8. You can also get the file as a File object as follows:

    File auxiliaryFile;
    try {
    	auxiliaryFile = Activator.getAuxiliaryFilesService().getAuxiliaryFile(getFilterInfo(), bodyFile);
    } catch (FileNotFoundException e) {
        throw new FilterConfigurationException("Body file '" + bodyFile + "' not found.");
    } catch (SecurityException e) {
        throw new FilterConfigurationException("Error opening body file '" + bodyFile + "'.");
    }
    

Configuring Your Custom Module to Use Other Rhapsody Services

Modifying Service.xml to Reference the Services

<?xml version="1.0" encoding="UTF-8"?>
<component name="com.orionhealth.EMEA.rhapsody.module.dicom" immediate="true">
                <implementation class="com.orionhealth.EMEA.rhapsody.module.dicom.Activator"/>
                <reference name="AUXILIARY_FILE" interface="com.orchestral.rhapsody.configuration.auxiliaryfiles.AuxiliaryFilesService" bind="setAuxiliaryFilesService" unbind="unsetAuxiliaryFilesService"/>
                <reference name="DEFINITION" interface="com.orchestral.rhapsody.model.definition.DefinitionService" bind="setDefinitionService" unbind="unsetDefinitionService"/>
                <reference name="MESSAGE_PARSING" interface="com.orchestral.rhapsody.messageparsing.MessageParsingService" bind="setMessageParsingService" unbind="unsetMessageParsingService"/>
                <reference name="PERSISTENT_MAP" interface="com.orchestral.rhapsody.persistentmap.PersistentMapService" bind="setPersistentMapService" unbind="unsetPersistentMapService"/>
                <reference name="SECURITY" interface="com.orchestral.rhapsody.configuration.security.SecurityObjectsService" bind="setSecurityObjectsService" unbind="unsetSecurityObjectsService"/>
                <reference name="XML" interface="javax.xml.parsers.DocumentBuilderFactory" target="(&amp;(parser.namespaceAware=true)(parser.validating=false))" bind="setDocumentBuilderFactory" unbind="unsetDocumentBuilderFactory"/>
                <reference name="ID" interface="com.orchestral.rhapsody.idgenerator.IdGeneratorFactory" unbind="unsetIdGeneratorFactory" bind="setIdGeneratorFactory"/>
                <reference name="VARIABLES" interface="com.orchestral.rhapsody.configuration.variables.VariablesService" unbind="unsetVariablesService" bind="setVariablesService"/>
</component>

Modifying Activator to Reference the Services

 import com.orchestral.rhapsody.configuration.auxiliaryfiles.AuxiliaryFilesService;
 import com.orchestral.rhapsody.configuration.security.SecurityObjectsService;
 import com.orchestral.rhapsody.configuration.variables.VariablesService;
 import com.orchestral.rhapsody.idgenerator.IdGeneratorFactory;
 import com.orchestral.rhapsody.messageparsing.MessageParsingService;
 import com.orchestral.rhapsody.model.definition.DefinitionService;
 import com.orchestral.rhapsody.module.FilterRegistration;
 import com.orchestral.rhapsody.module.communicationpoint.CommunicationPointInfo;
 import com.orchestral.rhapsody.persistentmap.PersistentMap;
 import com.orchestral.rhapsody.persistentmap.PersistentMapService;
 import com.orchestral.rhapsody.security.SecurityException;
 import com.orionhealth.EMEA.rhapsody.module.dicom.update.DICOMTagUpdater;
…

 public class Activator {
 
                 private static AuxiliaryFilesService auxiliaryFilesService;
                 private static DefinitionService definitionService;
                 private static MessageParsingService messageParsingService;
                 private static PersistentMapService persistentMapService;
                 private static SecurityObjectsService securityObjectsService;
                 private static DocumentBuilderFactory documentBuilderFactory;
                 private static IdGeneratorFactory idGeneratorFactory;
                 private static VariablesService variablesService;
 
                 private Set<ServiceRegistration> registrations = new HashSet<ServiceRegistration>();
 
                 protected void setAuxiliaryFilesService(
                                                 final AuxiliaryFilesService auxiliaryFilesService) {
                                 Activator.auxiliaryFilesService = auxiliaryFilesService;
                 }
 
                 protected void unsetAuxiliaryFilesService(
                                                 final AuxiliaryFilesService auxiliaryFilesService) {
                                 Activator.auxiliaryFilesService = null;
                 }
 
                 protected void setDefinitionService(
                                                 final DefinitionService definitionService) {
                                 Activator.definitionService = definitionService;
                 }
 
                 protected void unsetDefinitionService(
                                                 final DefinitionService definitionService) {
                                 Activator.definitionService = null;
                 }
 
                 protected void setMessageParsingService(
                                                 final MessageParsingService messageParsingService) {
                                 Activator.messageParsingService = messageParsingService;
                 }
 
                 protected void unsetMessageParsingService(
                                                 final MessageParsingService messageParsingService) {
                                 Activator.messageParsingService = null;
                 }
 
                 protected void setPersistentMapService(
                                                 final PersistentMapService persistentMapService) {
                                 Activator.persistentMapService = persistentMapService;
                 }
 
                 protected void unsetPersistentMapService(
                                                 final PersistentMapService persistentMapService) {
                                 Activator.persistentMapService = null;
                 }
 
                 protected void setSecurityObjectsService(
                                                 final SecurityObjectsService securityObjectsService) {
                                 Activator.securityObjectsService = securityObjectsService;
                 }
 
                 protected void unsetSecurityObjectsService(
                                                 final SecurityObjectsService securityObjectsService) {
                                 Activator.securityObjectsService = null;
                 }
 
                 public void setDocumentBuilderFactory(final DocumentBuilderFactory factory) {
                                 Activator.documentBuilderFactory = factory;
                 }
 
                 protected void unsetDocumentBuilderFactory(
                                                 final DocumentBuilderFactory factory) {
                                 Activator.documentBuilderFactory = null;
                 }
 
                 protected void setIdGeneratorFactory(
                                                 final IdGeneratorFactory idGeneratorFactory) {
                                 Activator.idGeneratorFactory = idGeneratorFactory;
                 }
 
                 protected void unsetIdGeneratorFactory(
                                                 final IdGeneratorFactory idGeneratorFactory) {
                                 Activator.idGeneratorFactory = null;
                 }
 
                 protected void setVariablesService(final VariablesService variablesService) {
                                 Activator.variablesService = variablesService;
                 }
 
                 protected void unsetVariablesService(final VariablesService variablesService) {
                                 Activator.variablesService = null;
                 }
 
                 public static AuxiliaryFilesService getAuxiliaryFilesService()
                                                 throws FileNotFoundException, SecurityException {
                                 return Activator.auxiliaryFilesService;
                 }
 
                 public static DefinitionService getDefinitionService() {
                                 return Activator.definitionService;
                 }
 
                 public static MessageParsingService getMessageParsingService() {
                                 return Activator.messageParsingService;
                 }
 
                 public static PersistentMap getPersistentMap(
                                                 final CommunicationPointInfo communicationPointInfo) {
                                 return Activator.persistentMapService
                                                                 .getPersistentMap(communicationPointInfo);
                 }
 
                 public static SecurityObjectsService getSecurityObjectsService() {
                                 return Activator.securityObjectsService;
                 }
 
                 public static DocumentBuilderFactory getDocumentBuilderFactory() {
                                 return Activator.documentBuilderFactory;
                 }
 
                 public static IdGeneratorFactory getIdGeneratorFactory() {
                                 return Activator.idGeneratorFactory;
                 }
 
                 public static VariablesService getVariablesService() {
                                 return Activator.variablesService;
                 }
 
                 ...
 
 }