cancel
Showing results for 
Search instead for 
Did you mean: 

Java code to add message to existing payload

Former Member
0 Kudos

Hello experts,

<br><br>

I have build an J2ee adapter module. To help me build this I let inspire throw document:

<br><br>

href="https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/docs/library/uuid/02706f11-0d01-0010-e5ae-ac25e74c4c81">How

to create modules for the j2ee adapter <span class=SpellE>engine.pdf</span>

<br><br>

The document describes an example of building an adapter module that creates a new payload in XI and send it with the mailadapter to an e-mailadres.

<br><br>

I would like to create an adapter module that adds a new element to an existing payload.

<br><br>

for example:

<br><br>

I have a data structure like:

<br><br>

<mt_example>

<Element1></Element1>

<Element2></Element2>

<Element3></Element3>

</mt_example>

<br><br>

XI processes the file. Now the adapter module has to add the element <signature>Luc Hermans</signature> to the XI Payload so the XML file finally looks like

<br><br>

<mt_example>

<Element1></Element1>

<Element2></Element2>

<Element3></Element3>

<signature>Luc Hermans</signature>

</mt_example>

<br><br>

I know how to build the J2EE adapter, but I don’t know the code to realise this. Anyone an idea? It had to be something like under need but this only creates an new message with the value Luc Hermans into the payload.

<br><br>

package sample;<br>

import javax.ejb.CreateException;<br>

import javax.ejb.SessionBean;<br>

import javax.ejb.SessionContext;<br>

import com.sap.aii.af.mp.module.*;<br>

import com.sap.aii.af.ra.ms.api.*;<br>

/**<br>

  • @ejbHome <{com.sap.aii.af.mp.module.ModuleHome}><br>

  • @ejbLocal <{com.sap.aii.af.mp.module.ModuleLocal}><br>

  • @ejbLocalHome <{com.sap.aii.af.mp.module.ModuleLocalHome}><br>

  • @ejbRemote <{com.sap.aii.af.mp.module.ModuleRemote}><br>

  • @stateless<br>

*/<br>

public class CreateAttachment implements SessionBean, Module{<br>

private SessionContext myContext;<br>

public void ejbRemove() {<br>

}<br>

public void ejbActivate() {<br>

}<br>

public void ejbPassivate() {<br>

}<br>

public void setSessionContext(SessionContext context) {<br>

myContext = context;<br>

}<br>

public void ejbCreate() throws CreateException {<br>

}<br>

public ModuleData process(ModuleContext moduleContext,<br>

ModuleData inputModuleData)<br>

throws ModuleException {<br>

<br><br>

// create a second attachment for the receiver mail adapter<br>

try {<br>

// get the XI message from the environment<br>

Message msg = (Message)<br>

inputModuleData.getPrincipalData();<br>

// create a new payload<br>

TextPayload attachment = msg.createTextPayload();<br>

// provide attributes and content for the new payload<br>

attachment.setName("Attachment");<br>

attachment.setContentType("text/plain");<br>

attachment.setText("Luc Hermans");<br>

// add the new payload as attachment to the message<br>

msg.addAttachment(attachment);<br>

// provide the XI message for returning<br>

inputModuleData.setPrincipalData(msg);<br>

} catch (Exception e) {<br>

// raise exception, when an error occurred<br>

ModuleException me = new ModuleException(e);<br>

throw me;<br>

}<br>

// return XI message<br>

return inputModuleData;<br>

}<br>

<br><br>

I don't know if it's possible to write an User Defiend function that can add the message from the payload and put it into the xml by an message mapping?<br><br>

Accepted Solutions (0)

Answers (2)

Answers (2)

henrique_pinto
Active Contributor
0 Kudos

Dude,

an attachment is like another payload in the same message (which has a main payload). It is not like your scenario.

You don't need a custom module at all for that. Just go for message mapping.

And if you do want to implement a full XML Digital Signature compliant signature field (as described in http://www.w3.org/TR/xmldsig-core/), refer to the Digital Signatures and Document Encryption API:

http://help.sap.com/saphelp_nw04s/helpdata/en/4f/65c3b32107964996a56e4165077e24/frameset.htm

In this case you'll need a java mapping or a custom module (java mapping is way easier, tho) to perform the signature, as described in the example:

http://help.sap.com/saphelp_nw04s/helpdata/en/a4/d0201854fb6a4cb9545892b49d4851/frameset.htm

Regards,

Henrique.

Former Member
0 Kudos

Hi,

See the below links may be useful...

Sender mail adapter - PayloadSwapBean - Step by step -/people/michal.krawczyk2/blog/2005/12/18/xi-sender-mail-adapter--payloadswapbean--step-by-step

SAPconnect - The Interface in the R/3 System for E-Mail/Fax Systems -

https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/4b4fa090-0201-0010-d3b7-b233296d...

Also you can use the alert management and configure the scot and use the sender spicific , mail address in user by su01, and finally raise an alert from payload .

Alerts with variables from the messages payload (XI) - UPDATED - /people/michal.krawczyk2/blog/2005/03/13/alerts-with-variables-from-the-messages-payload-xi--updated

Triggering XI Alerts from a User Defined Function - /people/bhavesh.kantilal/blog/2006/07/25/triggering-xi-alerts-from-a-user-defined-function

Regards

Chilla