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 » IBM MQ API Support » How to get a pdf into the buffer (no referance messages)

Post new topic  Reply to topic Goto page 1, 2  Next
 How to get a pdf into the buffer (no referance messages) « View previous topic :: View next topic » 
Author Message
PeterPotkay
PostPosted: Sun Sep 15, 2002 2:18 pm    Post subject: How to get a pdf into the buffer (no referance messages) Reply with quote

Poobah

Joined: 15 May 2001
Posts: 7722

I got a project coming up where I will have to send a pdf file from a VB MQSeries Client application to a JAVA MQSeries Client application. Is this possible?
I want to stay away from referance messages, since it involves creating message exits on both sides. http://www.mqseries.net/phpBB/viewtopic.php?t=4222&highlight=file+transfer.

We have a corporate VB Wrapper that all our MQ VB apps use, so I am looking for a way to have the new VB app read the file into a byte array, and then pass that string into the wrapper for the PUT.


The closest thing I was able to find to what I want to do is this:
http://www.mqseries.net/phpBB/viewtopic.php?t=1670&highlight=file+transfer

But no one ever answered oware's question on whether the code he posted was correct.

Will I be able to pull this off (pdf from A to B via MQ) if my apps are clients, one is VB and the other is JAVA, and I want to avoid Referance Messages?
_________________
Peter Potkay
Keep Calm and MQ On
Back to top
View user's profile Send private message
PeterPotkay
PostPosted: Wed Oct 02, 2002 9:07 am    Post subject: Reply with quote

Poobah

Joined: 15 May 2001
Posts: 7722

One of the VB guys at my company got it to work. Below is the code to PUT and GET a pdf file directly to/from an MQ queue using just the MQAPI.
Any comments? I am not a VB guy, so I don't know if there are any potential problems here. I did recomend that the message format be set to NONE, although it works OK as is.


The following put the PDF into MQ:
Code:

Private Sub PutServer2()

   .
   .
   .

    OpenReplyQueServer
   
    ' Setup MQMD and MQPMO to their respective
    ' initial values
    MQMD_DEFAULTS md
    md.Format = MQFMT_STRING
   
    MQPMO_DEFAULTS pmo
   
    sServerMsg = PutPdf1()
    BufLen = Len(sServerMsg)
    Buffer = sServerMsg
   
    md.MsgId = gMsgIdS
    md.CorrelId = gCorrIdS
   
    MQPUT gHcon, gHobjReplyToQueServer, md, pmo, BufLen, Buffer, CompCode, Reason

   .
   .
   .

End Sub

