We help IT Professionals succeed at work.

Object not bound in context

mike9483
mike9483 asked
on
Hi

I took over some source code from another developer.  Most of the items are working fine but I am battling with one part of the code where I am getting an [Object] not bound in this context error.

The source code from the relevant class is as follows:

      public static FileManager getFileManager() throws NamingException {
            log.trace("Trying to set up FM - step 1.");      
            FileManager fm = null;
            log.trace("Trying to set up FM - step 2.");      
            Properties env = new Properties();
            env.setProperty("java.naming.factory.initial","com.sun.jndi.rmi.registry.RegistryContextFactory");
            env.setProperty("java.naming.provider.url","localhost:1099");
            env.setProperty("java.naming.factory.url.pkgs","org.jnp.interfaces");
            InitialContext ctx = new InitialContext(env);
            log.trace("Trying to set up FM - step 3.");      
            fm = (FileManager) ctx.lookup("121/FileManager");
            log.trace("Trying to set up FM - step 4.");      
          return fm;
      }

The source code for the FileManager class is as follows:
package za.co.oneTwoOne.fileManager;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.sql.SQLException;

import javax.ejb.Local;
import javax.sql.RowSet;

@Local
public interface FileManager {

      /**
       * Returns a new fileID
       * @param userID The userID of the caller
       * @return A fileID that can be written to
       * @throws SQLException
       */
      public abstract int getFileID(int userID) throws SQLException;

      public abstract int getFileID(int userID, String fileName) throws SQLException;
      
      public abstract RowSet getFileProperties(int userID, int fileID)
                  throws SQLException;

      /**
       * Returns a java File object that can be manipulated. This file
       * represents a new file in the store.
       * @param userID The id of the user manipulating this fil
       * @param fileID The fileID of the file
       * @return A file object
       * @throws IOException
       * @throws SQLException
       */
      public abstract File getFile(int fileID) throws IOException, SQLException;

      /**
       * Returns a handle to a file (if the file did not exist, it is created).
       * @param userID The userID of the requesting user
       * @param fileID The fileID
       * @return A file object
       */
      public abstract File getFile(int userID, String fileName) throws IOException, SQLException;

      /**
       * Instead of returning a File object, this function returns an inputstream
       * @param fileID The fileID to read
       * @return
       * @throws SQLException
       * @throws IOException
       */
      public abstract InputStream getInputStream(int fileID)
                  throws SQLException, IOException;

      /**
       * For references to URLs stored in the file management system, return the associated URL
       * @param fileID the FileID
       * @return
       * @throws SQLException
       */
      public abstract String getURL(int fileID) throws SQLException;

      /**
       * Define this files' file name
       * @param userID
       * @param fileID
       * @param fileName
       * @throws SQLException
       */
      public abstract void setFileName(int userID, int fileID, String fileName)
                  throws SQLException;

      /**
       * Retrieve the filename associated with a fileID
       * @param fileID
       * @return
       * @throws SQLException
       */
      public abstract String getFileName(int fileID) throws SQLException;

      /**
       * Retrieves the mimetype of this file
       * @param fileID
       * @return
       * @throws SQLException
       */
      public abstract String getContentType(int fileID) throws SQLException;
      
      public abstract String getPathForFileID(int fileID);
      public abstract String getPathSeperator();
      public abstract int getMaxFilesPerDirectory();

}

There is a configuration file located at C:\ containing some parameters as set out below:
## FileManagerSettings
# Beware that if you enter this as c:\121\Files it will not work (the server will
# drop the \s (c:121Files) which won't work.
# All sizes in bytes
FileManagerRootDirectory=C:/var/121/Files
FilePathSeparator=/
FileUploadMaxSize=67108864
FileUploadMaxSizeHandledInMemory=16384
TemporaryFilePath=C:/var/121/TemporaryFiles/
DefaultFileID=237252

From the rest of the code it seems that this configuration file is being loaded successfully.

The full stack trace of the error is as follows:
2011-11-02T17:09:26 TRACE FileDownload:84 - Starting241075868
2011-11-02T17:09:26 TRACE FileDownload:86 - FileID: 247049
2011-11-02T17:09:26 TRACE FileDownload:258 - Trying to set up FM - step 1.
2011-11-02T17:09:26 TRACE FileDownload:260 - Trying to set up FM - step 2.
2011-11-02T17:09:26 TRACE FileDownload:267 - Trying to set up FM - step 3.
2011-11-02T17:09:26 ERROR FileDownload:64 - Error getting file to download: Name 121 is not bound in this Context
2011-11-02T17:09:26  INFO FileDownload:68 - Flag process as done exec FileDownloadProcessEnd 241075868
Nov 2, 2011 5:09:26 PM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet FileDownload threw exception
javax.naming.NameNotFoundException: Name 121 is not bound in this Context
        at org.apache.naming.NamingContext.lookup(NamingContext.java:770)
        at org.apache.naming.NamingContext.lookup(NamingContext.java:153)
        at org.apache.naming.SelectorContext.lookup(SelectorContext.java:152)
        at javax.naming.InitialContext.lookup(Unknown Source)
        at za.co.oneTwoOne.servlets.FileDownload.getFileManager(FileDownload.java:268)
        at za.co.oneTwoOne.servlets.FileDownload.processPost(FileDownload.java:88)
        at za.co.oneTwoOne.servlets.FileDownload.doPost(FileDownload.java:62)
        at za.co.oneTwoOne.servlets.FileDownload.doGet(FileDownload.java:34)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
        at za.co.oneTwoOne.filters.CacheController.doFilter(CacheController.java:31)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
        at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:859)
        at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
        at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
        at java.lang.Thread.run(Unknown Source)

I will appreciate your help.
Comment
Watch Question

Awarded 2011
Awarded 2011

Commented:
It looks like you are trying to access the server piece from the client while this server stuff was not deployed properly. Did you try to restart your application server and look at the logs ?
Commented:
I have figured that part out.  The lookup was obsolete and referencing a point that no longer existed.  The have bypassed that piece of code and struggling though some new challenges.  Thanks for your attempt.
Awarded 2011
Awarded 2011

Commented:
Well, good you reslved it.

Author

Commented:
I managed to resolve my own problem before any solutions were provided by the experts.

Explore More ContentExplore courses, solutions, and other research materials related to this topic.