Service Virtualization

  • 1.  How to create a custom request/response delimiter in CA DevTest

    Posted Dec 01, 2016 08:15 AM

    Has anyone worked on creating custom request/response delimiter(used during TCP virtualization)?If so, could you please share the steps for creating and share any sample?#DevTest#Protocol Delimiter



  • 2.  Re: How to create a custom request/response delimiter in CA DevTest

    Posted Dec 01, 2016 12:40 PM

    Perhaps, the attachment will assist you in figuring out what you want to look for...

    Create a JAR and drop it in hotdeploy with the .extensions file.  This link might provide insight as to the recorder.  LISA 8.0 - Delimiter screen in TCP Virtualization Recorder 

    If I recall, once you spin up the service, you will not see the delimiter in the LISTEN step, but the delimiter is embedded in the VSM's XML file.

     

    Override the locateRequest method with the logic to identify your delimiter.  When you create the jar, include the extensions file after changing it to point to your TCP Delimiter class.

    Attachment(s)



  • 3.  Re: How to create a custom request/response delimiter in CA DevTest

    Posted Dec 01, 2016 09:04 PM

    Thank you Joel.Will try this out.



  • 4.  Re: How to create a custom request/response delimiter in CA DevTest
    Best Answer

    Posted Dec 01, 2016 12:45 PM

    Here is sample code for a TCP delimiter:

     

    package com.itko.lisa.ext.vse;

     

    import java.util.List;
    import java.util.regex.Matcher;
    import java.util.regex.Pattern;

     

    import org.apache.commons.logging.Log;
    import org.apache.commons.logging.LogFactory;

     

    import com.itko.lisa.vse.stateful.protocol.tcp.delimiters.TCPDelimiter;
    import com.itko.util.StrUtil;

     

    public class FIXDelimiter implements TCPDelimiter {
        
        private static final Log log = LogFactory.getLog(FIXDelimiter.class);

     

        /*
         * FIX Messages will end with TAG 10, a FIX message checksum
         * followed by the SOH (Start of Header) character - ASCII 0x01
         */
        private Pattern pattern = Pattern.compile("10=\\d{3}");
        
        private int startOfNextRequest = 0;
        private int endOfRequest = -1;
        private String message;

     

        public boolean locateRequest(List<Byte> bytes) {
            log.debug("Entering FIXDelimiter.locateRequest");
            
            byte[] ba = new byte[bytes.size()];
            for (int i = 0; i < bytes.size(); i++) {
                ba[i] = bytes.get(i);
            }
            String request = new String(ba);
            
            log.debug("request=" + request);
            
            Matcher m = pattern.matcher(request);
            if (m.find()) {
                if (log.isDebugEnabled()) {
                    log.debug("FIX match found.  Matched: " + request.substring(m.start(), m.end()));
                }
                //TODO: Pattern.compile("10=\\d{3}\\x01") matches but doesn't get
                //      the last character 0x01.  Using Pattern.compile("10=\\d{3}")
                //      and +1 for now.
                endOfRequest = m.end() + 1;            
                startOfNextRequest = 0;
                return true;
            }
            endOfRequest = -1;
            startOfNextRequest = -1;
            return false;
        }

     

        public int getEndOfRequest() {
            return endOfRequest;
        }

     

        public int getStartOfNextRequest() {
            return startOfNextRequest;
        }

     

        public String validate() {
            return message;
        }

     

        public void configure(String config) {
            // Empty
        }
         public static void main(String[] args) {  
            Pattern pattern = Pattern.compile("10=\\d{3}\\x01");
            String request = "8=FIX.4.2 9=67 35=A 49=CDRG_TST 56=MSSB_EQ 34=53 52=20110811-16:50:28 108=30 98=0 10=018 ";    
            Matcher m = pattern.matcher(request);
            if (m.find()) {
                System.out.println("found");
                System.out.println(request.substring(m.start(), m.end()));
            } else {
                System.out.println("not found");
            }
         }
    }

     

     

    ====

     

    You would also need a .lisaextensions file where you would have something like this:

    tcpProtocolDelimiters=com.itko.lisa.ext.vse.FIXDelimiter
    # classname=Description,Can process requests,Can process responses,Should treat field as text, label for additional information
    com.itko.lisa.ext.vse.FIXDelimiter=FIX, true, true, false



  • 5.  Re: How to create a custom request/response delimiter in CA DevTest

    Posted Dec 01, 2016 09:04 PM

    This is helpful.Thank you so much.