cancel
Showing results for 
Search instead for 
Did you mean: 

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

Former Member
0 Kudos

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

Accepted Solutions (1)

Accepted Solutions (1)

manoj_khavatkopp
Active Contributor
0 Kudos

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

Former Member
0 Kudos

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 ?

Answers (8)

Answers (8)

Former Member
0 Kudos

HI Guys,

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

former_member190293
Active Contributor
0 Kudos

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.

Former Member
0 Kudos

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

manoj_khavatkopp
Active Contributor

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

Former Member
0 Kudos

Got it.

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

Regards,

Sherwin

manoj_khavatkopp
Active Contributor
0 Kudos

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();
Former Member
0 Kudos

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 ?

Former Member
0 Kudos

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

Andrzej_Filusz
Contributor
0 Kudos

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

Former Member
0 Kudos

Hi,

Can you tell me which classes I need to import ?

Thanks,

Sherwin

Andrzej_Filusz
Contributor

Hi,

Please look at the last screen: BASE64Encoder.

Regards,

Andrzej

Former Member
0 Kudos

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

Former Member
0 Kudos

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.

manoj_khavatkopp
Active Contributor
0 Kudos

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

Former Member
0 Kudos

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

Andrzej_Filusz
Contributor

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

Former Member
0 Kudos

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.

Andrzej_Filusz
Contributor

Hi Sherwin,

You can send me a message.

Regards,

Andrzej

manoj_khavatkopp
Active Contributor
0 Kudos

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