Java Mapping: payload as mail attachment and dynamic file name .

Hi,
I have written this piece of java code.
The code includes XPATH for fetching dynamic filename and the copysource( in, out ) to copy the content of payload as mail attchment.
The code seems to work fine, when either of the functionality is implemented.
but when both are implemented together ie parsing for xpath then again parsing to copy payload, then it doesnt executes the latter path i.e the payload is not fetched in the attachment.
public class MailPackage implements StreamTransformation {
  public void setParameter(Map map) {
  public void execute(InputStream in, OutputStream out)
          throws StreamTransformationException {
  String mailSubject = "test mail";
  String mailSender = "aaaaaaaa";
  String mailReceiver = "[email protected]";
  String attachmentName = null;
  DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = null;
  factory.setNamespaceAware(false);
factory.setValidating(false);
     try {
          builder = factory.newDocumentBuilder();
     Document doc = null;
      doc = builder.parse(in);
          String XPATH ="/*/Invoice/InvoiceHeader/InvoiceNumber/text()";
          Node fieldValueNode = org.apache.xpath.XPathAPI.selectSingleNode(doc,XPATH);
          System.out.print(fieldValueNode);
          attachmentName = fieldValueNode.getNodeValue() +".xml";
  String boundary = "--";
  String mailContent = "This is a sample file";
  String CRLF = "\r\n";
    //     create XML structure of mail package
    String output ="<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
           + "<ns:Mail xmlns:ns=\"http://sap.com/xi/XI/Mail/30\">"
           + "<Subject>" + mailSubject     + "</Subject>"
           + "<From>" + mailSender     + "</From>"
           + "<To>" + mailReceiver     + "</To>"
           + "<Content_Type>multipart/mixed; boundary=\"" + boundary + "\"</Content_Type>"
           + "<Content>";
    out.write(output.getBytes());
    // create the declaration of the MIME parts
    //First part
    output = "--" + boundary + CRLF
           + "Content-Type: text/plain; charset=UTF-8" + CRLF
           + "Content-Disposition: inline" + CRLF + CRLF
           + mailContent + CRLF
    //Second part
    + "--" + boundary + CRLF
    + "Content-Type: application/xml; name=" + attachmentName + CRLF
    + "Content-Disposition: attachment; filename=" + attachmentName + CRLF + CRLF;
    out.write(output.getBytes());
    //Source is taken as attachment
    copySource(in, out);
    out.write("</Content></ns:Mail>".getBytes());
  } catch (Exception ie) {
    throw new StreamTransformationException(ie.getMessage());
protected static void copySource(InputStream in, OutputStream out)throws IOException {
    byte[] bbuf = new byte[in.available()];
    int bblen = in.read(bbuf);
   if (!(bblen < 0)) {
      String sbuf = new String(bbuf);
       //replace all control characters with escape sequences
     sbuf = sbuf.replaceAll("&", "&amp;");
     sbuf = sbuf.replaceAll("\"", "&quot;");
     sbuf = sbuf.replaceAll("'", "&apos;");
    sbuf = sbuf.replaceAll("<", "&lt;");
    sbuf = sbuf.replaceAll(">", "&gt;");
    out.write(sbuf.getBytes());
Povide your suggestions.

Hi,
This is the sample o/p that I get by opening the mail attachment using notepad.
<?xml version="1.0" encoding="UTF-8"?>
<InvoiceTransmission><InvoiceTransmissionHeader><InvoiceCreationDate>2008-12-03T00:00:00</InvoiceCreationDate><Version>2.0.2</Version></InvoiceTransmissionHeader><Invoice><InvoiceHeader><CustomerEntityID>LH</CustomerEntityID><IssuingEntityID>009140559</IssuingEntityID><InvoiceNumber>913353669</InvoiceNumber><InvoiceIssueDate>2008-12-03</InvoiceIssueDate><InvoiceType InvoiceTransactionType="OR">INV</InvoiceType><InvoiceDeliveryLocation>aaa</InvoiceDeliveryLocation><TaxInvoiceNumber>Not Applicable</TaxInvoiceNumber><InvoiceCurrencyCode>USD</InvoiceCurrencyCode><InvoiceTotalAmount>517174.63</InvoiceTotalAmount><InvoiceIDDetails InvoiceIDType="BT"><InvoiceIDVATRegistrationNumber>0000000000</InvoiceIDVATRegistrationNumber><InvoiceIDName1>aaaaaaaaaaaaaaa</InvoiceIDName1><InvoiceIDName2>bbbbbbHKG</InvoiceIDName2><InvoiceIDCity>ccccccccc ccccc</InvoiceIDCity><InvoiceIDCountryCode>HK</InvoiceIDCountryCode></InvoiceIDDetails><InvoiceIDDetails InvoiceIDType="II"><InvoiceIDVATRegistrationNumber>0000000000</InvoiceIDVATRegistrationNumber><InvoiceIDName1>eeeeeeee</InvoiceIDName1><InvoiceIDName2>PAY BY WIRE TRANSFER</InvoiceIDName2><InvoiceIDCity>fffffffffffffff, NA</InvoiceIDCity><InvoiceIDCustomField ID="1"><InvoiceIDCustomFieldDescription>Company Registration Number</InvoiceIDCustomFieldDescription><InvoiceIDCustomFieldValue>0000000000</InvoiceIDCustomFieldValue></InvoiceIDCustomField></InvoiceIDDetails></InvoiceHeader><SubInvoiceHeader><InvoiceLine><ItemNumber>001</ItemNumber><ItemQuantity><ItemQuantityType>IN</ItemQuantityType><ItemQuantityFlag>GR</ItemQuantityFlag><ItemQuantityQty>28134.000</ItemQuantityQty><ItemQuantityUOM>USG</ItemQuantityUOM></ItemQuantity><ItemQuantity><ItemQuantityType>DL</ItemQuantityType><ItemQuantityFlag>GR</ItemQuantityFlag><ItemQuantityQty>106498.775</ItemQuantityQty><ItemQuantityUOM>LT</ItemQuantityUOM></ItemQuantity><ItemDeliveryReferenceValue ItemDeliveryReferenceType="DTN">590365</ItemDeliveryReferenceValue><ItemDeliveryReferenceValue ItemDeliveryReferenceType="!
ARN">DAL
CH</ItemDeliveryReferenceValue><ItemDeliveryReferenceValue ItemDeliveryReferenceType="FNO">mmmmmmmmm</ItemDeliveryReferenceValue><ItemDeliveryLocation>pppp</ItemDeliveryLocation><ItemReferenceLocalDate
If you notice the problem is, the undesired "exclamation mark" that gets added in some fields before the actual value.
In the above case.. look at "ItemDeliveryReferenceType="! ARN">DAL"
the exclamation mark before value "ARN is unwanted, which leads to improper XML formation.
Cant figure out why is this coming.
Regards,
Faria Mithani

Similar Messages

  • Mail Receiver adapter - dynamic file name without mail package

    I know that we can get the dynamic attachment name using mail package... As per the FAQ Mail adapter, the Mail package use is deprecated and hence we do not want to go that route.
    I have seen the following wiki entry for setting the file attachment name...
    http://wiki.sdn.sap.com/wiki/display/XI/Adapter%20Module%20PI%207.0%20Set%20Attachment%20Name?bc=true
    Is this the only approach to dynamic attachment name using Mail adapter (and without Mail package). Or a different approach without Adapter module is possible?

    There is a different approach without using mail package or adapter module.
    Have a look at this Wiki:
    http://wiki.sdn.sap.com/wiki/display/ESOAInfrastructure/Dynamic+Email+Attachment+name+for+Received+Mails+with+ASMA+and+without+using+mail+package

  • Mail Notification with Custom Subject, Mail Body and PDF File Name

    I have successful configured the Action Profile to send SmartForm Mail as PDF. But i would like to modify the Subject, PDF File Name & add text to mail body when a mail is sent to the user.
    The Subject of the Mail is the same as the PDF file name. How to maintain a pre-defined file name for the PDF file.

    I was able to find a commercial product that works very well. MaxBulk Mailer from Max Programming allows you to import a list of recipients, merge with personalized message and designate an attachment (just image types and PDFs, not all types work) and send.

  • BPM/File Content and Dynamic File Name

    Bit of a double whammy here!
    I am running a BPM :  R/3 Proxy > XI > BPM > File Adapter (x4)
    All working to a point.....
    The file I receive splits into two files, then I pass a Count file - number of records to a separate file and then a file that simply says "ready" on completion.  Four files are:
    Data file, Lookup (values and descripton for legacy), Count file and Ready file.
    To top this off, it will be run for 12 separate countries so hope to use the country code to add to the file naming - so generating 48 files (if successful). Data_GB.dat, lookup_GB.dat, Count_GB.dat and ready_GB.dat etc.... 
    The first three, I can do (with maybe a little help!), I have looked at the use of dynamic file naming and think I can do this, however, the count file uses the initial file sent, but the ready file passes across the word "ready" to destination file.  How can I utilise the dynamic naming convention if I do not use the original file for this?
    Also, the "ready" file is being created but it is empty.  It is okay using the the File Adapter, but when I convert it, the file is empty (but still created!)  IN sxmb_moni, it is showing correctly but once the file content conversion happens, it is empty!
    Any thoughts?

    Thanks Bhavesh.
    Time Stamp Status Description
    2007-05-08 17:43:57 Success Message successfully received by messaging system. Profile: XI URL: http://host.fqdn.net:55000/MessagingSystem/receive/AFW/XI Credential (User): XIISUSER
    2007-05-08 17:43:57 Success Using connection File_http://sap.com/xi/XI/System. Trying to put the message into the receive queue.
    2007-05-08 17:43:57 Success Message successfully put into the queue.
    2007-05-08 17:43:57 Success The message was successfully retrieved from the receive queue.
    2007-05-08 17:43:57 Success The message status set to DLNG.
    2007-05-08 17:43:57 Success Delivering to channel: EPIW_FTP_Receiver_EmployeeReady
    2007-05-08 17:43:57 Success MP: entering
    2007-05-08 17:43:57 Success MP: processing local module localejbs/CallSapAdapter
    2007-05-08 17:43:57 Success File adapter receiver: processing started; QoS required: ExactlyOnce
    2007-05-08 17:43:57 Success File adapter receiver channel EPIW_FTP_Receiver_EmployeeReady: start processing: party " ", service "XE_DEV_3RD_EPIW_001"
    2007-05-08 17:43:57 Success Connect to FTP server "ftp.ftp.ftp.ftp", directory "/ECS/Target"
    2007-05-08 17:43:57 Success Write to FTP server "ftp.ftp.ftp.ftp", directory "/ECS/Target",   file "xi_epiw_ready20070508-174357-635.dat"
    2007-05-08 17:43:57 Success Transfer: "BIN" mode, size 156 bytes, character encoding -
    2007-05-08 17:43:57 Success Start converting XML document content to plain text
    2007-05-08 17:43:57 Success File processing complete
    2007-05-08 17:43:57 Success MP: leaving
    2007-05-08 17:43:57 Success The message was successfully delivered to the application using connection File_http://sap.com/xi/XI/System.
    2007-05-08 17:43:57 Success The message status set to DLVD.
    <?xml version="1.0" encoding="UTF-8" ?>
    - <ns0:EPIWReadyFile xmlns:ns0="urn:com.xerox.esap.hr.epiwextract">
      <recordReady>READY</recordReady>
      </ns0:EPIWReadyFile>
    Transfer: Binary
    File Type : Text
    File Content Conversion:
    Record Set Structure: Detail
    Detail.fieldSeparator     ,
    Detail.endSeparator     'nl'
    It maybe something simple... 
    Hopefully you can help : )
    Thanks
    Barry

  • Dynamic file name as mail attachment in receiver Mail Adapter?

    Hi,
    Can any one tell the possibility of attaching file as a mail attachment without using mail Package with dynamic filename.
    Business requirement is to send error response as mail attachment with dynamic name.
    Ex: Error_Response_20110802_13.24 where 20110802 is Date and next part represents time stamp.
    File attachment name should change dynamically in Mail receiver Adapter. Thanks
    Regards,
    Sreeramulu Konjeti.

    there is no standard way.
    you will have to write a module to get this in place.
    other ways are;
    XI Mail Adapter: An approach for sending emails with attachment with help of Java mapping - /people/stefan.grube/blog/2007/04/17/xi-mail-adapter-an-approach-for-sending-emails-with-attachment-with-help-of-java-mapping
    Dynamic name in the mail attachment - pseudo "variable substitution" :
    /people/michal.krawczyk2/blog/2006/02/23/xi-dynamic-name-in-the-mail-attachment--pseudo-variable-substitution

  • Dynamic file name of the attachment in receiver mail adapter

    Hi
    I have configured a receiver mail adapter which receives the payload as an xml attachment.
    Right now the file name of the attachment is hardcoded to "invoice.xml".
    I want to set it to dynamic ie. instead of "invoice.xml"... i want it as "invoice<invoicenumber>.xml".
    Invoice number is present in the payload.
    please suggest a solution w/o the need to develop a custom adapter module.
    Thanks!
    Regards,
    Faria Mithani

    Hi,
    Go through this thread..
    Dynamic  File Name for Receiver File Adapter
    Regards,
    Sarvesh

  • Java mapping for Dynamic File name: stuctures?

    Hi,
    Scenario:  Sender AS2 adapter --> PI --> Receiver File (NFS) Adapter. Just a file pass through, no mapping
    Requirement: Want to have the receiver file name as C1.yymmdd.C2 where C1 and C2 are contants and yymmdd is current date.
    I was told in sdn forum that I have to write java mapping and provided the sample code also. However, I am not sure how and where to use that sample code. Could you please help on following questions:
    1) What is the source and target data type structures for mapping?
    2) Where do I develop java mapping? How do I import to PI?
    3) How do I get access to SAP Netweaver Developer Studio? Can I download it to my laptop? or if I dont have access, can I use any other tool to develop? ( NetBeans, Eclipse ??) and how?
    4) what are the files and libraries that we need to import to java mapping? (e.g.,  Import aii_map_api.jar library)
    5) How to generate .jar file?
    If someone has already developed java mapping (.jar file) ready to import into PI, please provide the same.
    Thanks in advance
    - Riya Patil

    Hi Sarvesh,
    Is this UDF work if I dont select ASMP on sender side? (We tested selecting ASMP on both sender & receiver file adapters, it works fine and it works without UDF also).
    In my requirement I have to use sender AS2 adpter, please confirm if I can use this UDF without selecting ASMP on sender side.
    I have done the following tests:
    Test-1) Select ASMP with 'File Name' on both sender and receiver file adapters without any mapping (UDF)
    It works great. No UDF or mapping required. It is just pass through of file having the receiver file name same as in sender channel.
    Test-2) Select ASMP with 'File Name', only on receiver file adapter without any mapping (UDF)
    It is obvious, it doesn't work. I am getting the following error:
    Could not process due to error: com.sap.aii.adapter.file.configuration.DynamicConfigurationException: The Adapter Message Property 'FileName' was configured as mandatory element, but there is no 'DynamicConfiguration' element in the XI Message header
    Test-3) Select ASMP with 'File Name', only on receiver file adapter with mapping (using DynamicConfiguratio UDF)
    We are getting the following error message in SXMB_MONI:
    Fatal Error: com.sap.engine.lib.xml.parser.Parser~
    <SAP:Stack>com.sap.aii.utilxi.misc.api.BaseRuntimeException thrown during application mapping com/sap/xi/tf/_MM_Filename_: Fatal Error: com.sap.engine.lib.xml.parser.Parser~</SAP:Stack>
    Here is the code we have in UDF:
    DynamicConfiguration conf = (DynamicConfiguration) container.getTransformationParameters().get(StreamTransformationConstants.DYNAMIC_CONFIGURATION);
    DynamicConfigurationKey key = DynamicConfigurationKey.create("http://sap.com/xi/XI/System/File","FileName");
    String SourceFileName = "C1." + a + ".C2";
    conf.put(key, SourceFileName);
    return " ";
    So looks like UDF is not working and it is failing in mapping. If I could make it work, I think there is good chance that I can see DynamicConfiguration under SOAP Header, which what required for the error we see in out test-2.
    Can someone please help me to straighten this UDF and make it work.
    Thanks in advance.
    - Riya Patil

  • Dynamic file name while using java mapping

    Hi All,
    i need help.
    I am using java mapping to convert xml file in zip file.
    Now i need to set output file name as SiteId_TimeStamp.zip.
    Site id is comping in xml file.
    How can i do this?
    I tried many thing but didnt get the solution..
    As their is no message mapping so I am unable to use ASMA.
    Please help.

    Did you check the wiki? You just need to add the code into you java mapping..
      Map mapParameters = (Map) transformationInput.getInputHeader().getAll();
       // a) Set Output File name
       mapParameters.put(DynamicConfigurationKey.create("http://sap.com/xi/XI/Dynamic",
                                                             StreamTransformationConstants.DYNAMIC_CONFIGURATION), "");
       DynamicConfiguration conf = (DynamicConfiguration) mapParameters.get(StreamTransformationConstants.DYNAMIC_CONFIGURATION);
       DynamicConfigurationKey key = DynamicConfigurationKey.create("http://sap.com/xi/XI/System/File", "FileName");
       //Depending on your requirement edit this logic. Here, NewDynamicName + CurrentDate will be output file name.
       DateFormat dateFormat = new SimpleDateFormat("yyyyMMdd");
       conf.put(key, ("NewDynamicName_" + dateFormat.format(new Date())) + ".pdf");

  • Dynamic file name from messsage payload

    Hi Friends,
    My requirement is to read one .xml file , which has  Purchase Order deatails and place .html file on receiver side, we are using XSLT for mapping.
    The file name should be "POnumber.html " , i've gone through below but couldn't get much
    http://help.sap.com/saphelp_nw04/helpdata/en/43/03612cdecc6e76e10000000a422035/content.htm
    Can any one send the that code , and steps to add that code in side XSLT.
    Thanks
    John

    Hi,
    With above links
    /people/jayakrishnan.nair/blog/2005/06/20/dynamic-file-name-using-xi-30-sp12-part--i - Dynamic File Name Part 1
    /people/jayakrishnan.nair/blog/2005/06/28/dynamic-file-namexslt-mapping-with-java-enhancement-using-xi-30-sp12-part-ii - Dynamic File Name Part 2
    See in the below Michal blog , how to conver the file as html , take that part only.
    /people/michal.krawczyk2/blog/2005/11/23/xi-html-e-mails-from-the-receiver-mail-adapter
    Regards
    Chilla

  • Dynamic file name from input payload (RFC 2 flat file)

    Hi,
    I have an RFC to flat file scenario. The output flat file has not an XML structure, it's just a plain text file generated with abap mapping.
    In my source interface (RFC), I have a field called <FILENAME>, I want to use the value of that field to create the target file using dynamic file name. But if  in variable substitution I use payload:ZRFC_NAME,1,FILENAME,1 It doesn't work because the dynamic variable substitution try to access to output payload, not the source one...
    What can I do?

    Hi Marshal,
           You can add a extra node to your target strucutre like
    FileName- Node
    --FileName - Element.
    do the mapping from the field filename of RFC to FileName field in u r target strucure. And use this  field path at Refrence in variable subtituion.
    In the Content converison add the Name & Values as below
    FileName.fileldNames -- FileName
    FileName.fieldFixedLengths -- 0
    FileName.fixedLengthTooShortHandling -- Cut
    So the extra field in u r target structure would not populate in u r target text file.
    Cheers
    Veera

  • Setting dynamic file name in Receiver file adapter - not from payload

    Guys I just remember reading a weblog but can't find it now that I need it, on how to set the file name in message mapping dynamically but not using any payload field.
    Please let me know if you remember this.
    Thanks a lot,
    Viktor Varga

    also u can check in
    <a href="/people/jayakrishnan.nair/blog/2005/06/28/dynamic-file-namexslt-mapping-with-java-enhancement-using-xi-30-sp12-part-ii file name(XSLT Mapping with Java Enhancement) using XI 3.0 SP12 Part -II</a>
    <a href="/people/michal.krawczyk2/blog/2005/11/10/xi-the-same-filename-from-a-sender-to-a-receiver-file-adapter--sp14: The same filename from a sender to a receiver file adapter - SP14</a>

  • Dynamic File Name on Receiver Side using XSLT mapping

    Hi,
      My scenario is a Proxy to File scenario.The File on the receiving side is a TEXT file generated due to XSLT mapping. The file name has to be dynamic like- TEST<DDMMYYHHMMSS>File.DAT.
    If somebody knows how to do the same please help.
    Regards
    Ritu

    Hi Ritu,
    I agree to Krishna.With your XSLT mapping create a XML output which can be converted to a text file with content conversion.
    And for the dynamic file name, i guess its the date that matters which needs to be in DDMMYYHHMMSS format. the same can be accomplished by a Java function and calling it in your XSLT .
    Do refer this weblog it will help you accomplish the same.
    >>> /people/pooja.pandey/blog/2005/06/27/xslt-mapping-with-java-enhancement-for-beginners
    Regards,
    Shabarish

  • Dynamic file name within 1:n mapping

    Dear all,
    I have a 1:n mapping and would like to use dynamic file names.
    I searched the forum but found just some few anserws.
    As far as I can determine, it is not possible to use dynamic file names for multiple target messages, right?
    We are using a 3rd party adapter (SFTP) that doesn't support variable substitution.
    Is there another way?
    Thanks
    Chris

    >>As far as I can determine, it is not possible to use dynamic file names for multiple target messages, right?
    I am afraid you are correct.
    >>Is there another way?
    One option I could think is have an adpter module and adding the dynamic configuration there.
    I personally have not tried this option. But I dont see any reason, why this approach would fail.
    If I am correct, the message is passed to the module chain after the split. So the above logic should work.
    I will be glad if you can try and let me know the results
    Regards
    Jai
    P.S: Let me know if you need any help creating the module. The coding should be so simple and not more than 10 lines

  • Dynamic File Name and File size

    Hi All
    I need some help in calling Dynamic File Name and Dynamic File size of a file in my adapter Module.
    Could you please provided some help on the same?
    I have tried the same through UDF it is working. Could anyone provide me the steps for the same
    Regards
    Abhishek Mahajan

    Hi,
    You can use the already available adapter module "DynamicConfigurationBean". Have this adapter module at the top of the module list in CC.
    Have the parameter value as insert http://sap.com/xi/XI/System/File FileName and http://sap.com/xi/XI/System/File SourceFileSize (corresponding to the key names)
    For more info:
    http://help.sap.com/saphelp_nw04/helpdata/en/45/da2239feb22e98e10000000a155369/frameset.htm
    There is also a SAP note available for the same....dont remember the note number:(.....
    Regards,
    Abhishek.

  • SFTP to Mail with attachment as same file name from sender side

    Hi All,
            I am Using a SFTP to Mail scenario, I have a requirement in which an Sftp adapter after picking up a file should have an attachment with same file name to the Receiver Mail Adapter.
    Can anyone help me out?
    Thanks in Advance
    Edited by: uday kumar on Feb 15, 2009 2:00 PM
    Edited by: uday kumar on Feb 15, 2009 2:02 PM

    Hi,
    Find below link will helpful for configuration, but as per my knowledge file name at attachment will take as message id.  Check it with below link, i hope it will work
    /people/prasad.ulagappan2/blog/2005/06/07/mail-adapter-scenarios-150-sap-exchange-infrastructure

Maybe you are looking for

  • How to Index a Lacie External Ethernet Drive

    I cannot seem to get Spotlight to (a) recognize and (b) index a Lacie external Ethernet Drive I run. Can anyone advise how I can get both, please? GWJ Melbourne, Australia

  • Table 'sitv.a' doesn't exist.  vendor code 1146

    Post Author: pattyg CA Forum: Crystal Reports I need help with a sql statement that I am using in Crystal reports.  The table that I am using is sitv and I get an error that it doesn't exist. Here is the statement: SELECT a.UID, a.fid, b.fname , c.ln

  • Home resides on a windows cluster, OS X doesnt see it

    I am having a issue where even though the users active directory profile has the pathing for the home folder, the users home folder does not mount. Could this be because the home resides on a cluster?

  • Oracle Change Notification issues

    Hi experts, I want to track all DML changes that are done with some tables. i have used oracle change notification feature for this. I have created setup but changes are not notified back to the caller procedure. procedure is not even called. version

  • Video glitch in Exported QT and Flash video pieces

    Hello, I am having a strange problem with my playback of exported videos. Currently I am exporting out video for website use both Highband and Lowband. For my highband I export out video using quicktime conversion. In QT conversion I use Flix Flash F