Re: [Catalyst] A suitable method to redraw a page

2008-09-24 Thread Dermot
2008/9/24 J. Shirley [EMAIL PROTECTED]:
 On Tue, Sep 23, 2008 at 4:30 PM, Dermot [EMAIL PROTECTED] wrote:


 Plugin::XMLRPC is -not- a controller, as such, you probably do want to use it.

Do you mean do or 'do not' want to use it.


 If you use Catalyst::Controller::REST handles serialization based on
 the Content-type header, with built-in support for JSON, YAML, XML and
 quite a few other formats.  It also isn't intrusive to your other code
 (like a Plugin is).


I installed this module and am trying to connect to it. Perhaps I
should start a new thread but I ask anyway.


If my the root of my app is /myapp. I have installed a the REST
Controller as lib/MyApp/Controller/REST.pm

The Controller has this for now.

sub files : Local : ActionClass('REST') {
  my ($self, $c) = @_;
  $c-log-debug(Hello from REST Controller);
}

sub files_GET {
  my ($self, $c) = @_;
  $self-status_ok(
$c,
entity = {
result = 'acceptable',
},
  );
}


My remote LWP client reads

...
 my $server = 'http://server.mydomain.com:3000'
 my $url = $server./myapp/rest;

 my $req = HTTP::Request-new(GET = $url);
 $req-content('files');
 my $ua = LWP::UserAgent-new();
 $ua-timeout(5);
 my $res = $ua-request($req);

 if ($res-is_success) {
print Content type=,$res-content_type,\n;
print $res-decoded_content;
 }
 else {
$res-status_line;
 }

But the result is alway not found.

.-+--.
| Path| Private  |
+-+--+
| /rest/files | /rest/files
..
[info] *** Request 7 (0.019/s) [16196] [Wed Sep 24 09:12:33 2008] ***
[debug] GET request for motion/rest from x.x.x.x
[debug] Arguments are myapp/rest


The whole thing needs fleshing out but I can't seems to get a basic
connection established. Any tips?

___
List: Catalyst@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/


Re: [Catalyst] A suitable method to redraw a page

2008-09-24 Thread Tomas Doran


On 24 Sep 2008, at 09:20, Dermot wrote:

If my the root of my app is /myapp. I have installed a the REST
Controller as lib/MyApp/Controller/REST.pm

The Controller has this for now.

sub files : Local : ActionClass('REST') {
  my ($self, $c) = @_;
  $c-log-debug(Hello from REST Controller);
}



So that's the public path /rest/files


sub files_GET {



And that should be called for GET requests.




My remote LWP client reads

...
 my $server = 'http://server.mydomain.com:3000'
 my $url = $server./myapp/rest;



I think you need /rest/files


.- 
+--.
| Path|  
Private  |
+- 
+--+

| /rest/files | /rest/files
..
[info] *** Request 7 (0.019/s) [16196] [Wed Sep 24 09:12:33 2008] ***
[debug] GET request for motion/rest from x.x.x.x
[debug] Arguments are myapp/rest


And this explains why - you're asking for /myapp/rest, but you only  
have /myapp/rest/files


Cheers
t0m


___
List: Catalyst@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/


Re: [Catalyst] A suitable method to redraw a page

2008-09-24 Thread Tomas Doran


On 24 Sep 2008, at 00:30, Dermot wrote:


2008/9/23 Mesdaq, Ali [EMAIL PROTECTED]:


I think ajax would be your friend here.


I think I'll try something like that. As the files and Cat App are on
one server and the referrer is a different server, I will have the
referrer call a local script and fire a request from there.


Are you sure that you actually want your web server running this  
script? It may not be an issue for you, but if this needs to be  
scalable then I'd highly recommend using a distributed job queue such  
as TheSchwartz.. This also buys you other architectural benefits as  
you've done a load of decoupling, so you can now trivially have  
command line admin tools which monitor jobs in progress etc...


If you take this approach, you don't have a problem, your first hit  
does a POST which submits a job (quick), then redirects the user to a  
page which refreshes regularly that reports on the job status, and  
once the job is complete, the next refresh can display a different  
page / redirect the user again as appropriate.


Also, you don't need no steenkin Javascipt (although you're free to  
use it to improve the user experience, you have graceful  
degredation), and you've got a system that can trivially be  
abstracted to handle running / reporting status on a whole multitude  
of jobs...


