Example usage for javax.xml.bind JAXBException getMessage

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

Introduction

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

Prototype

public String getMessage() 

Source Link

Document

Returns the detail message string of this throwable.

Usage

From source file:$.JaxbMapper.java

protected static JAXBContext getJaxbContext(Class clazz) {
        Assert.notNull(clazz, "'clazz' must not be null");
        JAXBContext jaxbContext = jaxbContexts.get(clazz);
        if (jaxbContext == null) {
            try {
                jaxbContext = JAXBContext.newInstance(clazz, CollectionWrapper.class);
                jaxbContexts.putIfAbsent(clazz, jaxbContext);
            } catch (JAXBException ex) {
                throw new RuntimeException(
                        "Could not instantiate JAXBContext for class [" + clazz + "]: " + ex.getMessage(), ex);
            }//ww  w. ja  v a  2  s  . c o m
        }
        return jaxbContext;
    }

From source file:com.cws.esolutions.core.listeners.CoreServiceInitializer.java

/**
 * Initializes the core 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 a2 s  .  c o  m*/
 *
 * @param configFile - The service configuration file to utilize
 * @param logConfig - The logging configuration file to utilize
 * @param loadSecurity - Flag to start security
 * @param startConnections - Flag to start connections
 * @throws CoreServiceException @{link com.cws.esolutions.core.exception.CoreServiceException}
 * if an exception occurs during initialization
 */
public static void initializeService(final String configFile, final String logConfig,
        final boolean loadSecurity, final boolean startConnections) throws CoreServiceException {
    URL xmlURL = null;
    JAXBContext context = null;
    Unmarshaller marshaller = null;
    SecurityConfig secConfig = null;
    CoreConfigurationData configData = null;
    SecurityConfigurationData secConfigData = null;

    if (loadSecurity) {
        secConfigData = SecurityServiceBean.getInstance().getConfigData();
        secConfig = secConfigData.getSecurityConfig();
    }

    final String serviceConfig = (StringUtils.isBlank(configFile)) ? System.getProperty("coreConfigFile")
            : configFile;
    final String loggingConfig = (StringUtils.isBlank(logConfig)) ? System.getProperty("coreLogConfig")
            : 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 = CoreServiceInitializer.class.getClassLoader().getResource(serviceConfig);

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

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

        CoreServiceInitializer.appBean.setConfigData(configData);

        if (startConnections) {
            Map<String, DataSource> dsMap = CoreServiceInitializer.appBean.getDataSources();

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

            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.getSalt(),
                            secConfig.getSecretAlgorithm(), secConfig.getIterations(), secConfig.getKeyBits(),
                            secConfig.getEncryptionAlgorithm(), secConfig.getEncryptionInstance(),
                            configData.getAppConfig().getEncoding()));
                    if (DEBUG) {
                        DEBUGGER.debug("BasicDataSource: {}", dataSource);
                    }

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

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

            CoreServiceInitializer.appBean.setDataSources(dsMap);
        }
    } catch (JAXBException jx) {
        jx.printStackTrace();
        throw new CoreServiceException(jx.getMessage(), jx);
    } catch (MalformedURLException mux) {
        mux.printStackTrace();
        throw new CoreServiceException(mux.getMessage(), mux);
    }
}

From source file:com.aionemu.gameserver.model.TribeRelationCheck.java

@BeforeClass
public static void init() throws Exception {
    File xml = new File("./data/static_data/tribe/tribe_relations.xml");
    Schema schema = null;//from   www. j  av a2s.c o m
    SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
    TribeRelationsData tribeRelations = null;
    NpcData npcTemplates = null;

    try {
        schema = sf.newSchema(new File("./data/static_data/tribe/tribe_relations.xsd"));
        JAXBContext jc = JAXBContext.newInstance(TribeRelationsData.class);
        Unmarshaller unmarshaller = jc.createUnmarshaller();
        unmarshaller.setSchema(schema);
        tribeRelations = (TribeRelationsData) unmarshaller.unmarshal(xml);

        xml = new File("./data/static_data/npcs/npc_templates.xml");
        schema = sf.newSchema(new File("./data/static_data/npcs/npcs.xsd"));
        jc = JAXBContext.newInstance(NpcData.class);
        unmarshaller = jc.createUnmarshaller();
        unmarshaller.setSchema(schema);
        npcTemplates = (NpcData) unmarshaller.unmarshal(xml);
    } catch (SAXException e1) {
        System.out.println(e1.getMessage());
    } catch (JAXBException e2) {
        System.out.println(e2.getMessage());
    }

    // Not interesting
    DataManager.NPC_SKILL_DATA = new NpcSkillData();
    DataManager.NPC_DATA = npcTemplates;
    DataManager.TRIBE_RELATIONS_DATA = tribeRelations;
    DataManager.ZONE_DATA = new DummyZoneData();
    DataManager.WORLD_MAPS_DATA = new DummyWorldMapData();

    Config.load();
    // AIConfig.ONCREATE_DEBUG = true;
    AIConfig.EVENT_DEBUG = true;
    ThreadConfig.THREAD_POOL_SIZE = 20;
    ThreadPoolManager.getInstance();

    AI2Engine.getInstance().load(null);

    /**
     * Comment out these lines in DAOManager.registerDAO() if not using DB: <tt> 
     * if (!dao.supports(getDatabaseName(),
     *       getDatabaseMajorVersion(), getDatabaseMinorVersion())) { return; } 
     * </tt>
     */
    DAOManager.init();

    world = World.getInstance();
    asmo = DummyPlayer.createAsmodian();
    asmoPosition = World.getInstance().createPosition(DummyWorldMapData.DEFAULT_MAP, 100f, 100f, 0f, (byte) 0,
            0);

    MapRegion asmoRegion = asmoPosition.getWorldMapInstance().getRegion(100f, 100f, 0);
    asmoRegion.getObjects().put(asmo.getObjectId(), asmo);
    asmoRegion.activate();
    asmo.setPosition(asmoPosition);

    ely = DummyPlayer.createElyo();
    elyPosition = World.getInstance().createPosition(DummyWorldMapData.DEFAULT_MAP, 200f, 200f, 0f, (byte) 0,
            0);
    MapRegion elyRegion = elyPosition.getWorldMapInstance().getRegion(200f, 200f, 0);
    elyRegion.getObjects().put(ely.getObjectId(), ely);
    elyRegion.activate();
    ely.setPosition(elyPosition);

    PacketBroadcaster.getInstance();
    DuelService.getInstance();
    PlayerMoveTaskManager.getInstance();
    MoveTaskManager.getInstance();
}

