3

I try to use WWW::Mechanize in order to automate a session with GeoServer.

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.

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.55.67.151: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:44.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;

# adding data store
$url = "http://$netloc/geoserver/web?wicket:bookmarkablePage=:org.geoserver.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::IFormSubmitListener::";
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.

MaxiReglisse
  • 3,093
  • 1
  • 13
  • 14

1 Answers1

0

Try setting timeout parameter while declaring $agent