List of usage examples for javax.xml.soap SOAPBody getChildElements
public Iterator<Node> getChildElements(Name name);
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 ava 2s .c o m }
From source file:SOAPResponse.java
public static void main(String[] args) { try {/*from w w w . j a va 2 s . c om*/ 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:fi.vrk.xroad.catalog.lister.WsdlCdataInterceptor.java
@Override public boolean handleResponse(MessageContext messageContext, Object o) throws Exception { WebServiceMessage response = messageContext.getResponse(); SaajSoapMessage saajSoapMessage = (SaajSoapMessage) response; SOAPMessage soapMessage = saajSoapMessage.getSaajMessage(); SOAPPart soapPart = soapMessage.getSOAPPart(); SOAPEnvelope envelope = soapPart.getEnvelope(); SOAPBody body = envelope.getBody(); Iterator responses = body .getChildElements(new QName("http://xroad.vrk.fi/xroad-catalog-lister", "GetWsdlResponse")); while (responses.hasNext()) { Node wsdlResponse = (Node) responses.next(); NodeList children = wsdlResponse.getChildNodes(); for (int i = 0; i < children.getLength(); i++) { Node child = children.item(i); if (child.getLocalName().equals("wsdl")) { CDATASection cdat = soapPart.createCDATASection(child.getFirstChild().getNodeValue()); child.removeChild(child.getFirstChild()); child.appendChild(cdat); }// www.j av a 2s. com } } return true; }
From source file:cl.nic.dte.net.ConexionSii.java
@SuppressWarnings("unchecked") private RESPUESTADocument getEstadoDTE(String rutConsultante, Documento dte, String token, String urlSolicitud) throws UnsupportedOperationException, SOAPException, MalformedURLException, XmlException { String rutEmisor = dte.getEncabezado().getEmisor().getRUTEmisor(); String rutReceptor = dte.getEncabezado().getReceptor().getRUTRecep(); Integer tipoDTE = dte.getEncabezado().getIdDoc().getTipoDTE().intValue(); long folioDTE = dte.getEncabezado().getIdDoc().getFolio(); String fechaEmision = Utilities.fechaEstadoDte .format(dte.getEncabezado().getIdDoc().getFchEmis().getTime()); long montoTotal = dte.getEncabezado().getTotales().getMntTotal(); 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();/*from w w w.j av a2 s .co m*/ Name bodyName = envelope.createName("getEstDte", "m", urlSolicitud); SOAPBodyElement gltp = body.addBodyElement(bodyName); Name toKname = envelope.createName("RutConsultante"); SOAPElement toKsymbol = gltp.addChildElement(toKname); toKsymbol.addTextNode(rutConsultante.substring(0, rutConsultante.length() - 2)); toKname = envelope.createName("DvConsultante"); toKsymbol = gltp.addChildElement(toKname); toKsymbol.addTextNode(rutConsultante.substring(rutConsultante.length() - 1, rutConsultante.length())); toKname = envelope.createName("RutCompania"); toKsymbol = gltp.addChildElement(toKname); toKsymbol.addTextNode(rutEmisor.substring(0, rutEmisor.length() - 2)); toKname = envelope.createName("DvCompania"); toKsymbol = gltp.addChildElement(toKname); toKsymbol.addTextNode(rutEmisor.substring(rutEmisor.length() - 1, rutEmisor.length())); toKname = envelope.createName("RutReceptor"); toKsymbol = gltp.addChildElement(toKname); toKsymbol.addTextNode(rutReceptor.substring(0, rutReceptor.length() - 2)); toKname = envelope.createName("DvReceptor"); toKsymbol = gltp.addChildElement(toKname); toKsymbol.addTextNode(rutReceptor.substring(rutReceptor.length() - 1, rutReceptor.length())); toKname = envelope.createName("TipoDte"); toKsymbol = gltp.addChildElement(toKname); toKsymbol.addTextNode(Integer.toString(tipoDTE)); toKname = envelope.createName("FolioDte"); toKsymbol = gltp.addChildElement(toKname); toKsymbol.addTextNode(Long.toString(folioDTE)); toKname = envelope.createName("FechaEmisionDte"); toKsymbol = gltp.addChildElement(toKname); toKsymbol.addTextNode(fechaEmision); toKname = envelope.createName("MontoDte"); toKsymbol = gltp.addChildElement(toKname); toKsymbol.addTextNode(Long.toString(montoTotal)); toKname = envelope.createName("Token"); toKsymbol = gltp.addChildElement(toKname); toKsymbol.addTextNode(token); message.getMimeHeaders().addHeader("SOAPAction", ""); URL endpoint = new URL(urlSolicitud); SOAPMessage responseSII = con.call(message, endpoint); SOAPPart sp = responseSII.getSOAPPart(); SOAPBody b = sp.getEnvelope().getBody(); for (Iterator<SOAPBodyElement> res = b.getChildElements( sp.getEnvelope().createName("getEstDteResponse", "ns1", urlSolicitud)); res.hasNext();) { for (Iterator<SOAPBodyElement> ret = res.next().getChildElements( sp.getEnvelope().createName("getEstDteReturn", "ns1", urlSolicitud)); ret.hasNext();) { HashMap<String, String> namespaces = new HashMap<String, String>(); namespaces.put("", "http://www.sii.cl/XMLSchema"); XmlOptions opts = new XmlOptions(); opts.setLoadSubstituteNamespaces(namespaces); return RESPUESTADocument.Factory.parse(ret.next().getValue(), opts); } } return null; }
From source file:cl.nic.dte.net.ConexionSii.java
@SuppressWarnings("unchecked") private String getSemilla() throws UnsupportedOperationException, SOAPException, IOException, XmlException, ConexionSiiException { 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();/*from w ww. jav a 2 s . com*/ String urlSolicitud = Utilities.netLabels.getString("URL_SOLICITUD_SEMILLA"); Name bodyName = envelope.createName("getSeed", "m", urlSolicitud); message.getMimeHeaders().addHeader("SOAPAction", ""); body.addBodyElement(bodyName); URL endpoint = new URL(urlSolicitud); SOAPMessage responseSII = con.call(message, endpoint); SOAPPart sp = responseSII.getSOAPPart(); SOAPBody b = sp.getEnvelope().getBody(); cl.sii.xmlSchema.RESPUESTADocument resp = null; for (Iterator<SOAPBodyElement> res = b.getChildElements( sp.getEnvelope().createName("getSeedResponse", "ns1", urlSolicitud)); res.hasNext();) { for (Iterator<SOAPBodyElement> ret = res.next().getChildElements( sp.getEnvelope().createName("getSeedReturn", "ns1", urlSolicitud)); ret.hasNext();) { HashMap<String, String> namespaces = new HashMap<String, String>(); namespaces.put("", "http://www.sii.cl/XMLSchema"); XmlOptions opts = new XmlOptions(); opts.setLoadSubstituteNamespaces(namespaces); resp = RESPUESTADocument.Factory.parse(ret.next().getValue(), opts); } } if (resp != null && resp.getRESPUESTA().getRESPHDR().getESTADO() == 0) { return resp.getRESPUESTA().getRESPBODY().getSEMILLA(); } else { throw new ConexionSiiException( "No obtuvo Semilla: Codigo: " + resp.getRESPUESTA().getRESPHDR().getESTADO() + "; Glosa: " + resp.getRESPUESTA().getRESPHDR().getGLOSA()); } }
From source file:cl.nic.dte.net.ConexionSii.java
@SuppressWarnings("unchecked") public String getToken(PrivateKey pKey, X509Certificate cert) throws NoSuchAlgorithmException, InvalidAlgorithmParameterException, KeyException, MarshalException, XMLSignatureException, SAXException, IOException, ParserConfigurationException, XmlException, UnsupportedOperationException, SOAPException, ConexionSiiException { String urlSolicitud = Utilities.netLabels.getString("URL_SOLICITUD_TOKEN"); String semilla = getSemilla(); GetTokenDocument req = GetTokenDocument.Factory.newInstance(); req.addNewGetToken().addNewItem().setSemilla(semilla); HashMap<String, String> namespaces = new HashMap<String, String>(); namespaces.put("", "http://www.sii.cl/SiiDte"); XmlOptions opts = new XmlOptions(); opts = new XmlOptions(); opts.setSaveImplicitNamespaces(namespaces); opts.setLoadSubstituteNamespaces(namespaces); opts.setSavePrettyPrint();/*from w ww . ja v a 2 s . c o m*/ opts.setSavePrettyPrintIndent(0); req = GetTokenDocument.Factory.parse(req.newInputStream(opts), opts); // firmo req.sign(pKey, cert); 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("getToken", "m", urlSolicitud); SOAPBodyElement gltp = body.addBodyElement(bodyName); Name toKname = envelope.createName("pszXml"); SOAPElement toKsymbol = gltp.addChildElement(toKname); opts = new XmlOptions(); opts.setCharacterEncoding("ISO-8859-1"); opts.setSaveImplicitNamespaces(namespaces); toKsymbol.addTextNode(req.xmlText(opts)); message.getMimeHeaders().addHeader("SOAPAction", ""); URL endpoint = new URL(urlSolicitud); message.writeTo(System.out); SOAPMessage responseSII = con.call(message, endpoint); SOAPPart sp = responseSII.getSOAPPart(); SOAPBody b = sp.getEnvelope().getBody(); cl.sii.xmlSchema.RESPUESTADocument resp = null; for (Iterator<SOAPBodyElement> res = b.getChildElements( sp.getEnvelope().createName("getTokenResponse", "ns1", urlSolicitud)); res.hasNext();) { for (Iterator<SOAPBodyElement> ret = res.next().getChildElements( sp.getEnvelope().createName("getTokenReturn", "ns1", urlSolicitud)); ret.hasNext();) { namespaces = new HashMap<String, String>(); namespaces.put("", "http://www.sii.cl/XMLSchema"); opts.setLoadSubstituteNamespaces(namespaces); resp = RESPUESTADocument.Factory.parse(ret.next().getValue(), opts); } } if (resp != null && resp.getRESPUESTA().getRESPHDR().getESTADO() == 0) { return resp.getRESPUESTA().getRESPBODY().getTOKEN(); } else { throw new ConexionSiiException( "No obtuvo Semilla: Codigo: " + resp.getRESPUESTA().getRESPHDR().getESTADO() + "; Glosa: " + resp.getRESPUESTA().getRESPHDR().getGLOSA()); } }
From source file:net.sf.jasperreports.olap.xmla.JRXmlaQueryExecuter.java
/** * Parses the result-Message into this class's structure * //w ww . j a v a2 s .c om * @param reply * The reply-Message from the Server */ protected void parseResult(SOAPMessage reply) throws SOAPException { SOAPPart soapPart = reply.getSOAPPart(); SOAPEnvelope soapEnvelope = soapPart.getEnvelope(); SOAPBody soapBody = soapEnvelope.getBody(); SOAPElement eElement = null; if (log.isDebugEnabled()) { log.debug("XML/A result envelope: " + prettyPrintSOAP(soapEnvelope)); } SOAPFault fault = soapBody.getFault(); if (fault != null) { handleResultFault(fault); } Name eName = soapEnvelope.createName("ExecuteResponse", "", XMLA_URI); // Get the ExecuteResponse-Node Iterator<?> responseElements = soapBody.getChildElements(eName); if (responseElements.hasNext()) { Object eObj = responseElements.next(); if (eObj == null) { throw new JRRuntimeException(EXCEPTION_MESSAGE_KEY_XMLA_NULL_ELEMENT, new Object[] { "ExecuteResponse" }); } eElement = (SOAPElement) eObj; } else { throw new JRRuntimeException(EXCEPTION_MESSAGE_KEY_XMLA_CANNOT_RETRIEVE_ELEMENT, new Object[] { "ExecuteResponse" }); } // Get the return-Node Name rName = soapEnvelope.createName("return", "", XMLA_URI); Iterator<?> returnElements = eElement.getChildElements(rName); SOAPElement returnElement = null; if (returnElements.hasNext()) { Object eObj = returnElements.next(); if (eObj == null) { throw new JRRuntimeException(EXCEPTION_MESSAGE_KEY_XMLA_NULL_ELEMENT, new Object[] { "return" }); } returnElement = (SOAPElement) eObj; } else { // Should be old-Microsoft XMLA-SDK. Try without m-prefix Name rName2 = soapEnvelope.createName("return", "", ""); returnElements = eElement.getChildElements(rName2); if (returnElements.hasNext()) { Object eObj = returnElements.next(); if (eObj == null) { throw new JRRuntimeException(EXCEPTION_MESSAGE_KEY_XMLA_NULL_ELEMENT, new Object[] { "return" }); } returnElement = (SOAPElement) eObj; } else { throw new JRRuntimeException(EXCEPTION_MESSAGE_KEY_XMLA_CANNOT_RETRIEVE_ELEMENT, new Object[] { "return" }); } } // Get the root-Node Name rootName = soapEnvelope.createName("root", "", MDD_URI); SOAPElement rootElement = null; Iterator<?> rootElements = returnElement.getChildElements(rootName); if (rootElements.hasNext()) { Object eObj = rootElements.next(); if (eObj == null) { throw new JRRuntimeException(EXCEPTION_MESSAGE_KEY_XMLA_NULL_ELEMENT, new Object[] { "root" }); } rootElement = (SOAPElement) eObj; } else { throw new JRRuntimeException(EXCEPTION_MESSAGE_KEY_XMLA_CANNOT_RETRIEVE_ELEMENT, new Object[] { "root" }); } // Get the OlapInfo-Node Name olapInfoName = soapEnvelope.createName("OlapInfo", "", MDD_URI); SOAPElement olapInfoElement = null; Iterator<?> olapInfoElements = rootElement.getChildElements(olapInfoName); if (olapInfoElements.hasNext()) { Object eObj = olapInfoElements.next(); if (eObj == null) { throw new JRRuntimeException(EXCEPTION_MESSAGE_KEY_XMLA_NULL_ELEMENT, new Object[] { "OlapInfo" }); } olapInfoElement = (SOAPElement) eObj; } else { throw new JRRuntimeException(EXCEPTION_MESSAGE_KEY_XMLA_CANNOT_RETRIEVE_ELEMENT, new Object[] { "OlapInfo" }); } parseOLAPInfoElement(olapInfoElement); // Get the Axes Element Name axesName = soapEnvelope.createName("Axes", "", MDD_URI); SOAPElement axesElement = null; Iterator<?> axesElements = rootElement.getChildElements(axesName); if (axesElements.hasNext()) { Object eObj = axesElements.next(); if (eObj == null) { throw new JRRuntimeException(EXCEPTION_MESSAGE_KEY_XMLA_NULL_ELEMENT, new Object[] { "Axes" }); } axesElement = (SOAPElement) eObj; } else { throw new JRRuntimeException(EXCEPTION_MESSAGE_KEY_XMLA_CANNOT_RETRIEVE_ELEMENT, new Object[] { "Axes" }); } parseAxesElement(axesElement); // Get the CellData Element Name cellDataName = soapEnvelope.createName("CellData", "", MDD_URI); SOAPElement cellDataElement = null; Iterator<?> cellDataElements = rootElement.getChildElements(cellDataName); if (cellDataElements.hasNext()) { Object eObj = cellDataElements.next(); if (eObj == null) { throw new JRRuntimeException(EXCEPTION_MESSAGE_KEY_XMLA_NULL_ELEMENT, new Object[] { "CellData" }); } cellDataElement = (SOAPElement) eObj; } else { throw new JRRuntimeException(EXCEPTION_MESSAGE_KEY_XMLA_CANNOT_RETRIEVE_ELEMENT, new Object[] { "CellData" }); } parseCellDataElement(cellDataElement); }
From source file:com.jaspersoft.ireport.designer.data.fieldsproviders.olap.OLAPQueryExecuter.java
/** * Parses the result-Message into this class's structure * * @param reply// ww w . j av a2s . c om * The reply-Message from the Server */ protected void parseResult(SOAPMessage reply) throws SOAPException, JRRuntimeException { SOAPPart soapPart = reply.getSOAPPart(); SOAPEnvelope soapEnvelope = soapPart.getEnvelope(); SOAPBody soapBody = soapEnvelope.getBody(); SOAPElement eElement = null; if (log.isDebugEnabled()) { log.debug("XML/A result envelope: " + soapEnvelope.toString()); } SOAPFault fault = soapBody.getFault(); if (fault != null) { handleResultFault(fault); } Name eName = soapEnvelope.createName("ExecuteResponse", "", XMLA_URI); // Get the ExecuteResponse-Node Iterator responseElements = soapBody.getChildElements(eName); if (responseElements.hasNext()) { Object eObj = responseElements.next(); if (eObj == null) { log.error("ExecuteResponse Element is null."); throw new JRRuntimeException("ExecuteResponse Element is null."); } eElement = (SOAPElement) eObj; } else { log.error("Could not retrieve ExecuteResponse Element."); throw new JRRuntimeException("Could not retrieve ExecuteResponse Element."); } // Get the return-Node Name rName = soapEnvelope.createName("return", "", XMLA_URI); Iterator returnElements = eElement.getChildElements(rName); SOAPElement returnElement = null; if (returnElements.hasNext()) { Object eObj = returnElements.next(); if (eObj == null) { log.error("return Element is null."); throw new JRRuntimeException("return Element is null."); } returnElement = (SOAPElement) eObj; } else { // Should be old-Microsoft XMLA-SDK. Try without m-prefix Name rName2 = soapEnvelope.createName("return", "", ""); returnElements = eElement.getChildElements(rName2); if (returnElements.hasNext()) { Object eObj = returnElements.next(); if (eObj == null) { log.error("return Element is null."); throw new JRRuntimeException("return Element is null."); } returnElement = (SOAPElement) eObj; } else { log.error("Could not retrieve return Element."); throw new JRRuntimeException("Could not retrieve return Element."); } } // Get the root-Node Name rootName = soapEnvelope.createName("root", "", MDD_URI); SOAPElement rootElement = null; Iterator rootElements = returnElement.getChildElements(rootName); if (rootElements.hasNext()) { Object eObj = rootElements.next(); if (eObj == null) { log.error("root Element is null."); throw new JRRuntimeException("root Element is null."); } rootElement = (SOAPElement) eObj; } else { log.error("Could not retrieve root Element."); throw new JRRuntimeException("Could not retrieve root Element."); } // Get the OlapInfo-Node Name olapInfoName = soapEnvelope.createName("OlapInfo", "", MDD_URI); SOAPElement olapInfoElement = null; Iterator olapInfoElements = rootElement.getChildElements(olapInfoName); if (olapInfoElements.hasNext()) { Object eObj = olapInfoElements.next(); if (eObj == null) { log.error("OlapInfo Element is null."); throw new JRRuntimeException("OlapInfo Element is null."); } olapInfoElement = (SOAPElement) eObj; } else { log.error("Could not retrieve OlapInfo Element."); throw new JRRuntimeException("Could not retrieve OlapInfo Element."); } parseOLAPInfoElement(olapInfoElement); // Get the Axes Element Name axesName = soapEnvelope.createName("Axes", "", MDD_URI); SOAPElement axesElement = null; Iterator axesElements = rootElement.getChildElements(axesName); if (axesElements.hasNext()) { Object eObj = axesElements.next(); if (eObj == null) { log.error("Axes Element is null"); throw new JRRuntimeException("Axes Element is null"); } axesElement = (SOAPElement) eObj; } else { log.error("Could not retrieve Axes Element."); throw new JRRuntimeException("Could not retrieve Axes Element."); } parseAxesElement(axesElement); // Get the CellData Element Name cellDataName = soapEnvelope.createName("CellData", "", MDD_URI); SOAPElement cellDataElement = null; Iterator cellDataElements = rootElement.getChildElements(cellDataName); if (cellDataElements.hasNext()) { Object eObj = cellDataElements.next(); if (eObj == null) { log.error("CellData element is null"); throw new JRRuntimeException("CellData element is null"); } cellDataElement = (SOAPElement) eObj; } else { log.error("Could not retrieve CellData Element."); throw new JRRuntimeException("Could not retrieve CellData Element."); } parseCellDataElement(cellDataElement); }