We help IT Professionals succeed at work.
Get Started

Object not bound in context

mike9483 asked
Last Modified: 2012-05-12

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();
            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;

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

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.
Watch Question
This problem has been solved!
Unlock 1 Answer and 4 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE