Hi Jerome,
As you said, there are sevral ways to solve the problem with Restlet and I
found another way to make it works (maybe not the easiest). Basically I
created a class extending from ServerResource and an application. In the
application, I use a certain configuration of the router :
router.attachDefault(FtpResource.class).setMatchingMode(Template.MODE_STARTS_WITH);
In the resource, I parse the representation returned by the FTP server using
a pattern ( private static final Pattern pattern =
Pattern.compile("[drwxs-]{10}");).
When my response matches with the pattern, it means that my response is a
contain of a FTP directory otherwise the response is a file.
In the case where the response is a contain of a FTP directory, I build a
referenceList. From this referenceList, I apply some representations (HTML,
text/uri-list).
In the case where the response is a file, I return the file.
It will be nice that the directory class can support the browse through a
FTP site.
Best regards,
J-Christophe
On Fri, Jul 2, 2010 at 4:06 PM, Jerome Louvel <[email protected]>wrote:
> Hi Jean-Christophe,
>
>
>
> I hope you solved this issue, sorry for the delay. In the response headers,
> you have “application/octet-stream” as content type/media type which
> explains the browser behavior.
>
>
>
> The FTP client connector provided by the “org.restlet.ext.net” extension
> automatically sets the media type when the file name has extensions such as
> “.txt”.
>
>
>
> In your case, it seems that your files have no extension which leads the
> engine to call MetadataService#getDefaultMediaType() which returns
> “application/octet-stream” by default.
>
>
>
> You have two solutions (at least):
>
> · Call MetadataService#setDefaultMediaType() with a different
> value (global to your application)
>
> · Add a filter in front of your directory that will change the
> media type appropriately
>
>
>
> Best regards,
> Jerome Louvel
> --
> Restlet ~ Founder and Technical Lead ~ http://www.restlet.org
> Noelios Technologies ~ http://www.noelios.com
>
>
>
>
>
>
>
> *De :* Jean-Christophe Malapert [mailto:[email protected]]
> *Envoyé :* vendredi 21 mai 2010 17:41
> *À :* Jerome Louvel
> *Cc :* discuss
> *Objet :* Re: Directory and FTP
>
>
>
> Hi Jerome,
>
> Here is the detail :
>
>
> GET /files/test HTTP/1.1
> Host: localhost:8180
> User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; fr; rv:1.9.2.3)
> Gecko/20100423 Ubuntu/10.04 (lucid) Firefox/3.6.3
> Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
> Accept-Language: fr,fr-fr;q=0.8,en-us;q=0.5,en;q=0.3
> Accept-Encoding: gzip,deflate
> Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
> Keep-Alive: 115
> Connection: keep-alive
>
> 21 mai 2010 17:33:41 org.restlet.engine.local.DirectoryServerResource
> doInit
> INFO: Converted target URI: ftp://193.190.231.123/
> 21 mai 2010 17:33:41 org.restlet.engine.local.DirectoryServerResource
> getVariants
> INFO: Getting variants for : ftp://193.190.231.123/
> 21 mai 2010 17:33:41 org.restlet.engine.log.LogFilter afterHandle
> INFO: 0:0:0:0:0:0:0:1 GET 200 /files/test AGENT:Mozilla/5.0 (X11; U;
> Linux x86_64; fr; rv:1.9.2.3) Gecko/20100423 Ubuntu/10.04 (lucid)
> Firefox/3.6.3 REF:
> HTTP/1.1 200 The request has succeeded
> Transfer-Encoding: chunked
> Date: Fri, 21 May 2010 15:33:41 GMT
> Accept-Ranges: bytes
> Server: Restlet-Framework/2.0rc3
> Vary: Accept-Charset, Accept-Encoding, Accept-Language, Accept
> Content-Language: fr
> Content-Location: http://localhost:8180/files/test
> Content-Type: application/octet-stream; charset=UTF-8
>
> 542
> drwxrws--- 3 1001 1000 4096 May 09 2009 1993
> drwxrws--- 3 1001 1000 4096 May 09 2009 1994
> drwxrws--- 7 1001 1000 4096 May 09 2009 1995
> drwxrws--- 9 1001 1000 4096 May 09 2009 1996
> drwxrws--- 9 1001 1000 4096 May 08 2009 1997
> drwxrws--- 9 1001 1000 4096 May 08 2009 1998
> drwxrws--- 9 1001 1000 4096 May 08 2009 1999
> drwxrws--- 9 1001 1000 4096 May 08 2009 2000
> drwxrws--- 10 1001 1000 4096 May 08 2009 2001
> drwxrws--- 10 1001 1000 4096 May 08 2009 2002
> drwxrws--- 10 1001 1000 4096 May 08 2009 2003
> drwxrws--- 11 1001 1000 4096 Dec 29 06:24 2004
> drwxrws--- 12 1001 1000 4096 Dec 29 06:24 2005
> drwxrws--- 11 1001 1000 4096 Dec 29 06:24 2006
> drwxrws--- 11 1001 1000 4096 Jan 15 06:49 2007
> drwxrws--- 11 1001 1000 4096 Jan 14 15:01 2008
> drwxrws--- 11 1001 1000 4096 Jan 14 07:17 2009
> drwxrws--- 11 1001 1000 4096 Mar 19 14:16 2010
> drwxrws--- 5 1001 1000 4096 Feb 03 15:41 MOL
> drwxrws--- 7 1001 1000 4096 Feb 03 14:45 OSTENDE
> drwxrws--- 9 1001 1000 4096 Feb 03 14:06 REDU
> drwxrws--- 6 1001 1000 4096 Feb 03 15:16 VIRTON
>
> Regards,
> J-Christophe
>
> On Thu, May 20, 2010 at 10:50 AM, Jerome Louvel <
> [email protected]> wrote:
>
> Hi Jean-Christophe,
>
>
>
> This is an interesting usage of Directory! It should work so I suspect a
> bug somewhere, in the DirectoryServerResource class maybe. I’ve entered an
> issue:
>
>
>
> “Directory exposing FTP missing metadata”
>
> http://restlet.tigris.org/issues/show_bug.cgi?id=1111
>
>
>
> Could you inspect the media type of the representation returned by the
> directory in this case. I suspect it is null or not HTML, explaining why the
> browser treats it a binary.
>
>
>
> Best regards,
> Jerome Louvel
> --
> Restlet ~ Founder and Technical Lead ~ http://www.restlet.org
> Noelios Technologies ~ http://www.noelios.com
>
>
>
>
>
>
>
>
>
> *De :* Jean-Christophe Malapert [mailto:[email protected]]
> *Envoyé :* jeudi 6 mai 2010 19:23
> *À :* [email protected]
> *Objet :* Directory and FTP
>
>
>
> Hello,
>
> I would like to use Directory class with FTP. I wrote the following code
>
> Router router = new Router();
> Directory dir = new Directory(getContext(), "ftp://193.190.231.123
> ");
> dir.setNegotiatingContent(true);
> dir.setListingAllowed(true);
> dir.setDeeplyAccessible(true);
> router.attachDefault(dir);
> return router;
>
> I expected a result as FILE protocole, I mean a HTML representation if I
> use my browser. But, instead of a HTML representation, I have something else
> : a popup appears to me for asking to save a file.
> How can I have a HTML representation using directory with FTP ?
>
> Thanks a lot,
> J-Christophe
>
>
>
------------------------------------------------------
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=2629456