[GeoNetwork-devel] Retrieving groups list with GetGroupsClient

Hi,

I am trying out the examples listed under ‘Java development with XML services’ at
http://geonetwork-opensource.org/manuals/2.10.2/eng/developer/xml_services/java_xml_services.html

When I execute the following Java code, I get HTTP response as 301 (moved permanently) but when I use the browser to access the URL http://localhost:8080/geonetwork/srv/en/xml.group.list , I get a proper XML response (Console output below confirms this).

Please let me know what is missing in Java part to get the response status code as 200?

Java Code (same as listed under ‘Java development with XML services’ )

public class GetGroupsClient {
public static void main(String args) {
// Create request xml**
Element request = new Element(“request”);
// Create PostMethod specifying service url**
String serviceUrl = “http://localhost:8080/geonetwork/srv/en/xml.group.list”;
PostMethod post = new PostMethod(serviceUrl);

try {
String postData = Xml.getString(new Document(request));

// Set post data, mime-type and encoding**
post.setRequestEntity(new StringRequestEntity(postData,
“application/xml”, “UTF8”));

// Send request**
HttpClient httpclient = new HttpClient();
int result = httpclient.executeMethod(post);

// Display status code**
System.out.println("Response status code: " + result);

// Display response**
System.out.println("Response body: ");
System.out.println(post.getResponseBodyAsString());

} catch (Exception ex) {
ex.printStackTrace();

} finally {
// Release current connection to the connection pool
// once you are done**
post.releaseConnection();
}
}
}

Geonetwork console output when using browser to access the URL http://localhost:8080/geonetwork/srv/en/xml.group.list

2013-11-13 09:53:56,827 INFO [jeeves.request] - ===============================

===========================
2013-11-13 09:53:56,828 INFO [jeeves.request] - HTML Request (from 127.0.0.1) :
/geonetwork/srv/eng/xml.group.list
2013-11-13 09:53:56,950 INFO [jeeves.service] - Dispatching : xml.group.list
2013-11-13 09:53:56,954 INFO [jeeves.service] - → dispatching to output for
: xml.group.list
2013-11-13 09:53:56,954 INFO [jeeves.service] - → writing xml for : xml.g
roup.list
2013-11-13 09:53:56,983 INFO [jeeves.service] - → output ended for : xml.gr
oup.list
2013-11-13 09:53:56,983 INFO [jeeves.service] - → dispatch ended for : xml.gr
oup.list

Regards,
Divya
www.dealbitte.com

Hi Divya

Change the url to: http://localhost:8080/geonetwork/srv/eng/xml.group.list , that should fix the issue.

Regards,
Jose García

···

On Wed, Nov 13, 2013 at 10:11 AM, divzee Chandrashakher <divzeeblog@anonymised.com…> wrote:

Hi,

I am trying out the examples listed under ‘Java development with XML services’ at
http://geonetwork-opensource.org/manuals/2.10.2/eng/developer/xml_services/java_xml_services.html

When I execute the following Java code, I get HTTP response as 301 (moved permanently) but when I use the browser to access the URL http://localhost:8080/geonetwork/srv/en/xml.group.list , I get a proper XML response (Console output below confirms this).

Please let me know what is missing in Java part to get the response status code as 200?

Java Code (same as listed under ‘Java development with XML services’ )

public class GetGroupsClient {
public static void main(String args) {
// Create request xml**
Element request = new Element(“request”);
// Create PostMethod specifying service url**
String serviceUrl = “http://localhost:8080/geonetwork/srv/en/xml.group.list”;
PostMethod post = new PostMethod(serviceUrl);

try {
String postData = Xml.getString(new Document(request));

// Set post data, mime-type and encoding**
post.setRequestEntity(new StringRequestEntity(postData,
“application/xml”, “UTF8”));

// Send request**
HttpClient httpclient = new HttpClient();
int result = httpclient.executeMethod(post);

// Display status code**
System.out.println("Response status code: " + result);

// Display response**
System.out.println("Response body: ");
System.out.println(post.getResponseBodyAsString());

} catch (Exception ex) {
ex.printStackTrace();

} finally {
// Release current connection to the connection pool
// once you are done**
post.releaseConnection();
}
}
}

