[GeoNetwork-users] How to use the xml csw transaction service with python in geonetwork 2.10?

Hi list

I had been using geonetwork 2.6 up until recently and had some python
scripts that used the csw interface to upload metadata records to my
catalogue. It worked flawlessly.

Since moving to version 2.10 my scripts stopped working...

Reading the docs[1], I could only find a reference to a change in the csw
transactions URL and nothing more.

So I thought that I only had to adapt my csw transaction url to:

geonetwork/srv/en/csw-publication

My script worked by

1 - logging out of any previous sessions
2 - logging in with my user credentials
3 - executing the csw insert request

But now I can't seem to even login to geonetwork through the xml services
anymore... What other changes have there been?

According to the manual on the user login service[2], I am trying to login
at the URL:

http://localhost:8080/geonetwork/srv/en/xml.user.login

I am using a POST request with 'username' and 'password' variables set to
the correct values. I always get back a 200 HTTP code (which would indicate
success) but the returned document is an HTML page[3] telling me that I
have to enable Javascript in the brwoser, which is really not what I would
expect. I would expect to get back an XML document with a response, even if
an error message.
My original request is being automatically redirected to another URL:

http://localhost:8080/geonetwork/login.jsp;jsessionid=28A2198AF954D32DC4F7EB720F84496E

So it seems to be storing some info in a cookie and then redirects to
another page that presumably performs the actual login. I don't know if my
username/password variables are getting lost along the redirection part...

I have been looking at the Javascript (a file called test-csw.js) code used
in the admin section of the geonetwork catalogue that is used for testing
the CSW server and found that it is not using the same login url as is
advised in the documentation, but rather:

http://localhost:8080/geonetwork/srv/en/j_spring_security_check

Should I be using this URL also? Is the documentation out of sync?

I am not an expert in these HTTP request and response things, so it is
possible that I am making some silly mistake, but on the other hand, the
script was working just fine before upgrading to geonetwork 2.10.

I am using cURL on the command-line to try and debug the problem, but my
ultimate goal is to get this working again in python using the requests
module, or urllib2.

In cURL, the login request that I am attempting is:

curl --verbose --data "username=XXXXXX&password=XXXXX" --header
"Content-Type: application/x-www-form-urlencoded" --location-trusted "
http://localhost:8080/geonetwork/srv/eng/xml.user.login"

The response is in [3].

Thanks for your help

[1] -
http://geonetwork-opensource.org/manuals/2.10.0/eng/developer/xml_services/csw_services.html

[2] -
http://geonetwork-opensource.org/manuals/2.10.0/eng/developer/xml_services/login_xml_services.html

[3] - cURL response:

