IBM webMethods Hybrid Integration

IBM webMethods Hybrid Integration

Join this online group to communicate across IBM product users and experts by sharing advice and best practices with peers and staying up to date regarding product enhancements.

 View Only
Expand all | Collapse all

base64 corrupting bytes

  • 1.  base64 corrupting bytes

    Posted Fri January 09, 2015 06:45 AM

    Hello

    I am currently working on the following process :
    pooling a directory containing pdf, then encapsulate each pdf into an xml file .

    To encapsulate the pdf into the xml document , I encode its bytes content into a base 64 string.
    Unfortunately, this base64 encoding cause the corruption of the pdf .

    Description of my process :

    pub.file:getFile (load as bytes, encoding=UTF-8 )
    pub.string:base64Encode

    For the tests, I have used pub.string:base64Decode in order to compare bytes before/after. And the bytes after process are not equals to the original ones.

    Did you already encounter such issue ?


    #webMethods-General
    #Integration-Server-and-ESB
    #webMethods


  • 2.  RE: base64 corrupting bytes

    Posted Fri January 09, 2015 08:04 AM

    Can you share your bytes data from the step pub.file:getFile (load as bytes, encoding=UTF-8 )

    And also the bytes before/after for comparison. I assume we can code a java service.


    #Integration-Server-and-ESB
    #webMethods
    #webMethods-General


  • 3.  RE: base64 corrupting bytes

    Posted Fri January 09, 2015 09:16 AM

    Hi Julien,

    You better go with java service for this requirement which is easy i believe.

    Thanks,


    #Integration-Server-and-ESB
    #webMethods
    #webMethods-General


  • 4.  RE: base64 corrupting bytes

    Posted Fri January 09, 2015 09:42 AM

    Or you can give a try for PSUtilities-Package, which should be available in the community software downloads.

    This Package also contains base64 coding services.

    Regards,
    Holger


    #webMethods-General
    #webMethods
    #Integration-Server-and-ESB


  • 5.  RE: base64 corrupting bytes

    Posted Fri January 09, 2015 09:50 AM

    Hello

    Thanks for your answers. I don’t know how to share the bytes( ?? )

    Anyway : I progressed since this morning :

    My pdf contain an image and after processing (I send the xml capsule and a distant service extract the pdf)
    The extract pdf can be opened but generate an error in ACreader. The image is no more visible.

    After opening the pdf editor, it appear that there is a stream included in the pdf file (pretty sure it is the image)
    This is the part which is corrupted by the base64encode.

    I tried a javaservice using org.apache.commons.codec.binary.Base64 : Base64.encodeBase64(bytes)

    Same result. I am not sure that is is possible to do what I want as the pdf is a combination of bytes and stream.

    What I don’t understand anyway, is that I can send me properly the pdf using the pub.client.SMTP service passing the bytes into attachments and specifying encoding = “base64”

    Really strange…


    #Integration-Server-and-ESB
    #webMethods-General
    #webMethods


  • 6.  RE: base64 corrupting bytes

    Posted Fri January 09, 2015 10:48 AM

    SOLVED

    The remaining problem was due to a wrong decode.

    The original problem was due to the use of pub.string:base64Encode .

    So, for such things, use a java service :

    byte[] bytesToWrite = null;
    String base64Encoded="";
    // pipeline
    IDataHashCursor pipelineCursor = pipeline.getHashCursor();
    if ( pipelineCursor.first( "bytesToWrite" ) ){
    bytesToWrite = (byte[]) pipelineCursor.getValue();
    }else{
    throw new ServiceException("bytesToWrite not specified");
    }
    
    
    try { 
    
    base64Encoded= new String(Base64.encodeBase64(bytesToWrite));
    } catch (Exception ioe) { 
    throw new ServiceException("IOException: " + ioe.getMessage()); 
    } finally {  
    
    
    } 
    
    // Place outputs into pipeline 
    pipelineCursor.last(); 
    pipelineCursor.insertAfter("base64Encoded", base64Encoded); 
    pipelineCursor.destroy();

    Thanks all for your help !


    #webMethods
    #Integration-Server-and-ESB
    #webMethods-General


  • 7.  RE: base64 corrupting bytes

    Posted Fri January 09, 2015 01:30 PM

    Yes this is the code I was talking about.

    Can you also share your import statements. It might be useful for other forum members.

    Have a nice week off :slight_smile:


    #webMethods-General
    #webMethods
    #Integration-Server-and-ESB


  • 8.  RE: base64 corrupting bytes

    Posted Fri January 09, 2015 10:31 PM

    Hi,

    You can use the below as part of imports.

    java.io.*
    java.lang.*
    java.util.*
    com.wm.lang.ns*
    com.wm.app.b2b.server.*

    @Mahesh: Definitly it is useful to other members including you :stuck_out_tongue:

    Thanks,


    #Integration-Server-and-ESB
    #webMethods-General
    #webMethods


  • 9.  RE: base64 corrupting bytes

    Posted Sat January 10, 2015 12:07 AM

    @MR as173d,
    Dude, Are you kidding :stuck_out_tongue: :stuck_out_tongue: :stuck_out_tongue: I guess there are some more imports missing!


    #webMethods-General
    #webMethods
    #Integration-Server-and-ESB


  • 10.  RE: base64 corrupting bytes

    Posted Mon January 12, 2015 03:48 AM

    The only one import : org.apache.commons.codec.binary.Base64

    :smiley:


    #webMethods-General
    #Integration-Server-and-ESB
    #webMethods


  • 11.  RE: base64 corrupting bytes

    Posted Mon January 12, 2015 04:08 AM

    Thanks… Not sure whether you have tried using the below import:

    com.wm.util.Base64

    I see for the import : org.apache.commons.codec.binary.Base64 you need apache jars to be installed in your IS. Correct me if I am wrong.


    #webMethods-General
    #Integration-Server-and-ESB
    #webMethods