Function PutPdf1()
    Dim intFileNum As Integer
   
    intFileNum = FreeFile
   
    Open "\\PLCADCTIDS3\DocuCorp\PROOFWeb\OnlineView\OnlineViewD\Quotes\TrainTestCIG\Pdf\" & _
        gPdfNameServer & ".pdf" For Binary As #intFileNum
    PutPdf1 = Input$(LOF(intFileNum), #intFileNum)
   
    Close #intFileNum
   
End Function




The following Gets the PDF from MQ and write it into a temp directory and then pass the filename into Adobe:

Code:

Private Sub GetResponse2(Optional bGetAny = False)
     Dim md As MQMD                    ' Message desciptor
     Dim gmo As MQGMO                  ' Get message options
     Dim BufLen As Long                ' Length of get buffer
     'Dim Buffer As String * CCHBUFFER  ' Got message
     Dim Buffer As String ' Got message
     Dim MessLen As Long               ' Length of returned message
     Dim CompCode As Long              ' Completion code
     Dim Reason As Long                ' Reason code

Start:
     ' Setup Get Message Options to the required values
     MQGMO_DEFAULTS gmo
     gmo.Options = MQGMO_WAIT + MQGMO_ACCEPT_TRUNCATED_MSG
     gmo.WaitInterval = 10000
   
     ' Setup message descriptor to the required values
     MQMD_DEFAULTS md
   
     ' Setup length of GET buffer
     BufLen = lConstantBuffLen
     Buffer = Space(lConstantBuffLen)
   
     ' Show get is in progess
     
     ' Get message from the queue
        md.MsgId = gMsgId
        md.CorrelId = gCorrId
     
     MQGET gHcon, gHobjReply, md, gmo, BufLen, Buffer, MessLen, CompCode, Reason

   .
   .
   .

     GetPdf Buffer, MessLen

   .
   .
   .

End Sub


Sub GetPdf(Buffer, MessLen)
    Dim intFileNum As Integer
    Dim sPath, sName, sReturn, sNameNew, i
   
    sName = gPdfNameServer
    i = 1
   
    Do
        sNameNew = gTempDir & sName & "-" & i & ".pdf"
        sReturn = Dir(sNameNew)
        If sReturn = "" Then Exit Do
        i = i + 1
    Loop
   
    intFileNum = FreeFile
   
    Open sNameNew For Binary Access Write As #intFileNum
    Put #intFileNum, , Left(Buffer, LenB(Trim(Buffer)))
   
    Close #intFileNum
   
    RC = Shell("C:\Program Files\Adobe\Acrobat 5.0\Reader\AcroRd32.exe " & sNameNew, vbMinimizedNoFocus)
   
End Sub


_________________
Peter Potkay
Keep Calm and MQ On
Back to top
View user's profile Send private message
jed
PostPosted: Mon Feb 16, 2004 9:04 pm    Post subject: Reply with quote

Centurion

Joined: 08 Jan 2004
Posts: 118
Location: MI, USA

PeterPotkay wrote:
One of the VB guys at my company got it to work. Below is the code to PUT and GET a pdf file directly to/from an MQ queue using just the MQAPI.
Any comments? I am not a VB guy, so I don't know if there are any potential problems here. I did recomend that the message format be set to NONE, although it works OK as is.


The following put the PDF into MQ:
Code:

Private Sub PutServer2()

   .
   .
   .

    OpenReplyQueServer
   
    ' Setup MQMD and MQPMO to their respective
    ' initial values
    MQMD_DEFAULTS md
    md.Format = MQFMT_STRING
   
    MQPMO_DEFAULTS pmo
   
    sServerMsg = PutPdf1()
    BufLen = Len(sServerMsg)
    Buffer = sServerMsg
   
    md.MsgId = gMsgIdS
    md.CorrelId = gCorrIdS
   
    MQPUT gHcon, gHobjReplyToQueServer, md, pmo, BufLen, Buffer, CompCode, Reason

   .
   .
   .

End Sub

Function PutPdf1()
    Dim intFileNum As Integer
   
    intFileNum = FreeFile
   
    Open "\\PLCADCTIDS3\DocuCorp\PROOFWeb\OnlineView\OnlineViewD\Quotes\TrainTestCIG\Pdf\" & _
        gPdfNameServer & ".pdf" For Binary As #intFileNum
    PutPdf1 = Input$(LOF(intFileNum), #intFileNum)
   
    Close #intFileNum
   
End Function




The following Gets the PDF from MQ and write it into a temp directory and then pass the filename into Adobe:

Code:

Private Sub GetResponse2(Optional bGetAny = False)
     Dim md As MQMD                    ' Message desciptor
     Dim gmo As MQGMO                  ' Get message options
     Dim BufLen As Long                ' Length of get buffer
     'Dim Buffer As String * CCHBUFFER  ' Got message
     Dim Buffer As String ' Got message
     Dim MessLen As Long               ' Length of returned message
     Dim CompCode As Long              ' Completion code
     Dim Reason As Long                ' Reason code

Start:
     ' Setup Get Message Options to the required values
     MQGMO_DEFAULTS gmo
     gmo.Options = MQGMO_WAIT + MQGMO_ACCEPT_TRUNCATED_MSG
     gmo.WaitInterval = 10000
   
     ' Setup message descriptor to the required values
     MQMD_DEFAULTS md
   
     ' Setup length of GET buffer
     BufLen = lConstantBuffLen
     Buffer = Space(lConstantBuffLen)
   
     ' Show get is in progess
     
     ' Get message from the queue
        md.MsgId = gMsgId
        md.CorrelId = gCorrId
     
     MQGET gHcon, gHobjReply, md, gmo, BufLen, Buffer, MessLen, CompCode, Reason

   .
   .
   .

     GetPdf Buffer, MessLen

   .
   .
   .

End Sub


Sub GetPdf(Buffer, MessLen)
    Dim intFileNum As Integer
    Dim sPath, sName, sReturn, sNameNew, i
   
    sName = gPdfNameServer
    i = 1
   
    Do
        sNameNew = gTempDir & sName & "-" & i & ".pdf"
        sReturn = Dir(sNameNew)
        If sReturn = "" Then Exit Do
        i = i + 1
    Loop
   
    intFileNum = FreeFile
   
    Open sNameNew For Binary Access Write As #intFileNum
    Put #intFileNum, , Left(Buffer, LenB(Trim(Buffer)))
   
    Close #intFileNum
   
    RC = Shell("C:\Program Files\Adobe\Acrobat 5.0\Reader\AcroRd32.exe " & sNameNew, vbMinimizedNoFocus)
   
End Sub




Whats the data type of the sServerMsg and Buffer variables on the MQPUT?
_________________
Jed
Back to top
View user's profile Send private message Send e-mail AIM Address Yahoo Messenger MSN Messenger
ironface
PostPosted: Tue Dec 28, 2004 10:02 am    Post subject: Get messages using correlation ID Reply with quote

Newbie

Joined: 28 Dec 2004
Posts: 8

I red your postings and they are quite clear. What I don't understand is:
- in the PutServer2 function, you assing the values gMsgIdS and gCorrIdS to, respectively, md.MsgId and md.CorrelId. What is the data type of both?
- same as above on the corresponding values of the GetResponse2 function.
Could You please help me?
Back to top
View user's profile Send private message
fjb_saper
PostPosted: Tue Dec 28, 2004 11:33 am    Post subject: Reply with quote

Grand High Poobah

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

Peter,

What's your max pdf size ? How would you handle it if the pdf were to come over 4 MB?
Your point of switching the format to none is well taken.
In the case of splits/message groups how do you garantee that you will reassemble in the right order and only after all messages in the group have made it. Remember about problems with multiple routes to same destination and relative speed of said routes...

Thanks
F.J.
Back to top
View user's profile Send private message Send e-mail
EddieA
PostPosted: Tue Dec 28, 2004 11:47 am    Post subject: Reply with quote

Jedi

Joined: 28 Jun 2001
Posts: 2453
Location: Los Angeles

Quote:
In the case of splits/message groups how do you garantee that you will reassemble in the right order and only after all messages in the group have made it

There are options avaialable on the GET that will only return mesages when ALL messages in the Group are avaialable. And, you can force MQ to return the messages in the correct logical order, no matter what order they arrived on the receipt Q.

Cheers,
_________________
Eddie Atherton
IBM Certified Solution Developer - WebSphere Message Broker V6.1
IBM Certified Solution Developer - WebSphere Message Broker V7.0
Back to top
View user's profile Send private message
PeterPotkay
PostPosted: Tue Dec 28, 2004 1:47 pm    Post subject: Reply with quote

Poobah

Joined: 15 May 2001
Posts: 7722

I don't have access to the programs any more, so I can't verify the datatype of those 2 fields.

The PDFs were only 1 MEG max. Queues defined as 4MEG max anyway.

We don't use groups or segments, but if we did, Eddie's got the correct solution.
_________________
Peter Potkay
Keep Calm and MQ On
Back to top
View user's profile Send private message
jed
PostPosted: Tue Dec 28, 2004 2:53 pm    Post subject: Reply with quote

Centurion

Joined: 08 Jan 2004
Posts: 118
Location: MI, USA

Well, sorry I didn't reply to my posting.
I was able to resolve my problem.
I was able to create C program as well as a Java program.
And, I can send/receive any type of file.
The file size can be of any size that can be managed by MQ (I think its a maximum of 100MB per message).
_________________
Jed
Back to top
View user's profile Send private message Send e-mail AIM Address Yahoo Messenger MSN Messenger
ironface
PostPosted: Wed Dec 29, 2004 3:25 am    Post subject: Reply with quote

Newbie

Joined: 28 Dec 2004
Posts: 8

Eddie, jesus_dino, fjb_saper,
could You please help in solving my issue , I need to put and retrieve a message verifying the messageId and the correlationId. My application is visual basic. The example posted by Peter is quite complete, but it's missing the gMsgIdS and gCorrIdS definitions.
Thanks for your help.
Back to top
View user's profile Send private message
PeterPotkay
PostPosted: Wed Dec 29, 2004 6:44 am    Post subject: Reply with quote

Poobah

Joined: 15 May 2001
Posts: 7722

What have you tried?
_________________
Peter Potkay
Keep Calm and MQ On
Back to top
View user's profile Send private message
ironface
PostPosted: Wed Dec 29, 2004 9:53 am    Post subject: Reply with quote

Newbie

Joined: 28 Dec 2004
Posts: 8

Peter,
if I try to insert any value I get an error that the value I'm trying to assign hasn't the same format as the variable. I also tried to use MQCI_NEW_SESSION (I'm a newbie, so don't laugh if it's wrong), but I still get the oldest message in the queue instead of the related one.
Back to top
View user's profile Send private message
EddieA
PostPosted: Wed Dec 29, 2004 10:34 am    Post subject: Reply with quote

Jedi

Joined: 28 Jun 2001
Posts: 2453
Location: Los Angeles

Quote:
MQCI_NEW_SESSION

This is a special value gthat is only used for the CICS Bridge. And it is used whwn PUTting a message, not GETting.

You will get the 1st message from the Queue if you don't set the matching IDs. The CorrelID is a 24 byte Byte field.

Cheers,
_________________
Eddie Atherton
IBM Certified Solution Developer - WebSphere Message Broker V6.1
IBM Certified Solution Developer - WebSphere Message Broker V7.0
Back to top
View user's profile Send private message
jed
PostPosted: Thu Dec 30, 2004 10:11 pm    Post subject: Reply with quote

Centurion

Joined: 08 Jan 2004
Posts: 118
Location: MI, USA

What are you trying to do?
You're trying to PUT (and probably GET) .PDF right?
And you need to pass the filename?

Well, I'm not really an expert yet. But, what I can advice you is you can probably include (by attaching at the end of your file or beginning) and send it out. Correspondingly, the other should have the the same parsing algorithm in order to extract the filename and the file content.

I hope this helps........
_________________
Jed
Back to top
View user's profile Send private message Send e-mail AIM Address Yahoo Messenger MSN Messenger
ironface
PostPosted: Fri Dec 31, 2004 12:55 am    Post subject: Again me Reply with quote

Newbie

Joined: 28 Dec 2004
Posts: 8

Guys,
first of all, thanks for your patience in replying to my messages.
In the PUT I use md.CorrelId = MQCI_NEW_SESSION and
In the GET Struc.MatchOptions = MQMO_MATCH_MSG_ID + MQMO_MATCH_CORREL_ID
But the program still retrieves the first message in the queue, instead of the related one.
What is wrong?
I was even thinking to add the md.MsgId = MQCI_NEW_SESSION in the PUT
But I guess it wouldn't change. I'm sure I'm missing something in the GET, but as I'm new, I don't understand what.
Back to top
View user's profile Send private message
PeterPotkay
PostPosted: Fri Dec 31, 2004 7:34 am    Post subject: Reply with quote

Poobah

Joined: 15 May 2001
Posts: 7722

ProgramA Puts a message to Queue1. Before doing the put, initialize the MQMD_MessageID and CorrelID so they are clean. When you do the put with the MessageID and CorrelID initialized, the Queue Manager will leave the CorrelID blank, but will fill in a MessageID for you. When the PUT call returns, inspect the MessageID field, as it will now contain the MessageID that was assigned to this message.

When ProgramA goes to get that message, once again, initialize the CorrelID, but this time populate the MessageID with that value you saved in the first step. Issue your MQGET. You will be returned the first messsage on the queue that has a MessagID with that value, which is your message, as long as each message on the queue has a unique MessageID, which it should if you do it the way I described above.

For you simple example, there is no need to bother with the CorrelID (although if you wanted to, you could.)

Stop using MQCI_NEW_SESSION. Eddie already explained why that is wrong.

Read the Application Programming Guide (documentation button, top of this screen.) This is basic MQ, and is covered in great detail in the manual.
_________________
Peter Potkay
Keep Calm and MQ On
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 » IBM MQ API Support » How to get a pdf into the buffer (no referance messages)
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.