cancel
Showing results for 
Search instead for 
Did you mean: 

File to Mail scenario

Former Member
0 Kudos

Hi Experts,

I have done file to mail scenario using Java Mappings and imported .xsd docs.

Presently my scenario is working fine.

External def are ::

Sender .xsd is

<?xml version="1.0" encoding="ISO-8859-1"?>

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified">

<xs:element name="EMAIL_Message">

<xs:complexType>

<xs:sequence>

<xs:element name="EMAIL_CONTENTS" minOccurs="0" maxOccurs="unbounded" />

</xs:sequence>

</xs:complexType>

</xs:element>

</xs:schema>

Receiver .xsd is ::

<?xml version="1.0" encoding="ISO-8859-1"?>

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xi="http://sap.com/xi/XI/Mail/30" targetNamespace="http://sap.com/xi/XI/Mail/30">

<xs:element name="Mail">

<xs:annotation>

<xs:documentation>

Mail package for XI - Mail Adapter

</xs:documentation>

</xs:annotation>

<xs:complexType>

<xs:sequence>

<xs:element name="Subject" type="xs:string" minOccurs="0">

<xs:annotation>

<xs:documentation>

optional subject line

</xs:documentation>

</xs:annotation>

</xs:element>

<xs:element name="From" type="xs:string" minOccurs="0">

<xs:annotation>

<xs:documentation>

optional sender email address (required for SMTP)

</xs:documentation>

</xs:annotation>

</xs:element>

<xs:element name="To" type="xs:string" minOccurs="0">

<xs:annotation>

<xs:documentation>

optional one or more receiver email addresses (required for SMTP)

</xs:documentation>

</xs:annotation>

</xs:element>

<xs:element name="Reply_To" type="xs:string" minOccurs="0">

<xs:annotation>

<xs:documentation>

optional reply-to email addresses

</xs:documentation>

</xs:annotation>

</xs:element>

<xs:element name="Content_Type" type="xs:string" minOccurs="0">

<xs:annotation>

<xs:documentation>

optional content type (default is text/plain)

</xs:documentation>

</xs:annotation>

</xs:element>

<xs:element name="Content_Description" type="xs:string" minOccurs="0">

<xs:annotation>

<xs:documentation>

optional content description

</xs:documentation>

</xs:annotation>

</xs:element>

<xs:element name="Content_Disposition" type="xs:string" minOccurs="0">

<xs:annotation>

<xs:documentation>

optional content disposition

</xs:documentation>

</xs:annotation>

</xs:element>

<xs:element name="Date" type="xs:dateTime" minOccurs="0">

<xs:annotation>

<xs:documentation>

optional date

</xs:documentation>

</xs:annotation>

</xs:element>

<xs:element name="Message_ID" type="xs:string" minOccurs="0">

<xs:annotation>

<xs:documentation>

optional message id

</xs:documentation>

</xs:annotation>

</xs:element>

<xs:element name="X_Mailer" type="xs:string" minOccurs="0">

<xs:annotation>

<xs:documentation>

optional mail program name

</xs:documentation>

</xs:annotation>

</xs:element>

<xs:element name="Content" minOccurs="0">

<xs:annotation>

<xs:documentation>

any mixed content type

</xs:documentation>

</xs:annotation>

</xs:element>

</xs:sequence>

<xs:attribute name="encoding" type="xs:string">

<xs:annotation>

<xs:documentation>

optional encoding name (base64, quoted-printable)

</xs:documentation>

</xs:annotation>

</xs:attribute>

</xs:complexType>

</xs:element>

<xs:element name="MailReceipt">

<xs:annotation>

<xs:documentation>

Mail Receipt for XI - Mail Adaper

</xs:documentation>

</xs:annotation>

<xs:complexType>

<xs:sequence>

<xs:element name="Server" type="xs:string">

<xs:annotation>

<xs:documentation>

Server URL

</xs:documentation>

</xs:annotation>

</xs:element>

<xs:element name="Greeting" type="xs:string">

<xs:annotation>

<xs:documentation>

Server Greeting Message

</xs:documentation>

</xs:annotation>

</xs:element>

<xs:element name="Format" type="xs:string">

<xs:annotation>

<xs:documentation>

Message Format XIALL or XIPAYLOAD

</xs:documentation>

</xs:annotation>

</xs:element>

<xs:element name="UseMailPackage" type="xs:boolean">

