1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 |
import java.io.ByteArrayInputStream; import java.io.InputStream; import java.io.StringWriter; import javax.xml.transform.stream.StreamResult; import com.sap.aii.mapping.api.AbstractTrace; import com.sap.aii.mapping.lookup.*; import com.sap.aii.mappingtool.tf7.rt.*; import javax.xml.transform.dom.DOMSource; import javax.xml.xpath.XPath; import javax.xml.xpath.XPathConstants; import javax.xml.xpath.XPathExpressionException; import javax.xml.xpath.XPathFactory; import javax.xml.parsers.*; import org.w3c.dom.*; /* * Chiamata del communication channel chName relativo al business system receiver busSys. * Il parametro emailValue e' relativo allo specfico webservice e rappresenta il parametro d'ingresso allo stesso. */ public String SOAPinvoke(String chName, String busSys, String emailValue, Container container) { AbstractTrace trace = container.getTrace(); String internalID = ""; try { /* * Pass the Business System and Communication Channel as input to the * getChannel(). * BS_SOAPLOOKUP – Business System * CC_Webservice_SOAP_CURRENCY_CONVERTOR – Receiver SOAP Adapter */ Channel channel = LookupService.getChannel(busSys, chName); SystemAccessor accessor = LookupService.getSystemAccessor(channel); InputStream inputStream = null; /* * Construct the SOAP Request Message using the InputParameters * emailValue is the Input Parameter. */ /* LA SEGUENTE ISTRUZIONE E' RELATIVA ALLO SPECIFICO WEBSERVICE */ Document req = createRequestPayload(emailValue); /* ============================================================ */ String SOAPxml = returnXML(req); inputStream = new ByteArrayInputStream(SOAPxml.getBytes()); XmlPayload payload = LookupService.getXmlPayload(inputStream); /* * The SOAP call is made here and the response obtained is in the * SOAPOutPayload. */ Payload SOAPOutPayload = accessor.call(payload); DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setNamespaceAware(true); DocumentBuilder builder = factory.newDocumentBuilder(); InputStream inp = SOAPOutPayload.getContent(); Document doc = builder.parse(inp); /* LA SEGUENTE ISTRUZIONE E' RELATIVA ALLO SPECIFICO WEBSERVICE */ internalID = returnResponse(doc); /* ============================================================ */ } catch (Exception e) { trace.addWarning("Error" + e); } return internalID; } /* * Crea il payload di request per il webservice da invocare. * Questa funzione dipende dallo specifico webservice. */ private static Document createRequestPayload(String emailValue) throws ParserConfigurationException{ DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setNamespaceAware(true); DocumentBuilder builder = factory.newDocumentBuilder(); Document doc = builder.newDocument(); doc.setXmlStandalone(true); Element el = doc.createElementNS("http://sap.com/xi/SAPGlobal20/Global", "glob:CustomerByElementsQuery_sync"); Node nroot = doc.appendChild(el); Node ncsbe = nroot.appendChild(doc.createElement("CustomerSelectionByElements")); el = doc.createElementNS("http://sap.com/xi/AP/CustomerExtension/BYD/A1WY2", "a1w:ExternalUnicCode_EA8AE8AUBVHCSXVYS0FJ1R3ON"); Node neuc = ncsbe.appendChild(el); Node nsbt = neuc.appendChild(doc.createElement("SelectionByText")); Node niec = nsbt.appendChild(doc.createElement("InclusionExclusionCode")); niec.setTextContent("I"); Node nibtc = nsbt.appendChild(doc.createElement("IntervalBoundaryTypeCode")); nibtc.setTextContent("1"); Node nlbn = nsbt.appendChild(doc.createElement("LowerBoundaryName")); nlbn.setTextContent(emailValue); Node npc = nroot.appendChild(doc.createElement("ProcessingConditions")); Node nqhui = npc.appendChild(doc.createElement("QueryHitsUnlimitedIndicator")); nqhui.setTextContent("false"); return doc; } /* * Ritorna la String relativa al DOM dell'XML. */ private static String returnXML(Document doc) throws javax.xml.transform.TransformerFactoryConfigurationError, javax.xml.transform.TransformerException { javax.xml.transform.Transformer transformer = javax.xml.transform.TransformerFactory.newInstance() .newTransformer(); StringWriter output = new StringWriter(); javax.xml.transform.Source input = new DOMSource(doc); transformer.transform(input, new StreamResult(output)); return output.toString(); } /* * Ritorna il payload relativo alla risposta del webservice invocato. * Questa funzione dipende dallo specifico webservice. */ static private String returnResponse(Document doc) throws XPathExpressionException { XPathFactory xpathfactory = XPathFactory.newInstance(); XPath xpath = xpathfactory.newXPath(); Node nroot = ((NodeList) xpath.compile("//InternalID/text()").evaluate( doc, XPathConstants.NODESET)).item(0); return nroot.getNodeValue(); } |