Code example for DocumentBuilder

Methods: parse

0
		HttpResponse httpResponse = client.execute(request);
		 
		if (httpResponse.getStatusLine().getStatusCode() == 200) {
			DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
			DocumentBuilder builder = factory.newDocumentBuilder();
			Document dom = builder.parse(httpResponse.getEntity().getContent());
			Element root = dom.getDocumentElement();
			String token = root.getTextContent();
			if (token != null) {
				return token;
			} 
			else { 
				throw new LoginException("Couldn't log-in to the WAZ Service: Invalid username or password");
			} 
		} 
		 
		throw new LoginException("Couldn't log-in to the WAZ Service: The login request returned " + httpResponse.getStatusLine().getReasonPhrase());
	} 
 
	public StorageCredentials getCredentials() throws Exception { 
		return new WAZServiceAccountCredentials(this.loginToWAZService());