Home » openejb-3.1.2-src » org.apache » openejb » server » [javadoc | source]

    1   /**
    2    * Licensed to the Apache Software Foundation (ASF) under one or more
    3    * contributor license agreements.  See the NOTICE file distributed with
    4    * this work for additional information regarding copyright ownership.
    5    * The ASF licenses this file to You under the Apache License, Version 2.0
    6    * (the "License"); you may not use this file except in compliance with
    7    * the License.  You may obtain a copy of the License at
    8    *
    9    *     http://www.apache.org/licenses/LICENSE-2.0
   10    *
   11    * Unless required by applicable law or agreed to in writing, software
   12    * distributed under the License is distributed on an "AS IS" BASIS,
   13    * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   14    * See the License for the specific language governing permissions and
   15    * limitations under the License.
   16    */
   17   package org.apache.openejb.server;
   18   
   19   import java.io;
   20   import java.net;
   21   import java.util;
   22   
   23   import org.apache.openejb.util;
   24   
   25   /**
   26    * @version $Rev: 617034 $ $Date: 2008-01-30 23:39:03 -0800 (Wed, 30 Jan 2008) $
   27    */
   28   public class ServiceLogger implements ServerService {
   29   
   30       Messages messages = new Messages("org.apache.openejb.server.util.resources");
   31       Logger logger;
   32   
   33       boolean logOnSuccess;
   34       boolean logOnFailure;
   35   
   36       ServerService next;
   37   
   38       public ServiceLogger(ServerService next) {
   39           this.next = next;
   40       }
   41   
   42       public void init(Properties props) throws Exception {
   43   
   44           logger = Logger.getInstance(LogCategory.OPENEJB_SERVER.createChild("service."+getName()), "org.apache.openejb.server.util.resources");
   45   
   46           next.init(props);
   47       }
   48   
   49       public void start() throws ServiceException {
   50   
   51           next.start();
   52       }
   53   
   54       public void stop() throws ServiceException {
   55   
   56           next.stop();
   57       }
   58   
   59       public void service(InputStream in, OutputStream out) throws ServiceException, IOException {
   60           throw new UnsupportedOperationException("service(in,out)");
   61       }
   62   
   63       
   64       public void service(Socket socket) throws ServiceException, IOException {
   65           InetAddress client = socket.getInetAddress();
   66   
   67           try {
   68               org.apache.log4j.MDC.put("HOST", client.getHostName());
   69               org.apache.log4j.MDC.put("SERVER", getName());
   70           } catch (Throwable e) {
   71           }
   72   
   73           try {
   74   
   75   //            logger.info("[request] "+socket.getPort()+" - "+client.getHostName());
   76               next.service(socket);
   77   //            logSuccess();
   78           } catch (Exception e) {
   79               logger.error("[failure] " + socket.getPort() + " - " + client.getHostName() + ": " + e.getMessage());
   80   
   81               e.printStackTrace();
   82           }
   83       }
   84   
   85       private void logIncoming() {
   86           logger.info("incomming request");
   87       }
   88   
   89       private void logSuccess() {
   90           logger.info("successful request");
   91       }
   92   
   93       private void logFailure(Exception e) {
   94           logger.error(e.getMessage());
   95       }
   96   
   97       public String getName() {
   98           return next.getName();
   99       }
  100   
  101       public String getIP() {
  102           return next.getIP();
  103       }
  104   
  105       public int getPort() {
  106           return next.getPort();
  107       }
  108   
  109   }

Home » openejb-3.1.2-src » org.apache » openejb » server » [javadoc | source]