[GeoNetwork-users] Insert a new metadata with wget

Hi all,

I'm trying to work with the GeoNetwork API. I work with Geonetwork 3.0.4. I would like to insert into Geonetwork a new metadata.
I use the manpage of WGET (http://www.delafond.org/traducmanfr/man/man1/wget.1.html) and the Geonetwork Developper Manuel 2.10.4 (http://geonetwork-opensource.org/manuals/2.10.4/eng/developer/xml_services/metadata_xml_insert_update_delete.html).

I'm using 2 commands : one to create the cookie (with login.xml which contains the admin login/password), the other to insert the metadata (with metadata_to_push.xml file, which is attached) :

    wget -v --keep-session-cookies --save-cookies cookies_gn.txt
    --post-file=login.xml --header "Content-type:application/xml"
    http://geonetwork-mshe.univ-fcomte.fr:8080/geonetwork/srv/en/xml.user/login

    wget -v --load-cookies cookies_gn.txt
    --post-file=metadata_to_push.xml --header
    "Content-type:application/xml"
    http://geonetwork-mshe.univ-fcomte.fr:8080/geonetwork/srv/eng/metadata.insert

At first sight, the command which creates cookie seems correct and generates the file cookies_gn.txt which contains :

    # HTTP cookie file.
    # Generated by Wget on 2016-04-20 09:38:47.
    # Edit at your own risk.

    geonetwork-mshe.univ-fcomte.fr:8080 FALSE / FALSE 0 sessionExpiry 1461137927178
    geonetwork-mshe.univ-fcomte.fr:8080 FALSE / FALSE 0 serverTime 1461137927178
    geonetwork-mshe.univ-fcomte.fr:8080 FALSE /geonetwork/ FALSE 0 JSESSIONID 5C78716C458C162448718CD6E46D6E64

The second command fails : there isn't a new metadata in Geonetwork and we can see in local_access_log a problem with the authentication :

    172.20.81.175 - - [20/Apr/2016:09:53:43 +0200] "POST
    /geonetwork/srv/eng/metadata.insert HTTP/1.1" 302 -
    172.20.81.175 - - [20/Apr/2016:09:53:43 +0200] "GET
    /geonetwork/login.jsp?node=srv HTTP/1.1" 302 -
    172.20.81.175 - - [20/Apr/2016:09:53:43 +0200] "GET
    /geonetwork/srv/eng/catalog.signin?node=srv HTTP/1.1" 200 1904

Maybe the cookie created by the first command is incorrect. Indeed, if we use a cookie recovered in the Firefox console, we haven't this problem but another :

    172.20.81.175 - - [20/Apr/2016:10:38:02 +0200] "POST
    /geonetwork/srv/eng/metadata.insert HTTP/1.1" 302 -
    172.20.81.175 - - [20/Apr/2016:10:38:02 +0200] "GET
    /geonetwork/srv/eng/service-not-allowed?referer=/geonetwork/srv/eng/metadata.insert
    HTTP/1.1" 200 2339

But in this case, why it doesn't work ? Is it a wrong service or a wrong metadata file ?

Is anyone have any idea?

Thank you in advance,

--
/Sophie MOLLARD/

/Pôle Géomatique/
/MSHE C. N. Ledoux (USR 3124) <http://mshe.univ-fcomte.fr>/
/Université de Franche-Comté/
/Tél : 03.81.66.51.55/

(attachments)

metadata_to_push.xml (12.2 KB)

A couple things.

1) Rather than xml.user.login, you should just use basic auth (via
the ‘--http-user=user’ and ‘--http-password=password’ options), as GN 3
uses the Spring framework for login. (
https://www.gnu.org/software/wget/manual/html_node/HTTP-Options.html)

2) I suggest taking a look at CSW Transactions
<http://geonetwork-opensource.org/manuals/2.10.4/eng/developer/xml_services/csw_services.html#transaction&gt;
for adding new records. I've had good luck using it for updating existing
records.

On Wed, Apr 20, 2016 at 4:23 AM, Sophie Mollard <
sophie.mollard@anonymised.com> wrote:

