on 2011 Dec 17 6:03 AM
Could anyone please let me know how to remove the XML header <?xml version="1.0" encoding="UTF-8" ?>
- <ns0:MT_Ack_Delivery_Inbound xmlns:ns0="urn:commscope.com/ALUespares/AckDelivery">
My trading partner doesn't require the XML header in the file that we are sending to them.
Actually he only want his xml header as mentioned below
<?xml version="1.0"?>
instead of the one which is shown below
<?xml version="1.0" encoding="UTF-8" ?>
- <ns0:MT_Ack_Delivery_Inbound xmlns:ns0="urn:commscope.com/ALUespares/AckDelivery">
Can any one please help me out of this
Request clarification before answering.
Hi ,
You need to add this java mapping code after your message mapping in the same interface mapping or operational mapping.
No need to change your existing message mapping. Let it remain as it is, just need to add this code after message mapping.
I tried with other mappings such as XSLT but could not achieve any results. Hence I feel only solution to your problem (other than writing adapter module) is java mapping.
For PI 7.1 and above
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Map;
import com.sap.aii.mapping.api.AbstractTransformation;
import com.sap.aii.mapping.api.StreamTransformationException;
import com.sap.aii.mapping.api.TransformationInput;
import com.sap.aii.mapping.api.TransformationOutput;
public class RemoveEncodingName extends AbstractTransformation {
/**
* @param args
*/
public void execute(InputStream in, OutputStream out)
throws StreamTransformationException {
// TODO Auto-generated method stub
try
{
byte b[]=new byte[in.available()];
String encoding="UTF-8";
in.read(b);
String inputXML=new String(b);
inputXML="<?xml version=\"1.0\" ?>"+inputXML.substring(inputXML.indexOf('>')+1,inputXML.length());
out.write(inputXML.getBytes(encoding));
}
catch(Exception e)
{
e.printStackTrace();
}
}
public void setParameter(Map arg0) {
// TODO Auto-generated method stub
}
public void transform(TransformationInput arg0, TransformationOutput arg1)
throws StreamTransformationException {
this.execute(arg0.getInputPayload().getInputStream(), arg1.getOutputPayload().getOutputStream());
}
}
For PI 7.0
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Map;
import com.sap.aii.mapping.api.StreamTransformation;
import com.sap.aii.mapping.api.StreamTransformationException;
public class RemoveEncodingName implements StreamTransformation {
/**
* @param args
*/
public void execute(InputStream in, OutputStream out)
throws StreamTransformationException {
// TODO Auto-generated method stub
try
{
byte b[]=new byte[in.available()];
String encoding="UTF-8";
in.read(b);
String inputXML=new String(b);
inputXML="<?xml version=\"1.0\" ?>"+inputXML.substring(inputXML.indexOf('>')+1,inputXML.length());
out.write(inputXML.getBytes(encoding));
}
catch(Exception e)
{
e.printStackTrace();
}
}
public void setParameter(Map arg0) {
// TODO Auto-generated method stub
}
}
if you need help in java mapping you can consult this link which shows steps to compile and upload java mapping codes to PI server
http://wiki.sdn.sap.com/wiki/display/XI/BeginnersguidetoJavamappingusingDOMparserinSAPXI
Regards
Anupam
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
you have not mentioned the version of PI you are working. Thus I am letting you know in generic way.
First you need to compile this java program and import the jar file into the PI server. The steps to do this is explained in the link i provided in my last post. you have to import the jar file to imported archive. Use proper external jar file to compile the code according to version of PI server you are working. Ask for proper external jar files from your colleagues or in SDN search for it.
you can consult this link http://wiki.sdn.sap.com/wiki/display/XI/WheretogetthelibrariesforXI+development
This is important since you need to compile the code with proper jar file and proper java version as per your PI server.
After import is complete, go into the interface or operation mapping where you have the old message mapping.
Here you import the java class file from imported archive. save and activate.
Regards
Anupam
HI
<?xml version="1.0"?>
It can be done easily with Java mapping by just taking the input xml as string and then removing the encoding part from the string
please refer below blog:
You can use the following code if your PI version is 7.1
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import com.sap.aii.mapping.api.AbstractTransformation;
import com.sap.aii.mapping.api.StreamTransformationException;
import com.sap.aii.mapping.api.TransformationInput;
import com.sap.aii.mapping.api.TransformationOutput;
public class Test extends AbstractTransformation {
@SuppressWarnings("null")
public void transform(TransformationInput transformationInput,
TransformationOutput transformationOutput)
throws StreamTransformationException {
getTrace().addDebugMessage("Entered transform method");
InputStream in = transformationInput.getInputPayload().getInputStream();
OutputStream out = transformationOutput.getOutputPayload()
.getOutputStream();
try {
byte[] b = new bytehttp://in.available();
in.read(b);
String req = new String(b);
req = req.replaceAll("<?xml version="1.0" encoding="UTF-8"?>" , "<?xml version="1.0"?>" );
out.write(req.getBytes());
out.flush();
}
catch (IOException ioe) {
getTrace().addWarning(
"Error While prerforming Java Transformation"
+ ioe.getMessage());
throw new StreamTransformationException(
"Error While prerforming Java Transformation"
+ ioe.getMessage(), ioe);
}
}
}
thanks,
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
77 | |
30 | |
10 | |
8 | |
8 | |
7 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.