// Path: api/src/main/java/org/openmrs/module/hl7query/AuthenticationErrorObject.java
// public class AuthenticationErrorObject extends LinkedHashMap<String, Object> {
// 
// 	private static final long serialVersionUID = 1L;
// 
// 	public AuthenticationErrorObject() {
// 		super();
// 	}
// 
// 	/**
// 	 * Puts a property in this map, and returns the map itself (for chained method calls)
// 	 * 
// 	 * @param key
// 	 * @param value
// 	 * @return
// 	 */
// 	public AuthenticationErrorObject add(String key, Object value) {
// 		put(key, value);
// 		return this;
// 	}
// 
// 	/**
// 	 * Removes a property from the map, and returns the map itself (for chained method calls)
// 	 * 
// 	 * @param key
// 	 * @return
// 	 */
// 	public AuthenticationErrorObject removeProperty(String key) {
// 		remove(key);
// 		return this;
// 	}
// 
// 	/**
// 	 * Creates an instance from the given json string.
// 	 * 
// 	 * @param json
// 	 * @return the simpleObject
// 	 * @throws JsonParseException
// 	 * @throws JsonMappingException
// 	 * @throws IOException
// 	 */
// 	public static AuthenticationErrorObject parseJson(String json) throws JsonParseException, JsonMappingException, IOException {
// 		ObjectMapper objectMapper = new ObjectMapper();
// 		AuthenticationErrorObject object = objectMapper.readValue(json, AuthenticationErrorObject.class);
// 		return object;
// 	}
// }


import java.io.IOException;
import java.io.StringWriter;
import java.io.Writer;
import java.util.LinkedHashMap;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.transform.OutputKeys;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import org.apache.commons.lang.exception.ExceptionUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.codehaus.jackson.JsonGenerationException;
import org.codehaus.jackson.map.JsonMappingException;
import org.codehaus.jackson.map.ObjectMapper;
import org.openmrs.module.hl7query.AuthenticationErrorObject;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Text;

	            //add a text element to the child
	            Text errorCodeText = doc.createTextNode(Integer.toString(error.getCode()));
	            errorCode.appendChild(errorCodeText);

	            //set up a transformer
	            TransformerFactory transfac = TransformerFactory.newInstance();
	            Transformer trans = transfac.newTransformer();
	            trans.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
	            trans.setOutputProperty(OutputKeys.INDENT, "yes");

	            //create string from xml tree
	            StringWriter sw = new StringWriter();
	            StreamResult result = new StreamResult(sw);
	            DOMSource source = new DOMSource(doc);
	            trans.transform(source, result);
	            xmlString = sw.toString();
	            
	        } catch (Exception e) {
	            e.printStackTrace();
	        }
		 return xmlString;
	}

	/**
	 * Wraps the exception message as a SimpleObject to be sent to client
	 * 
	 * @param ex
	 * @param reason
	 * @return
	 */

// Path: api/src/main/java/org/openmrs/module/hl7query/AuthenticationErrorObject.java
// public class AuthenticationErrorObject extends LinkedHashMap<String, Object> {
// 
// 	private static final long serialVersionUID = 1L;
// 
// 	public AuthenticationErrorObject() {
// 		super();
// 	}
// 
// 	/**
// 	 * Puts a property in this map, and returns the map itself (for chained method calls)
// 	 * 
// 	 * @param key
// 	 * @param value
// 	 * @return
// 	 */
// 	public AuthenticationErrorObject add(String key, Object value) {
// 		put(key, value);
// 		return this;
// 	}
// 
// 	/**
// 	 * Removes a property from the map, and returns the map itself (for chained method calls)
// 	 * 
// 	 * @param key
// 	 * @return
// 	 */
// 	public AuthenticationErrorObject removeProperty(String key) {
// 		remove(key);
// 		return this;
// 	}
// 
// 	/**
// 	 * Creates an instance from the given json string.
// 	 * 
// 	 * @param json
// 	 * @return the simpleObject
// 	 * @throws JsonParseException
// 	 * @throws JsonMappingException
// 	 * @throws IOException
// 	 */
// 	public static AuthenticationErrorObject parseJson(String json) throws JsonParseException, JsonMappingException, IOException {
// 		ObjectMapper objectMapper = new ObjectMapper();
// 		AuthenticationErrorObject object = objectMapper.readValue(json, AuthenticationErrorObject.class);
// 		return object;
// 	}
// }


// Path: api/src/main/java/org/openmrs/module/hl7query/util/ExceptionUtil.java
import java.io.IOException;
import java.io.StringWriter;
import java.io.Writer;
import java.util.LinkedHashMap;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.transform.OutputKeys;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import org.apache.commons.lang.exception.ExceptionUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.codehaus.jackson.JsonGenerationException;
import org.codehaus.jackson.map.JsonMappingException;
import org.codehaus.jackson.map.ObjectMapper;
import org.openmrs.module.hl7query.AuthenticationErrorObject;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Text;

	            //add a text element to the child
	            Text errorCodeText = doc.createTextNode(Integer.toString(error.getCode()));
	            errorCode.appendChild(errorCodeText);

	            //set up a transformer
	            TransformerFactory transfac = TransformerFactory.newInstance();
	            Transformer trans = transfac.newTransformer();
	            trans.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
	            trans.setOutputProperty(OutputKeys.INDENT, "yes");

	            //create string from xml tree
	            StringWriter sw = new StringWriter();
	            StreamResult result = new StreamResult(sw);
	            DOMSource source = new DOMSource(doc);
	            trans.transform(source, result);
	            xmlString = sw.toString();
	            
	        } catch (Exception e) {
	            e.printStackTrace();
	        }
		 return xmlString;
	}

	/**
	 * Wraps the exception message as a SimpleObject to be sent to client
	 * 
	 * @param ex
	 * @param reason
	 * @return
	 */

	public static AuthenticationErrorObject wrapErrorResponse(Exception ex, String reason) {
