public String newvAppFromTemplate( String vAppName, String templateLink, String catalogLink, String vdcLink, String network ) throws Exception 
	{
		// Step 1
		String response = doGet(templateLink);
		
		// Step 2 - look for NetowrkConnection element in the Vms contained
		Document doc = RestClient.stringToXmlDocument(response);
		Element childrenElement = (Element) doc.getElementsByTagName(Constants.CHILDREN).item(0);
		Element vmElement = (Element) childrenElement.getElementsByTagName(Constants.VM).item(0);
		Element netElement = (Element) vmElement.getElementsByTagName("NetworkConnectionSection").item(0);
		
		
		
		String ovfInfo = doc.getElementsByTagName("ovf:Info").item(0).getTextContent();
		String networkName = netElement.getElementsByTagName("NetworkConnection").item(0).getAttributes().getNamedItem("network").getTextContent().trim(); 
		
		String vdcResponse = doGet(vdcLink);
		String parentNetwork;
		if(network.isEmpty()) 
		{
			parentNetwork = findElement(vdcResponse, Constants.NETWORK, Constants.NETWORK_LINK, null);
		} 
		else {
			parentNetwork = findElement(vdcResponse, Constants.NETWORK, Constants.NETWORK_LINK, network);
		}
		
		// Step 3 - create an InstantiateVAppTemplate Params element
		DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
		DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
		
		// root elements
		doc = docBuilder.newDocument();
		Element rootElement = doc.createElement("InstantiateVAppTemplateParams");
		doc.appendChild(rootElement);
		
		rootElement.setAttribute("name", vAppName);
		rootElement.setAttribute("xmlns", Constants.XMLNS);
		rootElement.setAttribute("deploy", "true");
		rootElement.setAttribute("powerOn", "false");
		rootElement.setAttribute("xmlns:xsi", Constants.XMLNS_XSI);
		rootElement.setAttribute("xmlns:ovf", Constants.XMLNS_OVF);
		
		Element descElement = doc.createElement("Description");
		descElement.appendChild(doc.createTextNode("Created through Appdynamics controller"));
		rootElement.appendChild(descElement);
		
		Element paramsElement = doc.createElement("InstantiationParams");
		
		Element configElement = doc.createElement("Configuration");
		
		Element parentNetElement = doc.createElement("ParentNetwork");
		parentNetElement.setAttribute("href", parentNetwork);
		configElement.appendChild(parentNetElement);
		
		Element fenceElement = doc.createElement("FenceMode");
		fenceElement.appendChild(doc.createTextNode("bridged"));
		configElement.appendChild(fenceElement);
		
		Element netconfigSectionElement = doc.createElement("NetworkConfigSection");
		
		Element ovfInfoElement = doc.createElement("ovf:Info");
		ovfInfoElement.appendChild(doc.createTextNode(ovfInfo));
		netconfigSectionElement.appendChild(ovfInfoElement);
		
		Element netConfElement = doc.createElement("NetworkConfig");
		netConfElement.setAttribute("networkName", networkName);
		netConfElement.appendChild(configElement);
		netconfigSectionElement.appendChild(netConfElement);
		
		paramsElement.appendChild(netconfigSectionElement);
		rootElement.appendChild(paramsElement);
		
		Element sourceElement = doc.createElement("Source");
		sourceElement.setAttribute("href", templateLink);
		rootElement.appendChild(sourceElement);
		
		TransformerFactory tf = TransformerFactory.newInstance();
		Transformer transformer = tf.newTransformer();
		DOMSource source = new DOMSource(doc);
		StringWriter writer = new StringWriter();
		StreamResult result= new StreamResult(writer);
		
		transformer.transform(source, result);
		String xmlBody = writer.toString();
		
		
		// Step 4 - make a POST 
		
		String instantiateVAppLink = findElement(vdcResponse, Constants.LINK, Constants.INSTANTIATE_VAPP, null);
		
		StringEntity entity = new StringEntity(xmlBody);
		entity.setContentType(Constants.INSTANTIATE_VAPP);
		
		return doPost(instantiateVAppLink, entity);
	}