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