Mapping campi facoltativi
Alimentare l’elemento target solo se l’elemento source non è vuoto.
Tutti gli altri campi, gregari dell’elemento master, possono essere mappati senza alcun controllo ulteriore.
Alimentare l’elemento target solo se l’elemento source non è vuoto.
Tutti gli altri campi, gregari dell’elemento master, possono essere mappati senza alcun controllo ulteriore.
public Reference getReference(String idRole,String idUser){ String sql="SELECT * FROM refers WHERE id_role=? AND id_user=?"; Reference ref=(Reference)jdbcTemplate.queryForObject(sql, new Object[]{idRole,idUser},new BeanPropertyRowMapper(Reference.class){ public Reference extractData(ResultSet rs) throws SQLException,DataAccessException{ Reference ref=new Reference(); ref.setId(rs.getInt("id")); ref.setIdRole(rs.getString("id_role")); ref.setIdUser(rs.getString("id_user")); ref.setDescription(rs.getString("description")); return ref; } });
public String getUsernameBySapCode(StringsapCode){ String sql = "SELECT username FROM users WHERE sap_code=?"; String uname=(String)jdbcTemplate.queryForObject(sql,newObject[]{sapCode},String.class); return uname; }
Per passare da un form ad un altro si può ricorrere a “redirect:/index” che però non mantiene il contesto
ModelAndView mav=new ModelAndView("redirect:/index"));
oppure a RedirectView() che consente di conservare il contesto
String path=retContextPath(); ModelAndView mav=new ModelAndView(new RedirectView(path+"/index"));
Questa modalità richiede che venga passato il ContextPath che può essere ricavato nel modo seguente
/** * Ritorna il contextPath dall'URL. * Prerequisito: la classe controller deve dichiarare * @Autowired * private ApplicationContext appContext; * * @author N4N * @return */ private String retContextPath(){ String ctx = appContext.getId(); String path = ctx.substring(ctx.indexOf(":")+1); path = path.substring(0,path.indexOf("/",1)); return path; }
has_content
[#if refs?has_content] [#list refs as ref]${ref.getDescription()}[/#list] [/#if]
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>
<?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>
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.
FUNCTION ZN4N_PI_MESSAGE_DATA_GETLIST. *"---------------------------------------------------------------------- *"*"Local Interface: *" IMPORTING *" VALUE(IM_MESSAGE_LIST) TYPE SXMSMGUIDT *" EXPORTING *" VALUE(EX_MESSAGE_DATA_LIST) TYPE SXI_MESSAGE_DATA_LIST *" EXCEPTIONS *" NOT_AUTHORIZED *"---------------------------------------------------------------------- data: lv_guid type SXMSMGUID, ls_msgguid TYPE sxmsmguid, IM_PIPELINE_LIST TYPE SXMS_TAB_SXMSPID, lv_init_date type D, lv_init_time type T, lv_exe_date type D, lv_exe_time type T, lv_msg type SXI_MESSAGE_DATA . LOOP AT IM_MESSAGE_LIST INTO lv_guid. * ls_msgguid = lv_guid. clear IM_PIPELINE_LIST. CALL FUNCTION 'SXMB_GET_MESSAGE_DATA' EXPORTING IM_MESSAGE_LIST = IM_MESSAGE_LIST IM_PIPELINE_LIST = IM_PIPELINE_LIST IMPORTING EX_MESSAGE_DATA_LIST = EX_MESSAGE_DATA_LIST EXCEPTIONS NOT_AUTHORIZED = 1 OTHERS = 2. IF SY-SUBRC <> 0. * MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO * WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4. ENDIF. clear lv_msg. loop at EX_MESSAGE_DATA_LIST into lv_msg. CONVERT TIME STAMP lv_msg-INITTIMEST TIME ZONE sy-zonlo INTO DATE lv_init_date TIME lv_init_time. CONVERT TIME STAMP lv_msg-EXETIMEST TIME ZONE sy-zonlo INTO DATE lv_exe_date TIME lv_exe_time. * APPEND ls_msgguid TO rt_msgguid. ENDLOOP. ENDLOOP. ENDFUNCTION.
*&---------------------------------------------------------------------* *& Report ZSD001_TEST_OMC *& *&---------------------------------------------------------------------* *& *& *&---------------------------------------------------------------------* report zsd001_test_omc. data: my_interface type ref to zsdco_si_sd001_esito_ordini_ob, my_request type zsdmt_sd001_esito_ordini. * my_response type zmy_response_message_type. * create instance create object my_interface. * fill request data my_request-mt_sd001_esito_ordini-numero_ordine = '12345'. my_request-mt_sd001_esito_ordini-seriale = '123443545'. my_request-mt_sd001_esito_ordini-codice_esito_ordine = '51007'. my_request-mt_sd001_esito_ordini-descrizione_esito = 'Cliente inesistente'. * call proxy try. call method my_interface->si_sd001_esito_ordini_ob exporting output = my_request * importing * input = my_response. . catch cx_ai_system_fault . catch cx_ai_application_fault . endtry. commit work and wait.