Skip to content

Commit

Permalink
OZ-689 - Changed mechanism in which the filter is registered
Browse files Browse the repository at this point in the history
  • Loading branch information
wluyima committed Oct 3, 2024
1 parent e21a51a commit 80660e8
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 14 deletions.
13 changes: 13 additions & 0 deletions omod/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,19 @@
<artifactId>openmrs-web</artifactId>
<version>${openmrsPlatformVersion}</version>
<scope>provided</scope>
<exclusions>
<exclusion>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
</exclusion>
</exclusions>
</dependency>

<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.0.1</version>
<scope>provided</scope>
</dependency>

<!-- Test dependencies -->
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/**
* This Source Code Form is subject to the terms of the Mozilla Public License,
* v. 2.0. If a copy of the MPL was not distributed with this file, You can
* obtain one at http://mozilla.org/MPL/2.0/. OpenMRS is also distributed under
* the terms of the Healthcare Disclaimer located at http://openmrs.org/license.
*
* Copyright (C) OpenMRS Inc. OpenMRS is a registered trademark and the OpenMRS
* graphic logo is a trademark of OpenMRS Inc.
*/
package org.openmrs.module.fhirproxy.web;

import java.util.EnumSet;

import javax.servlet.DispatcherType;
import javax.servlet.FilterRegistration.Dynamic;
import javax.servlet.ServletContext;

import org.openmrs.module.fhirproxy.web.filter.FhirProxyFilter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import org.springframework.web.context.ServletContextAware;

@Component
public class FhirProxyFilterRegistrar implements ServletContextAware {

private static final Logger LOG = LoggerFactory.getLogger(FhirProxyFilterRegistrar.class);

private static final String[] MAPPINGS = { "/ws/fhir2/R4/ChargeItemDefinition/*", "/ws/fhir2/R4/InventoryItem/*" };

@Override
public void setServletContext(ServletContext servletContext) {
LOG.info("Adding FHIR Proxy Filter");

try {
Dynamic filter = servletContext.addFilter("FHIR Proxy", new FhirProxyFilter());
filter.addMappingForUrlPatterns(EnumSet.of(DispatcherType.REQUEST), false, MAPPINGS);
}
catch (Exception ex) {
//Ignore known issue, this happens when running openmrs the first time.
}
}

}
17 changes: 3 additions & 14 deletions omod/src/main/resources/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@

<!-- Module Activator -->
<activator>${project.parent.groupId}.${project.parent.artifactId}.FhirProxyActivator</activator>
<aware_of_modules>
<aware_of_module version="2.2.0">fhir2</aware_of_module>
</aware_of_modules>

<!-- Global properties -->
<globalProperty>
Expand All @@ -23,19 +26,5 @@
The base URL for the external API
</description>
</globalProperty>

<filter>
<filter-name>FHIR Proxy</filter-name>
<filter-class>org.openmrs.module.fhirproxy.web.filter.FhirProxyFilter</filter-class>
</filter>

<filter-mapping>
<filter-name>FHIR Proxy</filter-name>
<url-pattern>/ws/fhir2/R4/ChargeItemDefinition/*</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>FHIR Proxy</filter-name>
<url-pattern>/ws/fhir2/R4/InventoryItem/*</url-pattern>
</filter-mapping>
</module>

0 comments on commit 80660e8

Please sign in to comment.