Request Validations

Posted on 2004-10-27
Last Modified: 2010-04-17
getTest1( String tNo, String tn, String state) //all three required as input

getTest2(String tn, String State) // both data values required
for both of these input needs to be validated to see if it is null and is in the right format ..

I have this fn to test this
public void validateReq(String qualTrackNo, String tn, String state) throws ServicesApplicationException
      String fctStr = "ServiceRequestBean::checkReq()";
      PatternMatcher re = new Perl5Matcher();

      if (!reInit)
         if ( (tn == null) || (!re.matches(tn, reTn)) )
            throw exception;...                                                                        
         if ( TrackNo == null ||
           (!re.matches(TrackNo, reQualTrackNum)) )
            throw exception...                                                                              
            // EDIT THE STATE
       if ( state == null ||       (!re.matches(state, reState)) )
            throw exception...                                                
private synchronized void setupRePatterns() throws ServicesApplicationException
         TraceLog.write(TraceLog.DEBUG, "Initializing regular patterns...");
         if (reInit)
         reTn = new Perl5Compiler().compile(props.getValue(ServicesConstants.REGEXP_TN_10DIGIT), Perl5Compiler.READ_ONLY_MASK);
         reQualTrackNum = new Perl5Compiler().compile(props.getValue(ServicesConstants.REGEXP_QUAL_TRACK_NO), Perl5Compiler.READ_ONLY_MASK);
         reState = new Perl5Compiler().compile(props.getValue(ServicesConstants.REGEXP_STATE_2CHAR), Perl5Compiler.READ_ONLY_MASK);

         reInit = true;
   catch(Throwable t)
         ServicesError.throwProcessingException(t, "ServiceRequestBean::setupRePatterns()", props);


How do I retain the same fns and test for both getTest1 and getTest2? other than polymorphism?
Question by:skn73
    LVL 5

    Expert Comment

    getTest1( String tn, String state, String tNo = "xxx")

    where "xxx" is a valid value for tNo
    these way it can be used with 2 or 3 parameters

    Author Comment

    getTest1(tno, Tn, state) & getTest2(tn, state) needs to call validateReq() to validate the input
    I dont want to change getTest1 or getTest2.

    as it is written currently ..
    if getTest2() calls validateReq("",tn,state) because there is no tracknum ...
    it will error out saying tracknum is null or is in iinvalid format..

    How can I use validateReq fn to do validations for both getTest1 and getTest2
    LVL 1

    Accepted Solution


    The easiest way is makeup a tracking number that will validate (i.e.- "_VALID") and hardcode it into getTest2() so it will call:


    you would then have to modify your tn validation rule from

    if ( TrackNo == null ||
              (!re.matches(TrackNo, reQualTrackNum)) )


    if ( TrackNo == null || (!re.matches(TrackNo, reQualTrackNum)) || !TrackNo.equals("_VALID"))

    This is more or less what was suggested by Hammadian2, but with a little more detail.

    Hope it works for you

    Author Comment

    Thanks .. this is exactly what I did ...

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Do You Know the 4 Main Threat Actor Types?

    Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

    Suggested Solutions

    This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
    This is an explanation of a simple data model to help parse a JSON feed
    In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

    913 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    13 Experts available now in Live!

    Get 1:1 Help Now