提交 66f9720f 编写于 作者: K kohsuke

improved error diagnostics. Make sure temporary directory is well-configured.

This would forestall problems like http://www.nabble.com/Image-links-broken-tt15316354.html


git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@7014 71c3de6d-444a-0410-be80-ed276b4c234a
上级 4ea51133
......@@ -4,9 +4,18 @@ import com.thoughtworks.xstream.converters.reflection.PureJavaReflectionProvider
import com.thoughtworks.xstream.core.JVM;
import hudson.model.Hudson;
import hudson.model.User;
import hudson.triggers.Trigger;
import hudson.triggers.SafeTimerTask;
import hudson.util.*;
import hudson.triggers.Trigger;
import hudson.util.HudsonIsLoading;
import hudson.util.IncompatibleServletVersionDetected;
import hudson.util.IncompatibleVMDetected;
import hudson.util.InsufficientPermissionDetected;
import hudson.util.NoHomeDir;
import hudson.util.RingBufferLogHandler;
import hudson.util.NoTempDir;
import org.jvnet.localizer.LocaleProvider;
import org.kohsuke.stapler.Stapler;
import org.kohsuke.stapler.StaplerRequest;
import javax.naming.Context;
import javax.naming.InitialContext;
......@@ -20,16 +29,12 @@ import javax.xml.transform.TransformerFactoryConfigurationError;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.Locale;
import java.util.Properties;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.net.URLClassLoader;
import java.net.URL;
import org.kohsuke.stapler.Stapler;
import org.kohsuke.stapler.StaplerRequest;
import org.jvnet.localizer.LocaleProvider;
/**
* Entry point when Hudson is used as a webapp.
......@@ -97,6 +102,17 @@ public class WebAppMain implements ServletContextListener {
return;
}
// some containers (in particular Tomcat) doesn't abort a launch
// even if the temp directory doesn't exist.
// check that and report an error
try {
File f = File.createTempFile("test", "test");
f.delete();
} catch (IOException e) {
context.setAttribute(APP,new NoTempDir(e));
return;
}
// Tomcat breaks XSLT with JDK 5.0 and onward. Check if that's the case, and if so,
// try to correct it
try {
......
package hudson.util;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.StringWriter;
/**
* Model object used to display the error top page if
* there appears to be no temporary directory.
*
* <p>
* <tt>index.jelly</tt> would display a nice friendly error page.
*
* @author Kohsuke Kawaguchi
*/
public class NoTempDir {
public final IOException exception;
public NoTempDir(IOException exception) {
this.exception = exception;
}
public String getStackTrace() {
StringWriter sw = new StringWriter();
exception.printStackTrace(new PrintWriter(sw));
return sw.toString();
}
public String getTempDir() {
return System.getProperty("java.io.tmpdir");
}
}
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form" xmlns:i="jelly:fmt">
<l:layout>
<l:header title="Hudson" />
<l:side-panel />
<l:main-panel>
<h1><img src="${imagesURL}/48x48/error.gif" alt="[!]"/><st:nbsp/>${%Error}</h1>
<p>${%description(it.tempDir)}</p>
<pre>${it.stackTrace}</pre>
</l:main-panel>
</l:layout>
</j:jelly>
\ No newline at end of file
description=\
Unable to create a temporary file. This is most likely caused by \
a mis-configuration of the container. The JVM seems to be told to use \
"{0}" as the temporary directory. Does this directory exist and is it writable?
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册