@Test public void testQNameIncludeEverythingExcludeEverything() throws Exception { _regexContextMapper.setIncludeNamespaces(".*"); _regexContextMapper.setExcludeNamespaces(".*"); assertFalse(_regexContextMapper.matches(XMLHelper.createQName("urn:foo:1.0", "banana"))); assertFalse(_regexContextMapper.matches(XMLHelper.createQName("urn:foo:2.0", "banana"))); }
@Test public void testQNameInclude2Exclude1() throws Exception { _regexContextMapper.setIncludeNamespaces("urn:.*:2.0"); _regexContextMapper.setExcludeNamespaces("urn:.*:1.0"); assertTrue(_regexContextMapper.matches(XMLHelper.createQName("urn:foo:2.0", "foo"))); assertFalse(_regexContextMapper.matches(XMLHelper.createQName("urn:foo:1.0", "foo"))); }
@Test public void testQNameFooExcludeTxt() throws Exception { _regexContextMapper.setIncludeNamespaces("urn:foo:.*"); _regexContextMapper.setExcludes(".*.txt"); assertTrue(_regexContextMapper.matches(XMLHelper.createQName("urn:foo:1.0", "bar.xml"))); assertTrue(_regexContextMapper.matches(XMLHelper.createQName("urn:foo:2.0", "bar.pdf"))); assertFalse(_regexContextMapper.matches(XMLHelper.createQName("urn:foo:1.0", "bar.txt"))); }
@Test public void testQNameIncludeFooIncludeBar() throws Exception { _regexContextMapper.setIncludeNamespaces("urn:foo:1.0"); _regexContextMapper.setIncludes("bar"); assertTrue(_regexContextMapper.matches(XMLHelper.createQName("urn:foo:1.0", "bar"))); assertFalse(_regexContextMapper.matches(XMLHelper.createQName("urn:foo:1.0", "banana"))); assertFalse(_regexContextMapper.matches(XMLHelper.createQName("urn:foo:2.0", "bar"))); }
@Test public void testMixedIncludesExcludes() throws Exception { _regexContextMapper.setIncludes("david, tom.*"); _regexContextMapper.setExcludes("keith"); _regexContextMapper.setIncludeNamespaces("urn:.*:2.0,urn:.*:3.0"); _regexContextMapper.setExcludeNamespaces("urn:.*:3.0"); assertTrue(_regexContextMapper.matches(XMLHelper.createQName("urn:foo:2.0", "tomc"))); assertTrue(_regexContextMapper.matches(XMLHelper.createQName("urn:foo:2.0", "tomf"))); assertFalse(_regexContextMapper.matches(XMLHelper.createQName("urn:foo:1.0", "tomc"))); assertFalse(_regexContextMapper.matches(XMLHelper.createQName("urn:foo:3.0", "david"))); assertFalse(_regexContextMapper.matches(XMLHelper.createQName("urn:foo:2.0", "keith"))); }
@Override public void mapTo(Context context, SOAPBindingData target) throws Exception { SOAPMessage soapMessage = target.getSOAPMessage(); MimeHeaders mimeHeaders = soapMessage.getMimeHeaders(); SOAPHeader soapHeader = soapMessage.getSOAPHeader(); for (Property property : context.getProperties(Scope.IN)) { Object value = property.getValue(); if (value != null) { String name = property.getName(); QName qname = XMLHelper.createQName(name); boolean qualifiedForSoapHeader = Strings.trimToNull(qname.getNamespaceURI()) != null; if (qualifiedForSoapHeader && matches(qname)) { if (value instanceof Node) { Node domNode = soapHeader.getOwnerDocument().importNode((Node) value, true); soapHeader.appendChild(domNode); } else if (value instanceof Configuration) { Element configElement = new ElementPuller().pull(new StringReader(value.toString())); Node configNode = soapHeader.getOwnerDocument().importNode(configElement, true); soapHeader.appendChild(configNode); } else { String v = value.toString(); if (SOAPHeadersType.XML.equals(getSOAPHeadersType())) { try { Element xmlElement = new ElementPuller().pull(new StringReader(v)); Node xmlNode = soapHeader.getOwnerDocument().importNode(xmlElement, true); soapHeader.appendChild(xmlNode); } catch (Throwable t) { soapHeader.addChildElement(qname).setValue(v); } } else { soapHeader.addChildElement(qname).setValue(v); } } } else { if (matches(name)) { mimeHeaders.addHeader(name, String.valueOf(value)); } } } } }