Search in sources :

Example 81 with OMText

use of org.apache.axiom.om.OMText in project wso2-synapse by wso2.

the class HessianMessageFormatter method extractSynapseBinaryDataSource.

/**
 * Tries to extract the binary data source containing the Hessian message.
 *
 * @param omElement
 *
 * @return the binary data source containing the Hessian message or null, if the OMElement
 *         does not contain a binary datasource.
 */
private SynapseBinaryDataSource extractSynapseBinaryDataSource(OMElement omElement) {
    SynapseBinaryDataSource synapseBinaryDataSource = null;
    Iterator it = omElement.getChildren();
    while (it.hasNext() && synapseBinaryDataSource == null) {
        OMNode hessianElement = (OMNode) it.next();
        if (hessianElement instanceof OMText) {
            OMText tempNode = (OMText) hessianElement;
            if (tempNode.getDataHandler() != null && ((DataHandler) tempNode.getDataHandler()).getDataSource() instanceof SynapseBinaryDataSource) {
                synapseBinaryDataSource = (SynapseBinaryDataSource) ((DataHandler) tempNode.getDataHandler()).getDataSource();
            }
        }
    }
    return synapseBinaryDataSource;
}
Also used : OMNode(org.apache.axiom.om.OMNode) SynapseBinaryDataSource(org.apache.synapse.util.SynapseBinaryDataSource) Iterator(java.util.Iterator) OMText(org.apache.axiom.om.OMText) DataHandler(javax.activation.DataHandler)

Example 82 with OMText

use of org.apache.axiom.om.OMText in project wso2-synapse by wso2.

the class XFormURLEncodedBuilder method addRequestParameter.

private static void addRequestParameter(SOAPFactory soapFactory, OMElement bodyFirstChild, OMNamespace ns, String key, Object parameter) {
    if (parameter instanceof DataHandler) {
        DataHandler dataHandler = (DataHandler) parameter;
        OMText dataText = bodyFirstChild.getOMFactory().createOMText(dataHandler, true);
        soapFactory.createOMElement(key, ns, bodyFirstChild).addChild(dataText);
    } else {
        String textValue = parameter.toString();
        soapFactory.createOMElement(key, ns, bodyFirstChild).setText(textValue);
    }
}
Also used : OMText(org.apache.axiom.om.OMText) DataHandler(javax.activation.DataHandler)

Example 83 with OMText

use of org.apache.axiom.om.OMText in project wso2-synapse by wso2.

the class InboundEndpointFactory method createInboundEndpoint.

