cancel
Showing results for 
Search instead for 
Did you mean: 

How to set Properties for InitialContext creation in productive development

Former Member
0 Kudos

Hello,

I have implemented this class:

public class Conenctor {

private static final String USER = "Administrator";

private static final String PASSWORD = "*******";

private static final String SAP_NAMING_PROVIDER_URL = "vm-sapnwce:50004";

private static final String SAP_INITIAL_CONTEXT_FACTORY_IMPL = om.sap.engine.services.jndi.InitialContextFactoryImpl";

public void connect() {

Properties ctxProp = new Properties();

ctxProp.put(Context.INITIAL_CONTEXT_FACTORY,

SAP_INITIAL_CONTEXT_FACTORY_IMPL);

ctxProp.put(Context.PROVIDER_URL, SAP_NAMING_PROVIDER_URL);

ctxProp.put(Context.SECURITY_PRINCIPAL, USER);

ctxProp.put(Context.SECURITY_CREDENTIALS, PASSWORD);

/*

  • Create a JNDI API InitialContext object.

*/

Context jndiContext = null;

try {

jndiContext = new InitialContext(ctxProp);

} catch (NamingException e) {

System.out.println("Could not create JNDI API" + "context: "

+ e.toString());

e.printStackTrace();

}

...

}

...

}

Now my question:

The properties

private static final String USER = "Administrator";

private static final String PASSWORD = "*******";

private static final String SAP_NAMING_PROVIDER_URL = "vm-sapnwce:50004";

are set fix here.

In a productive development you can't set the properties fix because the properties would be different for several customers.

How would this be implemented in a productive development?

Regards,

Armin

Accepted Solutions (0)

Answers (1)

Answers (1)

volker_schropp
Explorer
0 Kudos

Hello Armin,

you could either create a property file, which you could read at the start of the application, where the information is stored in, or you could put the properties into your vm arguments like:

java

-Xmx256m -Dctx_user=Administrator -Dctx_password=***** and so on

<main_class>

All arguments which start with -D are loaded in to System-property table. You could use freely selected names for you arguments, but be careful, not to use already forgiven names.

To read this information use this code:

String ctx_user = System.getProperty("ctx_user");

To read a property file with this content:

ctx_user=Administrator

ctx_password=*****

you could use this code:

Properties properties = new Properties(),

properties.load(new FileInputStream(new File(<property file>));

String ctx_user = properties.getProperty("ctx_user");

Greetz

Volker