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
  • 1.  Generate a tar.gz compressed archive in webmethods

    Posted Thu July 21, 2016 10:38 AM

    Hello

    All is in the subject’s title :smiley:
    Is there a dedicated service I can use in webMethods ?
    or Does one of you know how to do that using flow services ?
    or Do I need to create a java service?

    Thanks for your help


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


  • 2.  RE: Generate a tar.gz compressed archive in webmethods

    Posted Thu July 21, 2016 02:33 PM

    do you mean, you want to create .gz files using wM ?
    which wM version you are using ?


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


  • 3.  RE: Generate a tar.gz compressed archive in webmethods

    Posted Thu July 21, 2016 06:23 PM

    OOTB there is no service to zip, gzip or tar a file. However you can leverage the Java API and write your own service.

    Also have a look at the PSUtilities (which can be downloaded via tech community code samples) as there are services to zip and unzip, you can re-use or re-write them as per your need.

    Let us know if you have any further questions.


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


  • 4.  RE: Generate a tar.gz compressed archive in webmethods

    Posted Mon July 25, 2016 04:22 AM

    You Can also use shell scripts by using os-command flow service


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


  • 5.  RE: Generate a tar.gz compressed archive in webmethods

    Posted Mon July 25, 2016 08:07 AM

    If you are using the service pub.utils:executeOSCommand make sure to update OSCommands.cnf file accordingly. However use pub.utils:executeOSCommand service with extreme caution; the commands can affect the production systems where Integration Server is running.


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


  • 6.  RE: Generate a tar.gz compressed archive in webmethods

    Posted Fri July 29, 2016 06:59 AM

    Hello

    I finally imported the commons-compress-1.12.jar and created a java service

    here is the code I used :

    The inputs are inputStream (the document in bytes) and tarFileName (the name of the file IN the tar.gz)
    return a bytes array which is the compressed content.

    package xxxxx;
    
    import com.wm.data.*;
    import com.wm.util.Values;
    import com.wm.app.b2b.server.Service;
    import com.wm.app.b2b.server.ServiceException;
    import java.io.BufferedInputStream;
    import java.io.BufferedOutputStream;
    import java.io.ByteArrayInputStream;
    import java.io.ByteArrayOutputStream;
    import java.io.File;
    import java.io.FileInputStream;
    import java.io.FileOutputStream;
    import java.io.IOException;
    import java.util.Collection;
    import java.util.zip.GZIPOutputStream;
    import org.apache.commons.compress.archivers.tar.TarArchiveOutputStream;
    import org.apache.commons.io.FilenameUtils;
    import org.apache.commons.lang.StringUtils;
    import org.apache.commons.compress.archivers.tar.TarArchiveEntry;
    import org.apache.commons.io.IOUtils;
    
    public final class Compression_SVC
    
    {
    
    /** 
    * The primary method for the Java service
    *
    * @param pipeline
    *            The IData pipeline
    * @throws ServiceException
    */
    public static final void Compression(IData pipeline) throws ServiceException {
    IDataCursor pipelineCursor = pipeline.getCursor();
    
    byte[] inputStream = null;
    if ( pipelineCursor.first ( "inputStream" ) ) {
    inputStream = (byte[])pipelineCursor.getValue();
    } else {
    throw new ServiceException("Missing required parameter 'inputStream'");
    }
    
    String tarFileName = (String)IDataUtil.get( pipelineCursor, "tarFileName" );
    
    
    // tar.gz file creation 
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    TarArchiveOutputStream taos = new TarArchiveOutputStream(bos);
    taos.setBigNumberMode(TarArchiveOutputStream.BIGNUMBER_STAR);
    taos.setLongFileMode(TarArchiveOutputStream.LONGFILE_GNU);
    
    try {
    
    // tar.gz content creation
    TarArchiveEntry entry = new TarArchiveEntry(tarFileName);
    entry.setSize(inputStream.length);
    taos.putArchiveEntry(entry);
    
    // put content in the file
    taos.write(inputStream);
    
    // close compressed file
    taos.closeArchiveEntry();
    
    
    IDataCursor pipelineCursor_1 = pipeline.getCursor();
    pipelineCursor_1.insertAfter("zippedContent", bos.toByteArray()); 
    pipelineCursor_1.destroy();
    } catch (Exception e) {
    throw new ServiceException(e);
    } finally{
    try {
    taos.finish();
    taos.close();
    } catch (Exception e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }
    
    }
    
    
    }
    
    // --- <<IS-BEGIN-SHARED-SOURCE-AREA>> ---
    
    
    
    // --- <<IS-END-SHARED-SOURCE-AREA>> ---
    
    final static Compression_SVC _instance = new Compression_SVC();
    
    static Compression_SVC _newInstance() { return new Compression_SVC(); }
    
    static Compression_SVC _cast(Object o) { return (Compression_SVC)o; }
    
    }

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


  • 7.  RE: Generate a tar.gz compressed archive in webmethods

    Posted Fri July 29, 2016 08:09 AM

    Thanks for the sharing the code.

    Make sure to put the required jar in the package (code/jars) containing the java service which will ease your code deployment. You can also put the jar in global location which will be available for other packages on IS but I would prefer make it local to the package.


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