Hi all,

I'm trying to work with the GeoNetwork API. I work with Geonetwork 3.0.4.
I would like to insert into Geonetwork a new metadata.
I use the manpage of WGET (
http://www.delafond.org/traducmanfr/man/man1/wget.1.html) and the
Geonetwork Developper Manuel 2.10.4 (
http://geonetwork-opensource.org/manuals/2.10.4/eng/developer/xml_services/metadata_xml_insert_update_delete.html
).

I'm using 2 commands : one to create the cookie (with login.xml which
contains the admin login/password), the other to insert the metadata (with
metadata_to_push.xml file, which is attached) :

   wget -v --keep-session-cookies --save-cookies cookies_gn.txt
   --post-file=login.xml --header "Content-type:application/xml"

http://geonetwork-mshe.univ-fcomte.fr:8080/geonetwork/srv/en/xml.user/login

   wget -v --load-cookies cookies_gn.txt
   --post-file=metadata_to_push.xml --header
   "Content-type:application/xml"

http://geonetwork-mshe.univ-fcomte.fr:8080/geonetwork/srv/eng/metadata.insert

At first sight, the command which creates cookie seems correct and
generates the file cookies_gn.txt which contains :

   # HTTP cookie file.
   # Generated by Wget on 2016-04-20 09:38:47.
   # Edit at your own risk.

   geonetwork-mshe.univ-fcomte.fr:8080 FALSE / FALSE 0
sessionExpiry 1461137927178
   geonetwork-mshe.univ-fcomte.fr:8080 FALSE / FALSE 0
serverTime 1461137927178
   geonetwork-mshe.univ-fcomte.fr:8080 FALSE /geonetwork/ FALSE
0 JSESSIONID 5C78716C458C162448718CD6E46D6E64

The second command fails : there isn't a new metadata in Geonetwork and we
can see in local_access_log a problem with the authentication :

   172.20.81.175 - - [20/Apr/2016:09:53:43 +0200] "POST
   /geonetwork/srv/eng/metadata.insert HTTP/1.1" 302 -
   172.20.81.175 - - [20/Apr/2016:09:53:43 +0200] "GET
   /geonetwork/login.jsp?node=srv HTTP/1.1" 302 -
   172.20.81.175 - - [20/Apr/2016:09:53:43 +0200] "GET
   /geonetwork/srv/eng/catalog.signin?node=srv HTTP/1.1" 200 1904

Maybe the cookie created by the first command is incorrect. Indeed, if we
use a cookie recovered in the Firefox console, we haven't this problem but
another :

   172.20.81.175 - - [20/Apr/2016:10:38:02 +0200] "POST
   /geonetwork/srv/eng/metadata.insert HTTP/1.1" 302 -
   172.20.81.175 - - [20/Apr/2016:10:38:02 +0200] "GET

/geonetwork/srv/eng/service-not-allowed?referer=/geonetwork/srv/eng/metadata.insert
   HTTP/1.1" 200 2339

But in this case, why it doesn't work ? Is it a wrong service or a wrong
metadata file ?

Is anyone have any idea?

Thank you in advance,

--
/Sophie MOLLARD/

/Pôle Géomatique/
/MSHE C. N. Ledoux (USR 3124) <http://mshe.univ-fcomte.fr>/
/Université de Franche-Comté/
/Tél : 03.81.66.51.55/

------------------------------------------------------------------------------
Find and fix application performance issues faster with Applications
Manager
Applications Manager provides deep performance insights into multiple
tiers of
your business applications. It resolves application problems quickly and
reduces your MTTR. Get your free trial!
https://ad.doubleclick.net/ddm/clk/302982198;130105516;z
_______________________________________________
GeoNetwork-users mailing list
GeoNetwork-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/geonetwork-users
GeoNetwork OpenSource is maintained at
http://sourceforge.net/projects/geonetwork

--
Kevin Dyke
Spatial Data Analyst/Curator
John R. Borchert Map Library, University of Minnesota Libraries
Office: 612.301.3932
Email: dykex005@anonymised.com
Web: kevinrdyke.com