List of usage examples for javax.xml.soap SOAPBodyElement getValue
public String getValue();
From source file:Main.java
public static void main(String[] args) throws Exception { SOAPConnectionFactory sfc = SOAPConnectionFactory.newInstance(); SOAPConnection connection = sfc.createConnection(); MessageFactory mf = MessageFactory.newInstance(); SOAPMessage sm = mf.createMessage(); QName bodyName = new QName("http://YourSOAPServer.com", "GetQuote", "d"); URL endpoint = new URL("http://YourSOAPServer.com"); SOAPMessage response = connection.call(sm, endpoint); SOAPBody sb = response.getSOAPBody(); java.util.Iterator iterator = sb.getChildElements(bodyName); while (iterator.hasNext()) { SOAPBodyElement bodyElement = (SOAPBodyElement) iterator.next(); String val = bodyElement.getValue(); System.out.println("The Value is:" + val); }//from w w w. j ava2 s .c o m }
From source file:SOAPResponse.java
public static void main(String[] args) { try {/*from w w w.j a v a 2 s. c o m*/ SOAPConnectionFactory sfc = SOAPConnectionFactory.newInstance(); SOAPConnection connection = sfc.createConnection(); MessageFactory mf = MessageFactory.newInstance(); SOAPMessage sm = mf.createMessage(); QName bodyName = new QName("http://YourSOAPServer.com", "GetQuote", "d"); URL endpoint = new URL("http://YourSOAPServer.com"); SOAPMessage response = connection.call(sm, endpoint); SOAPBody sb = response.getSOAPBody(); java.util.Iterator iterator = sb.getChildElements(bodyName); while (iterator.hasNext()) { SOAPBodyElement bodyElement = (SOAPBodyElement) iterator.next(); String val = bodyElement.getValue(); System.out.println("The Value is:" + val); } } catch (Exception ex) { ex.printStackTrace(); } }
From source file:com.offbynull.portmapper.upnpigd.UpnpIgdController.java
private Map<String, String> parseResponseXml(String expectedTagName, byte[] data) { try {//w w w .j av a 2 s . c om MessageFactory factory = MessageFactory.newInstance(); SOAPMessage soapMessage = factory.createMessage(new MimeHeaders(), new ByteArrayInputStream(data)); if (soapMessage.getSOAPBody().hasFault()) { StringWriter writer = new StringWriter(); try { Transformer transformer = TransformerFactory.newInstance().newTransformer(); transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8"); transformer.transform(new DOMSource(soapMessage.getSOAPPart()), new StreamResult(writer)); } catch (IllegalArgumentException | TransformerException | TransformerFactoryConfigurationError e) { writer.append("Failed to dump fault: " + e); } throw new ResponseException(writer.toString()); } Iterator<SOAPBodyElement> responseBlockIt = soapMessage.getSOAPBody() .getChildElements(new QName(serviceType, expectedTagName)); if (!responseBlockIt.hasNext()) { throw new ResponseException(expectedTagName + " tag missing"); } Map<String, String> ret = new HashMap<>(); SOAPBodyElement responseNode = responseBlockIt.next(); Iterator<SOAPBodyElement> responseChildrenIt = responseNode.getChildElements(); while (responseChildrenIt.hasNext()) { SOAPBodyElement param = responseChildrenIt.next(); String name = StringUtils.trim(param.getLocalName().trim()); String value = StringUtils.trim(param.getValue().trim()); ret.put(name, value); } return ret; } catch (IllegalArgumentException | IOException | SOAPException | DOMException e) { throw new IllegalStateException(e); // should never happen } }