@Test public void testExamineHeaderElementsToProcessUltimateDestination() throws Exception { QName qName = new QName(NAMESPACE, "localName", PREFIX); SoapHeaderElement headerElement = soapHeader.addHeaderElement(qName); headerElement.setActorOrRole(SoapVersion.SOAP_12.getUltimateReceiverRoleUri()); Iterator<SoapHeaderElement> iterator = ((Soap12Header) soapHeader).examineHeaderElementsToProcess(new String[] {"role"}, true); assertNotNull("header element iterator is null", iterator); headerElement = (SoapHeaderElement) iterator.next(); assertEquals( "Invalid name on header element", new QName(NAMESPACE, "localName", PREFIX), headerElement.getName()); assertFalse("header element iterator has too many elements", iterator.hasNext()); }
private void checkHeaderElement(SoapHeaderElement headerElement) { QName name = headerElement.getName(); assertTrue( "Invalid name on header element", new QName(NAMESPACE, "localName1", PREFIX).equals(name) || new QName(NAMESPACE, "localName3", PREFIX).equals(name)); }
@Test public void testExamineHeaderElementsToProcessActors() throws Exception { QName qName = new QName(NAMESPACE, "localName1", PREFIX); SoapHeaderElement headerElement = soapHeader.addHeaderElement(qName); headerElement.setActorOrRole("role1"); qName = new QName(NAMESPACE, "localName2", PREFIX); headerElement = soapHeader.addHeaderElement(qName); headerElement.setActorOrRole("role2"); qName = new QName(NAMESPACE, "localName3", PREFIX); headerElement = soapHeader.addHeaderElement(qName); headerElement.setActorOrRole(SoapVersion.SOAP_12.getNextActorOrRoleUri()); Iterator<SoapHeaderElement> iterator = ((Soap12Header) soapHeader).examineHeaderElementsToProcess(new String[] {"role1"}, false); assertNotNull("header element iterator is null", iterator); assertTrue("header element iterator has no elements", iterator.hasNext()); checkHeaderElement((SoapHeaderElement) iterator.next()); assertTrue("header element iterator has no elements", iterator.hasNext()); checkHeaderElement((SoapHeaderElement) iterator.next()); assertFalse("header element iterator has too many elements", iterator.hasNext()); }
@Test public void testAddUpgrade() throws Exception { String[] supportedUris = new String[] { "http://schemas.xmlsoap.org/soap/envelope/", "http://www.w3.org/2003/05/soap-envelope" }; Soap12Header soap12Header = (Soap12Header) soapHeader; SoapHeaderElement header = soap12Header.addUpgradeHeaderElement(supportedUris); StringResult result = new StringResult(); transformer.transform(soapHeader.getSource(), result); assertEquals( "Invalid name", header.getName(), new QName("http://www.w3.org/2003/05/soap-envelope", "Upgrade")); // XMLUnit can't test this: /* assertXMLEqual("Invalid contents of header", "<Header xmlns='http://www.w3.org/2003/05/soap-envelope' >" + "<Upgrade>" + "<SupportedEnvelope xmlns:ns0='http://schemas.xmlsoap.org/soap/envelope/' qname='ns0:Envelope'/>" + "<SupportedEnvelope xmlns:ns1='http://www.w3.org/2003/05/soap-envelope' qname='ns1:Envelope'/>" + "</Upgrade>" + "</Header>", result.toString()); */ }
@Override public void doWithMessage(WebServiceMessage message) throws IOException, TransformerException { SoapMessage soapMsg = (SoapMessage) message; SoapHeader header = soapMsg.getSoapHeader(); SoapHeaderElement edCodeHeader = header.addHeaderElement(getEdCode()); edCodeHeader.setText(getEdCodeText()); SoapHeaderElement cutOffDate = header.addHeaderElement(getCutOffDate()); cutOffDate.setText(getCutOffDateText()); SoapHeaderElement signatureData = header.addHeaderElement(getSignatureData()); signatureData.setText(getSignatureDataText()); SoapHeaderElement uploadDate = header.addHeaderElement(getUploadDate()); uploadDate.setText(getUploadDateText()); // Call the superclass method to add WS-Addressing headers super.doWithMessage(message); }