on 03-18-2016 5:08 AM
Hi Experts,
My Scenario is File(Tab delimiter) to proxy and the requirement is when ever i get an invalid char any where in file have to throw an exception.
Can you please suggest me guys.
Regards
Abdul.
Hi Abdul,
Use below java mapping before message mapping to throw an exception if there are any special characters.
import java.io.InputStream;
import java.io.OutputStream;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
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 CheckSpecialCharacters extends AbstractTransformation {
@Override
public void transform(TransformationInput transformationInput, TransformationOutput transformationOutput)
throws StreamTransformationException {
try {
InputStream inputStream = transformationInput.getInputPayload().getInputStream();
OutputStream outputStream = transformationOutput.getOutputPayload().getOutputStream();
byte[] buf = new byte[inputStream.available()];
inputStream.read(buf);
String inputPayload = new String(buf);
Pattern pattern = Pattern.compile("[^\\p{ASCII}]");
Matcher matcher = pattern.matcher(inputPayload);
if (matcher.find())
throw new StreamTransformationException("File got invalid characters");
outputStream.write(inputPayload.getBytes());
} catch (Exception ex) {
getTrace().addDebugMessage(ex.getMessage());
throw new StreamTransformationException(ex.toString());
}
}
}
Test mapping:
Regards,
Praveen.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Abdul,
Check this blog Throwing Smart Exceptions in XI Graphical Mapping | SCN or Debashish answer UDF to raise exception | SCN
Regards.
Abdul,
Links shared by Inaki should help you.
Once more link for your reference
SAPTechnical.COM - Handling and Tracing Runtime Exceptions in Java Mapping (SAP PI/XI)
User | Count |
---|---|
93 | |
11 | |
10 | |
9 | |
9 | |
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.