Java Code Examples for javax.xml.bind.JAXBException#getMessage()

The following examples show how to use javax.xml.bind.JAXBException#getMessage() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AbstractWeixinmpController.java    From weixinmp4java with Apache License 2.0 6 votes vote down vote up
/**
 * 从帮助信息中返回指定标题的帮助信息<br>
 * 请参考“weixinmp_helps.xml”文件格式创建一个自己的描述文件
 * @author [email protected], https://github.com/caijianqing/weixinmp4java/, 2013-10-21 下午2:48:30
 * @param title
 *            帮助信息标题,位于“weixinmp_helps.xml”文件中的help节点
 * @return 如果没有则返回null
 */
public String findHelp(String title) {
    Helps helps;
    String help = null;
    try {
        helps = loadHelps();
        if (helps != null) {
            Help h = helps.findHelp(title);
            if (h != null) {
                help = h.getContent();
            }
        }
    } catch (JAXBException e) {
        throw new RuntimeException(e.getMessage(), e);
    }
    if (help == null) {
        logWarn("无效帮助信息条目:" + title);
        return title;
    } else {
        logDebug("查找帮助信息:" + title + "=" + help);
        return help;
    }
}
 
Example 2
Source File: JAXBBridgeSource.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
public void parse() throws SAXException {
    // parses a content object by using the given bridge
    // SAX events will be sent to the repeater, and the repeater
    // will further forward it to an appropriate component.
    try {
        startDocument();
        // this method only writes a fragment, so need start/end document
        bridge.marshal( contentObject, this, null );
        endDocument();
    } catch( JAXBException e ) {
        // wrap it to a SAXException
        SAXParseException se =
            new SAXParseException( e.getMessage(),
                null, null, -1, -1, e );

        // if the consumer sets an error handler, it is our responsibility
        // to notify it.
        fatalError(se);

        // this is a fatal error. Even if the error handler
        // returns, we will abort anyway.
        throw se;
    }
}
 
Example 3
Source File: JAXBSource.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
public void parse() throws SAXException {
    // parses a content object by using the given marshaller
    // SAX events will be sent to the repeater, and the repeater
    // will further forward it to an appropriate component.
    try {
        marshaller.marshal( contentObject, (XMLFilterImpl)repeater );
    } catch( JAXBException e ) {
        // wrap it to a SAXException
        SAXParseException se =
            new SAXParseException( e.getMessage(),
                null, null, -1, -1, e );

        // if the consumer sets an error handler, it is our responsibility
        // to notify it.
        if(errorHandler!=null)
            errorHandler.fatalError(se);

        // this is a fatal error. Even if the error handler
        // returns, we will abort anyway.
        throw se;
    }
}
 
Example 4
Source File: JAXBSource.java    From jdk1.8-source-analysis with Apache License 2.0 6 votes vote down vote up
public void parse() throws SAXException {
    // parses a content object by using the given marshaller
    // SAX events will be sent to the repeater, and the repeater
    // will further forward it to an appropriate component.
    try {
        marshaller.marshal( contentObject, (XMLFilterImpl)repeater );
    } catch( JAXBException e ) {
        // wrap it to a SAXException
        SAXParseException se =
            new SAXParseException( e.getMessage(),
                null, null, -1, -1, e );

        // if the consumer sets an error handler, it is our responsibility
        // to notify it.
        if(errorHandler!=null)
            errorHandler.fatalError(se);

        // this is a fatal error. Even if the error handler
        // returns, we will abort anyway.
        throw se;
    }
}
 
Example 5
Source File: AbstractWorkflow.java    From carbon-identity with Apache License 2.0 6 votes vote down vote up
/**
 *
 *
 * @param metaDataXML Parameter Metadata XML string
 * @throws WorkflowRuntimeException
 */
public AbstractWorkflow(Class<? extends TemplateInitializer> templateInitializerClass, Class<? extends WorkFlowExecutor> workFlowExecutorClass, String metaDataXML) throws WorkflowRuntimeException {
    try {

        this.templateInitializerClass = templateInitializerClass ;
        this.workFlowExecutorClass = workFlowExecutorClass ;

        this.metaData = WorkflowManagementUtil.unmarshalXML(metaDataXML, MetaData.class);
        if(this.metaData == null || this.metaData.getWorkflowImpl() == null ){
            throw new WorkflowRuntimeException("Error occurred while Loading WorkflowImpl Meta Data");
        }
        this.parametersMetaData = this.metaData.getWorkflowImpl().getParametersMetaData();
    } catch (JAXBException e) {
        String errorMsg = "Error occurred while converting workflow parameter data to object : " + e.getMessage();
        log.error(errorMsg);
        throw new WorkflowRuntimeException(errorMsg, e);
    }
}
 
Example 6
Source File: JAXBBridgeSource.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
public void parse() throws SAXException {
    // parses a content object by using the given bridge
    // SAX events will be sent to the repeater, and the repeater
    // will further forward it to an appropriate component.
    try {
        startDocument();
        // this method only writes a fragment, so need start/end document
        bridge.marshal( contentObject, this, null );
        endDocument();
    } catch( JAXBException e ) {
        // wrap it to a SAXException
        SAXParseException se =
            new SAXParseException( e.getMessage(),
                null, null, -1, -1, e );

        // if the consumer sets an error handler, it is our responsibility
        // to notify it.
        fatalError(se);

        // this is a fatal error. Even if the error handler
        // returns, we will abort anyway.
        throw se;
    }
}
 
