Example usage for javax.xml.bind JAXBException printStackTrace

List of usage examples for javax.xml.bind JAXBException printStackTrace

Introduction

In this page you can find the example usage for javax.xml.bind JAXBException printStackTrace.

Prototype

public void printStackTrace() 

Source Link

Document

Prints this JAXBException and its stack trace (including the stack trace of the linkedException if it is non-null) to System.err .

Usage

From source file:com.cws.esolutions.security.listeners.SecurityServiceInitializer.java

/**
 * Initializes the security service in a standalone mode - used for applications outside of a container or when
 * run as a standalone jar.//from w  ww . j a v  a  2s  .  com
 *
 * @param configFile - The security configuration file to utilize
 * @param logConfig - The logging configuration file to utilize
 * @param startConnections - Configure, load and start repository connections
 * @throws SecurityServiceException @{link com.cws.esolutions.security.exception.SecurityServiceException}
 * if an exception occurs during initialization
 */
public static void initializeService(final String configFile, final String logConfig,
        final boolean startConnections) throws SecurityServiceException {
    URL xmlURL = null;
    JAXBContext context = null;
    Unmarshaller marshaller = null;
    SecurityConfigurationData configData = null;

    final ClassLoader classLoader = SecurityServiceInitializer.class.getClassLoader();
    final String serviceConfig = (StringUtils.isBlank(configFile)) ? System.getProperty("configFileFile")
            : configFile;
    final String loggingConfig = (StringUtils.isBlank(logConfig)) ? System.getProperty("secLogConfig")
            : logConfig;

    try {
        try {
            DOMConfigurator.configure(Loader.getResource(loggingConfig));
        } catch (NullPointerException npx) {
            try {
                DOMConfigurator.configure(FileUtils.getFile(loggingConfig).toURI().toURL());
            } catch (NullPointerException npx1) {
                System.err.println("Unable to load logging configuration. No logging enabled!");
                System.err.println("");
                npx1.printStackTrace();
            }
        }

        xmlURL = classLoader.getResource(serviceConfig);

        if (xmlURL == null) {
            // try loading from the filesystem
            xmlURL = FileUtils.getFile(serviceConfig).toURI().toURL();
        }

        context = JAXBContext.newInstance(SecurityConfigurationData.class);
        marshaller = context.createUnmarshaller();
        configData = (SecurityConfigurationData) marshaller.unmarshal(xmlURL);

        SecurityServiceInitializer.svcBean.setConfigData(configData);

        if (startConnections) {
            DAOInitializer.configureAndCreateAuthConnection(
                    new FileInputStream(FileUtils.getFile(configData.getSecurityConfig().getAuthConfig())),
                    false, SecurityServiceInitializer.svcBean);

            Map<String, DataSource> dsMap = SecurityServiceInitializer.svcBean.getDataSources();

            if (DEBUG) {
                DEBUGGER.debug("dsMap: {}", dsMap);
            }

            if (configData.getResourceConfig() != null) {
                if (dsMap == null) {
                    dsMap = new HashMap<String, DataSource>();
                }

                for (DataSourceManager mgr : configData.getResourceConfig().getDsManager()) {
                    if (!(dsMap.containsKey(mgr.getDsName()))) {
                        StringBuilder sBuilder = new StringBuilder()
                                .append("connectTimeout=" + mgr.getConnectTimeout() + ";")
                                .append("socketTimeout=" + mgr.getConnectTimeout() + ";")
                                .append("autoReconnect=" + mgr.getAutoReconnect() + ";")
                                .append("zeroDateTimeBehavior=convertToNull");

                        if (DEBUG) {
                            DEBUGGER.debug("StringBuilder: {}", sBuilder);
                        }

                        BasicDataSource dataSource = new BasicDataSource();
                        dataSource.setDriverClassName(mgr.getDriver());
                        dataSource.setUrl(mgr.getDataSource());
                        dataSource.setUsername(mgr.getDsUser());
                        dataSource.setConnectionProperties(sBuilder.toString());
                        dataSource.setPassword(PasswordUtils.decryptText(mgr.getDsPass(), mgr.getDsSalt(),
                                configData.getSecurityConfig().getSecretAlgorithm(),
                                configData.getSecurityConfig().getIterations(),
                                configData.getSecurityConfig().getKeyBits(),
                                configData.getSecurityConfig().getEncryptionAlgorithm(),
                                configData.getSecurityConfig().getEncryptionInstance(),
                                configData.getSystemConfig().getEncoding()));

                        if (DEBUG) {
                            DEBUGGER.debug("BasicDataSource: {}", dataSource);
                        }

                        dsMap.put(mgr.getDsName(), dataSource);
                    }
                }

                if (DEBUG) {
                    DEBUGGER.debug("dsMap: {}", dsMap);
                }

                SecurityServiceInitializer.svcBean.setDataSources(dsMap);
            }
        }
    } catch (JAXBException jx) {
        jx.printStackTrace();
        throw new SecurityServiceException(jx.getMessage(), jx);
    } catch (FileNotFoundException fnfx) {
        fnfx.printStackTrace();
        throw new SecurityServiceException(fnfx.getMessage(), fnfx);
    } catch (MalformedURLException mux) {
        mux.printStackTrace();
        throw new SecurityServiceException(mux.getMessage(), mux);
    } catch (SecurityException sx) {
        sx.printStackTrace();
        throw new SecurityServiceException(sx.getMessage(), sx);
    }
}

