You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@jackrabbit.apache.org by "Roman Graf (JIRA)" <ji...@apache.org> on 2010/08/02 14:24:17 UTC

[jira] Created: (JCR-2691) Workspace missmatch exception using remote jackrabbit standalone server with proxy. Because of proxy mappings response URI contains IP address instead of the host name.

Workspace missmatch exception using remote jackrabbit standalone server with proxy. Because of proxy mappings response URI contains IP address instead of the host name. 
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------

                 Key: JCR-2691
                 URL: https://issues.apache.org/jira/browse/JCR-2691
             Project: Jackrabbit Content Repository
          Issue Type: Bug
          Components: jackrabbit-spi2dav
    Affects Versions: 2.1.0
         Environment: Client on Windows, jackrabbit standalone server on Linux using proxy. Revision 981443
            Reporter: Roman Graf


Workspace missmatch exception occures. At the moment IdURICache.java class doesn't work properly with proxy. The proxy converts host name into ip. Thus response uri contains ip instead of the host name and threrefore workflowUri doesn't match uri in the add method. 

Solution: Class IdURICache.java from org.apache.jackrabbit.spi2dav package should check uri in add method. File proxy.properties defines mapping between hostname and ip.

Patch:

Index: C:/workplaces/patch/jackrabbitpatch/src/main/java/org/apache/jackrabbit/spi2dav/IdURICache.java
===================================================================
--- C:/workplaces/patch/jackrabbitpatch/src/main/java/org/apache/jackrabbit/spi2dav/IdURICache.java	(revision 981443)
+++ C:/workplaces/patch/jackrabbitpatch/src/main/java/org/apache/jackrabbit/spi2dav/IdURICache.java	(working copy)
@@ -20,8 +20,15 @@
 import org.slf4j.LoggerFactory;
 import org.apache.jackrabbit.spi.ItemId;
 
+import java.io.IOException;
+import java.io.InputStream;
 import java.util.Map;
 import java.util.HashMap;
+import java.util.Properties;
+
+import java.net.MalformedURLException;
+import java.net.URL;
+
 
 /**
  * <code>IdURICache</code>...
@@ -35,8 +42,36 @@
     private Map<ItemId, String> idToUriCache = new HashMap<ItemId, String>();
     private Map<String, ItemId> uriToIdCache = new HashMap<String, ItemId>();
 
+    /**
+     * Proxy settings.
+     */
+    private final Properties settings;
+    
     IdURICache(String workspaceUri) {
         this.workspaceUri = workspaceUri;
+        
+        // load proxy settings         
+        this.settings = getStaticProperties();
+    }
+
+    private static Properties getStaticProperties() {
+        Properties properties = new Properties();
+        try {
+            InputStream stream =
+                getResource("proxy.properties");
+            try {
+                properties.load(stream);
+            } finally {
+                stream.close();
+            }
+        } catch (IOException e) {
+            // TODO: Log warning
+        }
+        return properties;
+    }
+
+    private static InputStream getResource(String name) {
+        return IdURICache.class.getResourceAsStream(name);
     }
 
     public ItemId getItemId(String uri) {
@@ -55,8 +90,32 @@
         return idToUriCache.containsKey(itemId);
     }
 
+    /**
+     If response URI contains IP address instead of the host name (because of proxy mappings),
+     the request URI will be converted back to the original URI according to the configurations
+     provided in  proxy.properties file.
+	*/
+    protected String getUriWithProxyConfig(String uri) {
+    	 
+    	try {
+	    	URL url = new URL(uri);
+	    	String hostIp = url.getHost();
+	    	if (settings.containsKey(hostIp)) {
+	    		//get proxy configuration
+	    		String hostName = (String) settings.get(hostIp);
+	    		//replace Ip with hostname
+	    		if (hostName != null && !hostName.isEmpty()) 
+	    			return uri.replace(hostIp, hostName);
+	    	}
+    	} catch (MalformedURLException e) {
+            throw new IllegalArgumentException("Cannot parse request URI! " + e.getMessage());    		
+    	}
+
+    	return uri;
+    }
+    
     public void add(String uri, ItemId itemId) {
-        if (!uri.startsWith(workspaceUri)) {
+        if (!uri.startsWith(workspaceUri) && !getUriWithProxyConfig(uri).startsWith(workspaceUri)) {        		
             throw new IllegalArgumentException("Workspace missmatch.");
         }
         String cleanUri = getCleanUri(uri);
Index: C:/workplaces/patch/jackrabbitpatch/src/resources/org/apache/jackrabbit/core/proxy.properties.template
===================================================================
--- C:/workplaces/patch/jackrabbitpatch/src/resources/org/apache/jackrabbit/core/proxy.properties.template	(revision 0)
+++ C:/workplaces/patch/jackrabbitpatch/src/resources/org/apache/jackrabbit/core/proxy.properties.template	(revision 0)
@@ -0,0 +1,2 @@
+# proxy configuration (mapping between IP and host name)
+ip=hostname


-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Updated: (JCR-2691) Workspace missmatch exception using remote jackrabbit standalone server with proxy. Because of proxy mappings response URI contains IP address instead of the host name.

Posted by "Roman Graf (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/JCR-2691?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Roman Graf updated JCR-2691:
----------------------------

    Attachment: patch_981443.txt

Patch for IdURICache.java.

> Workspace missmatch exception using remote jackrabbit standalone server with proxy. Because of proxy mappings response URI contains IP address instead of the host name. 
> -------------------------------------------------------------------------------------------------------------------------------------------------------------------------
>
>                 Key: JCR-2691
>                 URL: https://issues.apache.org/jira/browse/JCR-2691
>             Project: Jackrabbit Content Repository
>          Issue Type: Bug
>          Components: jackrabbit-spi2dav
>    Affects Versions: 2.1.0
>         Environment: Client on Windows, jackrabbit standalone server on Linux using proxy. Revision 981443
>            Reporter: Roman Graf
>         Attachments: patch_981443.txt
>
>
> Workspace missmatch exception occures. At the moment IdURICache.java class doesn't work properly with proxy. The proxy converts host name into ip. Thus response uri contains ip instead of the host name and threrefore workflowUri doesn't match uri in the add method. 
> Solution: Class IdURICache.java from org.apache.jackrabbit.spi2dav package should check uri in add method. File proxy.properties defines mapping between hostname and ip.
> Patch:
> Index: C:/workplaces/patch/jackrabbitpatch/src/main/java/org/apache/jackrabbit/spi2dav/IdURICache.java
> ===================================================================
> --- C:/workplaces/patch/jackrabbitpatch/src/main/java/org/apache/jackrabbit/spi2dav/IdURICache.java	(revision 981443)
> +++ C:/workplaces/patch/jackrabbitpatch/src/main/java/org/apache/jackrabbit/spi2dav/IdURICache.java	(working copy)
> @@ -20,8 +20,15 @@
>  import org.slf4j.LoggerFactory;
>  import org.apache.jackrabbit.spi.ItemId;
>  
> +import java.io.IOException;
> +import java.io.InputStream;
>  import java.util.Map;
>  import java.util.HashMap;
> +import java.util.Properties;
> +
> +import java.net.MalformedURLException;
> +import java.net.URL;
> +
>  
>  /**
>   * <code>IdURICache</code>...
> @@ -35,8 +42,36 @@
>      private Map<ItemId, String> idToUriCache = new HashMap<ItemId, String>();
>      private Map<String, ItemId> uriToIdCache = new HashMap<String, ItemId>();
>  
> +    /**
> +     * Proxy settings.
> +     */
> +    private final Properties settings;
> +    
>      IdURICache(String workspaceUri) {
>          this.workspaceUri = workspaceUri;
> +        
> +        // load proxy settings         
> +        this.settings = getStaticProperties();
> +    }
> +
> +    private static Properties getStaticProperties() {
> +        Properties properties = new Properties();
> +        try {
> +            InputStream stream =
> +                getResource("proxy.properties");
> +            try {
> +                properties.load(stream);
> +            } finally {
> +                stream.close();
> +            }
> +        } catch (IOException e) {
> +            // TODO: Log warning
> +        }
> +        return properties;
> +    }
> +
> +    private static InputStream getResource(String name) {
> +        return IdURICache.class.getResourceAsStream(name);
>      }
>  
>      public ItemId getItemId(String uri) {
> @@ -55,8 +90,32 @@
>          return idToUriCache.containsKey(itemId);
>      }
>  
> +    /**
> +     If response URI contains IP address instead of the host name (because of proxy mappings),
> +     the request URI will be converted back to the original URI according to the configurations
> +     provided in  proxy.properties file.
> +	*/
> +    protected String getUriWithProxyConfig(String uri) {
> +    	 
> +    	try {
> +	    	URL url = new URL(uri);
> +	    	String hostIp = url.getHost();
> +	    	if (settings.containsKey(hostIp)) {
> +	    		//get proxy configuration
> +	    		String hostName = (String) settings.get(hostIp);
> +	    		//replace Ip with hostname
> +	    		if (hostName != null && !hostName.isEmpty()) 
> +	    			return uri.replace(hostIp, hostName);
> +	    	}
> +    	} catch (MalformedURLException e) {
> +            throw new IllegalArgumentException("Cannot parse request URI! " + e.getMessage());    		
> +    	}
> +
> +    	return uri;
> +    }
> +    
>      public void add(String uri, ItemId itemId) {
> -        if (!uri.startsWith(workspaceUri)) {
> +        if (!uri.startsWith(workspaceUri) && !getUriWithProxyConfig(uri).startsWith(workspaceUri)) {        		
>              throw new IllegalArgumentException("Workspace missmatch.");
>          }
>          String cleanUri = getCleanUri(uri);
> Index: C:/workplaces/patch/jackrabbitpatch/src/resources/org/apache/jackrabbit/core/proxy.properties.template
> ===================================================================
> --- C:/workplaces/patch/jackrabbitpatch/src/resources/org/apache/jackrabbit/core/proxy.properties.template	(revision 0)
> +++ C:/workplaces/patch/jackrabbitpatch/src/resources/org/apache/jackrabbit/core/proxy.properties.template	(revision 0)
> @@ -0,0 +1,2 @@
> +# proxy configuration (mapping between IP and host name)
> +ip=hostname

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.