Concatenare un array in una stringa

Utile nel caso di testi in cui ogni riga è un context e occorre ridurli tutti al valore di un unico campo

Il risultato della JoinInContainer() è salvato in un container il cui contenuto viene mosso nel campo target.

Includere le seguenti librerie:

N4NGeneralLibrary.jar

N4NPILibrary.jar

Includere i seguenti namespace:

com.n4n.std.*

com.n4n.std.xi.tools.*

Creare un UDF di tipo All Values of a Context.

public void JoinInContainer(String[] name, String[] arr, ResultList result, Container container) throws StreamTransformationException{
/*
name: Nome container di output
arr: Array contenente le stringhe da concatenare.

Concatena le stringhe corrispondenti agli elementi di arr separandole con spazio.
La stringa ottenuta è storicizzata nel container name.
*/
      if (StringManager.isArrayNull(arr)) {
				String[] tx = {""};
				Utils.loadArrayInContainer(name[0], tx, container);
      }

      String t = "";
      for (int i = 0; i < arr.length; i++) {
         if (!StringManager.isStringNull(arr[i])) {
            t += arr[i] + " ";
         }
      }

String[] txt = { t };
Utils.loadArrayInContainer(name[0], txt, container);
}
public String RestoreFromContainer(String name, String dummy1, Container container) throws StreamTransformationException{
/*
name:  Nome container
dummy1: 

Ritorna il valore storicizzato nel container name. Il parametro dummy serve esclusivamente nel mapping grafico 
per legare all’oggetto RestoreFromContainer il blocchetto che lo precede.
*/

GlobalContainer gc = container.getGlobalContainer(); 
String[] g = (String[]) gc.getParameter( name );  // il cast è in funzione di cosa ritorna la getParameter(), per es., potrebbe essere String
String ret = "";
if (!StringManager.isStringNull(g[0])) {
	ret = g[0];
}

return ret;

}

HTTP 415 Error

Utilizzando un adapter SOAP ed impostando il flag Don’t use SOAP Envelop, il messaggio receiver potrebbe fallire con il seguente errore
HTTP 415 Unsupported Media Type with SOAP adapter trying to put SOAP header

AF_Modules/MessageTransformBean
Transform.ContentType application/xml (per esempio)

Modificare il Content-Type con quello opportuno aggiungendo al canale SOAP Receiver, prima del XISOAPAdapterBean, il seguente modulo e relativa parametrizzazione:

http_415_error


Dynamic Configuration JMS DCJMSCorrelationID

Per i flussi verso JMS Web Logic occorre definire nella dynamic configuration l’attributo DCJMSCorreleationID.
Dal momento che questo attributo non è esposto dalla ASMA occorre valorizzarlo da mapping con la seguente UDF.

public String setCorrelationID(String corID, Container container) throws StreamTransformationException{

	container.getTransformationParameters().put(StreamTransformationConstants.CONVERSATION_ID, corID);
	DynamicConfiguration conf = (DynamicConfiguration)                                container.getTransformationParameters().get(StreamTransformationConstants.DYNAMIC_CONFIGURATION);
	
	DynamicConfigurationKey key = DynamicConfigurationKey.create("http://sap.com/xi/XI/System/JMS", "DCJMSCorreleationID");
	conf.put(key, corID);
	
	return "";

}
Dynamic Configuration JMS DCJMSCorreleationID

Dynamic Configuration set FileName

public String setDynConfFilename(String filename, String dummy, Container container) throws StreamTransformationException{
	/**
	 * Imposta il filename nel dynamic configuration parameter FileName della chiave http://sap.com/xi/XI/System/File.
	*/
	
	if ( filename.trim().length() == 0) return "";
	
	DynamicConfiguration conf1 = (DynamicConfiguration) container.getTransformationParameters()
						.get(StreamTransformationConstants.DYNAMIC_CONFIGURATION);
	DynamicConfigurationKey key1 = DynamicConfigurationKey.create( "http://sap.com/xi/XI/System/File","FileName");
	
	conf1.put(key1,filename);
	
	return filename;
}
Dynamic Configuration set FileName

Dynamic Configuration get FileName

UDF per ottenere il nome del file del communication channel file tramite la ASMA, Adapter-Specific Message Attribute, “http://sap.com/xi/XI/System/File” “FileName” delle Dynamic Configuration.

public String getDynConfFilename(Container container) throws StreamTransformationException{
	/*
	Ritorna la chiave "http://sap.com/xi/XI/System/File" "Directory" delle Dynamic Configuration.
	*/
	
	DynamicConfiguration dc = (DynamicConfiguration) container
					.getTransformationParameters().get(
							StreamTransformationConstants.DYNAMIC_CONFIGURATION);
	
	DynamicConfigurationKey k1 = DynamicConfigurationKey.create("http://sap.com/xi/XI/System/File", 
												"Directory");
	
	return dc.get(k1);

}

