on 04-01-2008 1:32 PM
Hi Friends,
We are creating adapters for XI. We have coded java (EJB) for converting text to XML and giving to XI. We used Module interface and overridden process method. we used following code,
public ModuleData process(ModuleContext moduleContext,ModuleData inputModuleData)throws ModuleException {
Object obj = null;
Message msg = null;
ModuleException mEx = null;
AuditMessageKey amk = null;
String givenText = "";
try{
obj = inputModuleData.getPrincipalData();
msg = (Message)obj;
amk = new AuditMessageKey(msg.getMessageId(),AuditDirection.INBOUND);
XMLPayload inputpayload = msg.getDocument() ;
givenText = new String(inputpayload.getText().toString());
}
catch(Exception e){
throw mEx = new ModuleException("Error while creating basic instances obj,msg,xmlplayload,text");
}
}
In this case I am getting string data in the variable "givenText", but same code used for getting XML data(OUTBOUND), but I am getting exception, I think it is not able to get the XML data.
Question; Could you provide the code for getting XML String from ModuleData to givenText.
advance Thanks.
hi,
have u got solution for your question.
If u found solution. plz share it.
we also need to do the same.
regards,
Shanthakumar.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi ShanthaKumar,
We got the solution,
for reading XML data from the ModuleData we used following code:
obj = inputModuleData.getPrincipalData();
msg = (Message)obj;
if (msg.getMessageDirection().equals(MessageDirection.INBOUND))
{amk = new AuditMessageKey(msg.getMessageId(),AuditDirection.INBOUND);}
else
{amk = new AuditMessageKey(msg.getMessageId(),AuditDirection.OUTBOUND);}
xmlpayload = msg.getDocument();
XMLData = xmlpayload.getText();
//Now we got xml data as a string in XMLData variable
//Do your requirement on XMLData and then set the converted string into moduledata again as follows.
//textEDI is the coverted string
xmlpayload.setText(textEDI);
msg.setDocument(xmlpayload);
inputModuleData.setPrincipalData(msg);
return inputModuleData;
//This code should be enclosed in try, catch.
If you have any queries, get back to me.
Don't forget to provide points.
Thanks & Regards,
Lakshmi Prasad
Hi Lakshmi,
this is the code to convert a .pdf to XML, see if this helps you in some way:
public ModuleData process(ModuleContext mc, ModuleData imd)
throws ModuleException {
Object obj = null;
Message msg = null;
try {
obj = imd.getPrincipalData();
msg = (Message) obj;
XMLPayload xp = msg.getDocument();
if (xp != null) {
xp.setContent(convertToText(xp));
}
imd.setPrincipalData(msg);
} catch (Exception e) {
}
return imd;
}
public byte[] convertToText(XMLPayload xp) throws Exception {
String textData = null;
String encoding = null;
int startPage = 1;
int endPage = Integer.MAX_VALUE;
PDDocument document = null;
String retXMLData = null;
try {
// Get PDDocument from the file content
document = PDDocument.load(xp.getInputStream());
ByteArrayOutputStream by = new ByteArrayOutputStream();
OutputStreamWriter out = new OutputStreamWriter(by);
PDFTextStripper stripper = null;
stripper = new PDFTextStripper();
stripper.setStartPage(startPage);
stripper.setEndPage(endPage);
stripper.writeText(document, out);
textData = by.toString();
retXMLData =
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n\n"
+ "<ns:"
+ "ReadPDF"
+ " xmlns:ns=\""
+ "http://demo.com"
+ "\">"
+ "<TextData>"
+ textData
+ "</TextData>\n"
+ "</ns:"
+ "ReadPDF"
+ ">";
} catch (Exception e) {
}
Though conversion from text to XML can also be done by file content conversion in file adapter of SAP PI.
Thanks,
Varun
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Varun,
Thank you for your response,
Actually I want to get XML data from ModuleData. while receiving data exception is throwing.
I have used the following code
XMLPayload inputpayload = msg.getDocument() ;
XMLData = new String(inputpayload.getText().toString());
My question: can I get xml string into XMLData variable in the above case.
Thanks,
Lakshmi Prasad.
User | Count |
---|---|
79 | |
9 | |
9 | |
7 | |
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.