use of org.openhab.binding.homematic.internal.model.CommonUnmarshallerListener in project openhab1-addons by openhab.
the class CcuClient method sendScript.
/**
* Main method for sending a TclRega script and parsing the XML result.
*/
@SuppressWarnings("unchecked")
private synchronized <T> T sendScript(String script, Class<T> clazz) throws HomematicClientException {
PostMethod post = null;
try {
script = StringUtils.trim(script);
if (StringUtils.isEmpty(script)) {
throw new RuntimeException("Homematic TclRegaScript is empty!");
}
if (TRACE_ENABLED) {
logger.trace("TclRegaScript: {}", script);
}
post = new PostMethod(context.getConfig().getTclRegaUrl());
RequestEntity re = new ByteArrayRequestEntity(script.getBytes("ISO-8859-1"));
post.setRequestEntity(re);
httpClient.executeMethod(post);
String result = post.getResponseBodyAsString();
result = StringUtils.substringBeforeLast(result, "<xml><exec>");
if (TRACE_ENABLED) {
logger.trace("Result TclRegaScript: {}", result);
}
Unmarshaller um = JAXBContext.newInstance(clazz).createUnmarshaller();
um.setListener(new CommonUnmarshallerListener());
return (T) um.unmarshal(new StringReader(result));
} catch (Exception ex) {
throw new HomematicClientException(ex.getMessage(), ex);
} finally {
if (post != null) {
post.releaseConnection();
}
}
}
Aggregations