cancel
Showing results for 
Search instead for 
Did you mean: 

JNDI Context Exception

Former Member
0 Kudos

Hi all ,

I am trying to upload a file from my machine on to the server and also trying to download the file that has been uploaded to the server . I am using the FileTransferServiceApi for this purpose . But when I run my code I am getting the following exception . Could anyone please help me with this

The exception is

<b>Failed to look up the service: com.sap.engine.services.jndi.persistent.exception

s.NamingException: Exception while trying to get InitialContext. [Root exception is com.sap.engine.services.security.exceptions.BaseLoginException: Cannot creat

e new RemoteLoginContext instance.]

The example stops...</b>

I am not able to resolve this issue . Could anyone please help me out ???

Here is the code

import java.io.*;

import java.util.*;

import javax.naming.*;

import com.sap.engine.services.file.RemoteFile;

import com.sap.engine.services.file.FileTransfer;

import com.sap.engine.services.deploy.DeployService;

public class FileTransferServiceExample {

  

  // provides path and file name for the server file to be downloaded

  private static String fileForDownload = null;

  

  private Context ctx = null;

   

  // provides upload() and download() methods

  private RemoteFile remoteFile = null;

  

  // sets protocol support for p4

  private final String[] support = {"p4"};

   

  // provides path and file name for user's file on local machine

  private final String earToDeploy = "D:\taz.doc";

  

  // provides path and name for the downloaded  file

  private final String downloadedFile = "D:\result\taz.doc";

 

  String serverEarName = "";

  String pathToTheService = "./data/";

  FileTransfer transferer = null;

  DeployService deploy = null;

  Properties props = null;

  Properties ctxProp;

public FileTransferServiceExample() {

    

    try {

      

      // properties for InitialContext

      ctxProp = new Properties();

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

      ctxProp.put(Context.PROVIDER_URL, "incata10:50200");

      ctxProp.put(Context.SECURITY_PRINCIPAL, "Administrator");

      ctxProp.put(Context.SECURITY_CREDENTIALS, "sap");

    

      ctx = new InitialContext(ctxProp);

      

      props = new Properties();

 

      // set server EAR name

      serverEarName = pathToTheService + new File(earToDeploy).getName();

 

      // get File Transfer Service reference

      transferer = (FileTransfer) ctx.lookup("file");

      

     } catch (Exception e)  {

       System.out.println("Failed to look up the service: " + e);

        System.out.println("The example stops...");

        System.exit(0);

      }

  }

public void process() {

    try {

      

      // creates the remote file 

     remoteFile = transferer.createRemoteFile(earToDeploy, serverEarName);

 

      // uploads the file

     remoteFile.upload();

      

     // deployment

     

      

    
      

     // download of the uploaded file

       fileForDownload = "./data/taz.doc";

     try {     

        // creates remote file 

        remoteFile = transferer.createRemoteFile(downloadedFile, fileForDownload);

         

       // downloads the file

       remoteFile.download();

     } catch (Exception e) {

     System.out.println("Cannot complete the download process: " + e);

     }

      

    } catch (Exception e) {

      System.out.println("Check if myEar application has been started. The example failed.: " + e);

    }

  }

public static void main(String[] args) {

      FileTransferServiceExample ftsExample = new FileTransferServiceExample();

      ftsExample.process();

   }

}

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi Tahzeeb,

Can you check in each step you catch this exception

1. - when getting the initial context or

2. when you make a lookup.

Is this the whole trace?

best regards,

mladen

Former Member
0 Kudos

Hi Mladen ,

Thanks for taking time out to answer the query . The problem seems to be when getting the Initial Context .

The full stack trace is as follows . Any pointers ??

<b>com.sap.engine.services.jndi.persistent.exceptions.NamingException: Exception wh

ile trying to get InitialContext. [Root exception is com.sap.engine.services.sec

urity.exceptions.BaseLoginException: Cannot create new RemoteLoginContext instan

ce.]

at com.sap.engine.services.jndi.InitialContextFactoryImpl.getInitialCont

ext(InitialContextFactoryImpl.java:539)

at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:6

62)

at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:243

)

at javax.naming.InitialContext.init(InitialContext.java:219)

at javax.naming.InitialContext.<init>(InitialContext.java:195)

at FileTransferServiceExample.<init>(FileTransferServiceExample.java:85)

at FileTransferServiceExample.main(FileTransferServiceExample.java:180)

Caused by: com.sap.engine.services.security.exceptions.BaseLoginException: Canno

t create new RemoteLoginContext instance.

at com.sap.engine.services.security.remote.login.RemoteLoginContext.<ini

t>(RemoteLoginContext.java:98)

at com.sap.engine.services.jndi.implclient.LoginHelper.clientSideLogin(L

oginHelper.java:78)

at com.sap.engine.services.jndi.InitialContextFactoryImpl.getInitialCont

ext(InitialContextFactoryImpl.java:403)

... 6 more

Caused by: com.sap.engine.services.rmi_p4.P4IOException: Cannot open connection

on host: 10.6.2.16 and port: 50200

at com.sap.engine.services.rmi_p4.P4ObjectBrokerClientImpl.getException(

P4ObjectBrokerClientImpl.java:713)

at com.sap.engine.services.rmi_p4.ConnectionManager.getConnection(Connec

tionManager.java:227)

at com.sap.engine.services.rmi_p4.P4ObjectBrokerClientImpl.resolveInitia

lReference(P4ObjectBrokerClientImpl.java:142)

at com.sap.engine.services.rmi_p4.P4ObjectBrokerClientImpl.resolveInitia

lReference(P4ObjectBrokerClientImpl.java:102)

at com.sap.engine.services.security.remote.login.RemoteLoginContext.<ini

t>(RemoteLoginContext.java:87)

... 8 more</b>

Former Member
0 Kudos

Hi Tahzeeb,

I think the port that you use is not correct. Can you try with 50204?

best regards,

mladen

Former Member
0 Kudos

Hi Mladen ,

Thanks a lot for your help . Can I use the same principle in a web dynpro application ?

Former Member
0 Kudos

Hi Tahzeeb,

you can use the same principle in each case when you are trying to get Initial context.

when you try yo get an initial context you have to use P4 Port

best regards,

mladen

Answers (0)