Example 7
Source File: CcuClient.java    From openhab1-addons with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Load predefined scripts from an XML file.
 */
private Map<String, String> loadTclRegaScripts() throws HomematicClientException {
    try {
        Unmarshaller um = JAXBContext.newInstance(TclScripts.class).createUnmarshaller();
        InputStream stream = Thread.currentThread().getContextClassLoader()
                .getResourceAsStream("homematic/tclrega-scripts.xml");
        TclScripts scripts = (TclScripts) um.unmarshal(stream);

        Map<String, String> result = new HashMap<String, String>();
        for (TclScript script : scripts.getScripts()) {
            result.put(script.getName(), script.getData());
        }
        return result;
    } catch (JAXBException ex) {
        throw new HomematicClientException(ex.getMessage(), ex);
    }
}
 
Example 8
Source File: ExampleXmlGenerator.java    From herd with Apache License 2.0 6 votes vote down vote up
/**
 * Gets an example XML body for the specified class.
 *
 * @param clazz the class.
 *
 * @throws MojoExecutionException if any problems were encountered.
 */
private void generateExampleXml(Class<?> clazz) throws MojoExecutionException
{
    Object finalInstance = processClass(clazz);
    try
    {
        if (finalInstance == null)
        {
            exampleXml = "";
            log.info("Can't produce XML for a null element for class \"" + clazz + "\" so using the empty string.");
        }
        else
        {
            // Convert the instance to XML and remove the extra \r characters which causes problems when viewing in the Swagger UI
            exampleXml = objectToXml(finalInstance).replaceAll("\r", "");
        }
    }
    catch (JAXBException e)
    {
        throw new MojoExecutionException("Unable to serialize XML for class \"" + clazz.getName() + "\". Reason: " + e.getMessage(), e);
    }
}
 
Example 9
Source File: AbstractJaxb2HttpMessageConverter.java    From java-technology-stack with MIT License 6 votes vote down vote up
/**
 * Return a {@link JAXBContext} for the given class.
 * @param clazz the class to return the context for
 * @return the {@code JAXBContext}
 * @throws HttpMessageConversionException in case of JAXB errors
 */
protected final JAXBContext getJaxbContext(Class<?> clazz) {
	Assert.notNull(clazz, "Class must not be null");
	JAXBContext jaxbContext = this.jaxbContexts.get(clazz);
	if (jaxbContext == null) {
		try {
			jaxbContext = JAXBContext.newInstance(clazz);
			this.jaxbContexts.putIfAbsent(clazz, jaxbContext);
		}
		catch (JAXBException ex) {
			throw new HttpMessageConversionException(
					"Could not instantiate JAXBContext for class [" + clazz + "]: " + ex.getMessage(), ex);
		}
	}
	return jaxbContext;
}
 
Example 10
Source File: SlaInfo.java    From SeaCloudsPlatform with Apache License 2.0 6 votes vote down vote up
public SlaInfo build(String dam) {
    
    /*
     * Using snakeyaml for the moment. Change to use A4C tosca parser if need to read the topology. 
     */
    try {
        
        Yaml yaml = new Yaml();
        @SuppressWarnings("rawtypes")
        Map doc = (Map) yaml.load(new StringReader(dam));

        Map<String, MonitoringRules> monitoringRules = rulesExtractor.extract(doc);

        return buildImpl(doc, monitoringRules);
    } catch (JAXBException e) {
        
        throw new SlaGeneratorException(e.getMessage(), e);
    }
}
 
Example 11
Source File: JAXBSerializer.java    From nifi-registry with Apache License 2.0 5 votes vote down vote up
/**
 * Load the JAXBContext.
 */
public JAXBSerializer(final Class<T> clazz) {
    try {
        this.jaxbContext = JAXBContext.newInstance(clazz);
    } catch (JAXBException e) {
        throw new RuntimeException("Unable to create JAXBContext: " + e.getMessage(), e);
    }
}
 
Example 12
Source File: JAXBHeader.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
public void writeTo(ContentHandler contentHandler, ErrorHandler errorHandler) throws SAXException {
    try {
        bridge.marshal(jaxbObject,contentHandler,null);
    } catch (JAXBException e) {
        SAXParseException x = new SAXParseException(e.getMessage(),null,null,-1,-1,e);
        errorHandler.fatalError(x);
        throw x;
    }
}
 
Example 13
Source File: AbstractJaxb2HttpMessageConverter.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Create a new {@link Marshaller} for the given class.
 * @param clazz the class to create the marshaller for
 * @return the {@code Marshaller}
 * @throws HttpMessageConversionException in case of JAXB errors
 */
