Skip to Content
0

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

Apr 11, 2017 at 11:11 AM

494

avatar image
Former Member

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)
10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

9 Answers

Best Answer
Manoj K Apr 17, 2017 at 10:13 AM
0

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();

scn.png (23.4 kB)
Show 2 Share
10 |10000 characters needed characters left characters exceeded
Former Member

Brilliant as always. I am going to test this interface next week. I will update you once I am done. Thank you so much again.

best regards,

Sherwin

1
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 ?

0
Manoj K Apr 11, 2017 at 02:47 PM
0

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

Share
10 |10000 characters needed characters left characters exceeded
avatar image
Former Member Apr 11, 2017 at 03:25 PM
0

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.

Show 5 Share
10 |10000 characters needed characters left characters exceeded

Sherwin,

I believe there are standard FM to gzip and base64 encoding cross check with this your ABAP team , or else u need to implement this in PI.

Br,

Manoj

0
Former Member

Thanks for the reply Manoj. I have to do it in PI so can you please let me know who to proceed.?

0

Hi Sherwin,

You can write a java mapping class and use it in your OM. In your java code, you can parse your message and take that part of it which have to be decompressed or compressed. You can use, for example, standard java classes to do that:

java.util.zip.GZIPOutputStream 
java.util.zip.GZIPInputStream 

Then you can encode the result using Base64 class (it's a part of Java standard now) and put into the output message.

Regards,

Andrzej

2
Former Member
Andrzej Filusz

Hi Andrzej,

Thank you so much for your inputs. I will use it and will let you know the solution. I might be giving the update by end of next week. Is there any way i can contact you directly if you don't mind? sorry for the inconvenience.

0

Hi Sherwin,

You can send me a message.

Regards,

Andrzej

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

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


1.png (34.9 kB)
2.png (76.2 kB)
3.png (26.6 kB)
Share
10 |10000 characters needed characters left characters exceeded
Andrzej Filusz Apr 25, 2017 at 11:12 AM
0

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

Show 2 Share
10 |10000 characters needed characters left characters exceeded
Former Member

Hi,

Can you tell me which classes I need to import ?

Thanks,

Sherwin

0

Hi,

Please look at the last screen: BASE64Encoder.

Regards,

Andrzej

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

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


7.png (30.9 kB)
8.png (35.7 kB)
9.png (33.9 kB)
Share
10 |10000 characters needed characters left characters exceeded
Evgeniy Kolmakov Apr 25, 2017 at 03:14 PM
0

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.

Show 4 Share
10 |10000 characters needed characters left characters exceeded
Former Member

Hi Evgeniy,

Thanks for the reply. If you check my updated screenshot, is showing as encoded. do you think it wont work when it is sent to third party? Can you please tell me what do you mean when you say map your result to leaf node. Attaching the screenshots again for you.

Thanks,

Sherwin

9.png (33.9 kB)
10.png (81.1 kB)
0

Sherwin,

You can see the result in Display Queue , but when you test it it wont appear in target structure as already Eve Suggested you are mapping it to a node and not a field which is capable of holding a value , so change your mapping so that target field is a field and not any parent note.

Br,

Manoj

1
Former Member

Got it.

what are the changes we have to do for decompression in the UDF which you have given ?

Regards,

Sherwin

0

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();
0
avatar image
Former Member Apr 25, 2017 at 03:10 PM
0

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 ?


7.png (30.9 kB)
10.png (81.1 kB)
Share
10 |10000 characters needed characters left characters exceeded
avatar image
Former Member Jun 13, 2017 at 09:20 AM
0

HI Guys,

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


map.png (55.7 kB)
Share
10 |10000 characters needed characters left characters exceeded