on 05-28-2015 5:10 AM
Hi All,
I have a requirement SFTP ----> Mail Attachment with same file with date (filename_YYYYMMDD)
I am trying to take file name from Dynamic configuration from sender and trying to put ContentType in Header output. But still not working..
How to set content type payload body? Kindly provide you help.
Thanks to all,
I have achieved my requirement. I am closing this thread.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
DynamicConfiguration conf = (DynamicConfiguration) mapParameters.get(StreamTransformationConstants.DYNAMIC_CONFIGURATION);
DynamicConfigurationKey key = DynamicConfigurationKey.create("http://sap.com/xi/XI/System/File", "FileName");
String FileName = conf.get(key);
String CRLF="\r\n";
String emailPackage=
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>"+CRLF+
"<ns:Mail xmlns:ns=\"http://sap.com/xi/XI/Mail/30\">"+CRLF+
"<Subject>Delivery notes</Subject>"+CRLF+
"<From>test@test.com</From>"+CRLF+
"<To>ambuj.mishra@ .com;someoneelse@ .com</To>"+CRLF+
"<Reply_To />"+CRLF+
"<Content_Type>text/plain</Content_Type>"+CRLF+
"<Content_Disposition>attachment; filename="+"\""+FileName+"\""+"</Content_Disposition>"+CRLF+
"<Content>"+"my file data"+"</Content>"+CRLF+
"</ns:Mail>";
return emailPackage;
trying to put ContentType in Header output.
"Trying to put FileName in Header from Source to Content type in target" ??
For that, write a udf, concatenate udf output to "_DDMMYYYY" and map it to ContentType in target email package.
DynamicConfiguration conf = (DynamicConfiguration) mapParameters.get(StreamTransformationConstants.DYNAMIC_CONFIGURATION);
DynamicConfigurationKey key = DynamicConfigurationKey.create("http://sap.com/xi/XI/System/File", "FileName");
String FileName = conf.get(key);
return FileName;
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
public void transform(TransformationInput in, TransformationOutput out) throws StreamTransformationException
{
try{
// Getting output stream to write email package
OutputStream os = out.getOutputPayload().getOutputStream();
DynamicConfiguration conf = (DynamicConfiguration) mapParameters.get(StreamTransformationConstants.DYNAMIC_CONFIGURATION);
DynamicConfigurationKey key = DynamicConfigurationKey.create("http://sap.com/xi/XI/System/File", "FileName");
String FileName = conf.get(key);
SimpleDateFormat dt = new SimpleDateFormat("YYYYMMDD");
Date date = new Date();
FileName=FileName+"_"+dt.format(date);
// forming Email Package
String emailPackage=
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>"+CRLF+
"<ns:Mail xmlns:ns=\"http://sap.com/xi/XI/Mail/30\">"+CRLF+
"<Subject>Delivery notes</Subject>"+CRLF+
"<From>certificates@ .com</From>"+CRLF+
"<To>ambuj.mishra@ .com;someoneelse@ .com</To>"+CRLF+
"<Reply_To />"+CRLF+
"<Content_Type>text/plain</Content_Type>"+CRLF+
"<Content_Disposition>attachment; filename="+"\""+FileName+"\""+"</Content_Disposition>"+CRLF+
"<Content>"+"file content"+"</Content>"+CRLF+
"</ns:Mail>";
// writing Email Package
os.write(emailPackage.getBytes());
os.flush();
os.close();
}
catch (Exception e)
{
throw new StreamTransformationException(e.getMessage());
}
}
public void transform(TransformationInput in, TransformationOutput out) throws StreamTransformationException
{
try{
// Getting output stream to write email package
OutputStream os = out.getOutputPayload().getOutputStream();
DynamicConfiguration conf = (DynamicConfiguration) mapParameters.get(StreamTransformationConstants.DYNAMIC_CONFIGURATION);
DynamicConfigurationKey key = DynamicConfigurationKey.create("http://sap.com/xi/XI/System/File", "FileName");
String FileName = conf.get(key);
SimpleDateFormat dt = new SimpleDateFormat("YYYYMMDD");
Date date = new Date();
FileName=FileName+"_"+dt.format(date);
String attachmentContent="This is my attachment content";
//creating output attachment
OutputAttachments outAtt = out.getOutputAttachments();
Attachment newAttachment = out.getOutputAttachments().create(FileName, attachmentContent.getBytes());
outAtt.setAttachment(newAttachment);
// forming Email Package
String emailPackage=
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>"+CRLF+
"<ns:Mail xmlns:ns=\"http://sap.com/xi/XI/Mail/30\">"+CRLF+
"<Subject>Delivery notes</Subject>"+CRLF+
"<From>certificates@ .com</From>"+CRLF+
"<To>ambuj.mishra@ .com;someoneelse@ .com</To>"+CRLF+
"<Reply_To />"+CRLF+
"<Content_Type></Content_Type>"+CRLF+
"<Content>"+"This is my payload, here it is writing it..."+"</Content>"+CRLF+
"</ns:Mail>";
// writing Email Package
os.write(emailPackage.getBytes());
os.flush();
os.close();
}
catch (Exception e)
{
throw new StreamTransformationException(e.getMessage());
}
}
your payload will be in <Content> and your file will be created as attachment with File name , coming in header.
Don't copy paste above code, and expect you will get your result instantly. Modify it accordingly. Your requirement is not clear at all. what are you trying to acheive?
Read these,
https://help.sap.com/javadocs/pi/pi711/com/sap/engine/interfaces/messaging/api/Payload.html
http://help.sap.com/saphelp_nw73/helpdata/en/6b/4493404f673028e10000000a1550b0/content.htm
Hi,
You can pick the filename from Sender SFTP using Dynamic Configuration and pass it to your header file.
DynamicConfiguration conf = (DynamicConfiguration) mapParameters.get(StreamTransformationConstants.DYNAMIC_CONFIGURATION);
DynamicConfigurationKey key = DynamicConfigurationKey.create("http://sap.com/xi/XI/System/File", "FileName");
String FileName = conf.get(key);
conf.put(key, Filename);
Are you using Mail Package at Receiver end?
Regards,
Azhar
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
87 | |
10 | |
10 | |
10 | |
7 | |
6 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.