<xs:annotation>

<xs:documentation>

Mail Package Flag

</xs:documentation>

</xs:annotation>

</xs:element>

<xs:element name="Encoding" type="xs:string">

<xs:annotation>

<xs:documentation>

Encoding name

</xs:documentation>

</xs:annotation>

</xs:element>

<xs:element name="Subject" type="xs:string" minOccurs="0">

<xs:annotation>

<xs:documentation>

Mail Subject

</xs:documentation>

</xs:annotation>

</xs:element>

<xs:element name="From" type="xs:dateTime" minOccurs="0">

<xs:annotation>

<xs:documentation>

Mail From

</xs:documentation>

</xs:annotation>

</xs:element>

<xs:element name="To" type="xs:string" minOccurs="0">

<xs:annotation>

<xs:documentation>

Mail To

</xs:documentation>

</xs:annotation>

</xs:element>

<xs:element name="Date" type="xs:dateTime" minOccurs="0">

<xs:annotation>

<xs:documentation>

Mail date

</xs:documentation>

</xs:annotation>

</xs:element>

<xs:element name="MailID" type="xs:string" minOccurs="0">

<xs:annotation>

<xs:documentation>

Mail ID

</xs:documentation>

</xs:annotation>

</xs:element>

</xs:sequence>

</xs:complexType>

</xs:element>

<xs:element name="FetchReport">

<xs:annotation>

<xs:documentation>

Fetch Report for XI - Mail Adaper

</xs:documentation>

</xs:annotation>

<xs:complexType>

<xs:sequence>

<xs:element name="Server" type="xs:string">

<xs:annotation>

<xs:documentation>

Server URL

</xs:documentation>

</xs:annotation>

</xs:element>

<xs:element name="Greeting" type="xs:string">

<xs:annotation>

<xs:documentation>

Server Greeting Message

</xs:documentation>

</xs:annotation>

</xs:element>

<xs:element name="User" type="xs:string">

<xs:annotation>

<xs:documentation>

User Name

</xs:documentation>

</xs:annotation>

</xs:element>

<xs:element name="Date" type="xs:dateTime" minOccurs="0">

<xs:annotation>

<xs:documentation>

Mail Date

</xs:documentation>

</xs:annotation>

</xs:element>

<xs:element name="Messages" type="xi:FetchedMessages">

<xs:annotation>

<xs:documentation>

Mail Messages

</xs:documentation>

</xs:annotation>

</xs:element>

</xs:sequence>

</xs:complexType>

</xs:element>

<xs:complexType name="FetchedMessages">

<xs:sequence>

<xs:element name="item" type="xi:FetchedMessage" minOccurs="0" maxOccurs="unbounded" />

</xs:sequence>

<xs:attribute name="new" type="xs:int">

<xs:annotation>

<xs:documentation>

the number of new messages found

</xs:documentation>

</xs:annotation>

</xs:attribute>

<xs:attribute name="total" type="xs:int">

<xs:annotation>

<xs:documentation>

the number of total messages found

</xs:documentation>

</xs:annotation>

</xs:attribute>

</xs:complexType>

<xs:complexType name="FetchedMessage">

<xs:sequence>

<xs:element name="Subject" type="xs:string">

<xs:annotation>

<xs:documentation>

Mail Subject

</xs:documentation>

</xs:annotation>

</xs:element>

<xs:element name="From" type="xs:string">

<xs:annotation>

<xs:documentation>

Mail From

</xs:documentation>

</xs:annotation>

</xs:element>

<xs:element name="To" type="xs:string">

<xs:annotation>

<xs:documentation>

Mail To

</xs:documentation>

</xs:annotation>

</xs:element>

<xs:element name="Message_ID" type="xs:string">

<xs:annotation>

<xs:documentation>

Mail ID

</xs:documentation>

</xs:annotation>

</xs:element>

</xs:sequence>

<xs:attribute name="status" type="xs:string">

<xs:annotation>

<xs:documentation>

the status of XI processing

</xs:documentation>

</xs:annotation>

</xs:attribute>

<xs:attribute name="id" type="xs:string">

<xs:annotation>

<xs:documentation>

the XI message ID associated with the mail message

</xs:documentation>

</xs:annotation>

</xs:attribute>

</xs:complexType>

</xs:schema>

I have done message mapping with source and target xsd.

