Search in sources :

Example 41 with OMNamespace

use of org.apache.axiom.om.OMNamespace in project webservices-axiom by apache.

the class TestCloneWithSourcedElement1 method runTest.

@Override
protected void runTest() throws Throwable {
    SOAPEnvelope sourceEnv = soapFactory.getDefaultEnvelope();
    SOAPBody body = sourceEnv.getBody();
    // Create a payload
    OMDataSource bads = new StringOMDataSource("<tns:payload xmlns:tns=\"urn://test\">Hello World</tns:payload>");
    OMNamespace ns = body.getOMFactory().createOMNamespace("urn://test", "tns");
    OMSourcedElement omse = body.getOMFactory().createOMElement(bads, "payload", ns);
    body.addChild(omse);
    copyAndCheck(sourceEnv);
    assertFalse(omse.isExpanded());
}
Also used : SOAPBody(org.apache.axiom.soap.SOAPBody) OMNamespace(org.apache.axiom.om.OMNamespace) OMDataSource(org.apache.axiom.om.OMDataSource) StringOMDataSource(org.apache.axiom.om.ds.StringOMDataSource) StringOMDataSource(org.apache.axiom.om.ds.StringOMDataSource) SOAPEnvelope(org.apache.axiom.soap.SOAPEnvelope) OMSourcedElement(org.apache.axiom.om.OMSourcedElement)

Example 42 with OMNamespace

use of org.apache.axiom.om.OMNamespace in project webservices-axiom by apache.

the class TestGetSOAPBodyFirstElementLocalNameAndNS method runTest.

@Override
protected void runTest() throws Throwable {
    SOAPEnvelope envelope = soapFactory.getDefaultEnvelope();
    OMElement bodyElement = soapFactory.createOMElement(qname.getLocalPart(), qname.getNamespaceURI(), qname.getPrefix());
    envelope.getBody().addChild(bodyElement);
    assertEquals(qname.getLocalPart(), envelope.getSOAPBodyFirstElementLocalName());
    OMNamespace ns = envelope.getSOAPBodyFirstElementNS();
    if (qname.getNamespaceURI().length() == 0) {
        assertNull(ns);
    } else {
        assertEquals(qname.getNamespaceURI(), ns.getNamespaceURI());
        assertEquals(qname.getPrefix(), ns.getPrefix());
    }
}
Also used : OMNamespace(org.apache.axiom.om.OMNamespace) OMElement(org.apache.axiom.om.OMElement) SOAPEnvelope(org.apache.axiom.soap.SOAPEnvelope)

Example 43 with OMNamespace

use of org.apache.axiom.om.OMNamespace in project webservices-axiom by apache.

the class TestSerializeAndConsumeWithOMSEInBody method runTest.

@Override
protected void runTest() throws Throwable {
    SOAPEnvelope envelope = soapFactory.createSOAPEnvelope();
    SOAPBody body = soapFactory.createSOAPBody();
    envelope.addChild(body);
    OMNamespace ns = soapFactory.createOMNamespace("http://ns1", "d");
    OMElement payload = soapFactory.createOMElement(new DummySource(), "dummy", ns);
    // This line will cause NoSuchElementException
    payload.setNamespace(ns);
    body.addChild(payload);
    StringWriter writer = new StringWriter();
    envelope.serializeAndConsume(writer);
//        System.out.println(writer);
}
Also used : SOAPBody(org.apache.axiom.soap.SOAPBody) OMNamespace(org.apache.axiom.om.OMNamespace) StringWriter(java.io.StringWriter) OMElement(org.apache.axiom.om.OMElement) SOAPEnvelope(org.apache.axiom.soap.SOAPEnvelope)

Example 44 with OMNamespace

use of org.apache.axiom.om.OMNamespace in project webservices-axiom by apache.

the class PushOMDataSourceReader method proceed.

