JDBC Lookup su Oracle

Il wizard di creazione dell’External Definition (dbtab) relativo alla tabella di lookup non vede la tabella in oggetto.

La ragione risiede nel fatto che all’utenza oracle utilizzata nel cc non è associato lo schema a cui la tabella appartiene.

Dal momento che il communication channel da utilizzare per la JDBC Lookup è un receiver, non è possibile associargli una query nella quale specificare lo schema Oracle; non è neppure possibile (per Oracle) indicare lo schema nella stringa di connessione JDBC.

A cura del dba, occorre far definire come schema di default dell’utenza utilizzata nel cc JDBC receiver quello a cui appartiene la tabella in oggetto.


Importare nuovo Idoc custom

Per importare un Idoc custom in PI procedere come segue:

WE31

Creare segmenti + rilascio
WE32 Creare IDoc + rilascio
WE81

Creare message type

WE82 Creare relazione message type / basic type
WE32 Creare view per IDoc

A questo punto l’IDoc può essere importato nell’ESR


Dynamic Configuration URL PlainHTTP

Assegnazione URL a cc PlainHTTP in modalità Assign Type URL Address

Assegnazione URL a cc PlainHTTP in modalità Assign Type HTTP Destination
public String PlainHTTPDestDynConf(String value, Container container) 
	throws StreamTransformationException{ 
	try { 
		String url = value; 
		DynamicConfiguration conf = (DynamicConfiguration) container .getTransformationParameters() .get(StreamTransformationConstants.DYNAMIC_CONFIGURATION); 
		DynamicConfigurationKey key=DynamicConfigurationKey.create("http://sap.com/xi/XI/System/HTTP", "TargetURL"); 
		conf.put(key, url); 
		return url; 
	} catch(Exception e) { 
		String exception = e.toString(); 
		return exception; 
	} 
}

getTimestamp()

   public String getTimestamp(Container container) throws StreamTransformationException {
      String DATE_FORMAT_NOW = "yyyyMMdd_HHmmss_SSS";
      Calendar cal = Calendar.getInstance();
      java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat(DATE_FORMAT_NOW);
      return sdf.format(cal.getTime());
   }

GlobalContainer

Per condividere un valore fra le UDF di un mapping

   public String initCounter(Container container) throws StreamTransformationException {
      container.getGlobalContainer().setParameter("COUNTER", "0");
      return in;
   }

   public String increaseCounter(Container container) throws StreamTransformationException {
      int theCounter = (new Integer((String) container.getGlobalContainer().getParameter("COUNTER"))).intValue();
      theCounter++;
      container.getGlobalContainer().setParameter("COUNTER", String.valueOf(theCounter));
      return String.valueOf(theCounter);
   }

getSystemName

Utile come input ad un FixedValue laddove l’output dipende dal tipo di ambiente sviluppo, test o produzione.

   public String getSystemName(String dummy, Container container) throws StreamTransformationException{
      /* Ritorna il SysID dell'istanza PI in esecuzione */
      return System.getProperty("SAPSYSTEMNAME");
   }

SOAPLookup

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();
}