Re: Serve static content using SpringBeanRouter?

2014-06-04 Thread Jerome Louvel
Thanks Jorge for the follow-up with your solution!
I'm not sure why you get two GET calls. Can you try with a regular HTTP
client such as POSTMAN?

Jérôme



On Fri, May 30, 2014 at 9:00 AM, Jorge Gallardo 
wrote:

> Thanks Jerome for the prompt reply.
>
> So after I got some rest I could address this with a clearer mind. I
> resolved it this way:
>
>
> *spring xml:*
>
>  >
>
>  
>
>  
>
>  
>
>  
>
>   CLAP
>
>   FILE
>
>  
>
>  
>
> 
>
>
>   "org.restlet.ext.wadl.WadlApplication"
>
>  scope="singleton">
>
>  
>
>  
>
>  
>
>  
>
>  
>
>  
>
>
>  
>
> * 
> * class="org.springframework.beans.factory.config.PropertyPathFactoryBean"
> />*
>
>
>  * 
> * factory-method="createChildContext" scope="prototype" />*
>
>
> * 
> * class="com.zebra.rest.directory.ImagesDirectory">*
>
> * *
>
> * *
>
>
> 
>
>   />
>
>
> and then I created a simple Java class extending from Directory
>
> import org.restlet.Context;
>
> import org.restlet.resource.Directory;
>
>
> public class ImagesDirectory extends Directory {
>
>
> public ImagesDirectory(Context context) {
>
>  super(context, "clap://class/images");
>
> }
>
> }
>
>
> And Voilá! it worked.
>
> The only funny thing I see is double logging:
>
> May 30, 2014 10:59:46 AM org.restlet.engine.log.LogFilter afterHandle
>
> INFO: 2014-05-30 10:59:46 0:0:0:0:0:0:0:1 - 0:0:0:0:0:0:0:1 9091 GET
> /images/zebra_logo.png - 200 - 0 15 http://localhost:9091 Mozilla/5.0
> (Macintosh; Intel Mac OS X 10_9_2) AppleWebKit/537.36 (KHTML, like Gecko)
> Chrome/35.0.1916.114 Safari/537.36 -
>
> May 30, 2014 10:59:46 AM org.restlet.engine.log.LogFilter afterHandle
>
> INFO: 2014-05-30 10:59:46 0:0:0:0:0:0:0:1 - 0:0:0:0:0:0:0:1 9091 GET
> /images/zebra_logo.png - 200 - 0 1 http://localhost:9091 Mozilla/5.0
> (Macintosh; Intel Mac OS X 10_9_2) AppleWebKit/537.36 (KHTML, like Gecko)
> Chrome/35.0.1916.114 Safari/537.36 -
>
> Could be related to the clap protocol? Other than that, I debugged it and
> looks it is working as expected, nothing strange under the sun.
>
>
> Thanks!
>
> -JG
>
>
>
>
> On Thu, May 29, 2014 at 4:15 PM, Jerome Louvel 
> wrote:
>
>> Hi Jorge,
>>
>> Normally, you shouldn't embed a Directory inside a ServerResource but
>> directly attach it to your SpringBeanRouter.
>> To not have to use the {imageId} path variable (for your file names I
>> guess), you can set the route's matchingMode to Template.STARTS_WITH. I'm
>> not sure exactly how to do it with SpringBeanRouter, but with a regular
>> router you would do this:
>>
>> myRouter.attach("/v1/images/",
>> myDirectory).setMatchingMode(Template.STARTS_WITH).
>>
>> Thanks,
>> Jerome
>> --
>> http://restlet.com
>> @jlouvel 
>>
>>
>>
>>
>> On Thu, May 29, 2014 at 1:48 PM, Jorge Gallardo > > wrote:
>>
>>> Hello all,
>>>
>>> Im trying to serve static content from the filesystem but I cant. I was
>>> able to do it with a plain and simple Reslet application but not using
>>> SpringBeanRouter.
>>> Here is the code:
>>>
>>>
>>> @Component("/v1/images/{imageId}")
>>>
>>> @Scope("prototype")
>>>
>>> public class ImagesResource extends DirectoryServerResource {
>>>
>>> private String imageId;
>>>
>>> @Override
>>>
>>> public void doInit() throws ResourceException {
>>>
>>>  Directory directory = new Directory(getContext(),
>>>
>>>  "file:///path/images");
>>>
>>>  getRequestAttributes().put("org.restlet.directory", directory);
>>>
>>>  super.doInit();
>>>
>>> }
>>>
>>> }
>>> And here the xml mapping:
>>>
>>>  >> "org.restlet.ext.spring.SpringComponent">
>>>
>>>  
>>>
>>>  
>>>
>>>  
>>>
>>>   CLAP
>>>
>>>   FILE
>>>
>>>  
>>>
>>>  
>>>
>>> 
>>>
>>> >> "org.restlet.ext.wadl.WadlApplication"
>>>
>>>  scope="singleton">
>>>
>>>  
>>>
>>>  
>>>
>>>  
>>>
>>> 
>>>
>>>  >> />
>>>
>>>
>>> Im facing two issues:
>>>
>>> 1- the URL mapping. If i use "/v1/images", SpringBeanRouter does not
>>> match it, so I went for "/v1/images/{imageId}"
>>>
>>> 2- If i dont put the Directory in the map, I get a NullPointerException.
>>> It looks odd, is there any other/better way of doing it?
>>>
>>> Thanks!
>>> --
>>> Jorge Gallardo
>>> 
>>> jorgeagalla...@gmail.com
>>>
>>
>>
>
>
> --
> Jorge Gallardo
> 
> jorgeagalla...@gmail.com
>

--
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=3079919

Re: Serve static content using SpringBeanRouter?

2014-05-30 Thread Jorge Gallardo
Thanks Jerome for the prompt reply.

So after I got some rest I could address this with a clearer mind. I
resolved it this way:


*spring xml:*



 

 

 

 

  CLAP

  FILE

 

 




 

 

 

 

 

 

 


 

* *


 * *


* *

* *

* *




 


and then I created a simple Java class extending from Directory

import org.restlet.Context;

import org.restlet.resource.Directory;


public class ImagesDirectory extends Directory {


public ImagesDirectory(Context context) {

super(context, "clap://class/images");

}

}


And Voilá! it worked.

The only funny thing I see is double logging:

May 30, 2014 10:59:46 AM org.restlet.engine.log.LogFilter afterHandle

INFO: 2014-05-30 10:59:46 0:0:0:0:0:0:0:1 - 0:0:0:0:0:0:0:1 9091 GET
/images/zebra_logo.png - 200 - 0 15 http://localhost:9091 Mozilla/5.0
(Macintosh; Intel Mac OS X 10_9_2) AppleWebKit/537.36 (KHTML, like Gecko)
Chrome/35.0.1916.114 Safari/537.36 -

May 30, 2014 10:59:46 AM org.restlet.engine.log.LogFilter afterHandle

INFO: 2014-05-30 10:59:46 0:0:0:0:0:0:0:1 - 0:0:0:0:0:0:0:1 9091 GET
/images/zebra_logo.png - 200 - 0 1 http://localhost:9091 Mozilla/5.0
(Macintosh; Intel Mac OS X 10_9_2) AppleWebKit/537.36 (KHTML, like Gecko)
Chrome/35.0.1916.114 Safari/537.36 -

Could be related to the clap protocol? Other than that, I debugged it and
looks it is working as expected, nothing strange under the sun.


Thanks!

-JG




On Thu, May 29, 2014 at 4:15 PM, Jerome Louvel  wrote:

> Hi Jorge,
>
> Normally, you shouldn't embed a Directory inside a ServerResource but
> directly attach it to your SpringBeanRouter.
> To not have to use the {imageId} path variable (for your file names I
> guess), you can set the route's matchingMode to Template.STARTS_WITH. I'm
> not sure exactly how to do it with SpringBeanRouter, but with a regular
> router you would do this:
>
> myRouter.attach("/v1/images/",
> myDirectory).setMatchingMode(Template.STARTS_WITH).
>
> Thanks,
> Jerome
> --
> http://restlet.com
> @jlouvel 
>
>
>
>
> On Thu, May 29, 2014 at 1:48 PM, Jorge Gallardo 
> wrote:
>
>> Hello all,
>>
>> Im trying to serve static content from the filesystem but I cant. I was
>> able to do it with a plain and simple Reslet application but not using
>> SpringBeanRouter.
>> Here is the code:
>>
>>
>> @Component("/v1/images/{imageId}")
>>
>> @Scope("prototype")
>>
>> public class ImagesResource extends DirectoryServerResource {
>>
>> private String imageId;
>>
>> @Override
>>
>> public void doInit() throws ResourceException {
>>
>>  Directory directory = new Directory(getContext(),
>>
>>  "file:///path/images");
>>
>>  getRequestAttributes().put("org.restlet.directory", directory);
>>
>>  super.doInit();
>>
>> }
>>
>> }
>> And here the xml mapping:
>>
>>  > "org.restlet.ext.spring.SpringComponent">
>>
>>  
>>
>>  
>>
>>  
>>
>>   CLAP
>>
>>   FILE
>>
>>  
>>
>>  
>>
>> 
>>
>> > "org.restlet.ext.wadl.WadlApplication"
>>
>>  scope="singleton">
>>
>>  
>>
>>  
>>
>>  
>>
>> 
>>
>>  > />
>>
>>
>> Im facing two issues:
>>
>> 1- the URL mapping. If i use "/v1/images", SpringBeanRouter does not
>> match it, so I went for "/v1/images/{imageId}"
>>
>> 2- If i dont put the Directory in the map, I get a NullPointerException.
>> It looks odd, is there any other/better way of doing it?
>>
>> Thanks!
>> --
>> Jorge Gallardo
>> 
>> jorgeagalla...@gmail.com
>>
>
>


