Thursday 24 October 2013

Regular Expressions in webMethods

When validating an IS document type or schema, Integration Server uses the Perl regular
expression compiler by default. If you need to change this behavior so that Integration
Server uses the Java regular expression compiler during validation, set the server
configuration parameter watt.core.datatype.usejavaregex to true.

Perl Regular Expression Definitions

In webMethods, Regular expression can be used in following three different ways: 
  1. Branch switch / Label
  2. WQL
  3. Built-in services
          There are two built-in services supporting regex: 
    • pub.string:lookupTable
    • pub.string:replace

Generate PDF files in webMethods

If your application needs to generate PDF documents dynamically, you need the Apache FOP library. The open source FOP library makes PDF creation a snap. This article gives a step-by-step guide to using it to generate PDF documents from webMethods.
 
  1. Download FOP library and upload to common lib directory on Integration Server. FOP library can be download from Apache FOP site.
  2. Create an IS document. The IS document is the container for all the elements of a PDF document.
  3. Invoke webMethods built-in service pub.xml:documentToXMLString, to convert IS document (IData object) to an XML string.
  4. Create a XSLT service. The XSLT service performs transformation of XML string to XSL-FO (a variant of XSL). It can also do input XML validation. Details of XSL-FO can be found at http://www.w3schools.com/xslfo/.
  5. Create a Java service to invoke FOP processor.

  Diagram below shows how it works.



XSLT processor in the diagram is the IS XSLT service that creates an XML containing formatting objects by taking data from the first XML. This resultant XML is de-serialized into Java objects. IS jave service de-serializes resultant XML into Java objects, invoke FOP processor to creates a PDF file using these Java objects.

Code snippet for Java Service:

IDataCursor idc = pipeline.getCursor();
String inputXSLFO = IDataUtil.getString( idc, "inputXSLFO" );

try {
            FopFactory fopFactory = FopFactory.newInstance();
           
            // a user agent is needed for transformation
            FOUserAgent foUserAgent = fopFactory.newFOUserAgent();
            // to store output
            ByteArrayOutputStream outStream = new ByteArrayOutputStream();

            TransformerFactory factory = TransformerFactory.newInstance();
            Transformer transformer = factory.newTransformer();

            FOP fop = fopFactory.newFop
                                    (MimeConstants.MIME_PDF, foUserAgent, outStream);
            // Resulting SAX events (the generated FO)
            // must be piped through to FOP
            Result res = new SAXResult(fop.getDefaultHandler());

            // Setup input for XSLT transformation
            InputStream xmlStream = (InputStream) (new ByteArrayInputStream(inputXSLFO.getBytes())) ;
            Source src = new StreamSource(xmlStream, "UTF-16");

            transformer.transform(src, res);
            xmlStream.close();

            idc.insertAfter("outputPDFByteArray", outStream.toByteArray() );
            idc.destroy();
            outStream.close();

}
catch (Exception e){     
            idc.insertAfter("outputPDFByteArray", null);
}
 

How to make service sleep in webMethods

Problem 

Suspending execution for a specified period is an efficient means of making processor time available to the other threads of an application or other applications that might be running on a computer system.

Solution

Making service sleep in webMethods can be implemented in a Java Service in webMethods. The code snippet is as follows.

IDataCursor idc = pipeline.getCursor();
int inString = IDataUtil.getInt( idc, "milliseconds", 0);

try{
           //do what you want to do before sleeping
           Thread.sleep(inString); //sleep for 1000 ms
           //do what you want to do after sleeptig
}
catch(InterruptedException ie){
           //If this thread was intrrupted by nother thread
}

idc.destroy();

Services Throttling in webMethods

Problem

Services throttling is the intentional slowing of service by a service provider. It can be implemented by webMethods components at the application level to limit network congestion, database slowdown and server crashes.

Using this behavior, you can fine-tune the performance of your application.

Solution

Service throttling can be implemented based on two conditions: the number of simultaneous messages processing and memory usage. Service throttling can be implemented in webMethods as such:

  1. Create publishable document for the messages to be processed, sync the document with Broker.
  2. Create a Trigger to subscribe to the Broker document, set up Trigger properties:
  • Message processing - Processing mode : Serial/Concurrent
  • Max Execution Threads
     3.      In the triggered service, control the duration of processing, i.e. set the sleep time to control the elapse of the service.
 
Throttling Threshold can be set up. When a high threshold is reached, Services starts to throttle. Throttling stops when the low threshold is reached.