mike9483
asked on
Object not bound in context
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.nami ng.factory .initial", "com.sun.j ndi.rmi.re gistry.Reg istryConte xtFactory" );
env.setProperty("java.nami ng.provide r.url","lo calhost:10 99");
env.setProperty("java.nami ng.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/FileManage r");
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.fileManage r;
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
FileUploadMaxSizeHandledIn Memory=163 84
TemporaryFilePath=C:/var/1 21/Tempora ryFiles/
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.S tandardWra pperValve invoke
SEVERE: Servlet.service() for servlet FileDownload threw exception
javax.naming.NameNotFoundE xception: Name 121 is not bound in this Context
at org.apache.naming.NamingCo ntext.look up(NamingC ontext.jav a:770)
at org.apache.naming.NamingCo ntext.look up(NamingC ontext.jav a:153)
at org.apache.naming.Selector Context.lo okup(Selec torContext .java:152)
at javax.naming.InitialContex t.lookup(U nknown Source)
at za.co.oneTwoOne.servlets.F ileDownloa d.getFileM anager(Fil eDownload. java:268)
at za.co.oneTwoOne.servlets.F ileDownloa d.processP ost(FileDo wnload.jav a:88)
at za.co.oneTwoOne.servlets.F ileDownloa d.doPost(F ileDownloa d.java:62)
at za.co.oneTwoOne.servlets.F ileDownloa d.doGet(Fi leDownload .java:34)
at javax.servlet.http.HttpSer vlet.servi ce(HttpSer vlet.java: 617)
at javax.servlet.http.HttpSer vlet.servi ce(HttpSer vlet.java: 717)
at org.apache.catalina.core.A pplication FilterChai n.internal DoFilter(A pplication FilterChai n.java:290 )
at org.apache.catalina.core.A pplication FilterChai n.doFilter (Applicati onFilterCh ain.java:2 06)
at za.co.oneTwoOne.filters.Ca cheControl ler.doFilt er(CacheCo ntroller.j ava:31)
at org.apache.catalina.core.A pplication FilterChai n.internal DoFilter(A pplication FilterChai n.java:235 )
at org.apache.catalina.core.A pplication FilterChai n.doFilter (Applicati onFilterCh ain.java:2 06)
at org.apache.catalina.core.S tandardWra pperValve. invoke(Sta ndardWrapp erValve.ja va:233)
at org.apache.catalina.core.S tandardCon textValve. invoke(Sta ndardConte xtValve.ja va:191)
at org.apache.catalina.core.S tandardHos tValve.inv oke(Standa rdHostValv e.java:127 )
at org.apache.catalina.valves .ErrorRepo rtValve.in voke(Error ReportValv e.java:102 )
at org.apache.catalina.core.S tandardEng ineValve.i nvoke(Stan dardEngine Valve.java :109)
at org.apache.catalina.connec tor.Coyote Adapter.se rvice(Coyo teAdapter. java:298)
at org.apache.coyote.http11.H ttp11Proce ssor.proce ss(Http11P rocessor.j ava:859)
at org.apache.coyote.http11.H ttp11Proto col$Http11 Connection Handler.pr ocess(Http 11Protocol .java:588)
at org.apache.tomcat.util.net .JIoEndpoi nt$Worker. run(JIoEnd point.java :489)
at java.lang.Thread.run(Unkno wn Source)
I will appreciate your help.
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.nami
env.setProperty("java.nami
env.setProperty("java.nami
InitialContext ctx = new InitialContext(env);
log.trace("Trying to set up FM - step 3.");
fm = (FileManager) ctx.lookup("121/FileManage
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.fileManage
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
FilePathSeparator=/
FileUploadMaxSize=67108864
FileUploadMaxSizeHandledIn
TemporaryFilePath=C:/var/1
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.S
SEVERE: Servlet.service() for servlet FileDownload threw exception
javax.naming.NameNotFoundE
at org.apache.naming.NamingCo
at org.apache.naming.NamingCo
at org.apache.naming.Selector
at javax.naming.InitialContex
at za.co.oneTwoOne.servlets.F
at za.co.oneTwoOne.servlets.F
at za.co.oneTwoOne.servlets.F
at za.co.oneTwoOne.servlets.F
at javax.servlet.http.HttpSer
at javax.servlet.http.HttpSer
at org.apache.catalina.core.A
at org.apache.catalina.core.A
at za.co.oneTwoOne.filters.Ca
at org.apache.catalina.core.A
at org.apache.catalina.core.A
at org.apache.catalina.core.S
at org.apache.catalina.core.S
at org.apache.catalina.core.S
at org.apache.catalina.valves
at org.apache.catalina.core.S
at org.apache.catalina.connec
at org.apache.coyote.http11.H
at org.apache.coyote.http11.H
at org.apache.tomcat.util.net
at java.lang.Thread.run(Unkno
I will appreciate your help.
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 ?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Well, good you reslved it.
ASKER
I managed to resolve my own problem before any solutions were provided by the experts.