Spring Camel: Fhir Route without explicit serverUrl parameter on XML

48 Views Asked by At

I would like to remove serverUrl from my camel route fhir. The route works fine when I include the &serverUrl={{camel.component.fhir.server-url}} part in the URI, but I want to avoid this and I would like dynamically load the FHIR server URL from the application.properties.

application.properties:

camel.component.fhir.server-url=http://hapi.fhir.org/baseR4

camel-context.xml:

<!-- camel-context.xml -->
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:camel="http://camel.apache.org/schema/spring"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
                           http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd">

    <camel:camelContext id="myCamelContext" xmlns="http://camel.apache.org/schema/spring">
        <!-- Use the configured FHIR server URL -->
        <camel:propertyPlaceholder id="propertiesPlaceholder" location="classpath:application.properties"/>

        <!-- Define your Camel routes here -->
        <camel:route id="readPatientById">
            <camel:from uri="direct:readPatientById"/>
            <camel:setHeader headerName="CamelFhir.resourceId">
                <camel:simple>${header.id}</camel:simple>
            </camel:setHeader>
            <!-- Use the configured FHIR server URL dynamically -->
            <camel:to uri="fhir://read/resourceById?resourceClass=Patient&amp;stringId=${header.CamelFhir.resourceId}&amp;prettyPrint=true&amp;serverUrl={{camel.component.fhir.server-url}}"/>
            <camel:log message="Patient read successfully. Body: ${body}"/>
        </camel:route>
    </camel:camelContext>

</beans>

camel-context.xml file is loaded in this way:

public class DemoApplication {
    
    public static void main(String[] args) {
...     
ClassPathXmlApplicationContext applicationContext = 
  new ClassPathXmlApplicationContext("classpath:camel-context.xml");
...

When I remove &serverUrl={{camel.component.fhir.server-url}} from the URI, it returns:

org.apache.camel.ResolveEndpointFailedException: Failed to resolve endpoint: fhir://read/resourceById?prettyPrint=true&resourceClass=Patient&stringId=592852 due to: The FHIR URL must be set!

On the contrary, Java counterpart (using RouterBuilder) works perfectly fine.

I would like to remove serverUrl parameter from the xml route, if you have any insights or suggestions on what might be causing the issue would be greatly appreciated.

0

There are 0 best solutions below