0

I am using IBM WebSphere Application Server Liberty to perform JNDI lookup.I am pretty sure about giving right about the location of resources in the project. However, when i run this I am getting a name not found error.

Here is the code performing the lookup:

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException 
{
  PrintWriter out = response.getWriter();
  response.setContentType("text/html");
  try {
      FlightService flightService = (FlightService)new InitialContext().lookup("java:comp/Web1/FlightService!com.airline.FlightService");
  }
  catch(Exception ex){
      ex.printStackTrace();
  }
  if(flightService !=null){
      out.println(flightService.getAirplaneModel());
      out.println(flightService.getFrom());
      out.println(flightService.getTo());

  }
}

Here is the server.xml:

<server description="new server">

  <!-- Enable features -->
    <featureManager>
      <feature>webProfile-7.0</feature>
      <feature>localConnector-1.0</feature>
    </featureManager>

  <!-- To access this server from a remote client add a host attribute to the following element, e.g. host="*" -->
  <httpEndpoint httpPort="9090" httpsPort="9443" id="defaultHttpEndpoint"/>

  <!-- Automatically expand WAR files and EAR files -->
  <applicationManager autoExpand="true"/>


  <applicationMonitor updateTrigger="mbean"/>

  <webApplication id="Web1" location="Web1-0.0.1-SNAPSHOT.war" name="Web1"/>
</server>

I am not sure , If i have to set any configuration related properties. Any help would be appreciated.

Andy Guibert
  • 41,446
  • 8
  • 38
  • 61
mohan babu
  • 1,388
  • 2
  • 17
  • 35
  • Can you post your server xml as well? Thanks – Abelard Chow Feb 13 '17 at 21:49
  • @AbelardChow Thanks for the quick comment edited! and included. – mohan babu Feb 13 '17 at 21:53
  • Can you include some detail on what exactly `FlightService` is (EJB, JAX-WS service, data source, etc)? Based on the JNDI lookup syntax you are using, it looks like you are attempting to lookup an EJB, in which case there are much easier ways to get an EJB reference (such as injection). – Andy Guibert Feb 13 '17 at 22:38

1 Answers1

0

Looking at the server xml. I don't see JNDI entry being defined. Based on the code, it should be trying to access a JNDI entry from a servlet. In this case, where do you define you JNDI entry in the first place?

I think you need the following to define the JNDI entry in the server xml

https://www.ibm.com/support/knowledgecenter/en/SSEQTP_8.5.5/com.ibm.websphere.wlp.doc/ae/twlp_dep_jndi_refentry.html

Please give it a try

Abelard Chow
  • 598
  • 1
  • 5
  • 12