MaxiReglisse has asked for the wisdom of the Perl Monks concerning the following question:
Hello everybody,
I try to use www::mechanize in order to automate a session with GeoServer.
More information on GeoServer here http://geoserver.org or https://en.wikipedia.org/wiki/GeoServer
Wikipedia says : GeoServer — an open-source server written in Java — allows users to share, process and edit geospatial data.
GeoServer comes with a REST API, which can be used with curl.But at the moment, it is impossible to create a datastore for ImageMosaicJDBC with the REST API, so i would like to add the new raster data source with a Perl script. it is based on www::mechanize.
but it fails, with this message : your session has expired.
May you help me, please ? the script is just below...
#!/usr/bin/perl use strict; use warnings; use WWW::Mechanize; use HTML::TreeBuilder; use HTML::Tree; use Getopt::Long; use HTTP::Cookies; my %CONF = ( username => 'admin', password => 'geoserver', ); GetOptions( \%CONF, "username=s", "password=s" )or die "Bad options"; my $netloc = "193.5x.6x.15x:8080"; my $url = "http://$netloc/geoserver/web/?wicket:bookmarkablePage= +:org.geoserver.web.GeoServerLoginPage"; my $cookie_jar = HTTP::Cookies->new; my $agent = WWW::Mechanize->new( cookie_jar => $cookie_jar ); $agent->agent('User-Agent=Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:4 +4.0) Gecko/20100101 Firefox/44.0'); # auth $agent->get($url); die $agent->res->status_line unless $agent->success; $agent->set_fields(%CONF); $agent->submit; die $agent->res->status_line unless $agent->success; print $cookie_jar->as_string; # adding data store $url = "http://$netloc/geoserver/web?wicket:bookmarkablePage=:org.geos +erver.web.data.store.NewDataPage"; my $content = $agent->get($url); die $agent->res->status_line unless $agent->success; my $tree = HTML::Tree->new(); $tree->parse($content); print $agent->content; # storeform $url = "http://$netloc/geoserver/web/?wicket:interface=:5:storeForm::I +FormSubmitListener::"; my $content = $agent->post($url); die $agent->res->status_line unless $agent->success; my $tree = HTML::Tree->new(); $tree->parse($content); print $agent->content; # newdatapage $url = "http://$netloc/geoserver/web/?wicket:interface=:6::::"; my $ref = "http://$netloc/geoserver/web/?wicket:bookmarkablePage=:org. +geoserver.web.data.store.NewDataPage"; my $content = $agent->get( $url, referer => $ref); die $agent->res->status_line unless $agent->success; my $tree = HTML::Tree->new(); $tree->parse($content); print $agent->content;
I cannot see where the problem comes from... In particular, i used WireShark to inspect the HTTP exchanges, but every thing was ok for me. The JSESSIONID cookie was for example correctly rescueing.
Thanks in advance.
Ernest.
|
|---|