List the Named Maps In the Repository
This Java application calls the Mapping Service's REST interface to list the named maps in the repository. The list of named maps that is returned in the response is then output at the command line.
Here is the code:
public static void main(String[] args)
{
java.io.InputStream is = null;
try
{
// Create the REST request URL
String serverUrl = "http://MyServer:8080/rest/Spatial/MappingService/maps.json";
java.net.URL url = new java.net.URL(serverUrl);
java.net.HttpURLConnection conn = (java.net.HttpURLConnection)url.openConnection();
String user = "user";
String password = "pass";
// Credentials need to be a base64 encoded string of the nature "user:pass"
String credentials = user + ":" + password;
byte[] encodedBytes = org.apache.commons.codec.binary.Base64.encodeBase64(credentials.getBytes());
String base64EncodedString = new String(encodedBytes);
// Apply the authorization header - a string of nature "Basic <base64EncodedCredentialsString>"
String authHeader = "Basic" + " " + base64EncodedString;
conn.addRequestProperty("Authorization", authHeader);
// Get response for the request
is = conn.getInputStream();
java.io.ByteArrayOutputStream bos = new java.io.ByteArrayOutputStream();
org.apache.commons.io.IOUtils.copy(is, bos);
is.close();
// Display the response
System.out.println(new String(bos.toByteArray()));
}
catch (Exception e)
{
System.out.println(e.getMessage());
}
finally
{
org.apache.commons.io.IOUtils.closeQuietly(is);
}
}