source EMAIL_CONTENTS is mapped to Content of target .xsd.

Remaining are mapped with constants to target .xsd.

In target .xsd i have not used Reply_To, Date, Message_ID, X_Mailer (for your info)

Constants are used same as mentioned in Java Mappings.

Content is handled in Java Mappings.

Kindly suggest and pls take this with pateince and do the needful.

If any info required please send.

Appreciate for pateince and inputs.

Thanks,

Swetha

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

As i can not send more that 15000 characters here i am sending remaining part

continuing to the above message here i am sending the java mappingss.

Here i am sending the java mappings what i have done.

Kindly paste in your notepad and please look into it.

/*

  • Created on Nov 28, 2009

*

  • To change the template for this generated file go to

  • Window&gt;Preferences&gt;Java&gt;Code Generation&gt;Code and Comments

*/

package com.chep.sap.xi.mappings;

import java.io.File;

import java.io.FileInputStream;

import java.io.FileOutputStream;

import java.io.IOException;

import java.io.InputStream;

import java.io.OutputStream;

import com.sap.aii.mapping.api.StreamTransformationException;

public class PGEmailMapping extends CHEPMapping {

public static void main(String[] args) {

try {

File inputDir =

new File("D:
ProjectFiles
SAP
TestData
In");

if (inputDir.isDirectory()) {

File[] files = inputDir.listFiles();

for (int i = 0; i < files.length; i++) {

InputStream in = new FileInputStream(files<i>);

PGEmailMapping mapping = new PGEmailMapping();

mapping.execute(

in,

new FileOutputStream(

"D:
ProjectFiles
SAP
TestData
Out
out"

+ i

+ ".xml"));

}

}

} catch (StreamTransformationException e) {

System.out.println(e.toString());

} catch (IOException e) {

System.out.println(e.toString());

}

}

/* (non-Javadoc)

  • @see com.sap.aii.mapping.api.StreamTransformation#execute(java.io.InputStream, java.io.OutputStream)

*/

public void execute(InputStream in, OutputStream out)

throws StreamTransformationException {

// TODO Auto-generated method stub

// Identify the environment

String systemID = "";

systemID = System.getProperty("SAPSYSTEMNAME");

String mailSubject = "CHEP";

if (!"X46".equals(systemID)) {

mailSubject += " [sent from non-production environment "

+ systemID

+ "]";

}

String mailReceiver =

"\"mailid\"&lt;maild&gt;";

if ("X46".equals(systemID)) {

mailReceiver = "mailid;mailid";

} else if ("X44".equals(systemID)) {

mailReceiver = "mailid;mailid";

} else if ("X42".equals(systemID)) {

mailReceiver = "mailid;maild";

}

String mailSender =

"\"mailid\"&lt;mailid&gt;";

String attachmentName = "Outgoing EDI.edi";

String boundary = "--AaZz";

String mailContent =

"Note: This is an automated e-mail. In the event of problems or queries, please contact the Support Centre: \r\n\r\n Tel: +11--- \r\nemail: mailid";

String CRLF = "\r\n";

try {

// 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: text/plain; "

+ "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 (IOException e) {

throw new StreamTransformationException(e.getMessage());

}

}

protected static void copySource(InputStream in, OutputStream out)

throws IOException {

byte[] bbuf = new byte[in.available()];

int bblen = in.read(bbuf);

String ediString = new String(bbuf);

// Replace any existing line breaks/carriage returns

ediString = ediString.replaceAll("

n", "");

ediString = ediString.replaceAll("

r", "");

ediString = ediString.replaceAll("'", "'\r\n");

if (ediString.endsWith("\r\n")) {

ediString = ediString.substring(0, (ediString.length() - 2));

}

if (!(bblen < 0)) {

// replace all control characters with escape sequences

ediString = ediString.replaceAll("&", "&amp;");

ediString = ediString.replaceAll("\"", "&quot;");

ediString = ediString.replaceAll("'", "&apos;");

ediString = ediString.replaceAll("<", "&lt;");

ediString = ediString.replaceAll(">", "&gt;");

out.write(ediString.getBytes());

}

}

}

I have not mentioned mailid in mappings for security reason.

with the above mapping my scenario is working fine.

but now business is asking in subject line should be as CHEP <datetime> (please see in java mappings you can find subject declared as CHEP)

I have written java codefor datatime in the above java mappings as::

(below is additional code added in java mapping)

import java.util.*;

import java.text.SimpleDateFormat;

String sysVar = PGEmailMapping.now("yyyyMMddhhmm");

System.out.println(sysVar);

String mailSubject = "CHEP <" sysVar ">";

public static String now(String dateFormat) {

Calendar cal = Calendar.getInstance();

SimpleDateFormat sdf = new SimpleDateFormat(dateFormat);

return sdf.format(cal.getTime());

}

When i added above code in Java mappings when i tested my sender cc is working fine.

but in receiver CC i am getting as

failed to send mail: com.sap.aii.messaging.util.XMLScanException: com.sap.engine.lib.xml.parser.NestedSAXParserException: Fatal Error: com.sap.engine.lib.xml.parser.ParserException: Name expected: 0x32(:main:, row:1, col:106)(:main:, row=1, col=106) -> com.sap.engine.lib.xml.parser.ParserException: Name expected: 0x32(:main:, row:1, col:106)"

why i am getting SAX parser Exception.can anyone suggest.

In message mapping i have mapped constant as CHEP with Subject.

Is any thing additional needed.

Thanks

Swetha

Former Member
0 Kudos

Hi experts,

Please copy the code and paste it in notepad.

Please test it fromyour end.

Please suggest.

Thanks,

Swetha

former_member187339
Active Contributor
0 Kudos

Hi Swetha,

Run your interface mapping in test environment (or see the after request mapping payload of moni) and see whether you are getting the correct xml output or not.. i guess since you have changed the subject parameter you are getting this error..

Also try to stop start the communication channel from runtime workbench..

Your query thread is not formatted, i would suggest you to use 'code' with curly braces at start and end of xsd, java code etc..

Regards

Suraj

Former Member
0 Kudos

Hi Suraj here is the .XSD code.

-


*********----


<?xml version="1.0" encoding="ISO-8859-1"?>

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xi="http://sap.com/xi/XI/Mail/30" targetNamespace="http://sap.com/xi/XI/Mail/30">

<xs:element name="Mail">

<xs:annotation>

<xs:documentation>

Mail package for XI - Mail Adapter

</xs:documentation>

</xs:annotation>

<xs:complexType>

<xs:sequence>

<xs:element name="Subject" type="xs:string" minOccurs="0">

<xs:annotation>

<xs:documentation>

optional subject line

</xs:documentation>

</xs:annotation>

</xs:element>

<xs:element name="From" type="xs:string" minOccurs="0">

<xs:annotation>

<xs:documentation>

optional sender email address (required for SMTP)

</xs:documentation>

</xs:annotation>

</xs:element>

<xs:element name="To" type="xs:string" minOccurs="0">

<xs:annotation>

<xs:documentation>

optional one or more receiver email addresses (required for SMTP)

</xs:documentation>

</xs:annotation>

</xs:element>

<xs:element name="Reply_To" type="xs:string" minOccurs="0">

<xs:annotation>

<xs:documentation>

optional reply-to email addresses

</xs:documentation>

</xs:annotation>

</xs:element>

<xs:element name="Content_Type" type="xs:string" minOccurs="0">

<xs:annotation>

<xs:documentation>

optional content type (default is text/plain)

</xs:documentation>

</xs:annotation>

</xs:element>

<xs:element name="Content_Description" type="xs:string" minOccurs="0">

<xs:annotation>

<xs:documentation>

optional content description

</xs:documentation>

</xs:annotation>

</xs:element>

<xs:element name="Content_Disposition" type="xs:string" minOccurs="0">

<xs:annotation>

<xs:documentation>

optional content disposition

</xs:documentation>

</xs:annotation>

</xs:element>

<xs:element name="Date" type="xs:dateTime" minOccurs="0">

<xs:annotation>

<xs:documentation>

optional date

</xs:documentation>

</xs:annotation>

</xs:element>

<xs:element name="Message_ID" type="xs:string" minOccurs="0">

<xs:annotation>

<xs:documentation>

optional message id

</xs:documentation>

</xs:annotation>

</xs:element>

<xs:element name="X_Mailer" type="xs:string" minOccurs="0">

<xs:annotation>

<xs:documentation>

optional mail program name

</xs:documentation>

</xs:annotation>

</xs:element>

<xs:element name="Content" minOccurs="0">

<xs:annotation>

<xs:documentation>

any mixed content type

</xs:documentation>

</xs:annotation>

</xs:element>

</xs:sequence>

<xs:attribute name="encoding" type="xs:string">

<xs:annotation>

<xs:documentation>

optional encoding name (base64, quoted-printable)

</xs:documentation>

</xs:annotation>

</xs:attribute>

</xs:complexType>

</xs:element>

<xs:element name="MailReceipt">

<xs:annotation>

<xs:documentation>

Mail Receipt for XI - Mail Adaper

</xs:documentation>

</xs:annotation>

<xs:complexType>

<xs:sequence>

<xs:element name="Server" type="xs:string">

<xs:annotation>

<xs:documentation>

Server URL

</xs:documentation>

</xs:annotation>

</xs:element>

<xs:element name="Greeting" type="xs:string">

<xs:annotation>

<xs:documentation>

Server Greeting Message

</xs:documentation>

</xs:annotation>

</xs:element>

<xs:element name="Format" type="xs:string">

<xs:annotation>

<xs:documentation>

Message Format XIALL or XIPAYLOAD

</xs:documentation>

</xs:annotation>

</xs:element>

<xs:element name="UseMailPackage" type="xs:boolean">

<xs:annotation>

<xs:documentation>

Mail Package Flag

</xs:documentation>

</xs:annotation>

</xs:element>

<xs:element name="Encoding" type="xs:string">

<xs:annotation>

<xs:documentation>

Encoding name

</xs:documentation>

</xs:annotation>

</xs:element>

<xs:element name="Subject" type="xs:string" minOccurs="0">

<xs:annotation>

<xs:documentation>

Mail Subject

</xs:documentation>

</xs:annotation>

</xs:element>

<xs:element name="From" type="xs:dateTime" minOccurs="0">

<xs:annotation>

<xs:documentation>

Mail From

</xs:documentation>

</xs:annotation>

</xs:element>

<xs:element name="To" type="xs:string" minOccurs="0">

<xs:annotation>

<xs:documentation>

Mail To

</xs:documentation>

</xs:annotation>

</xs:element>

<xs:element name="Date" type="xs:dateTime" minOccurs="0">

<xs:annotation>

<xs:documentation>

Mail date

</xs:documentation>

</xs:annotation>

</xs:element>

<xs:element name="MailID" type="xs:string" minOccurs="0">

<xs:annotation>

<xs:documentation>

Mail ID

</xs:documentation>

</xs:annotation>

</xs:element>

</xs:sequence>

</xs:complexType>

</xs:element>

<xs:element name="FetchReport">

<xs:annotation>

<xs:documentation>

Fetch Report for XI - Mail Adaper

</xs:documentation>

</xs:annotation>

<xs:complexType>

<xs:sequence>

<xs:element name="Server" type="xs:string">

<xs:annotation>

<xs:documentation>

Server URL

</xs:documentation>

</xs:annotation>

</xs:element>

<xs:element name="Greeting" type="xs:string">

<xs:annotation>

<xs:documentation>

Server Greeting Message

</xs:documentation>

</xs:annotation>

</xs:element>

<xs:element name="User" type="xs:string">

<xs:annotation>

<xs:documentation>

User Name

</xs:documentation>

</xs:annotation>

</xs:element>

<xs:element name="Date" type="xs:dateTime" minOccurs="0">

<xs:annotation>

<xs:documentation>

Mail Date

</xs:documentation>

</xs:annotation>

</xs:element>

<xs:element name="Messages" type="xi:FetchedMessages">

<xs:annotation>

<xs:documentation>

Mail Messages

</xs:documentation>

</xs:annotation>

</xs:element>

</xs:sequence>

</xs:complexType>

</xs:element>

<xs:complexType name="FetchedMessages">

<xs:sequence>

<xs:element name="item" type="xi:FetchedMessage" minOccurs="0" maxOccurs="unbounded" />

</xs:sequence>

<xs:attribute name="new" type="xs:int">

<xs:annotation>

<xs:documentation>

the number of new messages found

</xs:documentation>

</xs:annotation>

</xs:attribute>

<xs:attribute name="total" type="xs:int">

<xs:annotation>

<xs:documentation>

the number of total messages found

</xs:documentation>

</xs:annotation>

</xs:attribute>

</xs:complexType>

<xs:complexType name="FetchedMessage">

<xs:sequence>

<xs:element name="Subject" type="xs:string">

<xs:annotation>

<xs:documentation>

Mail Subject

</xs:documentation>

</xs:annotation>

</xs:element>

<xs:element name="From" type="xs:string">

<xs:annotation>

<xs:documentation>

Mail From

</xs:documentation>

</xs:annotation>

</xs:element>

<xs:element name="To" type="xs:string">

<xs:annotation>

<xs:documentation>

Mail To

</xs:documentation>

</xs:annotation>

</xs:element>

<xs:element name="Message_ID" type="xs:string">

<xs:annotation>

<xs:documentation>

Mail ID

</xs:documentation>

</xs:annotation>

</xs:element>

</xs:sequence>

<xs:attribute name="status" type="xs:string">

<xs:annotation>

<xs:documentation>

the status of XI processing

</xs:documentation>

</xs:annotation>

</xs:attribute>

<xs:attribute name="id" type="xs:string">

<xs:annotation>

<xs:documentation>

the XI message ID associated with the mail message

</xs:documentation>

</xs:annotation>

</xs:attribute>

</xs:complexType>

</xs:schema>

-


*********************----


former_member187339
Active Contributor
0 Kudos

Hi Swetha,

I have seen the XSD ( and hence replied earlier )

Did you tried the suggestion which I gave?? I am not having a PI environment here to test your interface.. Sorry

Regards

Suraj

Former Member
0 Kudos

Hi Suraj,

Here is the JAVA Mappings.

-


*****************----


/*

  • Created on Nov 28, 2009

*

  • To change the template for this generated file go to

  • Window&gt;Preferences&gt;Java&gt;Code Generation&gt;Code and Comments

*/

package com.chep.sap.xi.mappings;

import java.io.File;

import java.io.FileInputStream;

import java.io.FileOutputStream;

import java.io.IOException;

import java.io.InputStream;

import java.io.OutputStream;

import com.sap.aii.mapping.api.StreamTransformationException;

public class PGEmailMapping extends CHEPMapping {

public static void main(String[] args) {

try {

File inputDir =

new File("D:
ProjectFiles
SAP
TestData
In");

if (inputDir.isDirectory()) {

File[] files = inputDir.listFiles();

for (int i = 0; i < files.length; i++) {

InputStream in = new FileInputStream(files<i>);

PGEmailMapping mapping = new PGEmailMapping();

mapping.execute(

in,

new FileOutputStream(

"D:
ProjectFiles
SAP
TestData
Out
out"

+ i

+ ".xml"));

}

}

} catch (StreamTransformationException e) {

System.out.println(e.toString());

} catch (IOException e) {

System.out.println(e.toString());

}

}

/* (non-Javadoc)

  • @see com.sap.aii.mapping.api.StreamTransformation#execute(java.io.InputStream, java.io.OutputStream)

*/

public void execute(InputStream in, OutputStream out)

throws StreamTransformationException {

// TODO Auto-generated method stub

// Identify the environment

String systemID = "";

systemID = System.getProperty("SAPSYSTEMNAME");

String mailSubject = "CHEP";

if (!"X46".equals(systemID)) {

mailSubject += " [sent from non-production environment "

+ systemID

+ "]";

}

String mailReceiver =

"\"mailid\"&lt;maild&gt;";

if ("X46".equals(systemID)) {

mailReceiver = "mailid;mailid";

} else if ("X44".equals(systemID)) {

mailReceiver = "mailid;mailid";

} else if ("X42".equals(systemID)) {

mailReceiver = "mailid;maild";

}

String mailSender =

"\"mailid\"&lt;mailid&gt;";

String attachmentName = "Outgoing EDI.edi";

String boundary = "--AaZz";

String mailContent =

"Note: This is an automated e-mail. In the event of problems or queries, please contact the Support Centre: \r\n\r\n Tel: +11--- \r\nemail: mailid";

String CRLF = "\r\n";

try {

// 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: text/plain; "

+ "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 (IOException e) {

throw new StreamTransformationException(e.getMessage());

}

}

protected static void copySource(InputStream in, OutputStream out)

throws IOException {

byte[] bbuf = new byte[in.available()];

int bblen = in.read(bbuf);

String ediString = new String(bbuf);

// Replace any existing line breaks/carriage returns

ediString = ediString.replaceAll("

n", "");

ediString = ediString.replaceAll("

r", "");

ediString = ediString.replaceAll("'", "'\r\n");

if (ediString.endsWith("\r\n")) {

ediString = ediString.substring(0, (ediString.length() - 2));

}

if (!(bblen < 0)) {

// replace all control characters with escape sequences

ediString = ediString.replaceAll("&", "&amp;");

ediString = ediString.replaceAll("\"", "&quot;");

ediString = ediString.replaceAll("'", "&apos;");

ediString = ediString.replaceAll("<", "&lt;");

ediString = ediString.replaceAll(">", "&gt;");

out.write(ediString.getBytes());

}

}

}

-


********************************----


Former Member
0 Kudos

Hi Suraj,

Here is the request mapping payload.

The XML page cannot be displayed

Cannot view XML input using XSL style sheet. Please correct the error and then click the Refresh button, or try again later.

-


A name was started with an invalid character. Error processing resource 'file:///C:/Documents and Settings/proddusr/Local S...

<?xml version="1.0" encoding="UTF-8"?><ns:Mail xmlns:ns="http://sap.com/xi/XI/Mail/30"><Subject>CHEP &l...

How can test from IM i mean i dont find any test config.

please suggest.

Thanks,

Swetha

former_member187339
Active Contributor
0 Kudos

Hi Swetha,

I guess I found the problem the angular brackets


<  >

in subject field is the problem.. try removing them from the java code and test again

Regards

Suraj

Former Member
0 Kudos

Hi Suraj,

The below request mapping payload is successfull and tested without date and time stamp.

<?xml version="1.0" encoding="UTF-8" ?>

- <ns:Mail xmlns:ns="http://sap.com/xi/XI/Mail/30">

<Subject>CHEP [sent from non-production environment X44]</Subject>

<From>"mailids></From>

<To>mailids</To>

<Content_Type>multipart/mixed; boundary="--AaZz"</Content_Type>

<Content>----AaZz Content-Type: text/plain; charset=UTF-8 Content-Disposition: inline Note: This is an automated e-mail. In the event of problems or queries, please contact the CHEP Support Centre: Tel: 11 (0)602685 email: -


AaZz Content-Type: text/plain; name=CHEP.edi Content-Disposition: attachment; filename=CHEP.edi UNBUNOA:1GBLONSCLEHLC091204:1059091204' UNHGBLONSCLE0001CHEP:D:95B:UNGESU2054016' BGM24GESU20540169' NADEOGBLONSCLE:160:20' NADCLGBLIVGYCAGreycourt Transport Ltd:Greycourt Transport Ltd:Simonswood Industrial ParkNWE-GB-LIV-1283' EQDCNGESU205401622G1+4' RFFCV:M0301' RFFRE:752093' RFFICO:M0301' DTM137:200903230000:102' DTM201:200903230000:102' DTM7:200903230000:102' DTM575:1999030000:102' LOC165GBLIVGYCA:::Liverpool' DIM10MMT:605.80:243.80:259.10' CNT16:1' UNT16GBLONSCLE0001' UNZ1091204'</Content>

</ns:Mail>

I have added date and time stamp in the java mappings as follows.

import java.util.*;

import java.text.SimpleDateFormat;

String sysVar = PGEmailMapping.now("yyyyMMddhhmm");

System.out.println(sysVar);

String mailSubject = "CHEP <" sysVar ">";

public static String now(String dateFormat) {

Calendar cal = Calendar.getInstance();

SimpleDateFormat sdf = new SimpleDateFormat(dateFormat);

return sdf.format(cal.getTime());

}

i am i written wrong java code... please suggest.

i didnt get you should i remove the angular braces from <" sysVar ">"; or ...

please suggest.

thanks,

swetha

Former Member
0 Kudos

Sorry i have given wrong code.

please see the below code.

String sysVar = PGEmailMapping.now("yyyyMMddhhmm");

System.out.println(sysVar);

String mailSubject = "CHEP <" sysVar ">";

public static String now(String dateFormat) {

Calendar cal = Calendar.getInstance();

SimpleDateFormat sdf = new SimpleDateFormat(dateFormat);

return sdf.format(cal.getTime());

}

Thanks,

Swetha

Former Member
0 Kudos

My Question is answered.

Thanks Suraj.

Actually i have taken ;&lt and ;&gt for opening an dclose brackets.

Thanks,

Swetha.

Answers (0)