use of javax.xml.bind.JAXBException in project openhab1-addons by openhab.
the class LgTvMessageReader method doPost.
@Override
public void doPost(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
BufferedReader rd = null;
StringBuilder sb = null;
res.setContentType("text/plain");
res.setStatus(200);
OutputStream responseBody = res.getOutputStream();
LgtvStatusUpdateEvent event = new LgtvStatusUpdateEvent(this);
rd = new BufferedReader(new InputStreamReader(req.getInputStream()));
sb = new StringBuilder();
String line;
while ((line = rd.readLine()) != null) {
sb.append(line + '\n');
}
String remoteaddr = req.getRemoteAddr();
int start = remoteaddr.indexOf(":");
String t;
if (start > -1) {
t = remoteaddr.substring(0, start);
} else {
t = remoteaddr;
}
remoteaddr = t;
start = remoteaddr.indexOf("/");
if (start > -1) {
t = remoteaddr.substring(start + 1, remoteaddr.length());
} else {
t = remoteaddr;
}
remoteaddr = t;
logger.debug("httphandler called from remoteaddr=" + remoteaddr + " result=" + sb.toString());
LgTvEventChannelChanged myevent = new LgTvEventChannelChanged();
String result = "";
try {
result = myevent.readevent(sb.toString());
} catch (JAXBException e) {
logger.error("error in httphandler", e);
}
logger.debug("eventresult=" + result);
LgTvEventChannelChanged.envelope envel = myevent.getenvel();
String eventname = envel.getchannel().geteventname();
if (eventname.equals("ChannelChanged")) {
String name = "CHANNEL_CURRENTNAME=" + envel.getchannel().getchname();
String number = "CHANNEL_CURRENTNUMBER=" + envel.getchannel().getmajor();
String set = "CHANNEL_SET=" + envel.getchannel().getmajor();
sendtohandlers(event, remoteaddr, name);
sendtohandlers(event, remoteaddr, number);
sendtohandlers(event, remoteaddr, set);
} else if (eventname.equals("byebye")) {
sendtohandlers(event, remoteaddr, "BYEBYE_SEEN=1");
} else {
logger.debug("warning - unhandled event");
}
responseBody.close();
}
use of javax.xml.bind.JAXBException in project openhab1-addons by openhab.
the class DenonConnector method getDocument.
private <T> T getDocument(String uri, Class<T> response) {
try {
String result = doHttpRequest("GET", uri, null);
logger.trace("result of getDocument for uri '{}':\r\n{}", uri, result);
if (StringUtils.isNotBlank(result)) {
JAXBContext jc = JAXBContext.newInstance(response);
XMLInputFactory xif = XMLInputFactory.newInstance();
XMLStreamReader xsr = xif.createXMLStreamReader(IOUtils.toInputStream(result));
xsr = new PropertyRenamerDelegate(xsr);
@SuppressWarnings("unchecked") T obj = (T) jc.createUnmarshaller().unmarshal(xsr);
return obj;
}
} catch (UnmarshalException e) {
logger.debug("Failed to unmarshal xml document: {}", e.getMessage());
} catch (JAXBException e) {
logger.debug("Unexpected error occurred during unmarshalling of document: {}", e.getMessage());
} catch (XMLStreamException e) {
logger.debug("Communication error: {}", e.getMessage());
}
return null;
}
use of javax.xml.bind.JAXBException in project openhab1-addons by openhab.
the class DenonConnector method postDocument.
private <T, S> T postDocument(String uri, Class<T> response, S request) {
try {
JAXBContext jaxbContext = JAXBContext.newInstance(request.getClass());
Marshaller jaxbMarshaller = jaxbContext.createMarshaller();
StringWriter sw = new StringWriter();
jaxbMarshaller.marshal(request, sw);
String result = doHttpRequest("POST", uri, sw.toString());
if (StringUtils.isNotBlank(result)) {
JAXBContext jcResponse = JAXBContext.newInstance(response);
@SuppressWarnings("unchecked") T obj = (T) jcResponse.createUnmarshaller().unmarshal(IOUtils.toInputStream(result));
return obj;
}
} catch (JAXBException e) {
logger.debug("Encoding error in post", e);
}
return null;
}
use of javax.xml.bind.JAXBException in project platformlayer by platformlayer.
the class UntypedItemXml method setLinks.
public void setLinks(Links links) {
ItemBase item = new ItemBase();
item.links = links;
Document document;
JaxbHelper helper = JaxbHelper.get(ItemBase.class);
try {
document = helper.marshalToDom(item);
} catch (JAXBException e) {
throw new IllegalStateException("Error serializing data", e);
}
replaceNode("links", XmlHelper.findUniqueChild(document.getDocumentElement(), "links", false));
// To avoid any possible state problems, we set to null rather than copying
this.links = null;
}
use of javax.xml.bind.JAXBException in project platformlayer by platformlayer.
the class UntypedItemXml method setTags.
public void setTags(Tags tags) {
Document document;
JaxbHelper helper = JaxbHelper.get(Tags.class);
try {
document = helper.marshalToDom(tags);
} catch (JAXBException e) {
throw new IllegalStateException("Error parsing tags data", e);
}
replaceNode("tags", document.getDocumentElement());
// To avoid any possible state problems, we set to null rather than copying
this.tags = null;
}
Aggregations