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

Create file in UTF8 with BOM encoding

  • 1.  Create file in UTF8 with BOM encoding

    Posted Wed August 26, 2015 11:29 AM

    Hello,
    I need output file to be in UTF8 with BOM encoding, but all I can get is UTF8 without BOM. Can anyone suggest how can I make the encoding convertion or convert document to string straight with BOM?
    Thanks in advice.


    #Integration-Server-and-ESB
    #webMethods
    #Flow-and-Java-services


  • 2.  RE: Create file in UTF8 with BOM encoding

    Posted Wed August 26, 2015 12:30 PM

    Did you check pub.string:bytesToString. For more details refer BIS

    ignoreBOMChars - Flag indicating whether or not Integration Server removes the byte order mark (BOM) characters in the input sequence of bytes before converting the byte array to string.
    Set to: true to remove the byte order mark (BOM) characters before converting the input sequence of bytes to string, if the byte array contains BOM characters.
    false to include the byte order mark (BOM) characters while converting the input sequence of bytes to string. The default is false.

    Let me know if you need more details.


    #Flow-and-Java-services
    #webMethods
    #Integration-Server-and-ESB


  • 3.  RE: Create file in UTF8 with BOM encoding

    Posted Thu August 27, 2015 04:23 AM

    Hey,
    Thanks for the answer, but we are still using webMethods 7 and seems that bytesToString does have that flag in this version yet :frowning:


    #webMethods
    #Flow-and-Java-services
    #Integration-Server-and-ESB


  • 4.  RE: Create file in UTF8 with BOM encoding

    Posted Thu August 27, 2015 06:29 AM

    Ok, write a java service.

    Can you confirm if utf-16 is what your looking for.


    #webMethods
    #Flow-and-Java-services
    #Integration-Server-and-ESB


  • 5.  RE: Create file in UTF8 with BOM encoding

    Posted Thu August 27, 2015 06:46 AM

    I was trying to replace HEX by adding BOM (FEFF) but getting unreadable output file, like
    þÿ<?xml version="1.0"?>£ÇFç3¤Ö?7W6T?æfòa?ÖÆç3§?6?Ò&?GG¢ò÷wwrçs2æ÷… on the output.


    #Flow-and-Java-services
    #Integration-Server-and-ESB
    #webMethods


  • 6.  RE: Create file in UTF8 with BOM encoding

    Posted Thu August 27, 2015 08:07 AM

    Also I’ve just tried to put EFBBBF as BOM, got the same unreadable result.


    #Flow-and-Java-services
    #webMethods
    #Integration-Server-and-ESB


  • 7.  RE: Create file in UTF8 with BOM encoding

    Posted Thu August 27, 2015 08:18 AM

    Can you check and work on this code. See if it works for you.

    
    IDataCursor cursor =pipeline.getCursor();
    String xmlstring ="";
    boolean littleEnd = false;
    String encoding = "UnicodeBig";
    
    if (cursor.first("xmlstring")) {
    xmlstring = (String)cursor.getValue();
    }
    if (cursor.first("littleEndian")) {
    littleEnd =IDataUtil.getBoolean(cursor);
    if (littleEnd) encoding ="UnicodeLittle";
    }
    if (xmlstring.length() == 0) return;
    StringBuffer sb = new StringBuffer(xmlstring);
    
    if (sb.charAt(0) !=; '\uFEFF') {
    sb.insert(0, '\uFEFF');
    }
    xmlstring =sb.toString();
    try {
    cursor.insertAfter("bytes", xmlstring.getBytes(encoding));
    } 
    catch (UnsupportedEncodingException uex) {
    
    ServiceException se =; new ServiceException();
    se.fillInStackTrace();
    throw se;
    }
    
    cursor.destroy();
    

    #Integration-Server-and-ESB
    #webMethods
    #Flow-and-Java-services


  • 8.  RE: Create file in UTF8 with BOM encoding

    Posted Thu August 27, 2015 08:46 AM

    Hey,
    I’ve modifyed code a bit for my needs and it worked perfectly. Thanks for your help.


    #Integration-Server-and-ESB
    #webMethods
    #Flow-and-Java-services


  • 9.  RE: Create file in UTF8 with BOM encoding

    Posted Thu August 27, 2015 09:10 AM

    Hey that’s cool :wink:

    Do you mind sharing the working code here…

    Thanks


    #webMethods
    #Flow-and-Java-services
    #Integration-Server-and-ESB


  • 10.  RE: Create file in UTF8 with BOM encoding

    Posted Thu August 27, 2015 09:29 AM

    Sure thing. Here it is:

    IDataCursor pipelineCursor =pipeline.getCursor();  
    // documentSrc
    String xmlString = IDataUtil.getString( pipelineCursor, "xmlString");
    String encoding = IDataUtil.getString( pipelineCursor, "encoding");
    
    pipelineCursor.destroy();
    
    // pipeline
    IDataCursor pipelineCursor_1 = pipeline.getCursor();
    
    if (xmlString.length() == 0) return;  
    StringBuffer sb = new StringBuffer(xmlString);  
    
    if (sb.charAt(0) != '\uFEFF') {  
    sb.insert(0, '\uFEFF');  
    }  
    xmlString = sb.toString();  
    try {  
    pipelineCursor.insertAfter("bytes", xmlString.getBytes(encoding));  
    }   
    catch (UnsupportedEncodingException uex) {  
    
    ServiceException se = new ServiceException();  
    se.fillInStackTrace();  
    throw se;  
    }  
    IDataUtil.put( pipelineCursor_1, "xmlStringWithBOM", xmlString );
    pipelineCursor_1.destroy();

    The only thing is that now I’m trying to make it work depending on input encoding and just can’t get part where I’m setting BOM as ‘\uEFBBBF’ to work.


    #Flow-and-Java-services
    #Integration-Server-and-ESB
    #webMethods


  • 11.  RE: Create file in UTF8 with BOM encoding

    Posted Thu August 27, 2015 11:10 AM

    Seems that encoding doesn’t matter what BOM code to add in this case, so only \uFEFF can be left.


    #Flow-and-Java-services
    #webMethods
    #Integration-Server-and-ESB