Convert BrokerEvent.toBinData to Readable String

Please help. I have written some java application to allow access to view log outside of Integration Monitoring. The program is written to retrieve the data from the event fields as a binary byte array, using the BrokerEvent.toBinData method. Then i tried to parse it to a readable string, however some characters are unreadable. Can someone please explain how i can convert the binary data to a readable string?

Thanks,
Tiffani

toBinData and fromBinData serialize a BrokerEvent object. The byte array undoubtedly contains structure and other control information that will not make any sense when converted to characters. Indeed, you probably cannot be sure where the boundaries are for the start and end of bytes that represent chars.

Might the toString methods do what you’re looking for?

Thanks Reamon for responding. I tried using the toString() method and i got this:
String contents: [B@42ec965c

Hmm. That’s the default output of Object.toString() – it’s the address of the object.

Can you post the code snippet? It seems like at the time of the call the runtime doesn’t know it’s a BrokerEvent.

Hi Reamon,

Attached is my code. It gets the queue data using BrokerEvent.toBinData() method. Then i create a flow service to call this code as follow:

  1. Get brokerQueueData.java service
  2. Write objectToFile as “.ser” file type
  3. Call pub.file:getFile and loadAs String

I can read the string contents, but there are extra chars that’s not readable and i’m not sure how to delete them. If you can help me, i would greatly appreciate it.

Thanks,
Kim

Sorry forgot the attachment.
brokerQueueData.txt (1.49 KB)

Reamon,

That last message was from Tiffani. She’s step out to a meeting so asked me to posted for her and i forgot and signed my own name. I am sort of working with her on this, but i don’t have much about webMethods. Thanks again.

The only thing that can reliably done with the byte array returned by toBinData is to pass it to fromBinData. You definitely cannot load the file using getFile with loadAs string and expect a usable string.

In the for loop: for(int i=0;i<be.length;i++)
{
QDoc[i] = IDataFactory.create();
IDataCursor pipelineCursor2 = QDoc[i].getCursor();
byte[] contentBytes = be[i].toBinData();
pipelineCursor2.last();
pipelineCursor2.insertAfter(“evtType”, be[i].getTypeName());
//pipelineCursor2.insertAfter(“content”, be[i].toString());
pipelineCursor2.insertAfter(“content”, contentBytes);
pipelineCursor2.destroy();
}

Assuming you’ve uncommented the first insertAfter is the second insertAfter interferring in some way. What to you see if the second insertAfter is commented out? Or if you use a different variable name for the string?

Hi Reamon,

I know you’re busy yourself so i’m very thankful for taking the time to help me out. I really appreciated it. If i uncommented out the second insertAfter, i get the readable string. However, all i can see, is the event properties. But with the BrokerEvent.toBinData() method, i can see the actual data from the queued, but with extra chars that’s i can’t get rid off. I tried using the BrokerEvent.fromBinDat() method and all i get is null or client is already created. So i’m kind of stuck or lost :frowning:

Thanks,
Tiffani

I wish I could dig in more deeply but alas I cannot. My advice is to disregard toBinData/fromBinData. Those will not do what you’re after. Instead, explore the toString() toFormattedString() variations. Or just use MWS for browsing queues.

I have not use the toFormattedString() method. If you don’t mind, can you explain how to use it? What to enter for the formatString variable?

Never mind…i’ve figured it out how to use the method, however it’s not outputting the event actual data :frowning:

Thanks Reamon for all your help.