on 02-28-2014 10:45 AM
Hi All,
I am working on a synchronous scenario where I am sending an HTTP request to third party and I am getting back the response. My requirement is that I need to pass through this response as it is from XI, no transformation is required.
This happens twice:
1) In first case, I receive the html data which is ok
2) in second case, I receive PDF data which is getting corrupted and I cant view that pdf data after my message mapping.
I am using below code in response mapping (java mapping)....
public void transform(TransformationInput in, TransformationOutput out) throws StreamTransformationException {
try {
String sourceString = "";String line ="";
String append ="";
InputStream ins = in.getInputPayload().getInputStream();
BufferedReader br = new BufferedReader(new InputStreamReader(ins, "UTF-8"));
while ((line = br.readLine()) != null){
sourceString = sourceString + line;
}
br.close();
out.getOutputPayload().getOutputStream().write(sourceString.getBytes("UTF-8"));
}
catch (Exception e) {
throw new StreamTransformationException(e.getMessage());
}
}
Problem is that this code is working for case 1) when I receive HTML data but in case 2) the data gets corrupted.I think I would need to pass the response as binary data (as it is) for both the cases.
Do not forget that it is a synchronous interface so I do not have the option to bypass the IR development since I am making some transformation in the request mapping.
Can anyone suggest.
Thanks,
Ravi.
Actually You don't need a mapping for response
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello Ravi,
You are reading inputstream in character mode. i.e., BufferedReader
You should read the content in byte mode
Try with this code:
byte[] buffer = new byte[1024];
public void transform(TransformationInput in, TransformationOutput out) throws StreamTransformationException {
try {
InputStream is = (InputStream) in.getInputPayload().getInputStream();
OutputStream os = (OutputStream) out.getOutputPayload().getOutputStream();
while ((int len = is.read(buffer)) > 0)
{
os..write(buffer, 0, len);
} catch (Exception e) {
throw new StreamTransformationException(e.getMessage());
}
}
Regards,
Praveen Gujjeti
Message was edited by: PRAVEEN GUJJETI
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
93 | |
10 | |
10 | |
9 | |
9 | |
7 | |
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.