本文整理匯總了Java中javax.xml.soap.SOAPBody.getChildElements方法的典型用法代碼示例。如果您正苦於以下問題:Java SOAPBody.getChildElements方法的具體用法?Java SOAPBody.getChildElements怎麽用?Java SOAPBody.getChildElements使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javax.xml.soap.SOAPBody
的用法示例。
在下文中一共展示了SOAPBody.getChildElements方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: createXPath
import javax.xml.soap.SOAPBody; //導入方法依賴的package包/類
/**
* Constructs XPath query over the SOAP message
*
* @param query XPath query
* @param response SOAP message
* @return XPath query
* @throws SOAPException in case of SOAP issue
* @throws JaxenException XPath problem
*/
public final XPath createXPath(final String query, final SOAPMessage response) throws SOAPException, JaxenException {
/* Uses DOM to XPath mapping */
final XPath xpath = new DOMXPath(query);
/* Define a namespaces used in response */
final SimpleNamespaceContext nsContext = new SimpleNamespaceContext();
final SOAPPart sp = response.getSOAPPart();
final SOAPEnvelope env = sp.getEnvelope();
final SOAPBody bdy = env.getBody();
/* Add namespaces from SOAP envelope */
addNamespaces(nsContext, env);
/* Add namespaces of top body element */
final Iterator<?> bodyElements = bdy.getChildElements();
while (bodyElements.hasNext()) {
SOAPElement element = (SOAPElement) bodyElements.next();
addNamespaces(nsContext, element);
}
xpath.setNamespaceContext(nsContext);
return xpath;
}
示例2: getResult
import javax.xml.soap.SOAPBody; //導入方法依賴的package包/類
private int getResult(SOAPMessage response) {
SOAPBody body = null;
try {
body = response.getSOAPBody();
} catch (SOAPException e) {
e.printStackTrace();
return 0;
}
@SuppressWarnings("unchecked")
Iterator<SOAPElement> it = body.getChildElements(new QName(
NAMESPACE_URI, "result"));
return Integer.valueOf(it.next().getTextContent());
}
示例3: getFirstBodyElement
import javax.xml.soap.SOAPBody; //導入方法依賴的package包/類
/**
* Retrieves the first element name in the SOAP Envelope's body.
*
* @param soapMessage The SOAP message.
* @return The first Element QName.
* @throws SOAPException If the SOAP message is invalid
*/
public static QName getFirstBodyElement(final SOAPMessage soapMessage) throws SOAPException {
QName operationName = null;
SOAPBody body = soapMessage.getSOAPPart().getEnvelope().getBody();
if (body != null) {
Iterator<Node> nodes = body.getChildElements();
Node node = null;
while (nodes.hasNext()) {
node = nodes.next();
if (node instanceof Element) {
operationName = new QName(node.getNamespaceURI(), node.getLocalName());
}
}
}
return operationName;
}
示例4: testText
import javax.xml.soap.SOAPBody; //導入方法依賴的package包/類
@Validated @Test
public void testText() throws Exception {
SOAPEnvelope envelope = getSOAPEnvelope();
SOAPBody body = envelope.getBody();
Iterator iStart = body.getChildElements();
int countStart = getIteratorCount(iStart);
final String bodyText = "This is the body text";
SOAPElement se = body.addChildElement("Child");
assertTrue(se != null);
SOAPElement soapElement = se.addTextNode(bodyText);
assertEquals(bodyText, soapElement.getValue());
Iterator i = body.getChildElements();
int count = getIteratorCount(i);
assertTrue(count == countStart + 1);
}
示例5: testGetChildElements2
import javax.xml.soap.SOAPBody; //導入方法依賴的package包/類
@Validated @Test
public void testGetChildElements2() throws Exception {
MessageFactory fact = MessageFactory.newInstance();
SOAPMessage message = fact.createMessage();
SOAPPart soapPart = message.getSOAPPart();
SOAPEnvelope soapEnvelope = soapPart.getEnvelope();
SOAPBody soapBody = soapEnvelope.getBody();
Name name = soapEnvelope.createName("MyChild1");
SOAPElement se = soapBody.addChildElement(name);
Iterator childElementsCount = soapBody.getChildElements();
Iterator childElements = soapBody.getChildElements();
int childCount = 0;
while (childElementsCount.hasNext()) {
Node node = (Node)childElementsCount.next();
childCount++;
}
assertEquals(childCount, 1);
SOAPElement se2 = (SOAPElement)childElements.next();
if (!se.equals(se2)) {
fail();
} else {
System.out.println("SOAPElement se = se2 (expected)");
}
Name n = se.getElementName();
assertEquals(n, name);
}
示例6: testGetChildElements3
import javax.xml.soap.SOAPBody; //導入方法依賴的package包/類
@Validated @Test
public void testGetChildElements3() throws Exception {
MessageFactory fact = MessageFactory.newInstance();
SOAPMessage message = fact.createMessage();
SOAPPart soapPart = message.getSOAPPart();
SOAPEnvelope soapEnvelope = soapPart.getEnvelope();
SOAPBody soapBody = soapEnvelope.getBody();
//Name name = soapEnvelope.createName("MyChild1");
QName name = new QName("MyChild1");
SOAPElement se = soapBody.addChildElement(name);
Iterator childElementsCount = soapBody.getChildElements();
Iterator childElements = soapBody.getChildElements();
int childCount = 0;
while (childElementsCount.hasNext()) {
Node node = (Node)childElementsCount.next();
childCount++;
}
assertEquals(childCount, 1);
SOAPElement se2 = (SOAPElement)childElements.next();
assertEquals(se, se2);
QName n = se.getElementQName();
assertEquals(n, name);
}
示例7: getServiceParam
import javax.xml.soap.SOAPBody; //導入方法依賴的package包/類
public static SOAPBodyElement getServiceParam(SOAPMessageContext context,
String serviceName, String paramName) throws SOAPException {
SOAPMessage soapMessage = context.getMessage();
SOAPEnvelope soapEnvelope = soapMessage.getSOAPPart().getEnvelope();
SOAPBody soapBody = soapEnvelope.getBody();
@SuppressWarnings("unchecked")
Iterator<SOAPBodyElement> elements = soapBody.getChildElements();
while (elements.hasNext()) {
SOAPBodyElement element = elements.next();
if (element.getNodeName().contains(serviceName)) {
@SuppressWarnings("unchecked")
Iterator<SOAPBodyElement> params = element.getChildElements();
while (params.hasNext()) {
SOAPBodyElement param = params.next();
if (paramName.equals(param.getNodeName())) {
return param;
}
}
}
}
throw new SOAPException("Soap message param " + paramName
+ " not found.");
}
示例8: getStockQuote
import javax.xml.soap.SOAPBody; //導入方法依賴的package包/類
public String getStockQuote(String tickerSymbol) throws Exception {
SOAPConnectionFactory scFactory = SOAPConnectionFactory.newInstance();
SOAPConnection con = scFactory.createConnection();
MessageFactory factory = MessageFactory.newInstance();
SOAPMessage message = factory.createMessage();
SOAPPart soapPart = message.getSOAPPart();
SOAPEnvelope envelope = soapPart.getEnvelope();
SOAPHeader header = envelope.getHeader();
SOAPBody body = envelope.getBody();
header.detachNode();
Name bodyName = envelope.createName("getQuote", "n", "urn:xmethods-delayed-quotes");
SOAPBodyElement gltp = body.addBodyElement(bodyName);
Name name = envelope.createName("symbol");
SOAPElement symbol = gltp.addChildElement(name);
symbol.addTextNode(tickerSymbol);
URLEndpoint endpoint = new URLEndpoint("http://64.124.140.30/soap");
SOAPMessage response = con.call(message, endpoint);
con.close();
SOAPPart sp = response.getSOAPPart();
SOAPEnvelope se = sp.getEnvelope();
SOAPBody sb = se.getBody();
Iterator it = sb.getChildElements();
while (it.hasNext()) {
SOAPBodyElement bodyElement = (SOAPBodyElement) it.next();
Iterator it2 = bodyElement.getChildElements();
while (it2.hasNext()) {
SOAPElement element2 = (SOAPElement) it2.next();
return element2.getValue();
}
}
return null;
}
示例9: unwrapSoapResponse
import javax.xml.soap.SOAPBody; //導入方法依賴的package包/類
/**
* Unwrap the SOAP response into a DOM Node.
*/
protected Node unwrapSoapResponse(SOAPMessage soapResponse) throws ActivityException, AdapterException {
try {
// unwrap the soap content from the message
SOAPBody soapBody = soapResponse.getSOAPBody();
Node childElem = null;
Iterator<?> it = soapBody.getChildElements();
while (it.hasNext()) {
Node node = (Node) it.next();
if (node.getNodeType() == Node.ELEMENT_NODE && node.getLocalName().equals(getOutputMessageName())) {
NodeList childNodes = node.getChildNodes();
for (int i = 0; i < childNodes.getLength(); i++) {
if (getResponsePartName().equals(childNodes.item(i).getLocalName())) {
String content = childNodes.item(i).getTextContent();
childElem = DomHelper.toDomNode(content);
}
}
}
}
if (childElem == null)
throw new SOAPException("SOAP body child element not found");
// extract soap response headers
SOAPHeader header = soapResponse.getSOAPHeader();
if (header != null) {
extractSoapResponseHeaders(header);
}
return childElem;
}
catch (Exception ex) {
throw new ActivityException(ex.getMessage(), ex);
}
}
示例10: unwrapSoapResponse
import javax.xml.soap.SOAPBody; //導入方法依賴的package包/類
protected Node unwrapSoapResponse(SOAPMessage soapResponse)
throws ActivityException, AdapterException {
try {
SOAPBody soapBody = soapResponse.getSOAPBody();
Node childElem = null;
Iterator<?> it = soapBody.getChildElements();
while (it.hasNext()) {
Node node = (Node) it.next();
if (node.getNodeType() == Node.ELEMENT_NODE) {
childElem = node;
break;
}
}
if (childElem == null)
throw new SOAPException("SOAP body child element not found");
// extract soap response headers
SOAPHeader header = soapResponse.getSOAPHeader();
if (header != null) {
extractSoapResponseHeaders(header);
}
return childElem;
}
catch (Exception ex) {
throw new ActivityException(ex.getMessage(), ex);
}
}
示例11: getBodyChildren
import javax.xml.soap.SOAPBody; //導入方法依賴的package包/類
private Iterator<?> getBodyChildren(SOAPMessageContext context) {
try {
SOAPEnvelope envelope = context.getMessage().getSOAPPart().getEnvelope();
SOAPBody body = envelope.getBody();
return body.getChildElements();
} catch (SOAPException e) {
throw new IllegalStateException(e);
}
}
示例12: add
import javax.xml.soap.SOAPBody; //導入方法依賴的package包/類
public int add(int augend, int addend) throws Exception {
/** Create SOAPMessage request. **/
MessageFactory mf = MessageFactory
.newInstance(SOAPConstants.SOAP_1_1_PROTOCOL);
// Create a message.
SOAPMessage request = mf.createMessage();
// Obtain the SOAP body.
SOAPBody body = request.getSOAPBody();
// Construct the message payload.
SOAPElement operation = body
.addChildElement("add", "ns", NAMESPACE_URI);
SOAPElement arg0 = operation.addChildElement("arg0");
arg0.addTextNode(Integer.toString(augend));
SOAPElement arg1 = operation.addChildElement("arg1");
arg1.addTextNode(Integer.toString(addend));
request.saveChanges();
/** Invoke the service endpoint. **/
SOAPMessage response = dispatch.invoke(request);
/** Process the response. **/
body = response.getSOAPBody();
@SuppressWarnings("unchecked")
Iterator<SOAPElement> it = body.getChildElements(new QName(
NAMESPACE_URI, "addResponse"));
return Integer.valueOf(it.next().getTextContent());
}
示例13: testTypeSubstitution
import javax.xml.soap.SOAPBody; //導入方法依賴的package包/類
public void testTypeSubstitution() throws Exception {
Dispatch<SOAPMessage> dispatch = createDispatch();
String msg = reqMsgStart + GET_APPLES + reqMsgEnd;
MessageFactory factory = MessageFactory.newInstance();
SOAPMessage request = factory.createMessage(null,
new ByteArrayInputStream(msg.getBytes()));
SOAPMessage response = dispatch.invoke(request);
SOAPBody body = response.getSOAPBody();
TestLogger.logger.debug(">> Response [" + body + "]");
QName expectedXsiType1 = new QName(NS, "fuji");
QName expectedXsiType2 = new QName(NS, "freyburg");
Iterator iter;
SOAPElement element;
QName xsiType;
iter = body.getChildElements(new QName(NS, "getApplesResponse"));
assertTrue(iter.hasNext());
element = (SOAPElement)iter.next();
iter = element.getChildElements(new QName("return"));
// check value1
assertTrue(iter.hasNext());
element = (SOAPElement)iter.next();
xsiType = getXsiTypeAttribute(element);
assertEquals("xsi:type 1", expectedXsiType1, xsiType);
// check value2
assertTrue(iter.hasNext());
element = (SOAPElement)iter.next();
xsiType = getXsiTypeAttribute(element);
assertEquals("xsi:type 2", expectedXsiType2, xsiType);
}
示例14: testTransform
import javax.xml.soap.SOAPBody; //導入方法依賴的package包/類
@Validated @Test
public void testTransform() throws Exception {
MessageFactory fact = MessageFactory.newInstance();
SOAPMessage message = fact.createMessage();
SOAPBody body = message.getSOAPBody();
Source source = new DOMSource(createDocument());
Result result = new DOMResult(body);
TransformerFactory transformerFactory = TransformerFactory.newInstance();
Transformer transformer = transformerFactory.newTransformer();
transformer.transform(source, result);
assertEquals(1, body.getChildNodes().getLength());
Iterator iter = body.getChildElements();
assertTrue(iter.hasNext());
Object obj = iter.next();
assertTrue(obj instanceof SOAPBodyElement);
SOAPElement soapElement = (SOAPElement)obj;
assertEquals("http://example.com", soapElement.getNamespaceURI());
assertEquals("GetLastTradePrice", soapElement.getLocalName());
iter = soapElement.getChildElements();
assertTrue(iter.hasNext());
obj = iter.next();
assertTrue(obj instanceof SOAPElement);
soapElement = (SOAPElement)obj;
assertNull(soapElement.getNamespaceURI());
assertEquals("symbol", soapElement.getLocalName());
assertFalse(iter.hasNext());
iter = soapElement.getChildElements();
assertTrue(iter.hasNext());
obj = iter.next();
assertTrue(obj instanceof Text);
Text text = (Text)obj;
assertEquals("DEF", text.getData());
assertFalse(iter.hasNext());
}
示例15: testAddChildElement
import javax.xml.soap.SOAPBody; //導入方法依賴的package包/類
@Validated @Test
public void testAddChildElement() throws Exception {
String s = "MyName1";
String p = "MyPrefix1";
String u = "myURI";
SOAPBody body = MessageFactory.newInstance().createMessage().getSOAPBody();
SOAPElement myse = body.addNamespaceDeclaration(p, u);
SOAPElement se = body.addChildElement(s, p);
if (se == null) {
fail("SOAPElement was null");
} else {
Iterator i = body.getChildElements();
int count = getIteratorCount(i);
i = body.getChildElements();
if (count != 1) {
fail("Wrong iterator count returned of " + count + ", expected 1");
} else {
SOAPElement se2 = (SOAPElement)i.next();
if (!se.equals(se2)) {
fail("Elements not equal");
}
}
String name = se.getElementName().getLocalName();
Name n = se.getElementName();
String prefix = se.getElementName().getPrefix();
if (!name.equals(s) || !prefix.equals(p)) {
fail("addChildElement() did not return correct local name and prefix");
}
}
}