use of org.apache.axiom.soap.SOAPHeaderBlock in project webservices-axiom by apache.
the class TestGetHeadersToProcessWithNamespace method runTest.
@Override
protected void runTest() throws Throwable {
SOAPEnvelope envelope = soapFactory.createSOAPEnvelope();
SOAPHeader header = soapFactory.createSOAPHeader(envelope);
OMNamespace ns1 = soapFactory.createOMNamespace("urn:ns1", "ns1");
OMNamespace ns2 = soapFactory.createOMNamespace("urn:ns2", "ns2");
String myRole = "urn:myRole";
String otherRole = "urn:otherRole";
SOAPHeaderBlock headerBlock1 = header.addHeaderBlock("header1", ns1);
headerBlock1.setRole(myRole);
SOAPHeaderBlock headerBlock2 = header.addHeaderBlock("header2", ns2);
headerBlock2.setRole(myRole);
SOAPHeaderBlock headerBlock3 = header.addHeaderBlock("header3", ns1);
headerBlock3.setRole(myRole);
SOAPHeaderBlock headerBlock4 = header.addHeaderBlock("header4", ns1);
headerBlock4.setRole(otherRole);
Iterator<SOAPHeaderBlock> it = header.getHeadersToProcess(new MyRolePlayer(false, new String[] { myRole }), ns1.getNamespaceURI());
assertTrue(it.hasNext());
assertSame(headerBlock1, it.next());
assertTrue(it.hasNext());
assertSame(headerBlock3, it.next());
assertFalse(it.hasNext());
}
use of org.apache.axiom.soap.SOAPHeaderBlock in project webservices-axiom by apache.
the class TestBlobOMDataSource method runTest.
@Override
protected void runTest() throws Throwable {
SOAPEnvelope soapEnvelope = soapFactory.createSOAPEnvelope();
SOAPHeader soapHeader = soapFactory.createSOAPHeader(soapEnvelope);
String localName = "myPayload";
String encoding = "utf-8";
String payload = "<tns:myPayload xmlns:tns=\"urn://test\">Payload One</tns:myPayload>";
OMNamespace ns = soapFactory.createOMNamespace("urn://test", "tns");
BlobOMDataSource ds = new BlobOMDataSource(Blobs.createBlob(payload.getBytes(encoding)), encoding);
// Set an empty MustUnderstand property on the data source
ds.setProperty(SOAPHeaderBlock.MUST_UNDERSTAND_PROPERTY, null);
OMSourcedElement omse = soapFactory.createSOAPHeaderBlock(localName, ns, ds);
soapHeader.addChild(omse);
OMNode firstChild = soapHeader.getFirstOMChild();
assertTrue("Expected OMSourcedElement child", firstChild instanceof SOAPHeaderBlock);
SOAPHeaderBlock child = (SOAPHeaderBlock) firstChild;
assertTrue("OMSourcedElement is expanded. This is unexpected", !child.isExpanded());
assertThat(child.getDataSource()).isSameAs(ds);
// Make sure that getting the MustUnderstand property does not cause expansion.
assertTrue(!child.getMustUnderstand());
assertTrue("OMSourcedElement is expanded. This is unexpected", !child.isExpanded());
assertThat(child.getDataSource()).isSameAs(ds);
// A BlobOMDataSource does not consume the backing object when read.
// Thus getting the XMLStreamReader of the BlobOMDataSource should not
// cause expansion of the OMSourcedElement.
XMLStreamReader reader = child.getXMLStreamReader();
reader.next();
assertTrue("OMSourcedElement is expanded. This is unexpected", !child.isExpanded());
// Likewise, a BlobOMDataSource does not consume the backing object when
// written. Thus serializing the OMSourcedElement should not cause the expansion
// of the OMSourcedElement.
assertTrue("The payload was not present in the output", soapHeader.toString().indexOf(payload) > 0);
assertTrue("OMSourcedElement is expanded. This is unexpected", !child.isExpanded());
assertThat(child.getDataSource()).isSameAs(ds);
}
use of org.apache.axiom.soap.SOAPHeaderBlock in project webservices-axiom by apache.
the class TestGetBooleanAttributeDefault method runTest.
@Override
protected void runTest() throws Throwable {
SOAPHeader header = soapFactory.getDefaultEnvelope().getOrCreateHeader();
SOAPHeaderBlock headerBlock = header.addHeaderBlock(new QName("http://example.org", "test", "h"));
assertFalse(attribute.getAdapter(BooleanAttributeAccessor.class).getValue(headerBlock));
}
use of org.apache.axiom.soap.SOAPHeaderBlock in project webservices-axiom by apache.
the class TestGetBooleanAttribute method runTest.
@Override
protected void runTest() throws Throwable {
SOAPHeader header = soapFactory.getDefaultEnvelope().getOrCreateHeader();
SOAPHeaderBlock headerBlock = header.addHeaderBlock(new QName("http://example.org", "test", "h"));
headerBlock.addAttribute(attribute.getName(spec), literal.getLexicalRepresentation(), header.getNamespace());
assertEquals(literal.getValue(), attribute.getAdapter(BooleanAttributeAccessor.class).getValue(headerBlock));
}
use of org.apache.axiom.soap.SOAPHeaderBlock in project webservices-axiom by apache.
the class TestGetBooleanAttributeInvalid method runTest.
@Override
protected void runTest() throws Throwable {
SOAPHeader header = soapFactory.getDefaultEnvelope().getOrCreateHeader();
SOAPHeaderBlock headerBlock = header.addHeaderBlock(new QName("urn:test", "test", "p"));
headerBlock.addAttribute(attribute.getName(spec), value, header.getNamespace());
try {
attribute.getAdapter(BooleanAttributeAccessor.class).getValue(headerBlock);
fail("Expected SOAPProcessingException");
} catch (SOAPProcessingException ex) {
// Expected
}
}
Aggregations