Start of Content Area

Syntax documentation Example Program for the Virus Scan Provider  Locate the document in its SAP Library structure

The source code below demonstrates the use of the virus scan provider.

import javax.naming.*;
import com.sap.security.core.server.vsi.api.*;
import com.sap.security.core.server.vsi.api.exception.*;

 /* Virus Scan Interface example */

public class VsiTestScan ... {
...
try {
    /* Lookup the VSI service. */
    
    Context ctx = new InitialContext();
    VSIService vsiService = (VSIService)ctx.lookup(VSIService.JNDI_NAME);
   
    if (vsiService != null) {
        /* get scan instance */

       Instance myInstance = null;
       try {
          myInstance = vsiService.getInstance();
       
         /* perform virus scan */

         if (myInstance.scanBytes(Virus.EICAR) == true) {
            /*
             * true means no infection and no scan error:
             * Scanning the EICAR test pattern virus
             * must either return false or throw an Exception, 
             * otherwise the underlying scan engine has
             * not recognized the EICAR pattern.
             */
    
       /* not expected error */
          }
       }
       catch (VirusInfectionException vse) {

           Infection[] myInfections = vse.getInfections();

           if (myInfections.length == 1) {
              /* the scan engine has found the infection */            
               ...
           }
           else {
              /* not expected error */
               ...
           }    
       }
       catch (Exception e) {
         /* catch all other Exceptions,
          * including VirusScanException and
          * VSIServiceException here as
 not
          * expected error
          */

          /* always use the localized error

           * text for an output

           */

          String error = e. getLocalizedMessage();

          ...

       }
       finally {
         /* release the scan instance */
         vsiService.releaseInstance(myInstance);
       }
    }
    else {
       /* Virus Scan Provider service is not started */
       ...
    }
    ...
}

 

 

End of Content Area