protected final Marshaller createMarshaller(Class<?> clazz) {
	try {
		JAXBContext jaxbContext = getJaxbContext(clazz);
		Marshaller marshaller = jaxbContext.createMarshaller();
		customizeMarshaller(marshaller);
		return marshaller;
	}
	catch (JAXBException ex) {
		throw new HttpMessageConversionException(
				"Could not create Marshaller for class [" + clazz + "]: " + ex.getMessage(), ex);
	}
}
 
Example 14
Source File: RDBMSDSXMLConfiguration.java    From carbon-commons with Apache License 2.0 5 votes vote down vote up
public RDBMSDSXMLConfiguration() throws NDataSourceAdminDataSourceException {
	JAXBContext ctx;
	try {
		ctx = JAXBContext.newInstance(RDBMSDSXMLConfiguration.class);
		rdbmsMarshaller = ctx.createMarshaller();
	} catch (JAXBException e) {
		throw new NDataSourceAdminDataSourceException ("Error creating rdbms data source configuration info marshaller: "+ e.getMessage(), e);
	}
}
 
Example 15
Source File: AbstractJaxb2HttpMessageConverter.java    From java-technology-stack with MIT License 5 votes vote down vote up
/**
 * Create a new {@link Marshaller} for the given class.
 * @param clazz the class to create the marshaller for
 * @return the {@code Marshaller}
 * @throws HttpMessageConversionException in case of JAXB errors
 */
protected final Marshaller createMarshaller(Class<?> clazz) {
	try {
		JAXBContext jaxbContext = getJaxbContext(clazz);
		Marshaller marshaller = jaxbContext.createMarshaller();
		customizeMarshaller(marshaller);
		return marshaller;
	}
	catch (JAXBException ex) {
		throw new HttpMessageConversionException(
				"Could not create Marshaller for class [" + clazz + "]: " + ex.getMessage(), ex);
	}
}
 
Example 16
Source File: JAXBHeader.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public void writeTo(ContentHandler contentHandler, ErrorHandler errorHandler) throws SAXException {
    try {
        bridge.marshal(jaxbObject,contentHandler,null);
    } catch (JAXBException e) {
        SAXParseException x = new SAXParseException(e.getMessage(),null,null,-1,-1,e);
        errorHandler.fatalError(x);
        throw x;
    }
}
 
Example 17
Source File: XmlExtensionNotificationDataExtractor.java    From JVoiceXML with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public RecognitionResult getRecognitionResult(final Mmi mmi,
        final ExtensionNotification ext) throws ConversionException {
    JAXBContext context;
    try {
        context = JAXBContext.newInstance(Mmi.class);
        Marshaller marshaller = context.createMarshaller();
        final EmmaSemanticInterpretationExtractor extractor = new EmmaSemanticInterpretationExtractor();
        marshaller.marshal(mmi, extractor);
        return extractor.getRecognitonResult();
    } catch (JAXBException e) {
        throw new ConversionException(e.getMessage(), e);
    }
}
 
Example 18
Source File: SlaInfo.java    From SeaCloudsPlatform with Apache License 2.0 4 votes vote down vote up
public SlaInfo build(String dam, String rulesString) {
    
    try {
        
        Yaml yaml = new Yaml();
        @SuppressWarnings("rawtypes")
        Map doc = (Map) yaml.load(new StringReader(dam));

        Map<String, MonitoringRules> monitoringRules = rulesExtractor.fromSerializedRules(rulesString);
        
        return buildImpl(doc, monitoringRules);
    } catch (JAXBException e) {
        
        throw new SlaGeneratorException(e.getMessage(), e);
    }
}
 
Example 19
Source File: PrestacaoDesacordo.java    From Java_CTe with MIT License 4 votes vote down vote up
static TRetEvento eventoPrestacaoDesacordo(ConfiguracoesCte config, TEvento enviEvento, boolean valida) throws CteException {

        try {

            String xml = XmlCteUtil.objectToXml(enviEvento);
            xml = xml.replaceAll(" xmlns:ns2=\"http://www.w3.org/2000/09/xmldsig#\"", "");
            xml = xml.replaceAll("<evento v", "<evento xmlns=\"http://www.portalfiscal.inf.br/cte\" v");

            xml = Eventos.enviarEvento(config, xml, ServicosEnum.PRESTACAO_DESACORDO, valida);

            return XmlCteUtil.xmlToObject(xml, TRetEvento.class);

        } catch (JAXBException e) {
            throw new CteException(e.getMessage());
        }

    }
 
Example 20
Source File: CartaCorrecao.java    From Java_CTe with MIT License 4 votes vote down vote up
static TRetEvento eventoCCe(ConfiguracoesCte config, TEvento enviEvento, boolean valida)
        throws CteException {

    try {

        String xml = XmlCteUtil.objectToXml(enviEvento);
        xml = xml.replaceAll(" xmlns:ns2=\"http://www.w3.org/2000/09/xmldsig#\"", "");
        xml = xml.replaceAll("<evento v", "<evento xmlns=\"http://www.portalfiscal.inf.br/cte\" v");

        xml = Eventos.enviarEvento(config, xml, ServicosEnum.CCE, valida);

        return XmlCteUtil.xmlToObject(xml, TRetEvento.class);

    } catch (JAXBException e) {
        throw new CteException(e.getMessage());
    }

}