Example usage for javax.xml.stream XMLStreamException getMessage

List of usage examples for javax.xml.stream XMLStreamException getMessage

Introduction

In this page you can find the example usage for javax.xml.stream XMLStreamException getMessage.

Prototype

public String getMessage() 

Source Link

Document

Returns the detail message string of this throwable.

Usage

From source file:org.wso2.carbon.mediator.bam.config.services.BamServerProfileConfigAdmin.java

public BamServerConfig getBamServerConfig(String bamServerConfigLocation) {
    String resourceString = registryManager.getResourceString(bamServerConfigLocation);
    BamServerConfigBuilder bamServerConfigBuilder = new BamServerConfigBuilder();
    try {/*from   w w w  .j a va 2s . c  om*/
        OMElement resourceElement = new StAXOMBuilder(
                new ByteArrayInputStream(resourceString.getBytes(Charset.forName("UTF-8"))))
                        .getDocumentElement();
        bamServerConfigBuilder.createBamServerConfig(resourceElement);
        return bamServerConfigBuilder.getBamServerConfig();
    } catch (XMLStreamException e) {
        String errorMsg = "Failed to create XML OMElement from the String. " + e.getMessage();
        log.error(errorMsg, e);
    }
    return null;
}

From source file:org.wso2.carbon.mediator.bam.xml.BamMediatorFactory.java

public Mediator createSpecificMediator(OMElement omElement, Properties properties) {
    BamMediator bam = new BamMediator();
    BamServerConfigBuilder bamServerConfigBuilder = new BamServerConfigBuilder();
    String resourceString;/*  w  w w .ja  va 2s  .c  om*/
    String serverProfilePath = SERVER_PROFILE_LOCATION + "/" + this.getServerProfileName(omElement);
    String streamName = this.getStreamName(omElement);
    String streamVersion = this.getStreamVersion(omElement);
    if (isNotNullOrEmpty(serverProfilePath) && isNotNullOrEmpty(streamName)
            && isNotNullOrEmpty(streamVersion)) {
        bam.setServerProfile(serverProfilePath);
    }
    RegistryManager registryManager = new RegistryManager();
    if (registryManager.resourceAlreadyExists(serverProfilePath)) {
        resourceString = registryManager.getResourceString(serverProfilePath);
        try {
            OMElement resourceElement = new StAXOMBuilder(
                    new ByteArrayInputStream(resourceString.getBytes(Charset.forName("UTF-8"))))
                            .getDocumentElement();
            boolean bamServerConfigCreated = bamServerConfigBuilder.createBamServerConfig(resourceElement);
            if (bamServerConfigCreated) {
                this.updateBamMediator(bamServerConfigBuilder, bam, streamName, streamVersion);
            }
        } catch (XMLStreamException e) {
            String errorMsg = "Failed to create XML OMElement from the String. " + e.getMessage();
            log.error(errorMsg, e);
        }
    }
    return bam;
}

From source file:org.wso2.carbon.mediator.datamapper.engine.output.writers.XMLWriter.java

private void init(Schema outputSchema) throws SchemaException, WriterException {
    XMLOutputFactory xmlOutputFactory = XMLOutputFactory.newInstance();
    try {/*ww w. j  a v a 2 s.c o m*/
        xmlStreamWriter = xmlOutputFactory.createXMLStreamWriter(stringWriter);
        //creating root element of the xml message
        namespaceMap = outputSchema.getNamespaceMap();
        writeStartElement(outputSchema.getName(), xmlStreamWriter);
        Iterator<Map.Entry<String, String>> namespaceEntryIterator = namespaceMap.entrySet().iterator();
        while (namespaceEntryIterator.hasNext()) {
            Map.Entry<String, String> entry = namespaceEntryIterator.next();
            xmlStreamWriter.writeNamespace(entry.getValue(), entry.getKey());
        }
    } catch (XMLStreamException e) {
        throw new WriterException("Error while creating xml output factory. " + e.getMessage());
    }
}

From source file:org.wso2.carbon.mediator.datamapper.engine.output.writers.XMLWriter.java

@Override
public void writeStartObject(String name) throws WriterException {
    try {//  w w  w  .jav  a  2 s.c o  m
        if (name.endsWith(SCHEMA_ATTRIBUTE_PARENT_ELEMENT_POSTFIX)) {
            latestElementName = name.substring(0, name.lastIndexOf(SCHEMA_ATTRIBUTE_PARENT_ELEMENT_POSTFIX));
            writeStartElement(latestElementName, xmlStreamWriter);
        } else {
            writeStartElement(name, xmlStreamWriter);
            latestElementName = name;
        }
    } catch (XMLStreamException e) {
        throw new WriterException(e.getMessage());
    }
}

From source file:org.wso2.carbon.mediator.datamapper.engine.output.writers.XMLWriter.java