From source file:com.faceye.feature.util.JaxbMapper.java

protected static JAXBContext getJaxbContext(Class clazz) {
    Validate.notNull(clazz, "'clazz' must not be null");
    JAXBContext jaxbContext = jaxbContexts.get(clazz);
    if (jaxbContext == null) {
        try {//from   www.j a  v a 2 s  .  co  m
            jaxbContext = JAXBContext.newInstance(clazz, CollectionWrapper.class);
            //            jaxbContext = JAXBContext.newInstance(clazz, clazz);
            jaxbContexts.putIfAbsent(clazz, jaxbContext);
        } catch (JAXBException ex) {
            logger.error(">>FaceYe form xml 2 class exception:", ex);
            throw new RuntimeException(
                    "Could not instantiate JAXBContext for class [" + clazz + "]: " + ex.getMessage(), ex);
        }
    }
    return jaxbContext;
}

From source file:it.geosolutions.geostore.init.GeoStoreInit.java

private static JAXBContext getUserContext() {

    List<Class> allClasses = GeoStoreJAXBContext.getGeoStoreClasses();
    allClasses.add(InitUserList.class);

    if (LOGGER.isDebugEnabled())
        LOGGER.debug("Initializing JAXBContext with " + allClasses.size() + " classes " + allClasses);

    try {//  w  w  w  . j  a v  a2  s . co  m
        return JAXBContext.newInstance(allClasses.toArray(new Class[allClasses.size()]));
    } catch (JAXBException ex) {
        LOGGER.error("Can't create GeoStore context: " + ex.getMessage(), ex);
        return null;
    }
}

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  www .ja  va  2 s.c  o m*/
 *
 * @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:com.comcast.cats.service.util.HttpClientUtil.java

public static synchronized byte[] getPayload(Object domain, boolean prettyPrint) {
    byte[] payload = null;

    String xml = null;/*w  ww  .ja  va2  s . c om*/

    StringWriter writer = new StringWriter();

    try {
        JAXBContext context = JAXBContext.newInstance(domain.getClass());

        Marshaller marshaller = context.createMarshaller();

        if (prettyPrint) {
            marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
        }

        marshaller.marshal(domain, writer);
        xml = writer.toString();
    } catch (JAXBException e) {
        logger.error("[ JAXBException   ] " + e.getMessage());
    }

    logger.trace("[ PAYLOAD  ] " + xml);

    if (null != xml) {
        payload = xml.getBytes();
    }

    return payload;
}

From source file:be.fedict.eid.dss.ws.DSSUtil.java

public static Element getStorageInfoElement(StorageInfo storageInfo) {

    Document newDocument = documentBuilder.newDocument();
    Element newElement = newDocument.createElement("newNode");
    try {//from  w  ww . j  a  v  a2 s . co  m
        artifactMarshaller.marshal(artifactObjectFactory.createStorageInfo(storageInfo), newElement);
    } catch (JAXBException e) {
        throw new RuntimeException("JAXB error: " + e.getMessage(), e);
    }
    return (Element) newElement.getFirstChild();
}

From source file:eu.squadd.reflections.mapper.ServiceModelTranslator.java

public static Object unmarshallFromString(Class destClass, String xmlStr) {
    try {// w  w w .  ja  va  2 s. c o  m
        JAXBContext jaxbContext = JAXBContext.newInstance(destClass);
        Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
        StringReader reader = new StringReader(xmlStr);
        return unmarshaller.unmarshal(reader);
    } catch (JAXBException ex) {
        System.err.println(ex.getMessage());
        return null;
    }
}

From source file:eu.squadd.reflections.mapper.ServiceModelTranslator.java

public static String marshallToString(Class sourceClass, Object source) {
    try {//from w w  w.  ja v  a  2  s.  c o m
        JAXBContext jaxbContext = JAXBContext.newInstance(sourceClass);
        Marshaller marshaller = jaxbContext.createMarshaller();
        marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
        StringWriter sw = new StringWriter();
        marshaller.marshal(source, sw);
        return sw.toString();
    } catch (JAXBException ex) {
        System.err.println(ex.getMessage());
        return null;
    }
}