From source file:io.apiman.test.common.echo.EchoServerVertx.java

private static void writeXmlAndEnd(HttpServerResponse rep, EchoResponse echo) {
    try (BufferOutputStream bufferOutputStream = new BufferOutputStream(500, rep)) {
        Marshaller jaxbMarshaller = jaxbContext.createMarshaller();
        jaxbMarshaller.marshal(echo, bufferOutputStream);
    } catch (JAXBException e) {
        e.printStackTrace();
        throw new RuntimeException(e);
    }/*from   w w w. j ava2s . c  o  m*/
}

From source file:main.java.refinement_class.Useful.java

public static void mashal(Object o, String xml_file, Class c) {

    Marshaller marshaller;/*from ww  w .j a  v a 2  s.c  om*/
    // create a JAXBContext
    JAXBContext jaxbContext;

    try {
        jaxbContext = JAXBContext.newInstance(c);

        marshaller = jaxbContext.createMarshaller();
        marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, new Boolean(true));
        marshaller.marshal(o, new FileOutputStream(xml_file));
    } catch (JAXBException e) {
        e.printStackTrace();
        LOG.error(e.toString());
    } catch (FileNotFoundException e) {
        e.printStackTrace();
        LOG.error(e.toString());
    }
}

From source file:main.java.refinement_class.Useful.java

public static String mashal2(Object o, Class c) {

    Marshaller marshaller;/*ww  w. j  a  v  a2s  .c o  m*/
    // create a JAXBContext
    JAXBContext jaxbContext;
    String xmlString = "";

    try {
        jaxbContext = JAXBContext.newInstance(c);
        marshaller = jaxbContext.createMarshaller();
        marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, new Boolean(true));
        //  marshaller.marshal(o, new FileOutputStream(xml_file));

        StringWriter sw = new StringWriter();
        marshaller.marshal(o, sw);
        xmlString = sw.toString();
    } catch (JAXBException e) {
        e.printStackTrace();
    }

    return xmlString;
}

From source file:com.qpark.eip.core.failure.BaseFailureHandler.java

private static void addBaseMessages() {
    InputStream is = BaseFailureHandler.class
            .getResourceAsStream(new StringBuffer(32).append("/").append(FAILURE_MESSAGES_XML_BASE).toString());
    if (is != null) {
        try {//from w w w  .j a  v  a  2s. c  om
            FailureMessageListType failuresMessageList = (FailureMessageListType) MARSHALLER.getValue(is,
                    FailureMessageListType.class);
            addFailureMessageList(failuresMessageList);
        } catch (JAXBException e) {
            e.printStackTrace();
        }
    }
}

From source file:main.java.refinement_class.Useful.java

public static Object unmashal2(String schema_file, String xml_file, Class c) {
    Object obj = null;/* w ww .jav a 2 s . c  o  m*/
    try {

        // create a JAXBContext capable of handling classes generated into
        // JAXBContext jc = JAXBContext.newInstance(ObjectFactory.class );

        JAXBContext jc = JAXBContext.newInstance(c);

        // create an Unmarshaller
        Unmarshaller u = jc.createUnmarshaller();

        SchemaFactory sf = SchemaFactory.newInstance(W3C_XML_SCHEMA_NS_URI);

        try {

            javax.xml.validation.Schema schema = sf.newSchema(new File(schema_file));

            u.setSchema((javax.xml.validation.Schema) schema);
            u.setEventHandler(new ValidationEventHandler() {
                // allow unmarshalling to continue even if there are errors
                public boolean handleEvent(ValidationEvent ve) {
                    // ignore warnings
                    if (ve.getSeverity() != ValidationEvent.WARNING) {
                        ValidationEventLocator vel = ve.getLocator();
                        System.out.println("Line:Col[" + vel.getLineNumber() + ":" + vel.getColumnNumber()
                                + "]:" + ve.getMessage());
                    }
                    return true;
                }
            });
        } catch (org.xml.sax.SAXException se) {
            System.out.println("Unable to validate due to following error.");
            se.printStackTrace();
            LOG.error(se.toString());
        }

        obj = u.unmarshal(new File(xml_file));

        // even though document was determined to be invalid unmarshalling,
        // marshal out result.
        //           System.out.println("");
        //         System.out.println("Still able to marshal invalid document");
        //       javax.xml.bind.Marshaller m = jc.createMarshaller();
        // m.setProperty( Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE );
        //     m.marshal(poe, System.out);
    } catch (UnmarshalException ue) {
        // The JAXB specification does not mandate how the JAXB provider
        // must behave when attempting to unmarshal invalid XML data.
        // those cases, the JAXB provider is allowed to terminate the
        // call to unmarshal with an UnmarshalException.
        System.out.println("Caught UnmarshalException");
    } catch (JAXBException je) {
        je.printStackTrace();
        LOG.error(je.toString());
    }

    return obj;
}

