ASG
IBM
Zystems
Cressida
Icon
Netflexity
 
  MQSeries.net
Search  Search       Tech Exchange      Education      Certifications      Library      Info Center      SupportPacs      LinkedIn  Search  Search                                                                   FAQ  FAQ   Usergroups  Usergroups
 
Register  ::  Log in Log in to check your private messages
 
RSS Feed - WebSphere MQ Support RSS Feed - Message Broker Support

MQSeries.net Forum Index » WebSphere Message Broker (ACE) Support » Unzip using JCN

Post new topic  Reply to topic Goto page 1, 2  Next
 Unzip using JCN « View previous topic :: View next topic » 
Author Message
gagan.maverick
PostPosted: Tue Sep 30, 2014 10:27 pm    Post subject: Unzip using JCN Reply with quote

Acolyte

Joined: 30 Sep 2014
Posts: 50

Hi , i have a requirement that the server will send zip files to my queue , from there i need to unzip the contents using jcn and proceed. I have used RCD node to reset the domain to Blob. but its not working.
Back to top
View user's profile Send private message
Esa
PostPosted: Tue Sep 30, 2014 11:52 pm    Post subject: Reply with quote

Grand Master

Joined: 22 May 2008
Posts: 1387
Location: Finland

Yes, you will have to write some java code to unzip the message. Utility classes for that are a part of java standard edition.
Back to top
View user's profile Send private message
gagan.maverick
PostPosted: Wed Oct 01, 2014 12:04 am    Post subject: Reply with quote

Acolyte

Joined: 30 Sep 2014
Posts: 50

I don't have any knowledge on Java , after converting the message to blob i don't know how to access it in JCN and the processing..Thanks for the reply..
Back to top
View user's profile Send private message
vicentius
PostPosted: Wed Oct 01, 2014 1:05 am    Post subject: Reply with quote

Apprentice

Joined: 01 Mar 2013
Posts: 28

I would start here:
http://www-01.ibm.com/support/knowledgecenter/api/content/SSKM8N_8.0.0/com.ibm.etools.mft.doc/ac20805_.htm

I found this also useful:
http://www-01.ibm.com/support/knowledgecenter/api/content/SSKM8N_8.0.0/com.ibm.etools.mft.plugin.doc/index.html

You will easily find sample code to guide you.

Let us know how it goes, what you try and what you learn. Others might benefit from your experiences in the future.
Back to top
View user's profile Send private message
gagan.maverick
PostPosted: Wed Oct 01, 2014 1:50 am    Post subject: Reply with quote

Acolyte

Joined: 30 Sep 2014
Posts: 50

Hi guys , i got some code and modified it , but it goes to error,


Code:
import com.ibm.broker.javacompute.MbJavaComputeNode;
import java.io.*;
import java.util.zip.*;
import com.ibm.broker.plugin.*;



public class Dcompress_JavaCompute extends MbJavaComputeNode {

   public void evaluate(MbMessageAssembly assembly) throws MbException {
      MbOutputTerminal out = getOutputTerminal("out");
      MbOutputTerminal alt = getOutputTerminal("alternate");
      MbOutputTerminal fail = getOutputTerminal("failure");

      MbMessage inmessage = assembly.getMessage();

      // ----------------------------------------------------------
      // Add user code below

      MbMessage outMessage = new MbMessage(inmessage);
      MbMessageAssembly outAssembly = new MbMessageAssembly(assembly,outMessage);
      MbElement msgBody ;
      byte []msgByteStreamIn;   // ByteStream before compression
       byte []msgByteStreamOut;  // ByteStream after compression
       InflaterInputStream infInputStream = null;
       try {
         // Message body is the last child of Root
         msgBody = outMessage.getRootElement().getLastChild();
         msgBody.detach();  //detach the message body
         // Returns the bit stream representation of the element. This method causes
         // the parser associated with the element to serialize the element and all
         // its children. This method can only be called on the message body, i.e.
         // the last child of the message root.
         msgByteStreamIn = msgBody.toBitstream("","","",0,0,0);
         infInputStream = new GZIPInputStream(new ByteArrayInputStream(msgByteStreamIn));
         ByteArrayOutputStream bytesOut = new ByteArrayOutputStream(msgByteStreamIn.length);
         byte[] tempBuffer = new byte[msgByteStreamIn.length];
         int numBytesRead = 0;
         while (numBytesRead != -1) {
         numBytesRead = infInputStream.read(tempBuffer, 0, msgByteStreamIn.length);
           if (numBytesRead != -1) {
             bytesOut.write(tempBuffer, 0, numBytesRead);
           }
         }
         msgByteStreamOut = bytesOut.toByteArray();
         infInputStream.close();
         bytesOut.close();
         // After decompression, the resultant bitstream should be converted to
         // BLOB since we do not have a PARSER class corresponding to MRM.
         // Next, it has to be reattached to the output message.
         msgBody = outMessage.getRootElement().createElementAsLastChildFromBitstream
             (msgByteStreamOut,MbBLOB.PARSER_NAME,"","","",0,0,0);
         out.propagate(outAssembly);
       }
       catch (IOException e){
         e.printStackTrace();
         fail.propagate(outAssembly);
       }
       catch (MbException e){
         throw e;
       }
       finally {
         // clear the outMessage
         outMessage.clearMessage();
       }
     }
   }
      
      
      
      
      
      // End of user code
      // ----------------------------------------------------------

      // The following should only be changed
      // if not propagating message to the 'out' terminal
