I've the function below which creates or replaces an existing layer group:
public bool AddToLayerGroup(string layerGroupName, string layerName)
{
try
{
// Retrive the layer group
string cLayerGroup = GetLayerGroup(layerGroupName);
// Add the new layer as a new layer node among the retrieved layer nodes
XmlDocument newLayerGrpXml = AddLayerNodeToLayerGroupXml(layerName, cLayerGroup);
// Convert the newly created layer group xml to string
string newLayerGrpString = ConvertXmlToString(newLayerGrpXml);
newLayerGrpString = newLayerGrpString.Replace("<?xml version=\"1.0\" encoding=\"utf-16\"?>", "");
// Delete the existing layer group
//DeleteLayerGroup(layerGroupName);
// Now, do ur thing here
string gUrl = GEOSERVER_HOST + "/rest/layergroups/" + layerGroupName + ".xml";
WebRequest request = WebRequest.Create(gUrl);
request.ContentType = "application/xml";
request.Method = "PUT";
request.Credentials = new NetworkCredential(GEOSERVER_USER, GEOSERVER_PASSWD);
byte[] buffer = Encoding.GetEncoding("UTF-8").GetBytes(newLayerGrpString);
Stream requestStream = request.GetRequestStream();
requestStream.Write(buffer, 0, buffer.Length);
requestStream.Close();
WebResponse response = request.GetResponse();
return true;
}
catch (Exception e)
{
Console.Write(e.Message);
return false;
}
}
This executes successfully. Tomcat logs also indicates successful execution of the PUT method. However, I can't see the created layer group using GeoServer web UI. Is there anything else I need to do after executing the above code? Trying to create another layer group with the same name fails with the error layer group already exists; a further proof that the layer group was created. But, why can't I see it using the GeoServer web UI. Any assistance will be highly appreciated.