From source file:com.qpark.eip.core.failure.BaseFailureHandler.java

public static void addFailureMessages(final InputStream is) {
    FailureMessageListType failuresMessageList;
    if (messages.size() == 0) {
        addBaseMessages();//from   w  w  w  .j  a  v  a  2s  . c o  m
    }
    if (is != null) {
        try {
            failuresMessageList = (FailureMessageListType) MARSHALLER.getValue(is,
                    FailureMessageListType.class);
            addFailureMessageList(failuresMessageList);
        } catch (JAXBException e) {
            e.printStackTrace();
        }
    }
}

From source file:main.java.refinement_class.Useful.java

public static boolean validation(String schema_file, String xml_file) {
    Object obj = null;/*from  ww w.  ja v  a  2  s. c o m*/

    // create a JAXBContext capable of handling classes generated into
    // JAXBContext jc = JAXBContext.newInstance(ObjectFactory.class );

    JAXBContext jc;
    try {
        jc = JAXBContext.newInstance();

        // create an Unmarshaller
        Unmarshaller u = jc.createUnmarshaller();

        SchemaFactory sf = SchemaFactory.newInstance(W3C_XML_SCHEMA_NS_URI);

        try {

            javax.xml.validation.Schema schema = sf.newSchema(new File(schema_file));

            u.setSchema((javax.xml.validation.Schema) schema);
            u.setEventHandler(new ValidationEventHandler() {
                // allow unmarshalling to continue even if there are errors
                public boolean handleEvent(ValidationEvent ve) {
                    // ignore warnings
                    if (ve.getSeverity() != ValidationEvent.WARNING) {
                        ValidationEventLocator vel = ve.getLocator();
                        System.out.println("Line:Col[" + vel.getLineNumber() + ":" + vel.getColumnNumber()
                                + "]:" + ve.getMessage());
                    }
                    return true;
                }
            });
        } catch (org.xml.sax.SAXException se) {
            System.out.println("Unable to validate due to following error.");
            se.printStackTrace();
            LOG.error(se.toString());
        }

    } catch (JAXBException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        LOG.error(e.toString());
    }

    return true;

}

From source file:main.java.refinement_class.Useful.java