@Override
public boolean proceed() throws StreamException {
    // TODO: we might want to unwrap the NamespaceRepairingFilter (and some other filters) here
    XmlHandler handler = this.handler;
    OMOutputFormat format = null;
    XmlHandler current = handler;
    while (current instanceof XmlHandlerWrapper) {
        if (current instanceof XmlDeclarationRewriterHandler) {
            format = ((XmlDeclarationRewriterHandler) current).getFormat();
            break;
        }
        current = ((XmlHandlerWrapper) current).getParent();
    }
    if (format == null) {
        // This is for the OMSourcedElement expansion case
        format = new OMOutputFormat();
        format.setDoOptimize(true);
        handler = new PushOMDataSourceXOPHandler(handler);
    }
    try {
        XMLStreamWriter writer = new XmlHandlerStreamWriter(handler, null, AxiomXMLStreamWriterExtensionFactory.INSTANCE);
        // Seed the namespace context with the namespace context from the parent
        OMContainer parent = root.getParent();
        if (parent instanceof OMElement) {
            for (Iterator<OMNamespace> it = ((OMElement) parent).getNamespacesInScope(); it.hasNext(); ) {
                OMNamespace ns = it.next();
                writer.setPrefix(ns.getPrefix(), ns.getNamespaceURI());
            }
        }
        handler.startFragment();
        dataSource.serialize(new MTOMXMLStreamWriterImpl(new PushOMDataSourceStreamWriter(writer), format));
        handler.completed();
    } catch (XMLStreamException ex) {
        Throwable cause = ex.getCause();
        if (cause instanceof StreamException) {
            throw (StreamException) cause;
        } else {
            throw new StreamException(ex);
        }
    }
    return true;
}
Also used : OMNamespace(org.apache.axiom.om.OMNamespace) OMElement(org.apache.axiom.om.OMElement) XmlHandlerStreamWriter(org.apache.axiom.core.stream.stax.push.XmlHandlerStreamWriter) StreamException(org.apache.axiom.core.stream.StreamException) XMLStreamException(javax.xml.stream.XMLStreamException) XMLStreamException(javax.xml.stream.XMLStreamException) XmlHandlerWrapper(org.apache.axiom.core.stream.XmlHandlerWrapper) XmlHandler(org.apache.axiom.core.stream.XmlHandler) XMLStreamWriter(javax.xml.stream.XMLStreamWriter) OMOutputFormat(org.apache.axiom.om.OMOutputFormat) XmlDeclarationRewriterHandler(org.apache.axiom.om.impl.stream.XmlDeclarationRewriterHandler) OMContainer(org.apache.axiom.om.OMContainer)

Example 45 with OMNamespace

use of org.apache.axiom.om.OMNamespace in project webservices-axiom by apache.

the class RolePlayerChecker method matches.

@Override
public boolean matches(AxiomElement header, String unused1, String unused2) {
    // If we're filtering on namespace, check that first since the compare is simpler.
    if (namespace != null) {
        OMNamespace headerNamespace = header.getNamespace();
        if (headerNamespace == null || !namespace.equals(headerNamespace.getNamespaceURI())) {
            return false;
        }
    }
    String role = SOAPHeaderBlockHelper.getRole(header, soapHelper);
    SOAPVersion version = soapHelper.getVersion();
    // 1. If role is ultimatedest, go by what the rolePlayer says
    if (role == null || role.equals("") || (version instanceof SOAP12Version && role.equals(SOAP12Constants.SOAP_ROLE_ULTIMATE_RECEIVER))) {
        return (rolePlayer == null || rolePlayer.isUltimateDestination());
    }
    // 2. If role is next, always return true
    if (role.equals(version.getNextRoleURI()))
        return true;
    // 3. If role is none, always return false
    if (version instanceof SOAP12Version && role.equals(SOAP12Constants.SOAP_ROLE_NONE)) {
        return false;
    }
    // 4. Return t/f depending on match
    List<String> roles = (rolePlayer == null) ? null : rolePlayer.getRoles();
    if (roles != null) {
        for (String thisRole : roles) {
            if (thisRole.equals(role))
                return true;
        }
    }
    return false;
}
Also used : OMNamespace(org.apache.axiom.om.OMNamespace) SOAPVersion(org.apache.axiom.soap.SOAPVersion) SOAP12Version(org.apache.axiom.soap.SOAP12Version)

Aggregations

OMNamespace (org.apache.axiom.om.OMNamespace)171 OMElement (org.apache.axiom.om.OMElement)108 OMFactory (org.apache.axiom.om.OMFactory)101 QName (javax.xml.namespace.QName)34 SOAPEnvelope (org.apache.axiom.soap.SOAPEnvelope)22 OMAttribute (org.apache.axiom.om.OMAttribute)18 PullOMDataSource (org.apache.axiom.ts.om.sourcedelement.util.PullOMDataSource)16 StringWriter (java.io.StringWriter)15 SOAPHeaderBlock (org.apache.axiom.soap.SOAPHeaderBlock)13 SOAPHeader (org.apache.axiom.soap.SOAPHeader)12 OMSourcedElement (org.apache.axiom.om.OMSourcedElement)9 XMLStreamReader (javax.xml.stream.XMLStreamReader)8 OMText (org.apache.axiom.om.OMText)7 Iterator (java.util.Iterator)6 SOAPBody (org.apache.axiom.soap.SOAPBody)6 StringReader (java.io.StringReader)5 StringOMDataSource (org.apache.axiom.om.ds.StringOMDataSource)5 HashSet (java.util.HashSet)4 OMDataSource (org.apache.axiom.om.OMDataSource)4 OMNode (org.apache.axiom.om.OMNode)4