Geonetwork console output when using browser to access the URL http://localhost:8080/geonetwork/srv/en/xml.group.list

2013-11-13 09:53:56,827 INFO [jeeves.request] - ===============================

===========================
2013-11-13 09:53:56,828 INFO [jeeves.request] - HTML Request (from 127.0.0.1) :
/geonetwork/srv/eng/xml.group.list
2013-11-13 09:53:56,950 INFO [jeeves.service] - Dispatching : xml.group.list
2013-11-13 09:53:56,954 INFO [jeeves.service] - → dispatching to output for
: xml.group.list
2013-11-13 09:53:56,954 INFO [jeeves.service] - → writing xml for : xml.g
roup.list
2013-11-13 09:53:56,983 INFO [jeeves.service] - → output ended for : xml.gr
oup.list
2013-11-13 09:53:56,983 INFO [jeeves.service] - → dispatch ended for : xml.gr
oup.list

Regards,
Divya
www.dealbitte.com


DreamFactory - Open Source REST & JSON Services for HTML5 & Native Apps
OAuth, Users, Roles, SQL, NoSQL, BLOB Storage and External API Access
Free app hosting. Or install the open source package on any LAMP server.
Sign up and see examples for AngularJS, jQuery, Sencha Touch and Native!
http://pubads.g.doubleclick.net/gampad/clk?id=63469471&iu=/4140/ostg.clktrk


GeoNetwork-devel mailing list
GeoNetwork-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/geonetwork-devel
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

Yeah. Works now by changing the URL. As the browser automatically handles the redirection, it was’t a problem.

Thank you.

···

On Wed, Nov 13, 2013 at 10:19 AM, Jose Garcia <jose.garcia@anonymised.com> wrote:

Hi Divya

Change the url to: http://localhost:8080/geonetwork/srv/eng/xml.group.list , that should fix the issue.

Regards,
Jose García


Divya C
www.dealbitte.com
Ideas for smart shopping

On Wed, Nov 13, 2013 at 10:11 AM, divzee Chandrashakher <divzeeblog@anonymised.com> wrote:

Hi,

I am trying out the examples listed under ‘Java development with XML services’ at
http://geonetwork-opensource.org/manuals/2.10.2/eng/developer/xml_services/java_xml_services.html

When I execute the following Java code, I get HTTP response as 301 (moved permanently) but when I use the browser to access the URL http://localhost:8080/geonetwork/srv/en/xml.group.list , I get a proper XML response (Console output below confirms this).

Please let me know what is missing in Java part to get the response status code as 200?

Java Code (same as listed under ‘Java development with XML services’ )

public class GetGroupsClient {
public static void main(String args) {
// Create request xml**
Element request = new Element(“request”);
// Create PostMethod specifying service url**
String serviceUrl = “http://localhost:8080/geonetwork/srv/en/xml.group.list”;
PostMethod post = new PostMethod(serviceUrl);

try {
String postData = Xml.getString(new Document(request));

// Set post data, mime-type and encoding**
post.setRequestEntity(new StringRequestEntity(postData,
“application/xml”, “UTF8”));

// Send request**
HttpClient httpclient = new HttpClient();
int result = httpclient.executeMethod(post);

// Display status code**
System.out.println("Response status code: " + result);

// Display response**
System.out.println("Response body: ");
System.out.println(post.getResponseBodyAsString());

} catch (Exception ex) {
ex.printStackTrace();

} finally {
// Release current connection to the connection pool
// once you are done**
post.releaseConnection();
}
}
}

Geonetwork console output when using browser to access the URL http://localhost:8080/geonetwork/srv/en/xml.group.list

2013-11-13 09:53:56,827 INFO [jeeves.request] - ===============================

