Michael R. Head (suppressingfire) wrote,
Michael R. Head

One more trick for testing outside of a J2EE environment (Resource environments)

Recently, I was looking at running code -- that uses a container managed JMS connection factory -- outside of Websphere. I have some more code that uses some general "Resource environment entries" that provide application-wide configuration settings.

Here are the details. The managed code loads some name/value pairs from the resource environment like this:
		InitialContext ic = new InitialContext();
		ref = (Reference)ic.lookup("rep/MyRee");
		RefAddr refAddr = ref.get("foo");
		assert refAddr.getType().equals("java.lang.String"): "foo's type should be String, not "+refAddr.getType();
		String foo = (String) refAddr.getContent();
		System.out.println("Loaded value for foo: "+foo);

To support this code, I added the following code to bottom of setupNamingContext() (from the previous post):
		Context repCtx = ctx.createSubcontext("rep");
		Reference ref = new Reference("unused");
		StringRefAddr refAddr = new StringRefAddr("foo", "bar");
		repCtx.bind("MyRee", ref);

That's it!
  • Post a new comment


    default userpic

    Your reply will be screened

    Your IP address will be recorded