SWS-710 - Make it possible to retrieve SoapHeaderElement from SoapHeader by QName
This commit is contained in:
@@ -1,11 +1,11 @@
|
||||
/*
|
||||
* Copyright 2005-2010 the original author or authors.
|
||||
* Copyright 2005-2011 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
@@ -21,7 +21,7 @@ import javax.xml.namespace.QName;
|
||||
import javax.xml.transform.Result;
|
||||
|
||||
/**
|
||||
* Represents the <code>Header</code> element in a SOAP message. A SOAP header contains <code>SoapHeaderElement</code>s,
|
||||
* Represents the {@code Header} element in a SOAP message. A SOAP header contains {@code SoapHeaderElement}s,
|
||||
* which represent the individual headers.
|
||||
*
|
||||
* @author Arjen Poutsma
|
||||
@@ -32,25 +32,25 @@ import javax.xml.transform.Result;
|
||||
public interface SoapHeader extends SoapElement {
|
||||
|
||||
/**
|
||||
* Returns a <code>Result</code> that represents the contents of the header.
|
||||
* Returns a {@code Result} that represents the contents of the header.
|
||||
* <p/>
|
||||
* The result can be used for marshalling.
|
||||
*
|
||||
* @return the <code>Result</code> of this element
|
||||
* @return the {@code Result} of this element
|
||||
*/
|
||||
Result getResult();
|
||||
|
||||
/**
|
||||
* Adds a new <code>SoapHeaderElement</code> with the specified qualified name to this header.
|
||||
* Adds a new {@code SoapHeaderElement} with the specified qualified name to this header.
|
||||
*
|
||||
* @param name the qualified name of the new header element
|
||||
* @return the created <code>SoapHeaderElement</code>
|
||||
* @return the created {@code SoapHeaderElement}
|
||||
* @throws SoapHeaderException if the header cannot be created
|
||||
*/
|
||||
SoapHeaderElement addHeaderElement(QName name) throws SoapHeaderException;
|
||||
|
||||
/**
|
||||
* Removes the <code>SoapHeaderElement</code> with the specified qualified name from this header.
|
||||
* Removes the {@code SoapHeaderElement} with the specified qualified name from this header.
|
||||
* <p/>
|
||||
* This method will only remove the first child element with the specified name. If no element is found with the
|
||||
* specified name, this method has no effect.
|
||||
@@ -61,24 +61,34 @@ public interface SoapHeader extends SoapElement {
|
||||
void removeHeaderElement(QName name) throws SoapHeaderException;
|
||||
|
||||
/**
|
||||
* Returns an <code>Iterator</code> over all the <code>SoapHeaderElement</code>s that have the specified actor or
|
||||
* role and that have a <code>MustUnderstand</code> attribute whose value is equivalent to <code>true</code>.
|
||||
* Returns an {@code Iterator} over all the {@code SoapHeaderElement}s that have the specified actor or
|
||||
* role and that have a {@code MustUnderstand} attribute whose value is equivalent to {@code true}.
|
||||
*
|
||||
* @param actorOrRole the actor (SOAP 1.1) or role (SOAP 1.2) for which to search
|
||||
* @return an iterator over all the header elements that contain the specified actor/role and are marked as
|
||||
* <code>MustUnderstand</code>
|
||||
* {@code MustUnderstand}
|
||||
* @throws SoapHeaderException if the headers cannot be returned
|
||||
* @see SoapHeaderElement
|
||||
*/
|
||||
Iterator<SoapHeaderElement> examineMustUnderstandHeaderElements(String actorOrRole) throws SoapHeaderException;
|
||||
|
||||
/**
|
||||
* Returns an <code>Iterator</code> over all the <code>SoapHeaderElement</code>s in this header.
|
||||
* Returns an {@code Iterator} over all the {@code SoapHeaderElement}s in this header.
|
||||
*
|
||||
* @return an iterator over all the header elements
|
||||
* @throws SoapHeaderException if the header cannot be returned
|
||||
* @see SoapHeaderElement
|
||||
*/
|
||||
Iterator<SoapHeaderElement> examineAllHeaderElements() throws SoapHeaderException;
|
||||
|
||||
/**
|
||||
* Returns an {@code Iterator} over all the {@code SoapHeaderElement}s with the given qualified name in this header.
|
||||
*
|
||||
* @param name the qualified name for which to search
|
||||
* @return an iterator over all the header elements
|
||||
* @throws SoapHeaderException if the header cannot be returned
|
||||
* @see SoapHeaderElement
|
||||
*/
|
||||
Iterator<SoapHeaderElement> examineHeaderElements(QName name) throws SoapHeaderException;
|
||||
|
||||
}
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
/*
|
||||
* Copyright 2005-2010 the original author or authors.
|
||||
* Copyright 2005-2011 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
@@ -46,6 +46,17 @@ abstract class SaajSoapHeader extends SaajSoapElement<SOAPHeader> implements Soa
|
||||
return new SaajSoapHeaderElementIterator(iterator);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public Iterator<SoapHeaderElement> examineHeaderElements(QName name) throws SoapHeaderException {
|
||||
try {
|
||||
Iterator iterator = getImplementation().getChildElements(getSaajHeader(), name);
|
||||
return new SaajSoapHeaderElementIterator(iterator);
|
||||
}
|
||||
catch (SOAPException ex) {
|
||||
throw new SaajSoapHeaderException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
public Iterator<SoapHeaderElement> examineMustUnderstandHeaderElements(String actorOrRole) throws SoapHeaderException {
|
||||
Iterator<SOAPHeaderElement> iterator = getImplementation().examineMustUnderstandHeaderElements(getSaajHeader(), actorOrRole);
|
||||
return new SaajSoapHeaderElementIterator(iterator);
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
/*
|
||||
* Copyright 2005-2010 the original author or authors.
|
||||
* Copyright 2005-2011 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
@@ -88,6 +88,20 @@ public abstract class AbstractSoapHeaderTestCase extends AbstractSoapElementTest
|
||||
assertFalse("header element iterator has too many elements", iterator.hasNext());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExamineHeaderElementWithName() throws Exception {
|
||||
QName name1 = new QName(NAMESPACE, "name1", PREFIX);
|
||||
QName name2 = new QName(NAMESPACE, "name2", PREFIX);
|
||||
soapHeader.addHeaderElement(name1);
|
||||
soapHeader.addHeaderElement(name2);
|
||||
Iterator<SoapHeaderElement> iterator = soapHeader.examineHeaderElements(name1);
|
||||
assertNotNull("header element iterator is null", iterator);
|
||||
assertTrue("header element iterator has no elements", iterator.hasNext());
|
||||
SoapHeaderElement headerElement = iterator.next();
|
||||
assertEquals("Invalid qName for element", name1, headerElement.getName());
|
||||
assertFalse("header element iterator has too many elements", iterator.hasNext());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExamineMustUnderstandHeaderElements() throws Exception {
|
||||
QName qName1 = new QName(NAMESPACE, "localName1", PREFIX);
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
/*
|
||||
* Copyright 2005-2010 the original author or authors.
|
||||
* Copyright 2005-2011 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
@@ -84,6 +84,16 @@ abstract class StroapHeader extends StroapElement implements SoapHeader {
|
||||
return headerElements.iterator();
|
||||
}
|
||||
|
||||
public Iterator<SoapHeaderElement> examineHeaderElements(QName name) throws SoapHeaderException {
|
||||
List<SoapHeaderElement> result = new LinkedList<SoapHeaderElement>();
|
||||
for (StroapHeaderElement headerElement : this.headerElements) {
|
||||
if (headerElement.getName().equals(name)) {
|
||||
result.add(headerElement);
|
||||
}
|
||||
}
|
||||
return result.iterator();
|
||||
}
|
||||
|
||||
public Iterator<SoapHeaderElement> examineMustUnderstandHeaderElements(String actorOrRole)
|
||||
throws SoapHeaderException {
|
||||
List<SoapHeaderElement> result = new LinkedList<SoapHeaderElement>();
|
||||
|
||||
Reference in New Issue
Block a user