===========================
2013-11-13 09:53:56,828 INFO [jeeves.request] - HTML Request (from 127.0.0.1) :
/geonetwork/srv/eng/xml.group.list
2013-11-13 09:53:56,950 INFO [jeeves.service] - Dispatching : xml.group.list
2013-11-13 09:53:56,954 INFO [jeeves.service] - → dispatching to output for
: xml.group.list
2013-11-13 09:53:56,954 INFO [jeeves.service] - → writing xml for : xml.g
roup.list
2013-11-13 09:53:56,983 INFO [jeeves.service] - → output ended for : xml.gr
oup.list
2013-11-13 09:53:56,983 INFO [jeeves.service] - → dispatch ended for : xml.gr
oup.list

Regards,
Divya
www.dealbitte.com


DreamFactory - Open Source REST & JSON Services for HTML5 & Native Apps
OAuth, Users, Roles, SQL, NoSQL, BLOB Storage and External API Access
Free app hosting. Or install the open source package on any LAMP server.
Sign up and see examples for AngularJS, jQuery, Sencha Touch and Native!
http://pubads.g.doubleclick.net/gampad/clk?id=63469471&iu=/4140/ostg.clktrk


GeoNetwork-devel mailing list
GeoNetwork-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/geonetwork-devel
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

Hi,

I moved on to the next example (which is adding a user) listed under ‘Java development with XML services’ at
http://geonetwork-opensource.org/manuals/2.10.2/eng/developer/xml_services/java_xml_services.html

Please let me know

  1. Where to find the updated documentation on the GeoNetwork service URLs ? Looks like I need to change ‘en’ to ‘eng’ in the URLs listed in the official documentation.

  2. If GeoNetwork is a good choice for my use-case. I have an in-house application that generates around 300 files every 10-15 minutes. Each file is about 300-500 MB. I wrote a code that detects a new file generated by the in-house application and creates a Metadata file (<gmd:MD_Metadata …>). I want to insert this metadata into a catalog. I don’t want to insert metadata manually (which works without any issues). I am in the process of writing java module to automate metadata insertion. But I having issues (see item3 below) in running java examples listed in official Geonetwork page. Is Geonetwork suitable for machine to machine interfaces (like java application calling the metadata insert service or calling an add user service) ? I had looked at GeoNetwork & Deegree (http://www.deegree.org/) and chose GeoNetwork.

  3. what is incorrect in “Add User” example: the following code returns HTTP response code as 302 and the response body is empty. As a consequence, Xml.loadstring method throws exception. The same is true for metadata insertion code which I tested with the URL http://localhost:8080/geonetwork/srv/eng/xml.metadata.insert

Thanks in advance.

Java code snipper to add user

public void sendRequest() {
// Authenticate user
if (!login()) {
System.err.println(“Unablet to Log-in”);
System.exit(-1);
}

// Create request XML
Element request = new Element(“request”)
.addContent(new Element(“operation”).setText(“newuser”))
.addContent(new Element(“username”).setText(“dealbitte”))
.addContent(new Element(“password”).setText(“editor2”))
.addContent(new Element(“profile”).setText(“Editor”))
.addContent(new Element(“name”).setText(“firstname”))
.addContent(new Element(“city”).setText(“cityname”))
.addContent(new Element(“country”).setText(“Germany”))
.addContent(new Element(“email”).setText(“admin@anonymised.com87…”));

// Create PostMethod specifying service url
String serviceUrl = “http://localhost:8080/geonetwork/srv/eng/user.update”;
PostMethod post = new PostMethod(serviceUrl);

try {
String postData = Xml.getString(new Document(request));

// Set post data, mime-type and encoding
post.setRequestEntity(new StringRequestEntity(postData,
“application/xml”, “UTF8”));

// Send request httpClient has been set in
// login request with JSESSIONID cookie)
int result = httpclient.executeMethod(post);

// Display status code
System.out.println("Create user response status code: " + result);

if (result != HttpStatus.SC_OK) {
// Process exception
String responseBody = post.getResponseBodyAsString();
Element response = Xml.loadString(responseBody, false);
System.out.println("Error code: "

  • response.getAttribute(“id”).getValue());
    System.out.println("Error message: "
  • response.getChildText(“message”));
    }

} catch (Exception ex) {
ex.printStackTrace();

} finally {
// Release current connection to the connection pool
// once you are done
post.releaseConnection();
}

}

Output:

Login response status code: 200
Authentication session cookie: JSESSIONID=7na2mcq2mtxx10hwkrw7h461m
Create user response status code: 302
<Exception as the responseBody is empty)

