on 02-03-2011 9:53 PM
Hi,
The below mentioned code is for sending email with attachment using Java Mapping which was implemented in PI 7.0
I know the API for PI 7.1 has changed, I changed the below code using extends AbstractTransformation using Transform instead of implements streamTransformation and few other changes but I get lot of issues.
Could anyone point out what and all need to be changed in PI 7.1 for the below mentioned code. It would be greatly if anyone could let me know the changes
package dynamicconfmail;
import com.sap.aii.mapping.api.*;
import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
import javax.mail.*;
import javax.activation.*;
import javax.mail.internet.*;
import javax.mail.util.ByteArrayDataSource;
public class DynamicConfMail implements StreamTransformation {
private Map param;
//// Start of Main Class
// public static void main(String[] args) throws Exception
// {
// try
// {
// FileInputStream fin = new FileInputStream("c:/test/sam.txt");
// FileOutputStream fout = new FileOutputStream("H:/test/sam2_O.txt");
// DynamicConfMail mapping = new DynamicConfMail();
// mapping.execute(fin, fout);
// }
// catch (Exception e)
// {
// // e.printStackTrace();
// }
// }
// //End of Main Class
public DynamicConfMail() {
}
public void setParameter(Map map) {
param = map;
if (param == null) {
param = new HashMap();
}
}
public void execute(InputStream inputstream, OutputStream outputstream)
{
int IO_BUFFER_SIZE = 4 * 1024;
String llkj = "1111";
String llkj_f = "llkj.txt";
String llkj_dir = "/usr/sap/llkj/in";
String xyzv = "9999";
String xyzv_f = "xyzv.txt";
String xyzv_dir = "/usr/sap/xyzv/in";
String default_dir = "/usr/sap/Error";
String Flag = "";
String FileName = "";
try
{
// The following is for the FileName in the File Adapter
DynamicConfiguration conf = (DynamicConfiguration) param.get("DynamicConfiguration");
DynamicConfigurationKey key = DynamicConfigurationKey.create("http://sap.com/xi/XI/System/File", "FileName");
DynamicConfigurationKey key1 = DynamicConfigurationKey.create("http://sap.com/xi/XI/System/File", "Directory");
InputStream ins = inputstream;
// Start Copy the InputStream to OutputStream
byte[] b = new byte[IO_BUFFER_SIZE];
int read;
StringBuffer out = new StringBuffer();
try {
while ((read = inputstream.read(b)) != -1)
{
out.append(new String(b, 0, read));
String InputString = out.toString();
String substr = InputString.substring(2, 18);
System.out.println(substr);
if (substr.equals(llkj))
{
System.out.println("The given string is equals");
conf.put(key, llkj_f);
conf.put(key1, llkj_dir );
FileName = llkj_f;
}
else if (substr.equals(xyzv))
{
System.out.println("The given string is equals");
conf.put(key, xyzv_f);
conf.put(key1, xyzv_dir);
FileName = xyzv_f;
}
else
{
conf.put(key1, default_dir);
Flag = "F";
System.out.println("The given string is not equals");
FileName = substr;
}
// Writes to outputstream
outputstream.write(b, 0, read);
if (Flag.equals(""))
{
//* Code to Send Email*/
String att = outputstream.toString();
email obj1 = new email();
obj1.send("mailhost", "emailID", "Success", "Success", "emailID",InputString, FileName);
//End of Email Code/
}
else if (Flag.equals("F"))
{
//* Code to Send Email*/
String att = outputstream.toString();
email obj1 = new email();
obj1.send("mailhost", "emailID", "Failed", "Failed", "emailID",InputString, FileName);
//End of Email Code/
}
}
}
catch (IOException ex)
{
ex.printStackTrace();
}
// End of Copy the InputStream to OutputStream
}
catch (Throwable throwable)
{
throwable.printStackTrace();
}
}
public class email {
public void postMail(String mailhst, String recivers, String subject, String message, String from, String attachment, String FileName) throws MessagingException
{
boolean debug = false;
byte[] AttByteArray = attachment.getBytes();
Properties props = new Properties();
props.put("mail.smtp.host", mailhst);
Session session = Session.getDefaultInstance(props, null);
session.setDebug(debug);
Message msg = new MimeMessage(session);
InternetAddress addressFrom = new InternetAddress(from);
msg.setFrom(addressFrom);
String recipients[] = recivers.split(",");
InternetAddress[] addressTo = new InternetAddress[recipients.length];
for (int i = 0; i < recipients.length; i++)
addressTo<i> = new InternetAddress(recipients<i>);
msg.setRecipients(Message.RecipientType.TO, addressTo);
msg.addHeader("MyHeaderName", "myHeaderValue");
msg.setSubject(subject);
// Create the message part
BodyPart messageBodyPart = new MimeBodyPart();
// Fill the message
messageBodyPart.setText("TEST");
Multipart multipart = new MimeMultipart();
multipart.addBodyPart(messageBodyPart);
// Part two is attachment
messageBodyPart = new MimeBodyPart();
DataSource source = new ByteArrayDataSource("Test","text/plain", AttByteArray );
messageBodyPart.setDataHandler(new DataHandler(source));
messageBodyPart.setFileName(FileName);
multipart.addBodyPart(messageBodyPart);
// Put parts in message
msg.setContent(multipart);
Transport.send(msg);
}
public void send(String mailhst, String recivers, String subject, String message, String from, String attachment, String FileName)
{
try {
this.postMail(mailhst, recivers, subject, message, from, attachment, FileName );
}
catch (MessagingException mex) {
System.out.println("send failed, exception: " + mex);
}
}
class ByteArrayDataSource implements DataSource {
byte[] bytes;
String contentType;
String name;
ByteArrayDataSource( String name, String contentType, byte[] bytes ) {
this.name = name;
this.bytes = bytes;
this.contentType = contentType;
}
public String getContentType() {
return contentType;
}
public InputStream getInputStream() {
return new ByteArrayInputStream(bytes);
}
public String getName() {
return name;
}
public OutputStream getOutputStream() throws IOException {
throw new FileNotFoundException();
}
}
}
}
Edited by: PI-seeker on Feb 3, 2011 10:58 PM
Hi,
I understand new Java Mapping is throwing "Linkage error".
This error(java.lang.UnsupportedClassVersionError) is thrown when, version of java your are using on your desktop (eclipse on your system) is newer version than the java installed on XI server.
To see java version of SAP XI, open IR or ID
Then click help -> information -> Runtime Environment -> Java version.
Solution :-
Compile the java file using the less or equal version java (try to use JDK1.4 in eclipse) which is running on SAP XI server. Then import the new jar file again. [Link|http://www.webagesolutions.com/knowledgebase/javakb/jkb001/ ]
Regards,
Raghu_Vamsee
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
> The below mentioned code is for sending email with attachment using Java Mapping which was implemented in PI 7.0
> I know the API for PI 7.1 has changed, I changed the below code using extends AbstractTransformation using Transform instead of implements streamTransformation and few other changes but I get lot of issues.
Nothin needs to b changed, as PI 7.0 Java mapping code will run in PI 7.1 alos.
If you really want to use AbstractTransformation , then you just need add some lines like in this blog:
/people/stefan.grube/blog/2006/10/23/testing-and-debugging-java-mapping-in-developer-studio
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thansk a lot for your link.
I did implemented the same way as it mentioned, but I am getting the following error message
SAP:Error SOAP:mustUnderstand="" xmlns:SAP="http://sap.com/xi/XI/Message/30" xmlns:SOAP="http://schemas.xmlsoap.org/soap/envelope/">
<SAP:Category>Application</SAP:Category>
<SAP:Code area="MAPPING">LINKAGE_ERROR</SAP:Code>
<SAP:P1>dynamicconfmail/DynamicConfMail</SAP:P1>
<SAP:P2>java.lang.UnsupportedClassVersionError: dynamiccon</SAP:P2>
<SAP:P3>fmail/DynamicConfMail : Unsupported major.minor ve</SAP:P3>
<SAP:P4>rsion 50.0</SAP:P4>
<SAP:AdditionalText />
<SAP:Stack>Linkage error while loading class dynamicconfmail/DynamicConfMail; java.lang.UnsupportedClassVersionError: dynamicconfmail/DynamicConfMail : Unsupported major.minor version 50.0</SAP:Stack>
<SAP:Retry>M</SAP:Retry>
I am sure that I need to do include some library files, but I couln't figure it out. Couls you pls help to resolve this. The following library jar files were included
activation.jar
aii_map_api.jar
com.sap.xpi.ib.mapping.lib.jar
jce.jar
mail.jar
JRE System Library.............is anything else missed out??
By the way I included all these in Netweaver Developer studio , in JavaBuildPath ->Libraries.
Added those jar files as external jar's for development and then compiled it and exported as DynamicConfMailJar and imported in PI .
could anyone help?
I also got same error,but i resovled it by changing JDK compliance from 6.0 to 5.0
To do this right click on your project in NWDS and select properties and select java complier option.
check the box enable project specific settings and change JDK compliance from 6.0 to 5.0
Recompile your code and reimport the class files.
And also when you import your java class files in ESR,you can direclty check for version correctness by simply double clicking the class files, after saving the imported archive.if you get an error window then it has version error else you will get a window with method names in the java program.
Hope it helps.
User | Count |
---|---|
86 | |
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.