Search in sources :

Example 6 with XMLException

use of org.activiti.bpmn.exceptions.XMLException in project Activiti by Activiti.

the class MapExceptionConverterTest method testMapExceptionWithInvalidHasChildren.

@Test
public void testMapExceptionWithInvalidHasChildren() throws Exception {
    resourceName = "mapException/mapExceptionInvalidHasChildrenModel.bpmn";
    try {
        BpmnModel bpmnModel = readXMLFile();
        fail("No exception is thrown for mapExecution with invalid boolean for hasChildren");
    } catch (XMLException x) {
        assertTrue(x.getMessage().indexOf("is not valid boolean") != -1);
    } catch (Exception e) {
        fail("wrong exception thrown. XmlException expected, " + e.getClass() + " thrown");
    }
}
Also used : XMLException(org.activiti.bpmn.exceptions.XMLException) XMLException(org.activiti.bpmn.exceptions.XMLException) BpmnModel(org.activiti.bpmn.model.BpmnModel) Test(org.junit.Test)

Example 7 with XMLException

use of org.activiti.bpmn.exceptions.XMLException in project Activiti by Activiti.

the class MapExceptionConverterTest method testMapExceptionWithNoErrorCode.

@Test
public void testMapExceptionWithNoErrorCode() throws Exception {
    resourceName = "mapException/mapExceptionNoErrorCode.bpmn";
    try {
        BpmnModel bpmnModel = readXMLFile();
        fail("No exception is thrown for mapExecution with no Error Code");
    } catch (XMLException x) {
        assertTrue(x.getMessage().indexOf("No errorCode defined") != -1);
    } catch (Exception e) {
        fail("wrong exception thrown. XmlException expected, " + e.getClass() + " thrown");
    }
}
Also used : XMLException(org.activiti.bpmn.exceptions.XMLException) XMLException(org.activiti.bpmn.exceptions.XMLException) BpmnModel(org.activiti.bpmn.model.BpmnModel) Test(org.junit.Test)

Example 8 with XMLException

use of org.activiti.bpmn.exceptions.XMLException in project Activiti by Activiti.

the class BpmnXMLConverter method createXML.

private void createXML(FlowElement flowElement, BpmnModel model, XMLStreamWriter xtw) throws Exception {
    if (flowElement instanceof SubProcess) {
        SubProcess subProcess = (SubProcess) flowElement;
        if (flowElement instanceof Transaction) {
            xtw.writeStartElement(ELEMENT_TRANSACTION);
        } else {
            xtw.writeStartElement(ELEMENT_SUBPROCESS);
        }
        xtw.writeAttribute(ATTRIBUTE_ID, subProcess.getId());
        if (StringUtils.isNotEmpty(subProcess.getName())) {
            xtw.writeAttribute(ATTRIBUTE_NAME, subProcess.getName());
        } else {
            xtw.writeAttribute(ATTRIBUTE_NAME, "subProcess");
        }
        if (subProcess instanceof EventSubProcess) {
            xtw.writeAttribute(ATTRIBUTE_TRIGGERED_BY, ATTRIBUTE_VALUE_TRUE);
        } else if (subProcess instanceof Transaction == false) {
            if (subProcess.isAsynchronous()) {
                BpmnXMLUtil.writeQualifiedAttribute(ATTRIBUTE_ACTIVITY_ASYNCHRONOUS, ATTRIBUTE_VALUE_TRUE, xtw);
                if (subProcess.isNotExclusive()) {
                    BpmnXMLUtil.writeQualifiedAttribute(ATTRIBUTE_ACTIVITY_EXCLUSIVE, ATTRIBUTE_VALUE_FALSE, xtw);
                }
            }
        }
        if (StringUtils.isNotEmpty(subProcess.getDocumentation())) {
            xtw.writeStartElement(ELEMENT_DOCUMENTATION);
            xtw.writeCharacters(subProcess.getDocumentation());
            xtw.writeEndElement();
        }
        boolean didWriteExtensionStartElement = ActivitiListenerExport.writeListeners(subProcess, false, xtw);
        didWriteExtensionStartElement = BpmnXMLUtil.writeExtensionElements(subProcess, didWriteExtensionStartElement, model.getNamespaces(), xtw);
        if (didWriteExtensionStartElement) {
            // closing extensions element
            xtw.writeEndElement();
        }
        MultiInstanceExport.writeMultiInstance(subProcess, xtw);
        for (FlowElement subElement : subProcess.getFlowElements()) {
            createXML(subElement, model, xtw);
        }
        for (Artifact artifact : subProcess.getArtifacts()) {
            createXML(artifact, model, xtw);
        }
        xtw.writeEndElement();
    } else {
        BaseBpmnXMLConverter converter = convertersToXMLMap.get(flowElement.getClass());
        if (converter == null) {
            throw new XMLException("No converter for " + flowElement.getClass() + " found");
        }
        converter.convertToXML(xtw, flowElement, model);
    }
}
Also used : EventSubProcess(org.activiti.bpmn.model.EventSubProcess) SubProcess(org.activiti.bpmn.model.SubProcess) XMLException(org.activiti.bpmn.exceptions.XMLException) Transaction(org.activiti.bpmn.model.Transaction) FlowElement(org.activiti.bpmn.model.FlowElement) EventSubProcess(org.activiti.bpmn.model.EventSubProcess) Artifact(org.activiti.bpmn.model.Artifact)