-- 
Jorge Gallardo

jorgeagalla...@gmail.com

--
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=3079582

Re: Serve static content using SpringBeanRouter?

2014-05-29 Thread Jerome Louvel
Hi Jorge,

Normally, you shouldn't embed a Directory inside a ServerResource but
directly attach it to your SpringBeanRouter.
To not have to use the {imageId} path variable (for your file names I
guess), you can set the route's matchingMode to Template.STARTS_WITH. I'm
not sure exactly how to do it with SpringBeanRouter, but with a regular
router you would do this:

myRouter.attach("/v1/images/",
myDirectory).setMatchingMode(Template.STARTS_WITH).

Thanks,
Jerome
--
http://restlet.com
@jlouvel 




On Thu, May 29, 2014 at 1:48 PM, Jorge Gallardo wrote:

> Hello all,
>
> Im trying to serve static content from the filesystem but I cant. I was
> able to do it with a plain and simple Reslet application but not using
> SpringBeanRouter.
> Here is the code:
>
>
> @Component("/v1/images/{imageId}")
>
> @Scope("prototype")
>
> public class ImagesResource extends DirectoryServerResource {
>
> private String imageId;
>
> @Override
>
> public void doInit() throws ResourceException {
>
>  Directory directory = new Directory(getContext(),
>
>  "file:///path/images");
>
>  getRequestAttributes().put("org.restlet.directory", directory);
>
>  super.doInit();
>
> }
>
> }
> And here the xml mapping:
>
>   "org.restlet.ext.spring.SpringComponent">
>
>  
>
>  
>
>  
>
>   CLAP
>
>   FILE
>
>  
>
>  
>
> 
>
> 
>  scope="singleton">
>
>  
>
>  
>
>  
>
> 
>
>   />
>
>
> Im facing two issues:
>
> 1- the URL mapping. If i use "/v1/images", SpringBeanRouter does not match
> it, so I went for "/v1/images/{imageId}"
>
> 2- If i dont put the Directory in the map, I get a NullPointerException.
> It looks odd, is there any other/better way of doing it?
>
> Thanks!
> --
> Jorge Gallardo
> 
> jorgeagalla...@gmail.com
>

--
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=3079544

Serve static content using SpringBeanRouter?

2014-05-29 Thread Jorge Gallardo
Hello all,

Im trying to serve static content from the filesystem but I cant. I was
able to do it with a plain and simple Reslet application but not using
SpringBeanRouter.
Here is the code:


@Component("/v1/images/{imageId}")

@Scope("prototype")

public class ImagesResource extends DirectoryServerResource {

private String imageId;

@Override

public void doInit() throws ResourceException {

 Directory directory = new Directory(getContext(),

 "file:///path/images");

 getRequestAttributes().put("org.restlet.directory", directory);

 super.doInit();

}

}
And here the xml mapping:

 

 

 

 

  CLAP

  FILE

 

 





 

 

 



 


Im facing two issues:

1- the URL mapping. If i use "/v1/images", SpringBeanRouter does not match
it, so I went for "/v1/images/{imageId}"

2- If i dont put the Directory in the map, I get a NullPointerException. It
looks odd, is there any other/better way of doing it?

Thanks!
-- 
Jorge Gallardo

jorgeagalla...@gmail.com

--
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=3079543