1 45 package org.openejb.server; 46 47 import java.io.*; 48 import java.net.*; 49 import java.util.*; 50 import org.openejb.*; 51 import org.openejb.util.*; 52 53 66 public class ServiceLogger implements ServerService { 67 68 Messages messages = new Messages( "org.openejb.server.util.resources" ); 69 Logger logger; 70 71 boolean logOnSuccess; 72 boolean logOnFailure; 73 74 ServerService next; 75 76 public ServiceLogger(ServerService next){ 77 this.next = next; 78 } 79 80 87 public void init(Properties props) throws Exception { 88 String logCategory = "OpenEJB.server.service."+getName(); 90 91 logger = Logger.getInstance( logCategory, "org.openejb.server.util.resources" ); 92 next.init(props); 94 } 95 96 public void start() throws ServiceException{ 97 99 next.start(); 101 } 102 103 public void stop() throws ServiceException{ 104 106 next.stop(); 108 } 109 110 public void service(InputStream in, OutputStream out) throws ServiceException, IOException { 111 throw new UnsupportedOperationException ("service(in,out)"); 112 } 113 114 137 public void service(Socket socket) throws ServiceException, IOException{ 138 InetAddress client = socket.getInetAddress(); 140 org.apache.log4j.MDC.put("HOST", client.getHostName()); 141 org.apache.log4j.MDC.put("SERVER", getName()); 142 143 try{ 144 next.service(socket); 147 } catch (Exception e){ 149 logger.error("[failure] "+socket.getPort()+" - "+client.getHostName()+": "+e.getMessage()); 150 e.printStackTrace(); 152 } 153 } 154 155 private void logIncoming(){ 156 logger.info("incomming request"); 157 } 158 159 private void logSuccess(){ 160 logger.info("successful request"); 161 } 162 163 private void logFailure(Exception e){ 164 logger.error(e.getMessage()); 165 } 166 167 171 public String getName(){ 172 return next.getName(); 173 } 174 175 179 public String getIP(){ 180 return next.getIP(); 181 } 182 183 187 public int getPort(){ 188 return next.getPort(); 189 } 190 191 } 192 | Popular Tags |