Search in sources :

Example 1 with Catalog

use of jaxb1.Catalog in project Payara by payara.

the class Jaxb1MarshallingTestServlet method service.

@Override
protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    resp.setContentType("text/html;charset=UTF-8");
    PrintWriter out = resp.getWriter();
    out.println("jaxb1 marshalling test: ");
    try {
        JAXBContext jc = JAXBContext.newInstance("jaxb1");
        Marshaller m = jc.createMarshaller();
        ObjectFactory of = new ObjectFactory();
        Catalog c = of.createCatalog();
        c.setSection("jaxb1 section");
        StringWriter sw = new StringWriter();
        m.marshal(c, sw);
        String s = sw.toString();
        if (s.contains("<catalog section=\"jaxb1 section\"/>"))
            out.println("marshalled OK");
        else {
            out.println("jaxb1 marshalling failed");
            System.err.println("Error in Jaxb1MarshallingTestServlet. Marshalling result: " + s);
        }
    } catch (JAXBException e) {
        out.println("jaxb1 marshalling failed: " + e.getMessage());
        e.printStackTrace();
    }
}
Also used : Marshaller(javax.xml.bind.Marshaller) ObjectFactory(jaxb1.ObjectFactory) StringWriter(java.io.StringWriter) JAXBException(javax.xml.bind.JAXBException) JAXBContext(javax.xml.bind.JAXBContext) Catalog(jaxb1.Catalog) PrintWriter(java.io.PrintWriter)

Aggregations

PrintWriter (java.io.PrintWriter)1 StringWriter (java.io.StringWriter)1 JAXBContext (javax.xml.bind.JAXBContext)1 JAXBException (javax.xml.bind.JAXBException)1 Marshaller (javax.xml.bind.Marshaller)1 Catalog (jaxb1.Catalog)1 ObjectFactory (jaxb1.ObjectFactory)1