001: /**
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */package org.apache.openejb.server;
017:
018: import java.io.*;
019: import java.net.*;
020: import java.util.*;
021:
022: import org.apache.openejb.util.*;
023:
024: /**
025: * @version $Rev: 617034 $ $Date: 2008-01-30 23:39:03 -0800 $
026: */
027: public class ServiceLogger implements ServerService {
028:
029: Messages messages = new Messages(
030: "org.apache.openejb.server.util.resources");
031: Logger logger;
032:
033: boolean logOnSuccess;
034: boolean logOnFailure;
035:
036: ServerService next;
037:
038: public ServiceLogger(ServerService next) {
039: this .next = next;
040: }
041:
042: public void init(Properties props) throws Exception {
043:
044: logger = Logger.getInstance(LogCategory.OPENEJB_SERVER
045: .createChild("service." + getName()),
046: "org.apache.openejb.server.util.resources");
047:
048: next.init(props);
049: }
050:
051: public void start() throws ServiceException {
052:
053: next.start();
054: }
055:
056: public void stop() throws ServiceException {
057:
058: next.stop();
059: }
060:
061: public void service(InputStream in, OutputStream out)
062: throws ServiceException, IOException {
063: throw new UnsupportedOperationException("service(in,out)");
064: }
065:
066: public void service(Socket socket) throws ServiceException,
067: IOException {
068: InetAddress client = socket.getInetAddress();
069:
070: try {
071: org.apache.log4j.MDC.put("HOST", client.getHostName());
072: org.apache.log4j.MDC.put("SERVER", getName());
073: } catch (Throwable e) {
074: }
075:
076: try {
077:
078: // logger.info("[request] "+socket.getPort()+" - "+client.getHostName());
079: next.service(socket);
080: // logSuccess();
081: } catch (Exception e) {
082: logger.error("[failure] " + socket.getPort() + " - "
083: + client.getHostName() + ": " + e.getMessage());
084:
085: e.printStackTrace();
086: }
087: }
088:
089: private void logIncoming() {
090: logger.info("incomming request");
091: }
092:
093: private void logSuccess() {
094: logger.info("successful request");
095: }
096:
097: private void logFailure(Exception e) {
098: logger.error(e.getMessage());
099: }
100:
101: public String getName() {
102: return next.getName();
103: }
104:
105: public String getIP() {
106: return next.getIP();
107: }
108:
109: public int getPort() {
110: return next.getPort();
111: }
112:
113: }
|