Hello
All is in the subject’s title
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
Hello
All is in the subject’s title
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
do you mean, you want to create .gz files using wM ?
which wM version you are using ?
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.
You Can also use shell scripts by using os-command flow service
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.
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; }
}
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.