package org.example.test; import java.util.logging.Logger; import javax.inject.Inject; import org.switchyard.component.bean.Reference; import org.switchyard.component.bean.Service; @Service(Sample.class) public class SampleBean implements Sample{ private static final Logger LOG = Logger .getLogger(SampleBean.class.getName()); @Inject @Reference("SampleRemote") private Sample sampleRemote; @Override public String process(String request) { LOG.info("START"); String response = null; try { // This method will set the destination endpoint: setEndpoint(); response = sampleRemote.process(request); } catch (Throwable th){ th.printStackTrace(); response = "FAILURE"; } LOG.info("END"); return response; } private void setEndpoint() { // Get the System where the call will be made: String system = System.getProperty("SO_ROUTE_SYSTEM"); String endpoint = null; // If is ALPHA, then read the ALPHA Endpoint and save it. if ("ALPHA".equalsIgnoreCase(system)) { endpoint = System .getProperty("SO_ROUTE_ENDPOINT_ALPHA"); } else { // Else, read the BETA Endpoint and save it. endpoint = System .getProperty("SO_ROUTE_ENDPOINT_BETA"); } LOG.info("==> System: "+system+", Endpoint: " + endpoint); // This is the final endpoint which will be used by Switchyard: System.setProperty("SO_ROUTE_ENDPOINT", endpoint); // This log will print the correct value, while Switchyard will access the old value: LOG.info("SO_ROUTE_ENDPOINT="+System.getProperty("SO_ROUTE_ENDPOINT")); } }