on 04-20-2009 10:32 AM
Hello all,
My scenario is Mail -> PI - > SQL Server.
In order to bypass a problem of data format in my incoming mail, i use the java class Message Unwrapper.
Everything works fine except that it stuck all my words together !!
For example :
Input :
<Address>Test test test Test test test
test test test
Test test test Test test test
</adress>
Output :
<adress>TesttesttestTesttesttestTesttesttestTesttesttest</adress>
I want in output : <adress> test test test test test test test test test test </adress>
Do you know how i can handle that ?
My code is :
public class MessageUnwrapper implements StreamTransformation {
// Outbound structure
public static int bufferSize = 128;
private static final String XML_START_CONTENT = "<Content>";
/**
* @see com.sap.aii.mapping.api.StreamTransformation#setParameter(Map)
*/
public void setParameter(Map arg0) {
public void execute(InputStream in, OutputStream out)
throws StreamTransformationException {
try {
String xml = getStreamAsString(in);
writeOutputStream(xml, out);
} catch (Exception e) {
e.printStackTrace();
throw new StreamTransformationException(
"Exception during KeyMapping: (" + e.getClass().getName()
+ ") " + e.getMessage(), e);
}
}
private BufferedReader readInputStream(InputStream in) {
InputStreamReader isr = new InputStreamReader(in);
return new BufferedReader(isr);
}
/**
* @param output
* @return
*/
private void writeOutputStream(String xml, OutputStream out) {
try {
out.write(xml.getBytes());
} catch (Exception e) {
System.out.println(xml);
}
}
private String getStreamAsString(InputStream in) {
try {
StringBuffer output = new StringBuffer();
String xml = "";
BufferedReader br = readInputStream(in);
String line1;
while ((line1 = br.readLine()) != null) {
output.append(line1);
}
br.close();
// < and >
xml += output.toString();
int deb;
String xmldeb = "";
String xmlcontent = "";
if ( ((deb = xml.indexOf(XML_START_CONTENT)) != -1) ) {
xmldeb = xml.substring(0, deb);
xmlcontent = xml.substring(deb);
}
xmlcontent = xmlcontent.replaceAll("\\>\\;", ">");
xmlcontent = xmlcontent.replaceAll("\\<\\;", "<");
xmlcontent = xmlcontent.replaceAll("\\<\\;", "<");
xmlcontent = xmlcontent.replaceAll("\\>\\;", ">");
// &
xmlcontent = xmlcontent.replaceAll("\\&\\;", "&");
xmlcontent = xmlcontent.replaceAll("\\&\\;", "&");
xmlcontent = xmlcontent.replaceAll("&", "&");
xml = xmldeb + xmlcontent;
return xml;
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
public static void main(String[] args) {
if (args.length < 1) {
System.out.println("Input file not found!");
System.exit(0);
}
try {
InputStream in = new FileInputStream(args[0]);
System.out.println(args[0]);
OutputStream out = new FileOutputStream(args[0] + ".out.xml");
new MessageUnwrapper().execute(in, out);
} catch (Exception e) {
e.printStackTrace();
System.exit(0);
}
}
}
Edited by: Jean-Philippe PAIN on Apr 20, 2009 11:34 AM
Edited by: Jean-Philippe PAIN on Apr 20, 2009 11:35 AM
Hello,
Modify statement in your method private String getStreamAsString(InputStream in) , the following statement to modify:
case-1:
while ((line1 = br.readLine()) != null) {
xml += line1;
}
if case:1 doesn't work try case 2:
case-2:
output.append(line1); instead use output.writeln(line1) check with this, think you shall get that..
Regards..
P.K
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I still have my problem when i look the output in the Test tab of the Interface mapping.
I even tried to do :
output.append(line1+ "\n");
but it doesn't works either...
I recall my problem :
<text>
NAME : Brian
LASTNAME : BREAD
</text>
output:
<text>NAME : BrianLASTNAME : BREAD </text>
I don't understand why it doesn't work...I must miss something...
With the code, it's better !
I hope someone got an idea !
Thanks.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
TEST was an example. Normally, it's some commentary so the length is not fixed !!
My input date is in XML format (string), my output also.
I don't understand why it stucks all my words !!
e.g :
input :
<comment> Brian is in the kitchen.
Where is Brian ?
</comment>
Bad output :
<comment>Brianisinthekitchen.WhereisBrian?</comment>
Good output(what i want) :
<comment>Brian is in the kitchen. where is Brian ?</comment>
Hi
Hope u r using JAVA Mapping for u r Mapping requirement , am not sure why this is happening,
But try this solution
Mapping Program (MM1) --- JAVA Mapping
Create a Message Mapping (MM2) --- Do one to one --- Corresponding to the comment do one to one mapping
Now in Interface mapping use both Mapping program in sequence
IM_OUT -
MM1 -
IM_IN
MM2
Try this if it works lemme know
Srini
Hi
Give Address ELEMENT ---> ReplaceAll ("Test" , "test") --> Target Element
Srini
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.