Search in sources :

Example 1 with MarshallingException

use of org.kie.server.api.marshalling.MarshallingException in project droolsjbpm-integration by kiegroup.

the class JSONUnmarshallingTest method testWrongCNFEBehaviorValue.

@Test
public void testWrongCNFEBehaviorValue() {
    try {
        System.setProperty(KieServerConstants.JSON_CUSTOM_OBJECT_DESERIALIZER_CNFE_BEHAVIOR, "XXX");
        MarshallingException exception = assertThrows(MarshallingException.class, () -> unmarshalNonExistingClass());
        assertThat(exception.getMessage()).contains(Arrays.asList("IGNORE", "WARN", "EXCEPTION"));
    } finally {
        System.clearProperty(KieServerConstants.JSON_CUSTOM_OBJECT_DESERIALIZER_CNFE_BEHAVIOR);
    }
}
Also used : MarshallingException(org.kie.server.api.marshalling.MarshallingException) Test(org.junit.Test)

Example 2 with MarshallingException

use of org.kie.server.api.marshalling.MarshallingException in project droolsjbpm-integration by kiegroup.

the class JaxbMarshaller method unmarshall.

@Override
public <T> T unmarshall(String input, Class<T> type) {
    try {
        Unmarshaller unmarshaller = getUnmarshaller();
        ValidationEventCollector vec = new ValidationEventCollector();
        boolean strict = Boolean.getBoolean(KIE_SERVER_STRICT_JAXB_FORMAT);
        unmarshaller.setEventHandler(vec);
        Object result = unmarshaller.unmarshal(new StringReader(input));
        if (strict || logger.isWarnEnabled()) {
            String errorMessage = Arrays.stream(vec.getEvents()).filter(ve -> ve.getSeverity() == ERROR || ve.getSeverity() == FATAL_ERROR).map(ValidationEvent::getMessage).collect(Collectors.joining("\n"));
            if (!errorMessage.isEmpty()) {
                logger.warn(errorMessage);
                if (strict) {
                    throw new MarshallingException(errorMessage);
                }
            }
        }
        return (T) unwrap(result);
    } catch (JAXBException e) {
        throw new MarshallingException("Can't unmarshall input string: " + input, e);
    }
}
Also used : MarshallingException(org.kie.server.api.marshalling.MarshallingException) KIE_SERVER_STRICT_JAXB_FORMAT(org.kie.server.api.KieServerConstants.KIE_SERVER_STRICT_JAXB_FORMAT) JAXBException(javax.xml.bind.JAXBException) StringReader(java.io.StringReader) Unmarshaller(javax.xml.bind.Unmarshaller) ValidationEventCollector(javax.xml.bind.util.ValidationEventCollector)

Example 3 with MarshallingException

use of org.kie.server.api.marshalling.MarshallingException in project droolsjbpm-integration by kiegroup.

the class JaxbMarshaller method buildMarshaller.

protected void buildMarshaller(Set<Class<?>> classes, final ClassLoader classLoader) {
    try {
        logger.debug("Additional classes for JAXB context are {}", classes);
        Set<Class<?>> allClasses = new HashSet<Class<?>>();
        allClasses.addAll(Arrays.asList(KIE_SERVER_JAXB_CLASSES));
        if (classes != null) {
            allClasses.addAll(classes);
        }
        logger.debug("All classes for JAXB context are {}", allClasses);
        this.jaxbContext = JAXBContext.newInstance(allClasses.toArray(new Class[allClasses.size()]));
    } catch (JAXBException e) {
        logger.error("Error while creating JAXB Marshaller due to {}", e.getMessage(), e);
        throw new MarshallingException("Error while creating JAXB context from default classes! " + e.getMessage(), e);
    }
}
Also used : MarshallingException(org.kie.server.api.marshalling.MarshallingException) JAXBException(javax.xml.bind.JAXBException) HashSet(java.util.HashSet)

Aggregations

MarshallingException (org.kie.server.api.marshalling.MarshallingException)3 JAXBException (javax.xml.bind.JAXBException)2 StringReader (java.io.StringReader)1 HashSet (java.util.HashSet)1 Unmarshaller (javax.xml.bind.Unmarshaller)1 ValidationEventCollector (javax.xml.bind.util.ValidationEventCollector)1 Test (org.junit.Test)1 KIE_SERVER_STRICT_JAXB_FORMAT (org.kie.server.api.KieServerConstants.KIE_SERVER_STRICT_JAXB_FORMAT)1