Examples of OMNode


Examples of org.apache.axiom.om.OMNode

     * @param synCtx current message
     * @param synLog the logger to be used
     */
    private void performXSLT(MessageContext synCtx, SynapseLog synLog) {

        OMNode sourceNode = source.selectOMNode(synCtx, synLog);
        boolean isSoapEnvelope = (sourceNode == synCtx.getEnvelope());
        boolean isSoapBody = (sourceNode == synCtx.getEnvelope().getBody());

        if (synLog.isTraceTraceEnabled()) {
            synLog.traceTrace("Transformation source : " + sourceNode.toString());
        }

        // determine if it is needed to create or create the template
        if (isCreationOrRecreationRequired(synCtx)) {
            // many threads can see this and come here for acquiring the lock
            synchronized (transformerLock) {
                // only first thread should create the template
                if (isCreationOrRecreationRequired(synCtx)) {
                    createTemplate(synCtx, synLog);
                }
            }
        }

        try {
            // perform transformation
            Transformer transformer = cachedTemplates.newTransformer();
            if (!properties.isEmpty()) {
                // set the parameters which will pass to the Transformation
                applyProperties(transformer, synCtx, synLog);
            }

            transformer.setErrorListener(new ErrorListenerImpl(synLog, "XSLT transformation"));
           
            String outputMethod = transformer.getOutputProperty(OutputKeys.METHOD);
            String encoding = transformer.getOutputProperty(OutputKeys.ENCODING);

            if (synLog.isTraceOrDebugEnabled()) {
                synLog.traceOrDebug("output method: " + outputMethod
                        + "; encoding: " + encoding);
            }
           
            ResultBuilderFactory.Output output;
            if ("text".equals(outputMethod)) {
                synLog.traceOrDebug("Processing non SOAP/XML (text) transformation result");
                output = ResultBuilderFactory.Output.TEXT;
            } else if (isSoapEnvelope) {
                output = ResultBuilderFactory.Output.SOAP_ENVELOPE;
            } else {
                output = ResultBuilderFactory.Output.ELEMENT;
            }
           
            SynapseEnvironment synEnv = synCtx.getEnvironment();
            ResultBuilder resultBuilder =
                    resultBuilderFactory.createResultBuilder(synEnv, output);
            SourceBuilder sourceBuilder = sourceBuilderFactory.createSourceBuilder(synEnv);
           
            if (synLog.isTraceOrDebugEnabled()) {
                synLog.traceOrDebug("Using " + sourceBuilder.getClass().getName());
                synLog.traceOrDebug("Using " + resultBuilder.getClass().getName());
            }
           
            try {
                transformer.transform(sourceBuilder.getSource((OMElement)sourceNode),
                                      resultBuilder.getResult());
            } finally {
                sourceBuilder.release();
            }

            synLog.traceOrDebug("Transformation completed - processing result");

            // get the result OMElement
            OMElement result =
                resultBuilder.getNode(encoding == null ? null : Charset.forName(encoding));

            if (synLog.isTraceTraceEnabled()) {
                synLog.traceTrace("Transformation result : " + result.toString());
            }

            if (targetPropertyName != null) {
                // add result XML as a message context property to the message
                if (synLog.isTraceOrDebugEnabled()) {
                    synLog.traceOrDebug("Adding result as message context property : " +
                        targetPropertyName);
                }
                synCtx.setProperty(targetPropertyName, result);
            } else {
                if (synLog.isTraceOrDebugEnabled()) {
                    synLog.traceOrDebug("Replace " +
                        (isSoapEnvelope ? "SOAP envelope" : isSoapBody ? "SOAP body" : "node")
                        + " with result");
                }

                if (isSoapEnvelope) {
                    try {
                        synCtx.setEnvelope((SOAPEnvelope) result);
                    } catch (AxisFault ex) {
                        handleException("Unable to replace SOAP envelope with result", ex, synCtx);
                    }

                } else if (isSoapBody) {
                    for (Iterator itr = synCtx.getEnvelope().getBody().getChildElements();
                        itr.hasNext(); ) {
                        OMElement child = (OMElement) itr.next();
                        child.detach();
                    }

                    for (Iterator itr = result.getChildElements(); itr.hasNext(); ) {
                        OMElement child = (OMElement) itr.next();
                        synCtx.getEnvelope().getBody().addChild(child);
                    }

                } else {
                    sourceNode.insertSiblingAfter(result);
                    sourceNode.detach();
                }
            }

        } catch (TransformerException e) {
            handleException("Error performing XSLT transformation using : " + xsltKey, e, synCtx);
View Full Code Here

Examples of org.apache.axiom.om.OMNode

                    String type = child.getAttributeValue(new QName("", TYPE));
                    if (type == null || name == null) {
                        //bad!
                        continue;
                    }
                    OMNode data = child.getFirstOMChild();
                    if (data.getType() != OMNode.TEXT_NODE) {
                        continue; // BAD!
                    }
                    OMText text = (OMText)data;
                    if (type.equals(INTEGER)) {
                        this.put(name, new Integer(text.getText()));
View Full Code Here

Examples of org.apache.axiom.om.OMNode

        } else if (wsdlURI != null) {
            try {
              URL url = wsdlURI.toURL();
                publishWSDL = url.toString();

                OMNode node = SynapseConfigUtils.getOMElementFromURL(publishWSDL, synapseHome);
                if (node instanceof OMElement) {
                    wsdlElement = (OMElement) node;
                }
                wsdlFound = true;
            } catch (MalformedURLException e) {
View Full Code Here

Examples of org.apache.axiom.om.OMNode

        SOAPEnvelope newEnvelope  = soap12Factory.getDefaultEnvelope();

        if (clonedOldEnv.getHeader() != null) {
            Iterator itr = clonedOldEnv.getHeader().getChildren();
            while (itr.hasNext()) {
                OMNode omNode = (OMNode) itr.next();

                if (omNode instanceof SOAPHeaderBlock) {
                    SOAPHeaderBlock soapHeader = (SOAPHeaderBlock) omNode;
                    SOAPHeaderBlock newSOAPHeader = soap12Factory.createSOAPHeaderBlock(
                        soapHeader.getLocalName(), soapHeader.getNamespace());
                    Iterator allAttributes = soapHeader.getAllAttributes();

                    while(allAttributes.hasNext()) {
                        OMAttribute attr = (OMAttribute) allAttributes.next();
                        if(attr.getNamespace() != null
                            && SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI.equals(
                            attr.getNamespace().getNamespaceURI())) {
                            String attrName = attr.getLocalName();

                            if(SOAP_ATR_ACTOR.equals(attrName)) {
                                OMAttribute newAtr = omNode.getOMFactory().createOMAttribute(
                                    SOAP_ATR_ROLE, newEnvelope.getNamespace(),
                                    attr.getAttributeValue());
                                newSOAPHeader.addAttribute(newAtr);

                            } else if(SOAP_ATR_MUST_UNDERSTAND.equals(attrName)) {
                                boolean isMustUnderstand = soapHeader.getMustUnderstand();
                                newSOAPHeader.setMustUnderstand(isMustUnderstand);

                            } else {
                                log.warn("removed unsupported attribute from SOAP 1.1 " +
                                    "namespace when converting to SOAP 1.2:" + attrName);
                            }

                        } else {
                            newSOAPHeader.addAttribute(attr);
                        }

                        Iterator itrChildren = soapHeader.getChildren();
                        while (itrChildren.hasNext()) {
                            newSOAPHeader.addChild(((OMNode) itrChildren.next()));
                        }

                        newEnvelope.getHeader().addChild(newSOAPHeader);
                    } // while(allAttributes.hasNext())

                } else {
                    newEnvelope.getHeader().addChild(omNode);
                }

            } // while (itr.hasNext())

        } // if (clonedOldEnv.getHeader() != null)

        if (clonedOldEnv.getBody() != null) {

            Iterator itrBodyChildren = clonedOldEnv.getBody().getChildren();
            while (itrBodyChildren.hasNext()) {
                OMNode omNode = (OMNode) itrBodyChildren.next();

                if (omNode != null && omNode instanceof SOAPFault) {
                   
                    SOAPFault soapFault = (SOAPFault) omNode;
                    SOAPFault newSOAPFault = soap12Factory.createSOAPFault();
View Full Code Here

Examples of org.apache.axiom.om.OMNode

        SOAPFactory soap11Factory = OMAbstractFactory.getSOAP11Factory();
        SOAPEnvelope newEnvelope  = soap11Factory.getDefaultEnvelope();
        if (clonedOldEnv.getHeader() != null) {
            Iterator itr = clonedOldEnv.getHeader().getChildren();
            while (itr.hasNext()) {
                OMNode omNode = (OMNode) itr.next();

                if (omNode instanceof SOAPHeaderBlock) {
                    SOAPHeaderBlock soapHeaderBlock = (SOAPHeaderBlock) omNode;
                    SOAPHeaderBlock newSOAPHeader = soap11Factory.createSOAPHeaderBlock(
                        soapHeaderBlock.getLocalName(), soapHeaderBlock.getNamespace());

                    Iterator allAttributes = soapHeaderBlock.getAllAttributes();

                    while(allAttributes.hasNext()) {
                        OMAttribute attr = (OMAttribute) allAttributes.next();
                        if (attr.getNamespace() != null
                            && SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI.equals(
                            attr.getNamespace().getNamespaceURI())) {
                            String attrName = attr.getLocalName();

                            if (SOAP_ATR_ROLE.equals(attrName)) {
                                OMAttribute newAtr = omNode.getOMFactory().createOMAttribute(
                                    SOAP_ATR_ACTOR, newEnvelope.getNamespace(),
                                    attr.getAttributeValue());
                                newSOAPHeader.addAttribute(newAtr);

                            } else if(SOAP_ATR_MUST_UNDERSTAND.equals(attrName)) {
                                boolean isMustUnderstand = soapHeaderBlock.getMustUnderstand();
                                newSOAPHeader.setMustUnderstand(isMustUnderstand);

                            } else {
                                log.warn("removed unsupported attribute from SOAP 1.2 " +
                                    "namespace when converting to SOAP 1.1:" + attrName);
                            }

                        } else {
                            newSOAPHeader.addAttribute(attr);
                        }

                        Iterator itrChildren = soapHeaderBlock.getChildren();
                        while (itrChildren.hasNext()) {
                            newSOAPHeader.addChild(((OMNode) itrChildren.next()));
                        }

                        newEnvelope.getHeader().addChild(newSOAPHeader);
                    }

                } else {
                    newEnvelope.getHeader().addChild(omNode);
                }
            }
        }

        if (clonedOldEnv.getBody() != null) {
            if (clonedOldEnv.hasFault()) {
                SOAPFault soapFault = clonedOldEnv.getBody().getFault();
                SOAPFault newSOAPFault = soap11Factory.createSOAPFault();
                newEnvelope.getBody().addChild(newSOAPFault);

                SOAPFaultCode code = soapFault.getCode();
                if(code != null) {
                    SOAPFaultCode newSOAPFaultCode
                            = soap11Factory.createSOAPFaultCode(newSOAPFault);

                    SOAPFaultValue value = code.getValue();
                    if(value != null) {
                        // get the corresponding SOAP12 fault code
                        // for the provided SOAP11 fault code
                        soap11Factory.createSOAPFaultValue(newSOAPFaultCode);
                        if(value.getTextAsQName() != null) {
                            newSOAPFaultCode.setText(
                                    getMappingSOAP11Code(value.getTextAsQName()));
                        }
                    }
                }

                SOAPFaultReason reason = soapFault.getReason();
                if(reason != null) {
                    SOAPFaultReason newSOAPFaultReason
                            = soap11Factory.createSOAPFaultReason(newSOAPFault);

                    List allSoapTexts = reason.getAllSoapTexts();
                    Iterator iterAllSoapTexts = allSoapTexts.iterator();
                    if (iterAllSoapTexts.hasNext()) {
                        SOAPFaultText soapFaultText = (SOAPFaultText) iterAllSoapTexts.next();
                        newSOAPFaultReason.setText(soapFaultText.getText());
                    }
                }

                SOAPFaultDetail detail = soapFault.getDetail();
                if(detail != null) {
                    SOAPFaultDetail newSOAPFaultDetail
                            = soap11Factory.createSOAPFaultDetail(newSOAPFault);
                    Iterator<OMElement> iter = detail.getAllDetailEntries();
                    while (iter.hasNext()) {
                        OMElement detailEntry = iter.next();
                        newSOAPFaultDetail.addDetailEntry(detailEntry);
                    }
                    newSOAPFault.setDetail(newSOAPFaultDetail);
                }

            } else {
                Iterator itr = clonedOldEnv.getBody().getChildren();
                while (itr.hasNext()) {
                    OMNode omNode = (OMNode) itr.next();
                    if (omNode != null) {
                        newEnvelope.getBody().addChild(omNode);
                    }
                }
            }
View Full Code Here

Examples of org.apache.axiom.om.OMNode

     * @return the validation Source for the current message
     */
    private Source getValidationSource(MessageContext synCtx, SynapseLog synLog) {

        try {
            OMNode validateSource = source.selectOMNode(synCtx, synLog);
            if (synLog.isTraceOrDebugEnabled()) {
                synLog.traceOrDebug("Validation source : " + validateSource.toString());
            }

            return AXIOMUtils.asSource(validateSource);

        } catch (Exception e) {
View Full Code Here

Examples of org.apache.axiom.om.OMNode

            if (result != null) {
                if (targetXPath != null) {
                    Object o = targetXPath.evaluate(synCtx);

                    if (o != null && o instanceof OMElement) {
                        OMNode tgtNode = (OMElement) o;
                        tgtNode.insertSiblingAfter(result);
                        tgtNode.detach();
                    } else if (o != null && o instanceof List && !((List) o).isEmpty()) {
                        // Always fetches *only* the first
                        OMNode tgtNode = (OMElement) ((List) o).get(0);
                        tgtNode.insertSiblingAfter(result);
                        tgtNode.detach();
                    } else {
                        handleException("Evaluation of target XPath expression : " +
                            targetXPath.toString() + " did not yeild an OMNode", synCtx);
                    }
                } if (targetKey != null) {
View Full Code Here

Examples of org.apache.axiom.om.OMNode

                } catch (MalformedURLException e) {
                    handleException("The entry with key : " + key + " refers to an invalid URL");
                }

            } else {
                OMNode    nodeValue = elem.getFirstOMChild();
                OMElement elemValue = elem.getFirstElement();

                if (elemValue != null) {
                    entry.setType(Entry.INLINE_XML);
                    entry.setValue(elemValue);
View Full Code Here

Examples of org.apache.axiom.om.OMNode

    super.setParent((FOMElement)parent);
  }

  @SuppressWarnings("unchecked")
  public <T extends Element>T getPreviousSibling() {
    OMNode el = this.getPreviousOMSibling();
    while (el != null) {
      if (el instanceof Element) return (T)getWrapped((Element)el);
      else el = el.getPreviousOMSibling();
    }
    return null;
  }
View Full Code Here

Examples of org.apache.axiom.om.OMNode

    return null;
  }
 
  @SuppressWarnings("unchecked")
  public <T extends Element>T getNextSibling() {
    OMNode el = this.getNextOMSibling();
    while (el != null) {
      if (el instanceof Element) return (T)getWrapped((Element)el);
      else el = el.getNextOMSibling();
    }
    return null;
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.