Skip to Content
avatar image
Former Member

Step By Step Guide for Configuring interface has compressed field with Gzip

HI,

The requirement is that in a payload, client will send compressed data in a field which PI needs to send it to ECC. then ECC will respond back and PI will have to compress that data and send it to client. the scenario is soap sync. when we reply, we have to compress the service message again. In a payload, it is a compressed field which is zipped using Gzip and base64 encoded. Please suggest

compressed.png (112.6 kB)
Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

9 Answers

  • Best Answer
    Apr 17, 2017 at 10:13 AM

    Here is code which i tested :

    For Compressing :

    String encoded = ""; 
    try{ 
    	ByteArrayOutputStream baos = new ByteArrayOutputStream(); 
    	GZIPOutputStream gzip = new GZIPOutputStream(baos); 
    	BASE64Encoder encoder = new BASE64Encoder();
    	gzip.write(invoice.getBytes());
    	gzip.close(); 
    	encoded = encoder.encode( baos.toByteArray());
    } 
    catch(Exception e)
    { 
    	return "";
    } 
    return encoded;
    

    For Decompressing :

    String line="";
    StringBuilder sb = new StringBuilder();
    try {
    
    
    BASE64Decoder decoder = new BASE64Decoder();
    byte b[] = decoder.decodeBuffer(encoded);
    ByteArrayInputStream bis = new ByteArrayInputStream(b);
    GZIPInputStream gis = new GZIPInputStream(bis);
    BufferedReader br = new BufferedReader(new InputStreamReader(gis, "UTF-8"));
    while((line = br.readLine()) != null) {
    sb.append(line);
    }
    }
    catch (IOException e) {
     System.out.println(e);
    }
    return sb.toString();
    
    Add comment
    10|10000 characters needed characters exceeded

    • Former Member

      Hi,

      I wanted to know that under the node "compressedData" we have other child nodes. We will be using dynamic configuration for soap actions for the same. so when they will send operation as "initjob" we will send only Initjobrequest to third party. does compression will have any affect on dynamic selection of soap action ?

  • Apr 11, 2017 at 02:47 PM

    Sherwin,

    As you want to Compress/Uncompress only on field in the data so ther is no standard way to do so , you need to go for java few examples are here :

    http://www.avajava.com/tutorials/lessons/how-do-i-compress-and-uncompress-a-gzip-file.html

    http://stackoverflow.com/questions/16351668/compression-and-decompression-of-string-data-in-java

    Br,

    Manoj

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Apr 11, 2017 at 03:25 PM

    Thanks Manoj.

    Can you tell me how can I processed in PI by using the information you provided? should we do it in PI or should I ask ECC guys to do it?

    Thakns in advance.

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Apr 25, 2017 at 10:43 AM

    HI Guys,

    I am trying to use the code but it is throwing error.

    Screenshot 1 shot shows UDF

    Screenshot 2 shows the node which I need to compress.

    Screenshot 3 error

    Please suggest

    Add comment
    10|10000 characters needed characters exceeded

  • Apr 25, 2017 at 11:12 AM

    Hi Sherwin,

    Please add the classes you use in your UDF to the import section.

    The "invoice" variable is not defined in your code. It should be var1 as I understand.

    Regards,

    Andrzej

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Apr 25, 2017 at 02:57 PM

    Hi,

    I have done the changes. I ran the test. It ran completily but i dont see the node compressed. Any idea why ?

    I am attaching the screenshots.

    Screenshot 7 for the test result.

    Screenshot 8 for the UDF and classes used. I also Added the external sun.misc.BASE64Decoder.jar. added in imported archive. Also I changed the classes.

    Screenshot 9 for the mapping done for the node.

    What am I missing here ?

    9.png

    Add comment
    10|10000 characters needed characters exceeded

  • Apr 25, 2017 at 03:14 PM

    Hi Sherwin!

    As I could see, you map result of your UDF to node having subnodes? You should map result to leaf node in order to get it filled. There is no ability to create mixed type nodes in graphical mapping.

    Regards, Evgeniy.

    Add comment
    10|10000 characters needed characters exceeded

    • You firstly need to Decode it via Base64decoder and then Decompress it via Gzip. Below is the code for Decompressing

      String line="";
      StringBuilder sb = new StringBuilder();
      try {
      BASE64Decoder decoder = new BASE64Decoder();
      byte b[] = decoder.decodeBuffer(encoded);
      ByteArrayInputStream bis = new ByteArrayInputStream(b);
      GZIPInputStream gis = new GZIPInputStream(bis);
      BufferedReader br = new BufferedReader(new InputStreamReader(gis, "UTF-8"));
      while((line = br.readLine()) != null) {
      sb.append(line);
      }
      }
      catch (IOException e) {
       System.out.println(e);
      }
      return sb.toString();
  • avatar image
    Former Member
    Apr 25, 2017 at 03:10 PM

    Hi Guys,

    I checked the display queue and it showed like the screenshots. I think it is compressed. I just want to confirm. is it compressed ?

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Jun 13, 2017 at 09:20 AM

    HI Guys,

    I am able to decompress it. now how to map the fields which are decompressed ? MY structure is like this

    Add comment
    10|10000 characters needed characters exceeded