public static InboundEndpoint createInboundEndpoint(OMElement inboundEndpointElem, SynapseConfiguration config) {
    InboundEndpoint inboundEndpoint = new InboundEndpoint();
    if (inboundEndpointElem.getAttributeValue(ATT_NAME) != null) {
        inboundEndpoint.setName(inboundEndpointElem.getAttributeValue(ATT_NAME));
    } else {
        String msg = "Inbound Endpoint name cannot be null";
        log.error(msg);
        throw new SynapseException(msg);
    }
    if (inboundEndpointElem.getAttributeValue(ATT_PROTOCOL) != null) {
        inboundEndpoint.setProtocol(inboundEndpointElem.getAttributeValue(ATT_PROTOCOL));
    }
    if (inboundEndpointElem.getAttributeValue(ATT_ENDPOINT_CLASS) != null) {
        inboundEndpoint.setClassImpl(inboundEndpointElem.getAttributeValue(ATT_ENDPOINT_CLASS));
    }
    if (inboundEndpointElem.getAttributeValue(ATT_ENDPOINT_SUSPEND) != null) {
        inboundEndpoint.setSuspend(Boolean.parseBoolean(inboundEndpointElem.getAttributeValue(ATT_ENDPOINT_SUSPEND)));
    } else {
        inboundEndpoint.setSuspend(false);
    }
    if (inboundEndpointElem.getAttributeValue(ATT_SEQUENCE) != null) {
        inboundEndpoint.setInjectingSeq(inboundEndpointElem.getAttributeValue(ATT_SEQUENCE));
    }
    if (inboundEndpointElem.getAttributeValue(ATT_ERROR_SEQUENCE) != null) {
        inboundEndpoint.setOnErrorSeq(inboundEndpointElem.getAttributeValue(ATT_ERROR_SEQUENCE));
    }
    String nameString = inboundEndpoint.getName();
    if (nameString == null || "".equals(nameString)) {
        nameString = SynapseConstants.INBOUND_ENDPOINT_NAME;
    }
    AspectConfiguration aspectConfiguration = new AspectConfiguration(nameString);
    inboundEndpoint.configure(aspectConfiguration);
    OMAttribute statistics = inboundEndpointElem.getAttribute(new QName(XMLConfigConstants.NULL_NAMESPACE, XMLConfigConstants.STATISTICS_ATTRIB_NAME));
    if (statistics != null) {
        String statisticsValue = statistics.getAttributeValue();
        if (statisticsValue != null) {
            if (XMLConfigConstants.STATISTICS_ENABLE.equals(statisticsValue)) {
                aspectConfiguration.enableStatistics();
            }
        }
    }
    OMAttribute tracing = inboundEndpointElem.getAttribute(new QName(XMLConfigConstants.NULL_NAMESPACE, XMLConfigConstants.TRACE_ATTRIB_NAME));
    if (tracing != null) {
        String tracingValue = tracing.getAttributeValue();
        if (tracingValue != null) {
            if (XMLConfigConstants.TRACE_ENABLE.equals(tracingValue)) {
                aspectConfiguration.enableTracing();
            }
        }
    }
    // Set parameters
    OMElement parametersElt = inboundEndpointElem.getFirstChildWithName(new QName(XMLConfigConstants.SYNAPSE_NAMESPACE, InboundEndpointConstants.INBOUND_ENDPOINT_PARAMETERS));
    if (parametersElt != null) {
        Iterator parameters = parametersElt.getChildrenWithName(new QName(XMLConfigConstants.SYNAPSE_NAMESPACE, InboundEndpointConstants.INBOUND_ENDPOINT_PARAMETER));
        while (parameters.hasNext()) {
            OMElement parameter = (OMElement) parameters.next();
            String paramName = parameter.getAttributeValue(new QName(InboundEndpointConstants.INBOUND_ENDPOINT_PARAMETER_NAME));
            String paramKey = parameter.getAttributeValue(new QName(InboundEndpointConstants.INBOUND_ENDPOINT_PARAMETER_KEY));
            if (paramKey != null) {
                Object obj = config.getEntry(paramKey);
                if (obj == null) {
                    obj = config.getEntryDefinition(paramKey);
                    obj = config.getEntry(paramKey);
                }
                if (obj != null && obj instanceof OMTextImpl) {
                    OMText objText = (OMText) obj;
                    inboundEndpoint.addParameter(paramName, objText.getText(), paramKey);
                } else {
                    String msg = "Error while deploying inbound endpoint " + inboundEndpoint.getName() + ".Registry entry defined with key: " + paramKey + " not found.";
                    log.error(msg);
                    throw new SynapseException(msg);
                }
            } else if (parameter.getFirstElement() != null) {
                inboundEndpoint.addParameter(paramName, parameter.getFirstElement().toString());
            } else {
                inboundEndpoint.addParameter(paramName, parameter.getText());
            }
        }
    }
    inboundEndpoint.setFileName(inboundEndpointElem.getAttributeValue(new QName(InboundEndpointConstants.INBOUND_ENDPOINT_NAME)) + ".xml");
    return inboundEndpoint;
}
Also used : InboundEndpoint(org.apache.synapse.inbound.InboundEndpoint) SynapseException(org.apache.synapse.SynapseException) QName(javax.xml.namespace.QName) Iterator(java.util.Iterator) OMText(org.apache.axiom.om.OMText) OMTextImpl(org.apache.axiom.om.impl.llom.OMTextImpl) OMElement(org.apache.axiom.om.OMElement) AspectConfiguration(org.apache.synapse.aspects.AspectConfiguration) OMAttribute(org.apache.axiom.om.OMAttribute)

