Commit ab56c8da authored by Adrien's avatar Adrien Committed by GitHub

fix(Java 11) JAXBException (#1809)

* Weird behavior when throwing a JAXBException from Studio -> looks like
a class loader conflict issue, certainly due to the Java11 migration
* Catching the exception directly fix the issue

[BST-396](https://bonitasoft.atlassian.net/browse/BST-396)
parent 3f13da9a
......@@ -19,7 +19,6 @@ import java.util.List;
import org.bonitasoft.studio.common.repository.RepositoryAccessor;
import org.bonitasoft.studio.la.application.repository.ApplicationRepositoryStore;
import org.bonitasoft.studio.la.application.ui.validator.ApplicationXMLContentValidator;
import org.bonitasoft.studio.la.i18n.Messages;
import org.bonitasoft.studio.la.ui.validator.ImportFileStoreConflictsValidator;
import org.bonitasoft.studio.ui.page.AbstractImportPage;
import org.eclipse.core.databinding.validation.IValidator;
......@@ -35,7 +34,7 @@ public class ImportApplicationPage extends AbstractImportPage {
@Override
protected List<IValidator> getValidators() {
List<IValidator> validators = super.getValidators();
validators.add(new ApplicationXMLContentValidator(Messages.notAnApplicationError));
validators.add(new ApplicationXMLContentValidator());
validators.add(new ImportFileStoreConflictsValidator(
repositoryAccessor.getRepositoryStore(ApplicationRepositoryStore.class)));
return validators;
......
......@@ -23,22 +23,29 @@ import javax.xml.bind.JAXBException;
import org.bonitasoft.engine.business.application.exporter.ApplicationNodeContainerConverter;
import org.bonitasoft.studio.common.repository.RepositoryManager;
import org.bonitasoft.studio.la.application.repository.ApplicationRepositoryStore;
import org.bonitasoft.studio.ui.validator.XMLContentValidator;
import org.bonitasoft.studio.la.i18n.Messages;
import org.eclipse.core.databinding.validation.IValidator;
import org.eclipse.core.databinding.validation.ValidationStatus;
import org.eclipse.core.runtime.IStatus;
import org.xml.sax.SAXException;
public class ApplicationXMLContentValidator extends XMLContentValidator {
public class ApplicationXMLContentValidator implements IValidator<String> {
private ApplicationNodeContainerConverter applicationNodeContainerConverter;
public ApplicationXMLContentValidator(String errorMessage) {
super(errorMessage);
public ApplicationXMLContentValidator() {
this.applicationNodeContainerConverter = RepositoryManager.getInstance()
.getRepositoryStore(ApplicationRepositoryStore.class).getConverter();
}
@Override
protected void validateModel(String value) throws JAXBException, IOException, SAXException {
applicationNodeContainerConverter.unmarshallFromXML(Files.readAllBytes(Paths.get(value)));
public IStatus validate(String value) {
try {
applicationNodeContainerConverter.unmarshallFromXML(Files.readAllBytes(Paths.get(value)));
} catch (JAXBException | IOException | SAXException e) {
return ValidationStatus.error(Messages.notAnApplicationError);
}
return ValidationStatus.ok();
}
}
/*******************************************************************************
* Copyright (C) 2017 BonitaSoft S.A.
* BonitaSoft is a trademark of BonitaSoft SA.
* This software file is BONITASOFT CONFIDENTIAL. Not For Distribution.
* For commercial licensing information, contact:
* BonitaSoft, 32 rue Gustave Eiffel 38000 Grenoble
* or BonitaSoft US, 51 Federal Street, Suite 305, San Francisco, CA 94107
*******************************************************************************/
package org.bonitasoft.studio.ui.validator;
import java.io.IOException;
import javax.xml.bind.JAXBException;
import org.eclipse.core.databinding.validation.IValidator;
import org.eclipse.core.databinding.validation.ValidationStatus;
import org.eclipse.core.runtime.IStatus;
import org.xml.sax.SAXException;
public abstract class XMLContentValidator implements IValidator {
private String errorMessage;
public XMLContentValidator(String errorMessage) {
this.errorMessage = errorMessage;
}
@Override
public IStatus validate(Object value) {
try {
validateModel((String) value);
} catch (JAXBException | IOException | SAXException e) {
return ValidationStatus.error(errorMessage);
}
return ValidationStatus.ok();
}
protected abstract void validateModel(String value) throws JAXBException, IOException, SAXException;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment