Author: markt
Date: Wed Sep 12 19:46:28 2012
New Revision: 1384102
URL: http://svn.apache.org/viewvc?rev=1384102&view=rev
Log:
Implement some TODOs:
- Add debug logging for error conditions that are otherwise swallowed
- Implement created time for files
Added:
tomcat/sandbox/trunk-resources/java/org/apache/catalina/webresources/Constants.java
(with props)
tomcat/sandbox/trunk-resources/java/org/apache/catalina/webresources/LocalStrings.properties
(with props)
Modified:
tomcat/sandbox/trunk-resources/java/org/apache/catalina/webresources/FileResource.java
tomcat/sandbox/trunk-resources/java/org/apache/catalina/webresources/JarResource.java
tomcat/sandbox/trunk-resources/java/org/apache/catalina/webresources/ResourceBase.java
Added:
tomcat/sandbox/trunk-resources/java/org/apache/catalina/webresources/Constants.java
URL:
http://svn.apache.org/viewvc/tomcat/sandbox/trunk-resources/java/org/apache/catalina/webresources/Constants.java?rev=1384102&view=auto
==============================================================================
---
tomcat/sandbox/trunk-resources/java/org/apache/catalina/webresources/Constants.java
(added)
+++
tomcat/sandbox/trunk-resources/java/org/apache/catalina/webresources/Constants.java
Wed Sep 12 19:46:28 2012
@@ -0,0 +1,22 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.catalina.webresources;
+
+public final class Constants {
+
+ public static final String Package = "org.apache.catalina.webresoucres";
+}
Propchange:
tomcat/sandbox/trunk-resources/java/org/apache/catalina/webresources/Constants.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified:
tomcat/sandbox/trunk-resources/java/org/apache/catalina/webresources/FileResource.java
URL:
http://svn.apache.org/viewvc/tomcat/sandbox/trunk-resources/java/org/apache/catalina/webresources/FileResource.java?rev=1384102&r1=1384101&r2=1384102&view=diff
==============================================================================
---
tomcat/sandbox/trunk-resources/java/org/apache/catalina/webresources/FileResource.java
(original)
+++
tomcat/sandbox/trunk-resources/java/org/apache/catalina/webresources/FileResource.java
Wed Sep 12 19:46:28 2012
@@ -23,11 +23,17 @@ import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
+import java.nio.file.Files;
+import java.nio.file.attribute.BasicFileAttributes;
import org.apache.catalina.WebResourceRoot;
+import org.apache.juli.logging.Log;
+import org.apache.juli.logging.LogFactory;
public class FileResource extends ResourceBase {
+ private static final Log log = LogFactory.getLog(FileResource.class);
+
private final File resource;
public FileResource(WebResourceRoot root, File resource,
@@ -82,7 +88,10 @@ public class FileResource extends Resour
try {
return resource.getCanonicalPath();
} catch (IOException ioe) {
- // TODO Log this?
+ if (log.isDebugEnabled()) {
+ log.debug(sm.getString("fileResource.getCanonicalPathFail",
+ resource.getPath()), ioe);
+ }
return null;
}
}
@@ -120,8 +129,17 @@ public class FileResource extends Resour
@Override
public long getCreation() {
- // TODO Auto-generated method stub
- return 0;
+ try {
+ BasicFileAttributes attrs = Files.readAttributes(resource.toPath(),
+ BasicFileAttributes.class);
+ return attrs.creationTime().toMillis();
+ } catch (IOException e) {
+ if (log.isDebugEnabled()) {
+ log.debug(sm.getString("fileResource.getCreationFail",
+ resource.getPath()), e);
+ }
+ return 0;
+ }
}
@Override
@@ -130,7 +148,10 @@ public class FileResource extends Resour
try {
return resource.toURI().toURL();
} catch (MalformedURLException e) {
- // TODO Log this?
+ if (log.isDebugEnabled()) {
+ log.debug(sm.getString("fileResource.getUrlFail",
+ resource.getPath()), e);
+ }
return null;
}
} else {
Modified:
tomcat/sandbox/trunk-resources/java/org/apache/catalina/webresources/JarResource.java
URL:
http://svn.apache.org/viewvc/tomcat/sandbox/trunk-resources/java/org/apache/catalina/webresources/JarResource.java?rev=1384102&r1=1384101&r2=1384102&view=diff
==============================================================================
---
tomcat/sandbox/trunk-resources/java/org/apache/catalina/webresources/JarResource.java
(original)
+++
tomcat/sandbox/trunk-resources/java/org/apache/catalina/webresources/JarResource.java
Wed Sep 12 19:46:28 2012
@@ -24,9 +24,13 @@ import java.util.jar.JarEntry;
import java.util.jar.JarFile;
import org.apache.catalina.WebResourceRoot;
+import org.apache.juli.logging.Log;
+import org.apache.juli.logging.LogFactory;
public class JarResource extends ResourceBase {
+ private static final Log log = LogFactory.getLog(JarResource.class);
+
private final JarFile base;
private final String baseUrl;
private final JarEntry resource;
@@ -108,7 +112,10 @@ public class JarResource extends Resourc
try {
return base.getInputStream(resource);
} catch (IOException e) {
- // TODO log this?
+ if (log.isDebugEnabled()) {
+ log.debug(sm.getString("fileResource.getInputStreamFail",
+ resource.getName(), baseUrl), e);
+ }
return null;
}
}
@@ -129,7 +136,10 @@ public class JarResource extends Resourc
try {
return new URL(baseUrl + "!/" + resource.getName());
} catch (MalformedURLException e) {
- // TODO Log this?
+ if (log.isDebugEnabled()) {
+ log.debug(sm.getString("fileResource.getUrlFail",
+ resource.getName(), baseUrl), e);
+ }
return null;
}
}
Added:
tomcat/sandbox/trunk-resources/java/org/apache/catalina/webresources/LocalStrings.properties
URL:
http://svn.apache.org/viewvc/tomcat/sandbox/trunk-resources/java/org/apache/catalina/webresources/LocalStrings.properties?rev=1384102&view=auto
==============================================================================
---
tomcat/sandbox/trunk-resources/java/org/apache/catalina/webresources/LocalStrings.properties
(added)
+++
tomcat/sandbox/trunk-resources/java/org/apache/catalina/webresources/LocalStrings.properties
Wed Sep 12 19:46:28 2012
@@ -0,0 +1,21 @@
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+fileResource.getCanonicalPathFail=Unable to determine the canonical path for
the resource [{0}]
+fileResource.getCreationFail=Unable to determine the creation time for the
resource [{0}]
+fileResource.getUrlFail=Unable to determine a URL for the resource [{0}]
+
+jarResource.getInputStreamFail=Unable to obtain an InputStream for the
resource [{0}] located in the JAR [{1}]
+jarResource.getUrlFail=Unable to determine a URL for the resource [{0}]
located in the JAR [{1}]
Propchange:
tomcat/sandbox/trunk-resources/java/org/apache/catalina/webresources/LocalStrings.properties
------------------------------------------------------------------------------
svn:eol-style = native
Modified:
tomcat/sandbox/trunk-resources/java/org/apache/catalina/webresources/ResourceBase.java
URL:
http://svn.apache.org/viewvc/tomcat/sandbox/trunk-resources/java/org/apache/catalina/webresources/ResourceBase.java?rev=1384102&r1=1384101&r2=1384102&view=diff
==============================================================================
---
tomcat/sandbox/trunk-resources/java/org/apache/catalina/webresources/ResourceBase.java
(original)
+++
tomcat/sandbox/trunk-resources/java/org/apache/catalina/webresources/ResourceBase.java
Wed Sep 12 19:46:28 2012
@@ -18,9 +18,13 @@ package org.apache.catalina.webresources
import org.apache.catalina.WebResource;
import org.apache.catalina.WebResourceRoot;
+import org.apache.tomcat.util.res.StringManager;
public abstract class ResourceBase implements WebResource {
+ protected static final StringManager sm =
+ StringManager.getManager(Constants.Package);
+
private final WebResourceRoot root;
private final String webAppPath;
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]