cancel
Showing results for 
Search instead for 
Did you mean: 

Getting NULL for ctx.lookup

Former Member
0 Kudos

Hi,

I was creating a HTTP destination but getting below exception.

OUTPUT:

Start line

ctx : javax.naming.InitialContext@f32b694

Completed Step 1

tc~sec~destinations~service

Completed Step 2

Inside if of dstService

com.sap.engine.services.jndi.persistent.exceptions.NamingException: <--Localization failed: ResourceBundle='com.sap.engine.services.jndi.persistent.JNDIResourceBundle', ID='Destination Service not available', Arguments: []--> : Can't find resource for bundle java.util.PropertyResourceBundle, key Destination Service not available

  at Client.main(Client.java:46)

-----------------------------------------------------------------------------------------------------

below is the code. I think the code is not getting destination service object from server. What is the step to add "destinationservice" in SAP NW 731 portal?

import java.rmi.RemoteException;

import java.util.Hashtable;

import javax.naming.Context;

import javax.naming.InitialContext;

import com.sap.engine.services.jndi.persistent.exceptions.NamingException;

import com.sap.security.core.server.destinations.api.DestinationException;

import com.sap.security.core.server.destinations.api.DestinationService;

import com.sap.security.core.server.destinations.api.HTTPDestination;

public class Client {

  /**

  * @param args

  */

  public static void main(String[] args) {

  // TODO Auto-generated method stub

  Hashtable<String, String>  env = new Hashtable<String, String>();

     env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sap.engine.services.jndi.InitialContextFactoryImpl");

     env.put(Context.PROVIDER_URL, "<HostName>:<P4_port>");

     env.put(Context.SECURITY_PRINCIPAL, "<user>");

     env.put(Context.SECURITY_CREDENTIALS, "<password>");

  

  try{

  System.out.println("Start line");

  Context ctx = new InitialContext(env);

  System.out.println("ctx : " +ctx.toString());

  System.out.println("Completed Step 1");

  System.out.println(DestinationService.JNDI_KEY);

     DestinationService dstService = (DestinationService)ctx.lookup(DestinationService.JNDI_KEY); //getting null at this line

     System.out.println("Completed Step 2");

  

     if (dstService == null){

      System.out.println("Inside if of dstService");

      ctx.close();

         throw new NamingException("Destination Service not available");

     }

     //Note: this only created the destination

     //it needs to be stored using dstService.storeDestination

     System.out.println("Completed Step 4");

     HTTPDestination destination = (HTTPDestination)

     dstService.createDestination("HTTP");

     destination.setUrl("http://<host>:<HTTP_port>");

     destination.setName("UMEConnection");

     destination.setUsernamePassword("<userName>", "<password>");

     dstService.storeDestination("HTTP", destination);

  }catch(DestinationException | RemoteException | javax.naming.NamingException e){

  e.printStackTrace();

  }

}

}


The ctx is coming as null.

Accepted Solutions (0)

Answers (1)

Answers (1)

former_member193379
Active Contributor
0 Kudos

Hi Aligan,

Have you checked your stub (DestinationService.JNDI_KEY)? Please try by passing as a hard coded value.

Thanks,

Hamendra

Former Member
0 Kudos

Hi Hamendra,

Even after hard coding DestinationService.JNDI_KEY to tc~sec~destinations~service in the code, I am getting dstService = null.

Is there anything else I need to change in SAP portal NWA?

Is there any way to check the destination services that are available in SAP Portal?

Thanks

Alingan Patra

former_member193379
Active Contributor
0 Kudos

Hi Alingan,

This is not your JNDI. This first need to be created like for EJB or connection ,... etc.

Please check your requirement, why do you need this?

Thanks,

Hamendra