Cheers
t0m




___
List: Catalyst@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/


Re: [Catalyst] A suitable method to redraw a page

2008-09-24 Thread Dermot
2008/9/24 Dermot [EMAIL PROTECTED]:
 2008/9/24 J. Shirley [EMAIL PROTECTED]:
 On Tue, Sep 23, 2008 at 4:30 PM, Dermot [EMAIL PROTECTED] wrote:


 Plugin::XMLRPC is -not- a controller, as such, you probably do want to use 
 it.

 Do you mean do or 'do not' want to use it.



 My remote LWP client reads

 ...
  my $server = 'http://server.mydomain.com:3000'
  my $url = $server./myapp/rest;

  my $req = HTTP::Request-new(GET = $url);
  $req-content('files');
  my $ua = LWP::UserAgent-new();
  $ua-timeout(5);
  my $res = $ua-request($req);


Opps, dissgard that. My error.

I need to drop the /myapp while is running in debug mode
...:3000/rest/file works.

Thanx,
Dp.

___
List: Catalyst@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/


Re: [Catalyst] A suitable method to redraw a page

2008-09-24 Thread Dermot
2008/9/24 J. Shirley [EMAIL PROTECTED]:

 If you use Catalyst::Controller::REST

Wow. It's quite a nifty module. I really like it.
Thanx,
Dp.

___
List: Catalyst@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/


[Catalyst] A suitable method to redraw a page

2008-09-23 Thread Dermot
Hi,

I have a controller who's job is to copy some files (4-6). These files
can be quite big and the time it takes has been causing what looks
like timeouts on the server.

[Tue Sep 23 09:48:55 2008] [error] [client x.x.x.x] FastCGI: comm with
server /var/www/MyApp/script/motion_fastcgi.pl aborted: idle timeout
(30 sec), referer: http://somehost/cgi-bin/doit.cgi
[Tue Sep 23 09:48:55 2008] [error] [client x.x.x.x] FastCGI:
incomplete headers (0 bytes) received from server
/var/www/MyApp/script/myapp_fastcgi.pl

I could increase the timeout period on the httpd daemon. I thought a
more elegant solution would be to present a page with the results for
each file after it's copied that is updated with the status of each
copied file. So the same window refreshes and the next file is listed
with the copy status.

I have achieved this in the past (CGI) by putting a form on the page
and using javascript/onload/submit while items  1. It's a bit of a
hack but it works.

Is there a method within Catalyst that might help me reach my goal?
Something akin to Chained perhaps.

Alternatively can I loop through the list of files and $c-{template}
= 'files/rename.tt2'. My experiments haven't been successful. I get
the whole page of results. Is there something like $c-forward that I
should be using here?

Here an abridged versions of the controller.

sub rename : Local {
   my ($self, $c) = @_;
   die if ($c-request-param('id') !~ /\d+/);

   my $list = getFilesBySubID($c, $c-request-param('id'));
   my @moved;

   foreach my $file ( @{$list} ) {
my $source = $file-path;
my $type = getFileTypeFromName(basename($file-path));
my %state = (
   'id' = $c-request-param('id'),
   'source' = $file-path,
   'distin' = undef,
);
my $path =
getPathFromNumber($c-request-param('splnumber'), $type);
my $x = copy($source,$path) or warn Cannot copy
$source to $path: $!\n;
$state{'success'} = $x;
$state{'distin'} = $path;
}
else {
$state{'success'} = 0;
}
push(@moved, \%state);
$c-stash-{moved} = [EMAIL PROTECTED];
$c-stash-{template} = 'files/rename.tt2';
   }
}

I hope this makes sense :-/. Any advice would be appreciated.
Thanx,
Dp.

___
List: Catalyst@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/


RE: [Catalyst] A suitable method to redraw a page

2008-09-23 Thread Mesdaq, Ali
I think ajax would be your friend here. You could just make an ajax call to 
some function to check the status of the file copies and then update the DOM 
directly instead of refreshing the whole page. Or the actual call to start the 
copy can be made via ajax instead of the call to check the status that way your 
js code for that page can call the copy file function on the server 
sequentially for each file and update the page in a loop. There are a lot of 
ways to do this. You might even want to look into having a background process 
launched to do the actual copy so you don’t run into http timeout issues and 
just have your controllers start and check the copy process.