Back to top
View user's profile Send private message
McueMart
PostPosted: Wed Oct 01, 2014 1:51 am    Post subject: Reply with quote

Chevalier

Joined: 29 Nov 2011
Posts: 490
Location: UK...somewhere

So you have no knowledge of java, but you want to use a JCN? That's like saying you want to drive a car but you dont know how to drive a car. Obviously you are going to do some learning first else it wont be very successful

Here is some good information about how you can unzip files from Java:

http://stackoverflow.com/questions/9324933/what-is-a-good-java-library-to-zip-unzip-files

It wouldnt be very hard to get the BLOB data in the JCN and use one of the libraries (suggested in the link above) to unzip the stream.

(Note that there is also Supportpac ia99 : http://www-01.ibm.com/support/docview.wss?uid=swg24007617 - I have no idea if this works in WMBv8/9 )
Back to top
View user's profile Send private message
McueMart
PostPosted: Wed Oct 01, 2014 1:53 am    Post subject: Reply with quote

Chevalier

Joined: 29 Nov 2011
Posts: 490
Location: UK...somewhere

What is the error you are getting?
Back to top
View user's profile Send private message
gagan.maverick
PostPosted: Wed Oct 01, 2014 1:58 am    Post subject: Reply with quote

Acolyte

Joined: 30 Sep 2014
Posts: 50

Not in GZIP format... I have debugged my code in wmb debug mode it doesn't go beyond

infInputStream = new GZIPInputStream(new ByteArrayInputStream(msgByteStreamIn));


after this straight to catch.. i guess i need to remove gzip with some other stuff.
Back to top
View user's profile Send private message
gagan.maverick
PostPosted: Wed Oct 01, 2014 2:03 am    Post subject: Reply with quote

Acolyte

Joined: 30 Sep 2014
Posts: 50

I replaced it with ZipInputStream.. it is not showing any error now but in output queue i am not getting ang message
Back to top
View user's profile Send private message
gagan.maverick
PostPosted: Wed Oct 01, 2014 3:20 am    Post subject: Reply with quote

Acolyte

Joined: 30 Sep 2014
Posts: 50

When the message leaves JCN , then , Blob.blob is empty and in queue the message length is zero.. Can you guys suggest what i am missing here.
Back to top
View user's profile Send private message
Vitor
PostPosted: Wed Oct 01, 2014 7:40 am    Post subject: Reply with quote

Grand High Poobah

Joined: 11 Nov 2005
Posts: 26093
Location: Texas, USA

gagan.maverick wrote:
When the message leaves JCN , then , Blob.blob is empty and in queue the message length is zero.. Can you guys suggest what i am missing here.


Java skills? Seriously. There's a bug in your code. The output tree is not being correctly built and/or propagated.
_________________
Honesty is the best policy.
Insanity is the best defence.
Back to top
View user's profile Send private message
fjb_saper
PostPosted: Wed Oct 01, 2014 9:59 am    Post subject: Reply with quote

Grand High Poobah

Joined: 18 Nov 2003
Posts: 20756
Location: LI,NY

The assumption for the message body is wrong.

Message.getRoot().getLastChild().getLastChild() should allow you access to the body...
_________________
MQ & Broker admin
Back to top
View user's profile Send private message Send e-mail
gagan.maverick
PostPosted: Wed Oct 08, 2014 10:33 pm    Post subject: Reply with quote

Acolyte

Joined: 30 Sep 2014
Posts: 50

Hi guys I was able to unzip the zip files , but i am facing a very strange issue when i am trying to unzip customer files , the code doesn't but when i manually unzip the file and zip it again with same contents it works.. Can you suggest what i am missing.. below is my entire code for unzipping in JCN..

import com.ibm.broker.javacompute.MbJavaComputeNode;
import java.io.*;
import java.util.zip.*;

import com.ibm.broker.plugin.*;
import com.ibm.jvm.format.Message;



public class Dcompress_JavaCompute extends MbJavaComputeNode {


public void evaluate(MbMessageAssembly assembly) throws MbException {
MbOutputTerminal out = getOutputTerminal("out");

// ----------------------------------------------------------
// Add user code below
MbMessage inmessage = assembly.getMessage();
MbMessage outMessage = new MbMessage(inmessage);
MbMessageAssembly outAssembly = new MbMessageAssembly(assembly,
outMessage);

MbElement msgBody;
byte[] msgByteStreamIn;

byte[] msgBytes = null;

try {
// Message body is the last child of Root
msgBody = outMessage.getRootElement().getLastChild();
msgBody.detach(); //detach the message body
// Returns the bit stream representation of the element. This method causes
// the parser associated with the element to serialize the element and all
// its children. This method can only be called on the message body, i.e.
// the last child of the message root.

msgByteStreamIn = msgBody.toBitstream("", "", "", 0, 0, 0);
byte[] buffer = new byte[2048];

ZipInputStream zipStream = new ZipInputStream(new ByteArrayInputStream(msgByteStreamIn));

ZipEntry entry ;




int file_num = 0;
try {
while ((entry = zipStream.getNextEntry()) != null) {


String s = String.format("Entry: %s ",
entry.getName());
System.out.println(s);




int len= 0;

StringBuffer sb_result = new StringBuffer();

while ((len = zipStream.read(buffer)) > 0) {
sb_result.append(new String(buffer, 0, len));
}


zipStream.closeEntry();
String result = sb_result.toString();

file_num = file_num + 1;


msgBytes = result.getBytes();

msgBody = outMessage.getRootElement().createElementAsLastChildFromBitstream(msgBytes,"NONE", "", "", "", 0, 0, 0);

out.propagate(outAssembly);
msgBody.detach();
}
} catch (IOException e1) {
System.out.println("Error Reading The Archive.");
e1.printStackTrace();
}

} catch (MbException e) {
throw e;
} finally {
// clear the outMessage

outMessage.clearMessage();
}
}


}



// End of user code
// ----------------------------------------------------------

// The following should only be changed
// if not propagating message to the 'out' terminal
Back to top
View user's profile Send private message
smdavies99
PostPosted: Wed Oct 08, 2014 10:56 pm    Post subject: Reply with quote

Jedi Council

Joined: 10 Feb 2003
Posts: 6076
Location: Somewhere over the Rainbow this side of Never-never land.

Is the real customer file really a zip file. Utilities such as gzip, gunzip, zip, unzip are able to handle several different types of zip file.

The first few buyes of the file will tell you what sort it is. Dump the file Or
substring the first 20 bytes of the file (.BLOb.BLOB) into a separate BLOB and send it to a trace output. Then run your test zip and the customer zip and compare the output.
_________________
WMQ User since 1999
MQSI/WBI/WMB/'Thingy' User since 2002
Linux user since 1995

Every time you reinvent the wheel the more square it gets (anon). If in doubt think and investigate before you ask silly questions.
Back to top
View user's profile Send private message
gagan.maverick
PostPosted: Wed Oct 08, 2014 11:03 pm    Post subject: Reply with quote

Acolyte

Joined: 30 Sep 2014
Posts: 50

ok so you mean
DECLARE Payload BLOB;
SET Payload = SUBSTRING(InputRoot.BLOB.BLOB FROM 1 for 20);
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic  Reply to topic Goto page 1, 2  Next Page 1 of 2

MQSeries.net Forum Index » WebSphere Message Broker (ACE) Support » Unzip using JCN
Jump to:  



You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Protected by Anti-Spam ACP
 
 


Theme by Dustin Baccetti
Powered by phpBB © 2001, 2002 phpBB Group

Copyright © MQSeries.net. All rights reserved.