HttpClient client = new HttpClient();
HttpMethod method = new GetMethod(reqURI);
try {
client.executeMethod(method);
} catch (HttpException e) {
throw new SimalAPIException(
"Unable to retrieve data from the MyExperiment instance "
+ getBaseURI(), e);
} catch (IOException e) {
throw new SimalAPIException(
"Unable to retrieve data from the MyExperiment instance "
+ getBaseURI(), e);
}
StringWriter out;
try {
InputSource in = new InputSource(new StringReader(new String(method
.getResponseBody())));
DocumentBuilderFactory docBuildFactory = DocumentBuilderFactory
.newInstance();
DocumentBuilder parser = docBuildFactory.newDocumentBuilder();
Document document = parser.parse(in);
TransformerFactory xformFactory = TransformerFactory.newInstance();
StreamSource xslt = new StreamSource(PersonAPI.class
.getResourceAsStream("myExperiment-to-shindig.xsl"));
Transformer transformer = xformFactory.newTransformer(xslt);
DOMSource source = new DOMSource(document);
out = new StringWriter();
StreamResult scrResult = new StreamResult(out);
transformer.transform(source, scrResult);
} catch (IOException e) {
throw new SimalAPIException(
"Unable to read the response from the MyExperiment instance "
+ reqURI, e);
} catch (ParserConfigurationException e) {
throw new SimalAPIException("Unable to create an XML parser", e);
} catch (SAXException e) {
throw new SimalAPIException(
"Unable to parse the response from the MyExperiment instance "
+ reqURI, e);
} catch (TransformerConfigurationException e) {
throw new SimalAPIException("Unable to create an XSLT transformer", e);
} catch (TransformerException e) {
throw new SimalAPIException(
"Unable to transform the response from the MyExperiment instance "
+ reqURI, e);
}
return out.toString();