FileDocCategorySizeDatePackage
LogHandler.javaAPI DocApache Axis 1.42366Sat Apr 22 18:56:52 BST 2006samples.userguide.example4

LogHandler

public class LogHandler extends org.apache.axis.handlers.BasicHandler

Fields Summary
Constructors Summary
Methods Summary
public voidinvoke(org.apache.axis.MessageContext msgContext)

        /** Log an access each time we get invoked.
         */
        try {
            Handler serviceHandler = msgContext.getService();
            String filename = (String)getOption("filename");
            if ((filename == null) || (filename.equals("")))
                throw new AxisFault("Server.NoLogFile",
                                 "No log file configured for the LogHandler!",
                                    null, null);
            FileOutputStream fos = new FileOutputStream(filename, true);
            
            PrintWriter writer = new PrintWriter(fos);
            
            Integer numAccesses =
                             (Integer)serviceHandler.getOption("accesses");
            if (numAccesses == null)
                numAccesses = new Integer(0);
            
            numAccesses = new Integer(numAccesses.intValue() + 1);
            
            Date date = new Date();
            String result = date + ": service " +
                            msgContext.getTargetService() +
                            " accessed " + numAccesses + " time(s).";
            serviceHandler.setOption("accesses", numAccesses);
            
            writer.println(result);
            
            writer.close();
        } catch (Exception e) {
            throw AxisFault.makeFault(e);
        }