Author |
Message
|
gagan.maverick |
Posted: Tue Sep 30, 2014 10:27 pm Post subject: Unzip using JCN |
|
|
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 |
|
 |
Esa |
Posted: Tue Sep 30, 2014 11:52 pm Post subject: |
|
|
 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 |
|
 |
gagan.maverick |
Posted: Wed Oct 01, 2014 12:04 am Post subject: |
|
|
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 |
|
 |
vicentius |
Posted: Wed Oct 01, 2014 1:05 am Post subject: |
|
|
 Apprentice
Joined: 01 Mar 2013 Posts: 28
|
|
Back to top |
|
 |
gagan.maverick |
Posted: Wed Oct 01, 2014 1:50 am Post subject: |
|
|
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 |
|
 |
McueMart |
Posted: Wed Oct 01, 2014 1:51 am Post subject: |
|
|
 Chevalier
Joined: 29 Nov 2011 Posts: 490 Location: UK...somewhere
|
|
Back to top |
|
 |
McueMart |
Posted: Wed Oct 01, 2014 1:53 am Post subject: |
|
|
 Chevalier
Joined: 29 Nov 2011 Posts: 490 Location: UK...somewhere
|
What is the error you are getting? |
|
Back to top |
|
 |
gagan.maverick |
Posted: Wed Oct 01, 2014 1:58 am Post subject: |
|
|
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 |
|
 |
gagan.maverick |
Posted: Wed Oct 01, 2014 2:03 am Post subject: |
|
|
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 |
|
 |
gagan.maverick |
Posted: Wed Oct 01, 2014 3:20 am Post subject: |
|
|
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 |
|
 |
Vitor |
Posted: Wed Oct 01, 2014 7:40 am Post subject: |
|
|
 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 |
|
 |
fjb_saper |
Posted: Wed Oct 01, 2014 9:59 am Post subject: |
|
|
 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 |
|
 |
gagan.maverick |
Posted: Wed Oct 08, 2014 10:33 pm Post subject: |
|
|
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 |
|
 |
smdavies99 |
Posted: Wed Oct 08, 2014 10:56 pm Post subject: |
|
|
 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 |
|
 |
gagan.maverick |
Posted: Wed Oct 08, 2014 11:03 pm Post subject: |
|
|
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 |
|
 |
|