···

On Wed, Nov 13, 2013 at 10:24 AM, divzee Chandrashakher <divzeeblog@anonymised.com> wrote:

Yeah. Works now by changing the URL. As the browser automatically handles the redirection, it was’t a problem.

Thank you.


Divya C
www.dealbitte.com
Ideas for smart shopping

On Wed, Nov 13, 2013 at 10:19 AM, Jose Garcia <jose.garcia@anonymised.com> wrote:

Hi Divya

Change the url to: http://localhost:8080/geonetwork/srv/eng/xml.group.list , that should fix the issue.

Regards,
Jose García


Divya C
www.dealbitte.com
Ideas for smart shopping

On Wed, Nov 13, 2013 at 10:11 AM, divzee Chandrashakher <divzeeblog@anonymised.com> wrote:

Hi,

I am trying out the examples listed under ‘Java development with XML services’ at
http://geonetwork-opensource.org/manuals/2.10.2/eng/developer/xml_services/java_xml_services.html

When I execute the following Java code, I get HTTP response as 301 (moved permanently) but when I use the browser to access the URL http://localhost:8080/geonetwork/srv/en/xml.group.list , I get a proper XML response (Console output below confirms this).

Please let me know what is missing in Java part to get the response status code as 200?

Java Code (same as listed under ‘Java development with XML services’ )

public class GetGroupsClient {
public static void main(String args) {
// Create request xml**
Element request = new Element(“request”);
// Create PostMethod specifying service url**
String serviceUrl = “http://localhost:8080/geonetwork/srv/en/xml.group.list”;
PostMethod post = new PostMethod(serviceUrl);

try {
String postData = Xml.getString(new Document(request));

// Set post data, mime-type and encoding**
post.setRequestEntity(new StringRequestEntity(postData,
“application/xml”, “UTF8”));

// Send request**
HttpClient httpclient = new HttpClient();
int result = httpclient.executeMethod(post);

// Display status code**
System.out.println("Response status code: " + result);

// Display response**
System.out.println("Response body: ");
System.out.println(post.getResponseBodyAsString());

} catch (Exception ex) {
ex.printStackTrace();

} finally {
// Release current connection to the connection pool
// once you are done**
post.releaseConnection();
}
}
}

Geonetwork console output when using browser to access the URL http://localhost:8080/geonetwork/srv/en/xml.group.list

2013-11-13 09:53:56,827 INFO [jeeves.request] - ===============================

===========================
2013-11-13 09:53:56,828 INFO [jeeves.request] - HTML Request (from 127.0.0.1) :
/geonetwork/srv/eng/xml.group.list
2013-11-13 09:53:56,950 INFO [jeeves.service] - Dispatching : xml.group.list
2013-11-13 09:53:56,954 INFO [jeeves.service] - → dispatching to output for
: xml.group.list
2013-11-13 09:53:56,954 INFO [jeeves.service] - → writing xml for : xml.g
roup.list
2013-11-13 09:53:56,983 INFO [jeeves.service] - → output ended for : xml.gr
oup.list
2013-11-13 09:53:56,983 INFO [jeeves.service] - → dispatch ended for : xml.gr
oup.list

Regards,
Divya
www.dealbitte.com


DreamFactory - Open Source REST & JSON Services for HTML5 & Native Apps
OAuth, Users, Roles, SQL, NoSQL, BLOB Storage and External API Access
Free app hosting. Or install the open source package on any LAMP server.
Sign up and see examples for AngularJS, jQuery, Sencha Touch and Native!
http://pubads.g.doubleclick.net/gampad/clk?id=63469471&iu=/4140/ostg.clktrk


GeoNetwork-devel mailing list
GeoNetwork-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/geonetwork-devel
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