public static Object unmashal(String schema_file, String xml_file, Class c) {
    Object obj = null;//  w  ww .  java2 s  . c o  m
    try {

        // create a JAXBContext capable of handling classes generated into
        // JAXBContext jc = JAXBContext.newInstance(ObjectFactory.class );

        JAXBContext jc = JAXBContext.newInstance(c);

        // create an Unmarshaller
        Unmarshaller u = jc.createUnmarshaller();

        SchemaFactory sf = SchemaFactory.newInstance(W3C_XML_SCHEMA_NS_URI);

        try {

            //                LOG.info("\n\n  XX -->> Schema file: " + schema_file);
            //                LOG.info("\n\n  XX -->> xml_file file: " + xml_file);
            //++
            javax.xml.validation.Schema schema;
            if (schema_file.contains("/tmp/")) {
                schema = sf.newSchema(new File(schema_file));
            } else {
                URL urlSchema = getUrl(H2mserviceImpl.class, schema_file);
                //                    LOG.info("\n\n  XX -->> urlSchema: " + urlSchema.getPath());
                schema = sf.newSchema(urlSchema);
            }
            //--
            //javax.xml.validation.Schema schema =  sf.newSchema(new File(schema_file));
            // ++

            u.setSchema((javax.xml.validation.Schema) schema);
            u.setEventHandler(new ValidationEventHandler() {
                // allow unmarshalling to continue even if there are errors
                public boolean handleEvent(ValidationEvent ve) {
                    // ignore warnings
                    if (ve.getSeverity() != ValidationEvent.WARNING) {
                        ValidationEventLocator vel = ve.getLocator();
                        System.out.println("Line:Col[" + vel.getLineNumber() + ":" + vel.getColumnNumber()
                                + "]:" + ve.getMessage());
                    }
                    return true;
                }
            });
        } catch (org.xml.sax.SAXException se) {
            System.out.println("Unable to validate due to following error.");
            se.printStackTrace();
            LOG.error("===>[1]ERROR Unmashaling \n\n" + se.toString());
            LOG.error(Useful.getStackTrace(se));
        } catch (Exception e) {
            LOG.error("===>[2]ERROR Unmashaling \n\n" + e.toString());
            LOG.error(Useful.getStackTrace(e));
        }

        if (xml_file.contains("/tmp/")) {
            obj = u.unmarshal(new File(xml_file));
        } else {
            URL url_xml_file = getUrl(H2mserviceImpl.class, xml_file);
            LOG.info("\n\n  XX -->> url_xml_file: " + url_xml_file.getPath());
            obj = u.unmarshal(url_xml_file);
        }

        //--
        //obj = u.unmarshal( new File( xml_file));

        //++

        // even though document was determined to be invalid unmarshalling,
        // marshal out result.
        //           System.out.println("");
        //         System.out.println("Still able to marshal invalid document");
        //       javax.xml.bind.Marshaller m = jc.createMarshaller();
        // m.setProperty( Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE );
        //     m.marshal(poe, System.out);
    } catch (UnmarshalException ue) {
        // The JAXB specification does not mandate how the JAXB provider
        // must behave when attempting to unmarshal invalid XML data.
        // those cases, the JAXB provider is allowed to terminate the
        // call to unmarshal with an UnmarshalException.
        System.out.println("Caught UnmarshalException");
        LOG.error("===>[3]ERROR Unmashaling \n\n" + ue.toString());
    } catch (JAXBException je) {
        je.printStackTrace();
        LOG.error("===>[4]ERROR Unmashaling \n\n" + je.toString());
        LOG.error(Useful.getStackTrace(je));
    } catch (Exception e) {
        LOG.error("===>[5]ERROR Unmashaling \n\n" + e.toString());
        LOG.error(Useful.getStackTrace(e));
    }

    if (obj == null) {
        LOG.error("===>[6]ERROR Unmashaling Object NULL");
    }
    return obj;
}

From source file:labr_client.xml.ObjToXML.java

public static void jaxbObjectToXML(KmehrMessage kmehrMessage) {
    try {//from   w w  w.  java  2s.  co m
        JAXBContext context = JAXBContext.newInstance(KmehrMessage.class);
        Marshaller m = context.createMarshaller();
        //for pretty-print XML in JAXB
        m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
        //----------HEADER--------------------------
        kmehrMessage.header.id.setS("ID-KMEHR");
        kmehrMessage.header.id.setSV("1.15");
        kmehrMessage.header.id.setValue("0000000");
        kmehrMessage.header.setDate("20160519");
        kmehrMessage.header.setTime("09:40:31");
        kmehrMessage.header.standard.cd.setS("CD-STANDARD");
        kmehrMessage.header.standard.cd.setSV("1.15");
        kmehrMessage.header.standard.cd.setValue("20150901");
        //----------HEADER-ZENDER-------------------------
        kmehrMessage.header.sender.hcparty.id.setS("ID-HCPARTY");
        kmehrMessage.header.sender.hcparty.id.setSV("1.15");
        kmehrMessage.header.sender.hcparty.id.setValue("000000");
        kmehrMessage.header.sender.hcparty.cd.setS("CD-HCPARTY");
        kmehrMessage.header.sender.hcparty.cd.setSV("1.15");
        kmehrMessage.header.sender.hcparty.cd.setValue("persphysician");
        kmehrMessage.header.sender.hcparty.setFamilyname("Pieters");
        kmehrMessage.header.sender.hcparty.setFirstname("Piet");
        //----------HEADER-ONTVANGER(S)--------------------
        Hcparty receiver = new Hcparty();
        receiver.id.setS("ID-HCPARTY");
        receiver.id.setSV("1.15");
        receiver.id.setValue("000000");
        receiver.cd.setS("CD-HCPARTY");
        receiver.cd.setSV("1.15");
        receiver.cd.setValue("persphysician");
        receiver.setFamilyname("Pieters");
        receiver.setFirstname("Piet");
        kmehrMessage.header.receiver.getHcparty().add(receiver);
        //----------FOLDER-------------------------
        kmehrMessage.folder.id.setS("ID-HCPARTY");
        kmehrMessage.folder.id.setSV("1.15");
        kmehrMessage.folder.patient.setFamilyname("De Mey");
        kmehrMessage.folder.patient.setFirstname("Matthias");
        kmehrMessage.folder.patient.birthdate.setDate("1990/06/07");

        kmehrMessage.setXmlns("http://www.ehealth.fgov.be/standards/kmehr/schema/v1");

        m.marshal(kmehrMessage, new File("C:\\Users\\labbl\\Documents\\testKMEHR.xml"));
    } catch (JAXBException e) {
        e.printStackTrace();
    }
}