cancel
Showing results for 
Search instead for 
Did you mean: 

Passing binary information in a synchronous scenario

former_member195202
Participant
0 Kudos

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.


Accepted Solutions (1)

Accepted Solutions (1)

former_member181985
Active Contributor
0 Kudos

Actually You don't need a mapping for response

former_member195202
Participant
0 Kudos

Hi Praveen,

I was doubting that I can remove the response mapping but I did not try that .. Thanks to the laziness

Yes, I can remove the mapping from the response and it still works so that I am receiving the same data and I can view the pdf data also.

Many thanks Praveen..

Ravi.

former_member181985
Active Contributor
0 Kudos

Cheers Ravi

Answers (1)

Answers (1)

former_member181985
Active Contributor
0 Kudos

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