Hi,

I am trying to create a Directory using a path with some space character in
it. Here a sample code:

public static void main(String[] args) throws MalformedURLException {
        String path = "C:\\Program Files\\Apache Software Foundation\\Tomcat
5.5\\webapps\\mywebapp\\";
        System.out.println("Path: "+path);
        URL url = new File(path).toURL();
        System.out.println("File URL: "+url);
        Directory d = new Directory(new Context(),url.toString());
        System.out.println(d);
    }


Here the output and exception I get:

Path: C:\Program Files\Apache Software Foundation\Tomcat
5.5\webapps\mywebapp\

File URL:  file:/C:/Program Files/Apache Software Foundation/Tomcat
5.5/webapps/mywebapp

Exception in thread "main" java.lang.IllegalArgumentException: Invalid
character detected in URI reference at index '16': " "
    at org.restlet.data.Reference.checkValidity(Reference.java:666)
    at org.restlet.data.Reference.<init>(Reference.java:531)
    at org.restlet.data.Reference.<init>(Reference.java:562)
    at org.restlet.Directory.<init>(Directory.java:142)
    at
com.usersmarts.ksb.services.servlet.TestReference.main(TestReference.java:27)

I tried to encode the URL by doing using the Reference.encode or URLEncoder

    public static void main(String[] args) throws MalformedURLException {
        String path = "C:\\Program Files\\Apache Software Foundation\\Tomcat
5.5\\webapps\\mywebapp\\";
        System.out.println("Path"+path);
        URL url = new File(path).toURL();
        System.out.println("File URL"+url);
        System.out.println("Encoded
reference:"+Reference.encode(url.toString()));
        Directory d = new Directory(new
Context(),Reference.encode(url.toString()));
        System.out.println(d);
    }


Path:  C:\Program Files\Apache Software Foundation\Tomcat
5.5\webapps\mywebapp\
File URL:  file:/C:/Program Files/Apache Software Foundation/Tomcat
5.5/webapps/mywebapp
Encoded reference:
file%3A%2FC%3A%2FProgram+Files%2FApache+Software+Foundation%2FTomcat+5.5%2Fwebapps%2Fmywebapp
Exception in thread "main" java.lang.IllegalArgumentException: Relative
references are only usable when a base reference is set.
    at org.restlet.data.Reference.getTargetRef(Reference.java:1674)
    at org.restlet.Directory.<init>(Directory.java:104)
    at org.restlet.Directory.<init>(Directory.java:142)
    at
com.usersmarts.ksb.services.servlet.TestReference.main(TestReference.java:23)

I cannot see what is wrong here. Could you help.

Thanks in advance.

Stephane Fellah
Senior Software Engineer
Image Matters LLC

Reply via email to