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());
}
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());
}
}
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);
}
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;
}
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;
}
Aggregations