Skip to content

Regarding the InterceptorService in the RestfulServer #870

@fight-nn

Description

@fight-nn

Description

The root cause of the issue was that I wanted to intercept the /$mdm-merge-golden-resources operation and perform some custom operations after that. Therefore, I implemented an interceptor in the hapi-fhir-jpa-server. However, I found that the interceptor was not actually invoked. After in-depth debugging, I discovered that the RestfulServer was constructed in the StarterJpaConfig, and the specific code is as follows:

RestfulServer fhirServer = new RestfulServer(fhirSystemDao.getContext());

The code inside the constructor of this RestfulServer is as follows:
the hapi-fhir link is:
https://github.com/hapifhir/hapi-fhir/blob/76163efbb8dee90a37d945c44b94e74fa12a775d/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/RestfulServer.java#L191-L198
the hapi-fhir code is:

	public RestfulServer(FhirContext theCtx) {
		this(theCtx, new InterceptorService());
	}

You will find that the constructor creates a new InterceptorService. In fact, this class has already been instantiated in Spring. Please refer to the specific code for details:

the hapi-fhir link is:
https://github.com/hapifhir/hapi-fhir/blob/76163efbb8dee90a37d945c44b94e74fa12a775d/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/config/JpaConfig.java#L518-L521

the hapi-fhir code is:

	@Bean
	public IInterceptorService jpaInterceptorService() {
		return new InterceptorService();
	}

And in other places, this InterceptorService is injected as well.

Was there any consideration when constructing the RestfulServer without obtaining it from the Spring Beans?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions