[ 
https://issues.apache.org/jira/browse/JCR-2691?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13751343#comment-13751343
 ] 

Roman Graf commented on JCR-2691:
---------------------------------

Dear sender,

Thank you very much for your E-mail. I am currently out of the office and will 
be back on 02 September 2013.
Please note that I will only occasionally be able to check my E-mails.
Please direct any SCAPE-related queries to [email protected]

Please direct any other queries to [email protected]

Thank you!

Kind regards


                
> 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
>         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.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

Reply via email to