diff --git a/hapi-fhir-jaxrsserver-base/src/main/java/ca/uhn/fhir/jaxrs/server/util/JaxRsMethodBindings.java b/hapi-fhir-jaxrsserver-base/src/main/java/ca/uhn/fhir/jaxrs/server/util/JaxRsMethodBindings.java index 8406c5e64b9..4dcb47c3eff 100644 --- a/hapi-fhir-jaxrsserver-base/src/main/java/ca/uhn/fhir/jaxrs/server/util/JaxRsMethodBindings.java +++ b/hapi-fhir-jaxrsserver-base/src/main/java/ca/uhn/fhir/jaxrs/server/util/JaxRsMethodBindings.java @@ -20,17 +20,19 @@ package ca.uhn.fhir.jaxrs.server.util; * #L% */ -import java.lang.reflect.Method; -import java.util.concurrent.ConcurrentHashMap; - -import org.apache.commons.lang3.StringUtils; - import ca.uhn.fhir.jaxrs.server.AbstractJaxRsProvider; import ca.uhn.fhir.rest.annotation.Search; import ca.uhn.fhir.rest.api.RestOperationTypeEnum; import ca.uhn.fhir.rest.server.exceptions.NotImplementedOperationException; -import ca.uhn.fhir.rest.server.method.*; +import ca.uhn.fhir.rest.server.method.BaseMethodBinding; +import ca.uhn.fhir.rest.server.method.OperationMethodBinding; +import ca.uhn.fhir.rest.server.method.SearchMethodBinding; import ca.uhn.fhir.util.ReflectionUtil; +import org.apache.commons.lang3.StringUtils; + +import java.lang.reflect.Method; +import java.util.LinkedHashSet; +import java.util.concurrent.ConcurrentHashMap; /** * Class that contains the method bindings defined by a ResourceProvider @@ -52,7 +54,9 @@ public class JaxRsMethodBindings { * @param theProviderClass the class definition contaning the operations */ public JaxRsMethodBindings(AbstractJaxRsProvider theProvider, Class theProviderClass) { - for (final Method m : ReflectionUtil.getDeclaredMethods(theProviderClass)) { + LinkedHashSet declaredMethodsForCurrentProvider = ReflectionUtil.getDeclaredMethods(theProviderClass); + declaredMethodsForCurrentProvider.addAll(ReflectionUtil.getDeclaredMethods(theProviderClass.getSuperclass())); + for (final Method m : declaredMethodsForCurrentProvider) { final BaseMethodBinding foundMethodBinding = BaseMethodBinding.bindMethod(m, theProvider.getFhirContext(), theProvider); if (foundMethodBinding == null) { continue; diff --git a/hapi-fhir-jaxrsserver-base/src/test/java/ca/uhn/fhir/jaxrs/server/test/AbstractDummyPatientProvider.java b/hapi-fhir-jaxrsserver-base/src/test/java/ca/uhn/fhir/jaxrs/server/test/AbstractDummyPatientProvider.java new file mode 100644 index 00000000000..7a36fbc812b --- /dev/null +++ b/hapi-fhir-jaxrsserver-base/src/test/java/ca/uhn/fhir/jaxrs/server/test/AbstractDummyPatientProvider.java @@ -0,0 +1,34 @@ +package ca.uhn.fhir.jaxrs.server.test; + +import ca.uhn.fhir.context.FhirContext; +import ca.uhn.fhir.jaxrs.server.AbstractJaxRsResourceProvider; +import ca.uhn.fhir.rest.annotation.RequiredParam; +import ca.uhn.fhir.rest.annotation.Search; +import ca.uhn.fhir.rest.param.StringParam; +import org.hl7.fhir.r4.model.Patient; + +import java.util.List; + +/** + * A dummy patient provider exposing no methods + */ +public abstract class AbstractDummyPatientProvider extends AbstractJaxRsResourceProvider { + + public AbstractDummyPatientProvider() { + super(FhirContext.forR4()); + } + + @Override + public abstract String getBaseForServer(); + + + @Search + public List search(@RequiredParam(name = Patient.SP_NAME) final StringParam name) { + return null; + } + + @Override + public Class getResourceType() { + return Patient.class; + } +} diff --git a/hapi-fhir-jaxrsserver-base/src/test/java/ca/uhn/fhir/jaxrs/server/test/TestJaxRsDummyPatientProviderR4.java b/hapi-fhir-jaxrsserver-base/src/test/java/ca/uhn/fhir/jaxrs/server/test/TestJaxRsDummyPatientProviderR4.java index 1c3f91f4c1d..981128316bc 100644 --- a/hapi-fhir-jaxrsserver-base/src/test/java/ca/uhn/fhir/jaxrs/server/test/TestJaxRsDummyPatientProviderR4.java +++ b/hapi-fhir-jaxrsserver-base/src/test/java/ca/uhn/fhir/jaxrs/server/test/TestJaxRsDummyPatientProviderR4.java @@ -1,15 +1,11 @@ package ca.uhn.fhir.jaxrs.server.test; -import ca.uhn.fhir.jaxrs.server.AbstractJaxRsResourceProvider; -import org.hl7.fhir.r4.model.Patient; - /** * A dummy patient provider exposing no methods */ -public class TestJaxRsDummyPatientProviderR4 extends AbstractJaxRsResourceProvider { +public class TestJaxRsDummyPatientProviderR4 extends AbstractDummyPatientProvider { - @Override - public Class getResourceType() { - return Patient.class; + @Override public String getBaseForServer() { + return "https://fhirserver/fhir/r4"; } } diff --git a/hapi-fhir-jaxrsserver-base/src/test/java/ca/uhn/fhir/jaxrs/server/test/TestJaxRsDummyPatientProviderR4MimeType.java b/hapi-fhir-jaxrsserver-base/src/test/java/ca/uhn/fhir/jaxrs/server/test/TestJaxRsDummyPatientProviderR4MimeType.java new file mode 100644 index 00000000000..719206b1453 --- /dev/null +++ b/hapi-fhir-jaxrsserver-base/src/test/java/ca/uhn/fhir/jaxrs/server/test/TestJaxRsDummyPatientProviderR4MimeType.java @@ -0,0 +1,12 @@ +package ca.uhn.fhir.jaxrs.server.test; + +/** + * A dummy patient provider exposing no methods + */ +public class TestJaxRsDummyPatientProviderR4MimeType extends AbstractDummyPatientProvider { + + @Override public String getBaseForServer() { + return "https://fhirserver/fhir"; + } + +} diff --git a/hapi-fhir-jaxrsserver-base/src/test/java/ca/uhn/fhir/jaxrs/server/util/JaxRsMethodBindingsMimeTypeTest.java b/hapi-fhir-jaxrsserver-base/src/test/java/ca/uhn/fhir/jaxrs/server/util/JaxRsMethodBindingsMimeTypeTest.java new file mode 100644 index 00000000000..c4ea3fb3530 --- /dev/null +++ b/hapi-fhir-jaxrsserver-base/src/test/java/ca/uhn/fhir/jaxrs/server/util/JaxRsMethodBindingsMimeTypeTest.java @@ -0,0 +1,28 @@ +package ca.uhn.fhir.jaxrs.server.util; + +import ca.uhn.fhir.jaxrs.server.test.AbstractDummyPatientProvider; +import ca.uhn.fhir.jaxrs.server.test.TestJaxRsDummyPatientProviderR4; +import ca.uhn.fhir.jaxrs.server.test.TestJaxRsDummyPatientProviderR4MimeType; +import ca.uhn.fhir.rest.api.RestOperationTypeEnum; +import org.junit.Before; +import org.junit.FixMethodOrder; +import org.junit.Test; +import org.junit.runners.MethodSorters; + +import static org.junit.Assert.assertEquals; + +@FixMethodOrder(MethodSorters.DEFAULT) +public class JaxRsMethodBindingsMimeTypeTest { + + @Before + public void setUp() { + JaxRsMethodBindings.getClassBindings().clear(); + } + + @Test + public void testFindMethodsFor2ProvidersWithMethods() { + assertEquals(AbstractDummyPatientProvider.class, new TestJaxRsDummyPatientProviderR4().getBindings().getBinding(RestOperationTypeEnum.SEARCH_TYPE, "").getMethod().getDeclaringClass()); + assertEquals(AbstractDummyPatientProvider.class, new TestJaxRsDummyPatientProviderR4MimeType().getBindings().getBinding(RestOperationTypeEnum.SEARCH_TYPE, "").getMethod().getDeclaringClass()); + } + + }