1

I have deployed an spring boot web application in WAS Liberty server (WebSphere Application Server Version 8.5.5.9 Liberty Profile).

I have a JNDI url entry added in server.xml which is given below but one of my class in api is not able to access it.

<jndiURLEntry jndiName="url/SSOService" value="http://ssoserver.dev.intranet/SSOService/SSOFacade" />

I found one weird thing in Liberty is that whenever I add java:comp/env/ to any of the JNDI entry , application is not able to pick it and getting javax.naming.NameNotFoundException:

I fixed the datasource issue by not adding the prefix, but the above URL is used in only of the api which is not in my control.

So how can we enable java:com/env prefix in Websphere Liberty server ? or is there any alternative available to make this working ?

Andy Guibert
  • 41,446
  • 8
  • 38
  • 61
vijaidhas
  • 94
  • 9
  • Did you see [this WAS config page](https://www.ibm.com/support/knowledgecenter/en/SSEQTP_8.5.5/com.ibm.websphere.wlp.doc/ae/twlp_dep_jndi.html)? Your example looks reasonable. Perhaps create a test endpoint to see if you can lookup the resource in your own code. Perhaps the API is expecting a String instead of a URL instance? – Andrew S Jan 16 '18 at 14:47

1 Answers1

1

When you define a JNDI URL entry in the following way:

<jndiURLEntry jndiName="url/SSOService" value="..."/>

It will make the java.net.URL available literally at the url/SSOService name (i.e. no sort of java: prefix). Looking up a JNDI entry from this location is known as a "direct lookup", because you are looking something up that was defined directly in server configuration.

If you want to register this in the java:comp/env/ namespace, you must define a "resource reference", which will create a binding from the server-defined entry to a java:comp/env/ entry. A resource reference can be defined annotatively or via web.xml.

Here is how you can define an annotative resource reference:

@Resource(lookup="url/SSOService", name="url/SSOServiceRef")
URL ssoServiceURL;

In this example, we're saying:

  1. Perform a direct lookup of url/SSOService
  2. Bind that object to java:comp/env/url/SSOServiceRef
Andy Guibert
  • 41,446
  • 8
  • 38
  • 61
  • Thanks for your inputs, I have the same code working properly in tomcat hosted in local machine. its able to retrieve the JNDI properly but not the case when deployed in WAS Liberty. Its skipping the prefix `"java:comp/env/"`. In tomcat, without prefix its not working. I have gone through almost all of the websphere website including which you mentioned and did not find any clear clue. Finally I will try to fetch `url/SSOService` and bind it to `java:comp/env/url/SSOServiceRef` and post my result here. – vijaidhas Jan 18 '18 at 07:53
  • Hi Andy, I tried to bind the object but got another error initial context is read-only, so not able to proceed. any idea on this. – vijaidhas Jan 25 '18 at 10:26