Vra

I have a POJO component which basically contains some Java classes. At this point I have some settings hardcoded (such as some credentials) that I would like to configure somehow in the flow via the Studio GUI.

Is is possible to store somehow in the flow some settings that can easily be read by my POJO component?

Was dit nuttig?

Oplossing

I see two options:

  1. Setting the credentials as System Properties using -M-Dproperty in command line and retrieving it from your POJO using java.lang.System.getProperty("property")
  2. Configuring the credentials in a .properties file and retrieve them from the Property placeholder from the Mule Registry. You can implement org.mule.api.context.MuleContextAware perhaps, or a Lookup annotation.

Also read this

Ander wenke

I ended up using this solution.

  1. Storing configuration as global properties:
<global-property name="mysystem.username" value="JSmith" doc:name="Global Property"/>
  1. Using the @Lookup annotation in the POJO to read it:

    import org.mule.api.MuleContext;
    import org.mule.api.annotations.expressions.Lookup;
    
    
    public class MulePOJO {
    
    /* http://www.mulesoft.org/documentation/display/current/Lookup+Annotation*/
    @Lookup
    private MuleContext muleContext;
    
    public String singleArgumentMethod(String x)
    {
        String value = muleContext.getRegistry().get("mysystem.username");
    
        return  x;
    }
    }
    
Gelisensieer onder: CC-BY-SA met toeskrywing
Nie verbonde aan StackOverflow
scroll top