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);
}
}
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);
}
}
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);
}
}
Aggregations