Thanks,
--
Ali Mesdaq (CISSP, GIAC-GREM)
Sr. Security Researcher
Websense Security Labs
http://www.WebsenseSecurityLabs.com
--


-Original Message-
From: Dermot [mailto:[EMAIL PROTECTED]
Sent: Tuesday, September 23, 2008 3:53 AM
To: The elegant MVC web framework
Subject: [Catalyst] A suitable method to redraw a page

Hi,

I have a controller who's job is to copy some files (4-6). These files
can be quite big and the time it takes has been causing what looks
like timeouts on the server.

[Tue Sep 23 09:48:55 2008] [error] [client x.x.x.x] FastCGI: comm with
server /var/www/MyApp/script/motion_fastcgi.pl aborted: idle timeout
(30 sec), referer: http://somehost/cgi-bin/doit.cgi
[Tue Sep 23 09:48:55 2008] [error] [client x.x.x.x] FastCGI:
incomplete headers (0 bytes) received from server
/var/www/MyApp/script/myapp_fastcgi.pl

I could increase the timeout period on the httpd daemon. I thought a
more elegant solution would be to present a page with the results for
each file after it's copied that is updated with the status of each
copied file. So the same window refreshes and the next file is listed
with the copy status.

I have achieved this in the past (CGI) by putting a form on the page
and using javascript/onload/submit while items  1. It's a bit of a
hack but it works.

Is there a method within Catalyst that might help me reach my goal?
Something akin to Chained perhaps.

Alternatively can I loop through the list of files and $c-{template}
= 'files/rename.tt2'. My experiments haven't been successful. I get
the whole page of results. Is there something like $c-forward that I
should be using here?

Here an abridged versions of the controller.

sub rename : Local {
   my ($self, $c) = @_;
   die if ($c-request-param('id') !~ /\d+/);

   my $list = getFilesBySubID($c, $c-request-param('id'));
   my @moved;

   foreach my $file ( @{$list} ) {
my $source = $file-path;
my $type = getFileTypeFromName(basename($file-path));
my %state = (
   'id' = $c-request-param('id'),
   'source' = $file-path,
   'distin' = undef,
);
my $path =
getPathFromNumber($c-request-param('splnumber'), $type);
my $x = copy($source,$path) or warn Cannot copy
$source to $path: $!\n;
$state{'success'} = $x;
$state{'distin'} = $path;
}
else {
$state{'success'} = 0;
}
push(@moved, \%state);
$c-stash-{moved} = [EMAIL PROTECTED];
$c-stash-{template} = 'files/rename.tt2';
   }
}

I hope this makes sense :-/. Any advice would be appreciated.
Thanx,
Dp.

___
List: Catalyst@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/





 Protected by Websense Messaging Security -- www.websense.com 

___
List: Catalyst@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/


Re: [Catalyst] A suitable method to redraw a page

2008-09-23 Thread J. Shirley
On Tue, Sep 23, 2008 at 4:30 PM, Dermot [EMAIL PROTECTED] wrote:
 2008/9/23 Mesdaq, Ali [EMAIL PROTECTED]:

I think ajax would be your friend here.

 I think I'll try something like that. As the files and Cat App are on
 one server and the referrer is a different server, I will have the
 referrer call a local script and fire a request from there.

 The question then is what type of Controller to use. There seems to be
 2 choices, REST and XMLRPC. I'll try plugin::XMLRPC.

 Thanx,
 Dp.


Plugin::XMLRPC is -not- a controller, as such, you probably do want to use it.

Ajax is nothing more than an async request from a browser, with a
serialization format attached (but doesn't have to be, you can send
out html snippets just fine).  If you want to use a DWIM approach and
fetch data REST will be the best bet.  If you want html snippets,
don't use any of the plugins, just return the snippet of the page you
want to serve and code it in the JS.

If you use Catalyst::Controller::REST handles serialization based on
the Content-type header, with built-in support for JSON, YAML, XML and
quite a few other formats.  It also isn't intrusive to your other code
(like a Plugin is).

-J

___
List: Catalyst@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/