Search in sources :

Example 26 with JAXBException

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();
}
Also used : InputStreamReader(java.io.InputStreamReader) LgtvStatusUpdateEvent(org.openhab.binding.lgtv.internal.LgtvStatusUpdateEvent) OutputStream(java.io.OutputStream) JAXBException(javax.xml.bind.JAXBException) BufferedReader(java.io.BufferedReader)

Example 27 with JAXBException

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;
}
Also used : XMLStreamReader(javax.xml.stream.XMLStreamReader) XMLStreamException(javax.xml.stream.XMLStreamException) UnmarshalException(javax.xml.bind.UnmarshalException) JAXBException(javax.xml.bind.JAXBException) JAXBContext(javax.xml.bind.JAXBContext) XMLInputFactory(javax.xml.stream.XMLInputFactory)

Example 28 with JAXBException

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;
}
Also used : Marshaller(javax.xml.bind.Marshaller) StringWriter(java.io.StringWriter) JAXBException(javax.xml.bind.JAXBException) JAXBContext(javax.xml.bind.JAXBContext)

Example 29 with JAXBException

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;
}
Also used : ItemBase(org.platformlayer.core.model.ItemBase) JAXBException(javax.xml.bind.JAXBException) JaxbHelper(org.platformlayer.xml.JaxbHelper) Document(org.w3c.dom.Document)

Example 30 with JAXBException

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;
}
Also used : JAXBException(javax.xml.bind.JAXBException) JaxbHelper(org.platformlayer.xml.JaxbHelper) Document(org.w3c.dom.Document)

Aggregations

JAXBException (javax.xml.bind.JAXBException)402 JAXBContext (javax.xml.bind.JAXBContext)126 IOException (java.io.IOException)93 Unmarshaller (javax.xml.bind.Unmarshaller)91 Marshaller (javax.xml.bind.Marshaller)69 ArrayList (java.util.ArrayList)38 StringWriter (java.io.StringWriter)35 List (java.util.List)35 Map (java.util.Map)33 SAXException (org.xml.sax.SAXException)32 File (java.io.File)29 InputStream (java.io.InputStream)29 AMConsoleException (com.sun.identity.console.base.model.AMConsoleException)28 HashSet (java.util.HashSet)28 JAXBElement (javax.xml.bind.JAXBElement)24 XMLStreamException (javax.xml.stream.XMLStreamException)23 SAML2MetaException (com.sun.identity.saml2.meta.SAML2MetaException)22 StringReader (java.io.StringReader)21 HashMap (java.util.HashMap)21 SAML2MetaManager (com.sun.identity.saml2.meta.SAML2MetaManager)20