Example 9 with XMLException

use of org.activiti.bpmn.exceptions.XMLException in project Activiti by Activiti.

the class BpmnXMLConverter method convertToBpmnModel.

public BpmnModel convertToBpmnModel(InputStreamProvider inputStreamProvider, boolean validateSchema, boolean enableSafeBpmnXml, String encoding) {
    XMLInputFactory xif = XMLInputFactory.newInstance();
    if (xif.isPropertySupported(XMLInputFactory.IS_REPLACING_ENTITY_REFERENCES)) {
        xif.setProperty(XMLInputFactory.IS_REPLACING_ENTITY_REFERENCES, false);
    }
    if (xif.isPropertySupported(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES)) {
        xif.setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, false);
    }
    if (xif.isPropertySupported(XMLInputFactory.SUPPORT_DTD)) {
        xif.setProperty(XMLInputFactory.SUPPORT_DTD, false);
    }
    InputStreamReader in = null;
    try {
        in = new InputStreamReader(inputStreamProvider.getInputStream(), encoding);
        XMLStreamReader xtr = xif.createXMLStreamReader(in);
        try {
            if (validateSchema) {
                if (!enableSafeBpmnXml) {
                    validateModel(inputStreamProvider);
                } else {
                    validateModel(xtr);
                }
                // The input stream is closed after schema validation
                in = new InputStreamReader(inputStreamProvider.getInputStream(), encoding);
                xtr = xif.createXMLStreamReader(in);
            }
        } catch (Exception e) {
            throw new XMLException(e.getMessage(), e);
        }
        // XML conversion
        return convertToBpmnModel(xtr);
    } catch (UnsupportedEncodingException e) {
        throw new XMLException("The bpmn 2.0 xml is not UTF8 encoded", e);
    } catch (XMLStreamException e) {
        throw new XMLException("Error while reading the BPMN 2.0 XML", e);
    } finally {
        if (in != null) {
            try {
                in.close();
            } catch (IOException e) {
                LOGGER.debug("Problem closing BPMN input stream", e);
            }
        }
    }
}
Also used : XMLException(org.activiti.bpmn.exceptions.XMLException) XMLStreamReader(javax.xml.stream.XMLStreamReader) InputStreamReader(java.io.InputStreamReader) XMLStreamException(javax.xml.stream.XMLStreamException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) IOException(java.io.IOException) XMLInputFactory(javax.xml.stream.XMLInputFactory) XMLStreamException(javax.xml.stream.XMLStreamException) XMLException(org.activiti.bpmn.exceptions.XMLException) SAXException(org.xml.sax.SAXException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) IOException(java.io.IOException)

Aggregations

XMLException (org.activiti.bpmn.exceptions.XMLException)9 IOException (java.io.IOException)3 UnsupportedEncodingException (java.io.UnsupportedEncodingException)3 XMLStreamException (javax.xml.stream.XMLStreamException)3 BpmnModel (org.activiti.bpmn.model.BpmnModel)3 EventSubProcess (org.activiti.bpmn.model.EventSubProcess)3 SubProcess (org.activiti.bpmn.model.SubProcess)3 SAXException (org.xml.sax.SAXException)3 Artifact (org.activiti.bpmn.model.Artifact)2 FlowElement (org.activiti.bpmn.model.FlowElement)2 Process (org.activiti.bpmn.model.Process)2 Test (org.junit.Test)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 InputStreamReader (java.io.InputStreamReader)1 OutputStreamWriter (java.io.OutputStreamWriter)1 MalformedURLException (java.net.MalformedURLException)1 ArrayList (java.util.ArrayList)1 XMLInputFactory (javax.xml.stream.XMLInputFactory)1 XMLOutputFactory (javax.xml.stream.XMLOutputFactory)1 XMLStreamReader (javax.xml.stream.XMLStreamReader)1