Solved

$CATALINA_TMPDIR No such file or directory error

Posted on 2007-03-28
15
661 Views
Last Modified: 2013-11-24
I have a problem that is occuring in a production environment but the problem does not occur in a development and test environment.  The problem in production happens when uploading a file.  The error is:

HTTP Status 500 -

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

type Exception report

message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

org.apache.jasper.JasperException: Processing of multipart/form-data request failed. $CATALINA_TMPDIR/upload_00000546.tmp (No such file or directory)
      at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:248)
      at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:295)
      at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:241)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:247)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193)
      at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:256)
      at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
      at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
      at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
      at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
      at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
      at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
      at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
      at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2417)
      at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:180)
      at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
      at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:171)
      at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
      at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:172)
      at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
      at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
      at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
      at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:174)
      at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
      at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
      at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
      at org.apache.coyote.tomcat4.CoyoteAdapter.service(CoyoteAdapter.java:193)
      at org.apache.jk.server.JkCoyoteHandler.invoke(JkCoyoteHandler.java:309)
      at org.apache.jk.common.HandlerRequest.invoke(HandlerRequest.java:387)
      at org.apache.jk.common.ChannelSocket.invoke(ChannelSocket.java:673)
      at org.apache.jk.common.ChannelSocket.processConnection(ChannelSocket.java:615)
      at org.apache.jk.common.SocketConnection.runIt(ChannelSocket.java:786)
      at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:666)
      at java.lang.Thread.run(Thread.java:534)


root cause

javax.servlet.ServletException: Processing of multipart/form-data request failed. $CATALINA_TMPDIR/upload_00000546.tmp (No such file or directory)
      at org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:533)
      at org.apache.jsp.voicemail_jsp._jspService(voicemail_jsp.java:1888)
      at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:137)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
      at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:204)
      at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:295)
      at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:241)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:247)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193)
      at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:256)
      at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
      at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
      at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
      at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
      at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
      at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
      at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
      at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2417)
      at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:180)
      at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
      at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:171)
      at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
      at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:172)
      at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
      at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
      at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
      at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:174)
      at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
      at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
      at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
      at org.apache.coyote.tomcat4.CoyoteAdapter.service(CoyoteAdapter.java:193)
      at org.apache.jk.server.JkCoyoteHandler.invoke(JkCoyoteHandler.java:309)
      at org.apache.jk.common.HandlerRequest.invoke(HandlerRequest.java:387)
      at org.apache.jk.common.ChannelSocket.invoke(ChannelSocket.java:673)
      at org.apache.jk.common.ChannelSocket.processConnection(ChannelSocket.java:615)
      at org.apache.jk.common.SocketConnection.runIt(ChannelSocket.java:786)
      at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:666)
      at java.lang.Thread.run(Thread.java:534)



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

Apache Tomcat/4.1.29-LE-jdk14

The JSP code used to upload the file is:

boolean bIsMultipart = FileUpload.isMultipartContent(request);
if (bIsMultipart) {
      DiskFileUpload upload = new DiskFileUpload();

      // Parse the request
      java.util.List /* FileItem */ items = upload.parseRequest(request);
      psCollection formFields = new psCollection();

      Iterator iter = items.iterator();

      while (iter.hasNext() && !bErrorFlag) {
            boolean bFileExists = false;
            FileItem item = (FileItem) iter.next();
            if (item.isFormField()) {
                  //first get the all the data entered.  Process the data after the while loop
                  formFields.add(new String(item.getString()), new String(item.getFieldName()));
            } else {
                  sName = item.getFieldName();
                  sFileName = item.getName().substring(item.getName().lastIndexOf("\\") + 1);
                  sContentType = item.getContentType();
                  bInMemory = item.isInMemory();
                  lSizeInBytes = item.getSize();
                  
                  // Process the file upload in memory
                  try {
                        data = item.get();
                  } catch (Exception e) {
                        bErrorFlag = true;
                        sDisplayMessage = "We were unable to access the uploaded file.";
                        logger.debug("unable to get the data from the file.");
                  }



The main difference between the development/test environment and the production environment is that the development/test environment have Apache and Tomcat on the same server while the production environment has one server running Apache and another server running Tomcat.
0
Comment
Question by:david_m_jacobson
  • 5
  • 5
  • 3
  • +1
15 Comments
 
LVL 23

Accepted Solution

by:
Ajay-Singh earned 500 total points
ID: 18813627
check if there is write access to CATALINA_TMPDIR folder
0
 

Author Comment

by:david_m_jacobson
ID: 18813679
I did that.  The permissions were set to 744.  I changed it to 777 and recreated the bug but I did not restart Tomcat because it's a production box.  Do you know if I need to restart Tomcat before the permission change will take effect?
0
 
LVL 30

Expert Comment

by:mayankeagle
ID: 18813686
Maybe - I would say try that on a test instance first and verify - then bring down the production
0
 

Author Comment

by:david_m_jacobson
ID: 18813726
I don't have the authority to restart the production environment.  I will ask someone to do this tomorrow.
0
 
LVL 30

Expert Comment

by:mayankeagle
ID: 18813730
Test it first for verification
0
 
LVL 27

Expert Comment

by:rrz
ID: 18817793
If you can use commons-fileupload-1.2 , then you can stream the files. Please try the following(create the folder "fileUploads" in your web app's root folder manually prior to testing).
<%@ page import="java.util.*,
                 java.io.*,
                 org.apache.commons.fileupload.*,
                 org.apache.commons.fileupload.servlet.*,
                 org.apache.commons.fileupload.disk.*,
                 org.apache.commons.fileupload.util.*"%>
<%
  boolean isMultipart = ServletFileUpload.isMultipartContent(request);
  if(isMultipart){
                  ServletFileUpload upload = new ServletFileUpload();
                  FileItemIterator iter = upload.getItemIterator(request);
                  FileItemStream item = null;
                  String name = "";
                  InputStream stream = null;
                  while (iter.hasNext()){
                                         item = iter.next();
                                         name = item.getFieldName();
                                         stream = item.openStream();
                    if(item.isFormField()){out.println("Form field " + name + " with value "
                                               + Streams.asString(stream) + " detected.<br/>");}
                    else {
                          name = item.getName();
                          if(name != null && !"".equals(name)){
                             out.println("File field " + name + " with file name "
                                                        + item.getName() + " detected.<br/>");
                             String fileName = new File(item.getName()).getName();
                             File file = new File(application.getRealPath("/fileUploads/"
                                                       + fileName));
                             FileOutputStream fos = new FileOutputStream(file);
                             int c;
                             while( ( c=stream.read() ) != -1 ) fos.write( c );
                             out.print(fileName
                                + " was uploaded to the fileUploads folder.<br/>");
                          }
                       }
                  }
  }
0
 
LVL 27

Expert Comment

by:rrz
ID: 18821658
I thought of another idea. What about going into catalina.bat and changing  $CATALINA_TMPDIR  to something that will work for you.
0
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 

Author Comment

by:david_m_jacobson
ID: 18823067
OK, I tested changing the permissions of the temp directory.  That did not work.  I still get the same error.

I think the error has something to do with the fact that the Apache server is separate from the Tomcat server.  Is it possible that the code is somehow trying to find $CATALINA_TMPDIR on the Apache server and cannot find it since Tomcat isn't loaded on the Apache server?

Also, I connected to the Tomcat server and confirmed that the variable CATALINA_TMPDIR exists but is it possible that the connection from the Apache server to the Tomcat server is using a different username and that username does not have CATALINA_TMPDIR defined?

We are using the mod_jk2 connector and I could not find where the connection is defined.

Also, note that the existing code works fine in our development and test environments but we have both environments set up on a single server.  A customer implmented Apache and Tomcat on separate servers and that is where it is bombing.
0
 
LVL 27

Expert Comment

by:rrz
ID: 18823327
Please try this page.
<%@ page import="java.io.*" %>
<%
  File testFile = new File(application.getRealPath("/testFile.txt"));
  FileWriter fw = new FileWriter(testFile);
  fw.write("This is a test to see if testFile was created..");
  fw.close();
  out.print("File creation test. Please look in your web app's root folder.");
%>
0
 
LVL 27

Expert Comment

by:rrz
ID: 18825811
If you are able to create a test file within your web app, then try streaming the files to the server(see my first post).       rrz
0
 

Author Comment

by:david_m_jacobson
ID: 18825890
I haven't tested out using streaming but I am reluctant to change the code since it works in the development environment and the test environment.  Can anyone explain why it doesn't work in this production environment?
0
 
LVL 27

Expert Comment

by:rrz
ID: 18826836
0
 

Author Comment

by:david_m_jacobson
ID: 19476321
I found the problem.  $CATALINA_TMPDIR was misspelled as $CATALINA_TEMPDIR (with an extra "E") and as a result the server couldn't find the directory.
0
 
LVL 30

Expert Comment

by:mayankeagle
ID: 19477928
Points to Ajay-Singh, he gave the right spelling in his first comment
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

It is possible to boost certain documents at query time in Solr. Query time boosting can be a powerful resource for finding the most relevant and "best" content. Of course the more information you index, the more fields you will be able to use for y…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
The viewer will learn how to implement Singleton Design Pattern in Java.
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now