* About to connect() to localhost port 8080 (#0)
* Trying 127.0.0.1... % Total % Received % Xferd Average Speed
Time Time Time Current
                                 Dload Upload Total Spent Left
Speed
  0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:--
  0connected

POST /geonetwork/srv/eng/xml.user.login HTTP/1.1
User-Agent: curl/7.22.0 (x86_64-pc-linux-gnu) libcurl/7.22.0

OpenSSL/1.0.1 zlib/1.2.3.4 libidn/1.23 librtmp/2.3

Host: localhost:8080
Accept: */*
Content-Type: application/x-www-form-urlencoded
Content-Length: 30

} [data not shown]
* upload completely sent off: 30out of 30 bytes
< HTTP/1.1 302 Moved Temporarily
< Server: Apache-Coyote/1.1
< Set-Cookie: JSESSIONID=6518AC8D5DA92C6EA5A76E929B4F3D57;
Path=/geonetwork/; HttpOnly
< Location:
http://localhost:8080/geonetwork/login.jsp;jsessionid=6518AC8D5DA92C6EA5A76E929B4F3D57
< Content-Length: 0
< Date: Wed, 26 Jun 2013 15:21:19 GMT
<
100 30 0 0 100 30 0 3889 --:--:-- --:--:-- --:--:--
4285
* Connection #0 to host localhost left intact
* Issue another request to this URL: '
http://localhost:8080/geonetwork/login.jsp;jsessionid=6518AC8D5DA92C6EA5A76E929B4F3D57
'
* Violate RFC 2616/10.3.3 and switch from POST to GET
* Re-using existing connection! (#0) with host localhost
* Connected to localhost (127.0.0.1) port 8080 (#0)

GET /geonetwork/login.jsp;jsessionid=6518AC8D5DA92C6EA5A76E929B4F3D57

HTTP/1.1

User-Agent: curl/7.22.0 (x86_64-pc-linux-gnu) libcurl/7.22.0

OpenSSL/1.0.1 zlib/1.2.3.4 libidn/1.23 librtmp/2.3

Host: localhost:8080
Accept: */*
Content-Type: application/x-www-form-urlencoded

< HTTP/1.1 200 OK
< Server: Apache-Coyote/1.1
< Content-Type: text/html;charset=ISO-8859-1
< Content-Length: 1965
< Date: Wed, 26 Jun 2013 15:21:19 GMT
<
<html xmlns="http://www.w3.org/1999/xhtml&quot; lang="fr" xml:lang="fr">
<head>
<meta http-equiv="Pragma" content="no-cache">
<meta http-equiv="Cache-Control" content="no-cache,no-store">
<link rel="stylesheet" type="text/css" href="geonetwork.css">
<script language="Javascript1.5" type="text/javascript">
function init() {
var userLang = "null"
if(!userLang) {
userLang = (navigator.language) ? navigator.language :
navigator.userLanguage;
}

if(!userLang) {
userLang = "eng";
}
userLang = userLang.split('-')[0].toLowerCase();
if (userLang.match("^en")) {
userLang = "eng";
} else if (userLang.match("^fr")) {
userLang = "fre";
} else if (userLang.match("^de")) {
userLang = "ger";
} else if (userLang.match("^it")) {
userLang = "ita";
} else if (userLang.match("^ca")) {
userLang = "cat";
} else if (userLang.match("^es")) {
userLang = "spa";
} else if (userLang.match("^fi")) {
userLang = "fin";
} else if (userLang.match("^pl")) {
userLang = "pol";
} else if (userLang.match("^no")) {
userLang = "nor";
} else if (userLang.match("^nl")) {
userLang = "dut";
} else if (userLang.match("^pt")) {
userLang = "por";
} else if (userLang.match("^ar")) {
userLang = "ara";
} else if (userLang.match("^zh")) {
userLang = "chi";
} else if (userLang.match("^ru")) {
userLang = "rus";
} else if (userLang.match("^tr")) {
userLang = "tur";
} else {
userLang = "eng";
}

   window.location="srv/"+userLang+"/login.form"+window.location.search;
}
</script>
</head>
<body onload="init()">
<p>&nbsp;&nbsp;Please wait...</p>
<p>&nbsp;&nbsp;Patientez s'il vous plaît...</p>
<p>&nbsp;&nbsp;Bitte warten...</p>
<p>&nbsp;&nbsp;Un momento per favore...</p>

<noscript>
<h2>JavaScript warning</h2>
<p>To use GeoNetwork you need to enable JavaScript in your browser</p>
</noscript>
</body>
</html>

--
___________________________ ___ __
Ricardo Garcia Silva

Hi Ricardo

GeoNetwork 2.10 uses Spring Security and no longer the xml.login service.
If I'm not wrong, Basic Authentication is enabled by default, so you can
send the credentials in the http request header.

Regards,
Jose García

On Wed, Jun 26, 2013 at 5:27 PM, Ricardo Filipe Soares Garcia da <
ricardo.garcia.silva@anonymised.com> wrote:

Hi list

I had been using geonetwork 2.6 up until recently and had some python
scripts that used the csw interface to upload metadata records to my
catalogue. It worked flawlessly.

Since moving to version 2.10 my scripts stopped working...

Reading the docs[1], I could only find a reference to a change in the csw
transactions URL and nothing more.

So I thought that I only had to adapt my csw transaction url to:

geonetwork/srv/en/csw-publication

My script worked by

1 - logging out of any previous sessions
2 - logging in with my user credentials
3 - executing the csw insert request

But now I can't seem to even login to geonetwork through the xml services
anymore... What other changes have there been?

According to the manual on the user login service[2], I am trying to login
at the URL:

http://localhost:8080/geonetwork/srv/en/xml.user.login

I am using a POST request with 'username' and 'password' variables set to
the correct values. I always get back a 200 HTTP code (which would indicate
success) but the returned document is an HTML page[3] telling me that I
have to enable Javascript in the brwoser, which is really not what I would
expect. I would expect to get back an XML document with a response, even if
an error message.
My original request is being automatically redirected to another URL:

http://localhost:8080/geonetwork/login.jsp;jsessionid=28A2198AF954D32DC4F7EB720F84496E

So it seems to be storing some info in a cookie and then redirects to
another page that presumably performs the actual login. I don't know if my
username/password variables are getting lost along the redirection part...

I have been looking at the Javascript (a file called test-csw.js) code used
in the admin section of the geonetwork catalogue that is used for testing
the CSW server and found that it is not using the same login url as is
advised in the documentation, but rather:

http://localhost:8080/geonetwork/srv/en/j_spring_security_check

Should I be using this URL also? Is the documentation out of sync?

I am not an expert in these HTTP request and response things, so it is
possible that I am making some silly mistake, but on the other hand, the
script was working just fine before upgrading to geonetwork 2.10.

I am using cURL on the command-line to try and debug the problem, but my
ultimate goal is to get this working again in python using the requests
module, or urllib2.

In cURL, the login request that I am attempting is:

curl --verbose --data "username=XXXXXX&password=XXXXX" --header
"Content-Type: application/x-www-form-urlencoded" --location-trusted "
http://localhost:8080/geonetwork/srv/eng/xml.user.login&quot;

The response is in [3].

Thanks for your help

[1] -

http://geonetwork-opensource.org/manuals/2.10.0/eng/developer/xml_services/csw_services.html

[2] -

http://geonetwork-opensource.org/manuals/2.10.0/eng/developer/xml_services/login_xml_services.html

[3] - cURL response:

* About to connect() to localhost port 8080 (#0)
* Trying 127.0.0.1... % Total % Received % Xferd Average Speed
Time Time Time Current
                                 Dload Upload Total Spent Left
Speed
  0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:--
  0connected
> POST /geonetwork/srv/eng/xml.user.login HTTP/1.1
> User-Agent: curl/7.22.0 (x86_64-pc-linux-gnu) libcurl/7.22.0
OpenSSL/1.0.1 zlib/1.2.3.4 libidn/1.23 librtmp/2.3
> Host: localhost:8080
> Accept: */*
> Content-Type: application/x-www-form-urlencoded
> Content-Length: 30
>
} [data not shown]
* upload completely sent off: 30out of 30 bytes
< HTTP/1.1 302 Moved Temporarily
< Server: Apache-Coyote/1.1
< Set-Cookie: JSESSIONID=6518AC8D5DA92C6EA5A76E929B4F3D57;
Path=/geonetwork/; HttpOnly
< Location:

http://localhost:8080/geonetwork/login.jsp;jsessionid=6518AC8D5DA92C6EA5A76E929B4F3D57
< Content-Length: 0
< Date: Wed, 26 Jun 2013 15:21:19 GMT
<
100 30 0 0 100 30 0 3889 --:--:-- --:--:-- --:--:--
4285
* Connection #0 to host localhost left intact
* Issue another request to this URL: '

http://localhost:8080/geonetwork/login.jsp;jsessionid=6518AC8D5DA92C6EA5A76E929B4F3D57
'
* Violate RFC 2616/10.3.3 and switch from POST to GET
* Re-using existing connection! (#0) with host localhost
* Connected to localhost (127.0.0.1) port 8080 (#0)
> GET /geonetwork/login.jsp;jsessionid=6518AC8D5DA92C6EA5A76E929B4F3D57
HTTP/1.1
> User-Agent: curl/7.22.0 (x86_64-pc-linux-gnu) libcurl/7.22.0
OpenSSL/1.0.1 zlib/1.2.3.4 libidn/1.23 librtmp/2.3
> Host: localhost:8080
> Accept: */*
> Content-Type: application/x-www-form-urlencoded
>
< HTTP/1.1 200 OK
< Server: Apache-Coyote/1.1
< Content-Type: text/html;charset=ISO-8859-1
< Content-Length: 1965
< Date: Wed, 26 Jun 2013 15:21:19 GMT
<
<html xmlns="http://www.w3.org/1999/xhtml&quot; lang="fr" xml:lang="fr">
<head>
<meta http-equiv="Pragma" content="no-cache">
<meta http-equiv="Cache-Control" content="no-cache,no-store">
<link rel="stylesheet" type="text/css" href="geonetwork.css">
<script language="Javascript1.5" type="text/javascript">
function init() {
var userLang = "null"
if(!userLang) {
userLang = (navigator.language) ? navigator.language :
navigator.userLanguage;
}

if(!userLang) {
userLang = "eng";
}
userLang = userLang.split('-')[0].toLowerCase();
if (userLang.match("^en")) {
userLang = "eng";
} else if (userLang.match("^fr")) {
userLang = "fre";
} else if (userLang.match("^de")) {
userLang = "ger";
} else if (userLang.match("^it")) {
userLang = "ita";
} else if (userLang.match("^ca")) {
userLang = "cat";
} else if (userLang.match("^es")) {
userLang = "spa";
} else if (userLang.match("^fi")) {
userLang = "fin";
} else if (userLang.match("^pl")) {
userLang = "pol";
} else if (userLang.match("^no")) {
userLang = "nor";
} else if (userLang.match("^nl")) {
userLang = "dut";
} else if (userLang.match("^pt")) {
userLang = "por";
} else if (userLang.match("^ar")) {
userLang = "ara";
} else if (userLang.match("^zh")) {
userLang = "chi";
} else if (userLang.match("^ru")) {
userLang = "rus";
} else if (userLang.match("^tr")) {
userLang = "tur";
} else {
userLang = "eng";
}

   window.location="srv/"+userLang+"/login.form"+window.location.search;
}
</script>
</head>
<body onload="init()">
<p>&nbsp;&nbsp;Please wait...</p>
<p>&nbsp;&nbsp;Patientez s'il vous plaît...</p>
<p>&nbsp;&nbsp;Bitte warten...</p>
<p>&nbsp;&nbsp;Un momento per favore...</p>

<noscript>
<h2>JavaScript warning</h2>
<p>To use GeoNetwork you need to enable JavaScript in your browser</p>
</noscript>
</body>
</html>

--
___________________________ ___ __
Ricardo Garcia Silva

------------------------------------------------------------------------------
This SF.net email is sponsored by Windows:

Build for Windows Store.

http://p.sf.net/sfu/windows-dev2dev
_______________________________________________
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

--
*
GeoCat Bridge for ArcGIS allows instant publishing of data and metadata on
GeoServer and GeoNetwork. Visit http://geocat.net for details.
_________________________
Jose García
GeoCat bv
Veenderweg 13
6721 WD Bennekom
The Netherlands
http://GeoCat.net/&gt;

*