@Override
public void writeField(String name, Object fieldValue) throws WriterException {
    try {/*from w w  w.j  ava  2  s .c  o  m*/
        //with in a element attributes must come first before any of other field values
        if (fieldValue != null) {
            String value = getFieldValueAsString(fieldValue);
            if (name.contains(SCHEMA_ATTRIBUTE_FIELD_PREFIX)) {
                String attributeNameWithNamespace = name.replaceFirst(SCHEMA_ATTRIBUTE_FIELD_PREFIX, "");
                if (attributeNameWithNamespace.contains("_")) {
                    String[] attributeNameArray = attributeNameWithNamespace.split("_");
                    if (namespaceMap.values().contains(attributeNameArray[0])) {
                        Iterator<Map.Entry<String, String>> entryIterator = namespaceMap.entrySet().iterator();
                        while (entryIterator.hasNext()) {
                            Map.Entry<String, String> entry = entryIterator.next();
                            if (attributeNameArray[0].equals(entry.getValue())) {
                                xmlStreamWriter.writeAttribute(entry.getKey(),
                                        attributeNameArray[attributeNameArray.length - 1], value);
                            }
                        }
                    } else {
                        xmlStreamWriter.writeAttribute(attributeNameWithNamespace, value);
                    }
                } else {
                    xmlStreamWriter.writeAttribute(attributeNameWithNamespace, value);
                }
            } else if (name.equals(SCHEMA_XML_ELEMENT_TEXT_VALUE_FIELD)) {
                xmlStreamWriter.writeCharacters(value);
            } else if (name.equals(latestElementName)) {
                xmlStreamWriter.writeCharacters(value);
                xmlStreamWriter.writeEndElement();
            } else {
                writeStartElement(name, xmlStreamWriter);
                xmlStreamWriter.writeCharacters(value);
                xmlStreamWriter.writeEndElement();
            }
        }
    } catch (XMLStreamException e) {
        throw new WriterException(e.getMessage());
    }
}

From source file:org.wso2.carbon.mediator.datamapper.engine.output.writers.XMLWriter.java

@Override
public void writeEndObject(String objectName) throws WriterException {
    try {//ww  w .  j  a v a  2s. com
        xmlStreamWriter.writeEndElement();
    } catch (XMLStreamException e) {
        throw new WriterException(e.getMessage());
    }
}

From source file:org.wso2.carbon.mediator.datamapper.engine.output.writers.XMLWriter.java

@Override
public String terminateMessageBuilding() throws WriterException {
    try {/*w ww. j  ava  2  s .  com*/
        xmlStreamWriter.writeEndElement();
        xmlStreamWriter.flush();
        xmlStreamWriter.close();
        return stringWriter.getBuffer().toString();
    } catch (XMLStreamException e) {
        throw new WriterException(e.getMessage());
    }
}

From source file:org.wso2.carbon.mediator.datamapper.engine.output.writers.XMLWriter.java

@Override
public void writeStartAnonymousObject() throws WriterException {
    try {//w ww  . j av  a2 s.c  o  m
        writeStartElement(arrayElementStack.peek(), xmlStreamWriter);
    } catch (XMLStreamException e) {
        throw new WriterException(e.getMessage());
    }
}

From source file:org.wso2.carbon.mediator.datamapper.engine.output.writers.XMLWriter.java

@Override
public void writePrimitive(Object value) throws WriterException {
    try {//from  w  w  w .  j a  v  a2  s .c o m
        xmlStreamWriter.writeCharacters(getFieldValueAsString(value));
    } catch (XMLStreamException e) {
        throw new WriterException(e.getMessage());
    }
}

From source file:org.wso2.carbon.proxyadmin.common.ProxyData.java

public OMElement retrieveOM() throws ProxyAdminException {
    OMFactory fac = OMAbstractFactory.getOMFactory();

    OMNamespace syn = SynapseConstants.SYNAPSE_OMNAMESPACE;
    OMNamespace nullNS = fac.createOMNamespace("", "");

    OMElement proxy = fac.createOMElement("proxy", syn);
    proxy.addAttribute("name", name, nullNS);

    // adds any transports listed in the configuration
    if (!(transports == null)) {
        proxy.addAttribute("transports", createCSString(transports), nullNS);
    }// w ww .j a v  a 2s . co  m

    if (!(pinnedServers == null)) {
        proxy.addAttribute("pinnedServers", createCSString(pinnedServers), nullNS);
    }

    // adds the state of statistics and tracing
    if (enableStatistics) {
        proxy.addAttribute(XMLConfigConstants.STATISTICS_ATTRIB_NAME, XMLConfigConstants.STATISTICS_ENABLE,
                nullNS);
    } else {
        proxy.addAttribute(XMLConfigConstants.STATISTICS_ATTRIB_NAME, XMLConfigConstants.STATISTICS_DISABLE,
                nullNS);
    }

    if (enableTracing) {
        proxy.addAttribute(XMLConfigConstants.TRACE_ATTRIB_NAME, XMLConfigConstants.TRACE_ENABLE, nullNS);
    } else {
        proxy.addAttribute(XMLConfigConstants.TRACE_ATTRIB_NAME, XMLConfigConstants.TRACE_DISABLE, nullNS);
    }

    if (startOnLoad) {
        proxy.addAttribute("startOnLoad", "true", nullNS);
    } else {
        proxy.addAttribute("startOnLoad", "false", nullNS);
    }

    // creates the target section of the configuration
    OMElement element = fac.createOMElement("target", syn);
    if (inSeqKey != null) {
        element.addAttribute("inSequence", inSeqKey, nullNS);
    } else if (inSeqXML != null) {
        try {
            element.addChild(createElement(inSeqXML));
        } catch (XMLStreamException e) {
            String msg = "Unable to build the \"inSequence\" element";
            log.error(msg + e.getMessage());
            throw new ProxyAdminException(msg, e);
        }
    }

    if (outSeqKey != null) {
        element.addAttribute("outSequence", outSeqKey, nullNS);
    } else if (outSeqXML != null) {
        try {
            element.addChild(createElement(outSeqXML));
        } catch (XMLStreamException e) {
            String msg = "Unable to build the \"outSequence\" element";
            log.error(msg + e.getMessage());
            throw new ProxyAdminException(msg, e);
        }
    }

    if (faultSeqKey != null) {
        element.addAttribute("faultSequence", faultSeqKey, nullNS);
    } else if (faultSeqXML != null) {
        try {
            element.addChild(createElement(faultSeqXML));
        } catch (XMLStreamException e) {
            String msg = "Unable to build the \"faultSequence\" element";
            log.error(msg + e.getMessage());
            throw new ProxyAdminException(msg, e);
        }
    }

    if (endpointKey != null) {
        element.addAttribute("endpoint", endpointKey, nullNS);
    } else if (endpointXML != null && !"".equals(endpointXML)) {
        try {
            element.addChild(createElement(endpointXML));
        } catch (XMLStreamException e) {
            String msg = "Unable to build the \"endpoint\" element";
            log.error(msg + e.getMessage());
            throw new ProxyAdminException(msg, e);
        }
    }
    proxy.addChild(element);

    // creates the publishWSDL section of the configuration
    element = fac.createOMElement("publishWSDL", syn);
    if (publishWSDLEndpoint != null) {
        publishWSDL = true;
        element.addAttribute("endpoint", publishWSDLEndpoint, nullNS);
    } else if (wsdlKey != null) {
        publishWSDL = true;
        element.addAttribute("key", wsdlKey, nullNS);
    } else if (wsdlURI != null) {
        publishWSDL = true;
        element.addAttribute("uri", wsdlURI, nullNS);
    } else if (wsdlDef != null) {
        publishWSDL = true;
        try {
            element.addChild(createElement(wsdlDef));
        } catch (XMLStreamException e) {
            String msg = "Unable to build the in line WSDL definition";
            log.error(msg + e.getMessage());
            throw new ProxyAdminException(msg, e);
        }
    }

    if (publishWSDL) {
        // builds the additional resources (if any) required by the WSDL
        if (wsdlResources != null && wsdlResources.length != 0) {
            OMElement resource;
            Entry wsdlResource;
            for (int i = 0; i < wsdlResources.length; i++) {
                wsdlResource = wsdlResources[i];
                resource = fac.createOMElement("resource", syn);
                resource.addAttribute("location", wsdlResource.getKey(), nullNS);
                resource.addAttribute("key", wsdlResource.getValue(), nullNS);
                element.addChild(resource);
            }
        }
        proxy.addChild(element);
    }

    // creates the additional service level parameter list of the configuration
    if (serviceParams != null && serviceParams.length != 0) {
        Entry serviceParam;
        String value;
        for (int i = 0; i < serviceParams.length; i++) {
            serviceParam = serviceParams[i];
            element = fac.createOMElement("parameter", syn);
            element.addAttribute("name", serviceParam.getKey(), nullNS);
            value = serviceParam.getValue();
            if (value.startsWith("<")) {
                try {
                    element.addChild(
                            new StAXOMBuilder(new ByteArrayInputStream(value.getBytes())).getDocumentElement());
                } catch (XMLStreamException e) {
                    String msg = "Service parameter: " + serviceParam.getKey()
                            + " has an invalid XML as its value";
                    log.error(msg);
                    throw new ProxyAdminException(msg, e);
                }
            } else {
                element.setText(value);
            }
            proxy.addChild(element);
        }
    }
    return proxy;
}