Example 84 with OMText

use of org.apache.axiom.om.OMText in project wso2-synapse by wso2.

the class AbstractDBMediatorSerializer method createStatementElement.

private OMNode createStatementElement(Statement statement) {
    OMElement stmntElt = fac.createOMElement(AbstractDBMediatorFactory.STMNT_Q.getLocalPart(), synNS);
    OMElement sqlElt = fac.createOMElement(AbstractDBMediatorFactory.SQL_Q.getLocalPart(), synNS);
    OMText sqlText = fac.createOMText(statement.getRawStatement(), XMLStreamConstants.CDATA);
    sqlElt.addChild(sqlText);
    stmntElt.addChild(sqlElt);
    // serialize parameters of the statement
    for (Statement.Parameter param : statement.getParameters()) {
        OMElement paramElt = createStatementParamElement(param);
        stmntElt.addChild(paramElt);
    }
    // serialize any optional results of the statement
    for (String name : statement.getResultsMap().keySet()) {
        String columnStr = statement.getResultsMap().get(name);
        OMElement resultElt = fac.createOMElement(AbstractDBMediatorFactory.RESULT_Q.getLocalPart(), synNS);
        resultElt.addAttribute(fac.createOMAttribute("name", nullNS, name));
        resultElt.addAttribute(fac.createOMAttribute("column", nullNS, columnStr));
        stmntElt.addChild(resultElt);
    }
    return stmntElt;
}
Also used : Statement(org.apache.synapse.mediators.db.Statement) OMText(org.apache.axiom.om.OMText) OMElement(org.apache.axiom.om.OMElement)

Example 85 with OMText

use of org.apache.axiom.om.OMText in project wso2-synapse by wso2.

the class AbstractDBMediator method fetchFromRegistry.

/**
 * Fetch the registry resources pointed by registry path.
 * @param config
 * @param key
 * @return Resource value
 */
private String fetchFromRegistry(SynapseConfiguration config, String key) {
    Object obj = config.getEntry(key);
    if (obj == null) {
        config.getEntryDefinition(key);
        obj = config.getEntry(key);
    }
    if (obj != null && obj instanceof OMTextImpl) {
        OMText objText = (OMText) obj;
        return objText.getText();
    } else {
        String msg = "Error DB Mediator datasource: " + dataSourceName + ".Registry entry defined with key: " + key + " not found.";
        log.error(msg);
        throw new SynapseException(msg);
    }
}
Also used : SynapseException(org.apache.synapse.SynapseException) OMText(org.apache.axiom.om.OMText) OMTextImpl(org.apache.axiom.om.impl.llom.OMTextImpl)

Aggregations

OMText (org.apache.axiom.om.OMText)92 OMElement (org.apache.axiom.om.OMElement)62 OMFactory (org.apache.axiom.om.OMFactory)39 DataHandler (javax.activation.DataHandler)26 OMNode (org.apache.axiom.om.OMNode)21 OMNamespace (org.apache.axiom.om.OMNamespace)10 QName (javax.xml.namespace.QName)8 OMException (org.apache.axiom.om.OMException)8 IOException (java.io.IOException)7 Iterator (java.util.Iterator)7 InputStream (java.io.InputStream)6 OMAttribute (org.apache.axiom.om.OMAttribute)6 Entry (org.apache.synapse.config.Entry)6 ArrayList (java.util.ArrayList)5 DataSource (javax.activation.DataSource)5 ByteArrayDataSource (org.apache.axiom.attachments.ByteArrayDataSource)5 OMOutputFormat (org.apache.axiom.om.OMOutputFormat)5 SOAPEnvelope (org.apache.axiom.soap.SOAPEnvelope)5 OutputStream (java.io.OutputStream)4 StringReader (java.io.StringReader)4