XSLT: Eliminare imbustamento SOAP

Elimina l’imbustamento SOAP Envelope dal messaggio di response

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl" xmlns:ns0="urn:SPLA_LOGISTIC_SAP_COMMESSE" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
	<xsl:output method="xml" indent="yes"/>
	<xsl:template match="/">
		<xsl:apply-templates select="soapenv:Envelope/soapenv:Body"/>
	</xsl:template>
	<xsl:template match="soapenv:Body">
		<xsl:copy-of select="*"/>
	</xsl:template>
</xsl:stylesheet>



XSLT: Aggiungere imbustamento SOAP e AuthenticationInfo

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="n0:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl">
	<xsl:output method="xml" indent="yes"/>
	<xsl:template match="/">
		<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance" xmlns:xsd="http://www.w3.org/1999/XMLSchema" xmlns:n0="n0:SPLA_LOGISTIC_SAP_COMMESSE">
			<SOAP-ENV:Header>
				<n0:AuthenticationInfo>
					<n0:userName>Web_Service_SAP</n0:userName>
					<n0:password>9786</n0:password>
					<n0:authentication/>
					<n0:locale/>
					<n0:timeZone/>
				</n0:AuthenticationInfo>
			</SOAP-ENV:Header>
			<SOAP-ENV:Body>
				<xsl:copy-of select="*"/>
			</SOAP-ENV:Body>
		</SOAP-ENV:Envelope>
	</xsl:template>
</xsl:stylesheet>

Ritorna payload del messaggio PI

FUNCTION ZN4N_PI_GET_PAYLOAD .
*"----------------------------------------------------------------------
*"*"Local Interface:
*"  IMPORTING
*"     VALUE(IM_MSGKEY) TYPE  SXMSMKEY
*"  EXPORTING
*"     VALUE(PAYLOAD) TYPE  STRING
*"  EXCEPTIONS
*"      NOT_AUTHORIZED
*"      NO_MESSAGE
*"      INTERNAL_ERROR
*"      NO_PAYLOAD
*"      GENERIC_ERROR
*"----------------------------------------------------------------------
  data: pay_bytes type xstring.
  data: ref_bytes type string.
  data: pay_load  type string.

  CALL FUNCTION 'SXMB_GET_MESSAGE_PAYLOAD'
    EXPORTING
      IM_MSGKEY      = IM_MSGKEY
*     IM_ARCHIVE     =
*     IM_VERSION     =
    IMPORTING
      EX_MSG_BYTES   = pay_bytes
    EXCEPTIONS
      NOT_AUTHORIZED = 1
      NO_MESSAGE     = 2
      INTERNAL_ERROR = 3
      NO_PAYLOAD     = 4
      OTHERS         = 5.
  IF SY-SUBRC <> 0.
    case sy-subrc.
      when 1.
        raise NOT_AUTHORIZED.
      when 2.
        raise NO_MESSAGE.
      when 3.
        raise INTERNAL_ERROR.
      when 4.
        raise NO_PAYLOAD.
      when 5.
        raise GENERIC_ERROR.
    endcase.
  ENDIF.

  try.
      CALL FUNCTION 'ECATT_CONV_XSTRING_TO_STRING'
        EXPORTING
          IM_XSTRING  = pay_bytes
*         IM_ENCODING = 'UTF-8'
        IMPORTING
          EX_STRING   = PAYLOAD.

    catch cx_root.
      raise cx_root.
  endtry.
*
*  data l_filename LIKE  RLGRAP-FILENAME.
*  l_filename  = 'c:\tmp\payload.xml'.
*
*  data: begin of tab occurs 0,
*    field type string,
*    end of tab.
*
*  clear tab.
*  refresh tab.
*
*  tab-field = payload.
*  append tab.
*
*  CALL FUNCTION 'WS_DOWNLOAD'
* EXPORTING
*   FILENAME                      = l_filename
*   FILETYPE                      = 'ASC'
*  TABLES
*    DATA_TAB                      = tab
* EXCEPTIONS
*   FILE_OPEN_ERROR               = 1
*   FILE_WRITE_ERROR              = 2
*   INVALID_FILESIZE              = 3
*   INVALID_TYPE                  = 4
*   NO_BATCH                      = 5
*   UNKNOWN_ERROR                 = 6
*   INVALID_TABLE_WIDTH           = 7
*   GUI_REFUSE_FILETRANSFER       = 8
*   CUSTOMER_ERROR                = 9
*   NO_AUTHORITY                  = 10
*   OTHERS                        = 11
*    .
*  IF SY-SUBRC <> 0.

*  ENDIF.


ENDFUNCTION.