Additional checks in URL proxy
authorMathieu Baudier <mbaudier@argeo.org>
Mon, 13 Feb 2012 16:52:25 +0000 (16:52 +0000)
committerMathieu Baudier <mbaudier@argeo.org>
Mon, 13 Feb 2012 16:52:25 +0000 (16:52 +0000)
git-svn-id: https://svn.argeo.org/commons/trunk@5073 4cfe0d0a-d680-48aa-b62c-e0a02a3f76cc

server/runtime/org.argeo.server.jcr/src/main/java/org/argeo/jcr/proxy/AbstractUrlProxy.java

index 357ec1f37262aa0a847fcdc41309314d43b90453..7f1788427b36ac2d118df005d0922137cda660f5 100644 (file)
@@ -1,5 +1,6 @@
 package org.argeo.jcr.proxy;
 
+import java.io.IOException;
 import java.io.InputStream;
 import java.net.URL;
 
@@ -89,15 +90,19 @@ public abstract class AbstractUrlProxy implements ResourceProxy {
        }
 
        /** Session is not saved */
-       protected Node proxyUrl(Session session, String baseUrl, String path) {
+       protected Node proxyUrl(Session session, String baseUrl, String path)
+                       throws RepositoryException {
+               String nodePath = getNodePath(path);
+               if (jcrAdminSession.itemExists(nodePath))
+                       throw new ArgeoException("Node " + nodePath + " already exists");
                Node node = null;
                String remoteUrl = baseUrl + path;
                InputStream in = null;
                try {
                        URL u = new URL(remoteUrl);
                        in = u.openStream();
-                       node = importFile(session, getNodePath(path), in);
-               } catch (Exception e) {
+                       node = importFile(session, nodePath, in);
+               } catch (IOException e) {
                        if (log.isTraceEnabled()) {
                                log.trace("Cannot read " + remoteUrl + ", skipping... "
                                                + e.getMessage());