/* Copyright (c) 2011 Peter Troshin * * JAva Bioinformatics Analysis Web Services (JABAWS) @version: 2.0 * * This library is free software; you can redistribute it and/or modify it under the terms of the * Apache License version 2 as published by the Apache Software Foundation * * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the Apache * License for more details. * * A copy of the license is in apache_license.txt. It is also available here: * @see: http://www.apache.org/licenses/LICENSE-2.0.txt * * Any republication or derived work distributed in source code form * must include this copyright and license notice. */ package compbio.ws.server; import javax.servlet.http.HttpServletRequest; import javax.xml.ws.WebServiceContext; import javax.xml.ws.handler.MessageContext; import org.apache.log4j.Level; import org.apache.log4j.Logger; import compbio.util.Timer; import compbio.util.Util; import compbio.ws.client.Services; @Deprecated public class _WSLogger { private static final String SPACER = " "; private final String wsname; private final WebServiceContext wsContext; private final Logger wsAccessLog; private _WSLogger(Services wsname, WebServiceContext context) { this.wsname = wsname.toString(); this.wsContext = context; this.wsAccessLog = Logger.getLogger(wsname.toString() + "-stats"); assert context != null : "WSContext was not injected"; assert wsAccessLog != null : "wsAccessLog is not obtained"; } public static final _WSLogger getStatLogger(Services service, WebServiceContext wsContext) { assert service != null; return new _WSLogger(service, wsContext); } /** * [Request_thread timeofRequest] configured via log4j configuration * RequestSource web_service timeToProcessRequest methodname {taskid} * * @param statLog * @param wsContext * @param jobId * @param activity */ private void log(Timer timer, String activity, Level level, String jobId) { assert !Util.isEmpty(jobId) || !Util.isEmpty(activity); // At least one // of the two must be defined if (Util.isEmpty(jobId)) { jobId = ""; // prevent is to be printed as null } else { assert !Util.isEmpty(activity) : "if jobId is defined, then activity must be defined too"; } wsAccessLog.log(level, getRemoteAddress() + SPACER + wsname + SPACER + timer.getTotalTime() + SPACER + activity + SPACER + jobId); } public void logAll(Timer timer, String activity) { assert !Util.isEmpty(activity); log(timer, activity, Level.TRACE, ""); } public void logFine(Timer timer, String activity) { assert !Util.isEmpty(activity); log(timer, activity, Level.DEBUG, ""); } public void log(Timer timer, String activity) { assert !Util.isEmpty(activity); log(timer, activity, Level.INFO, ""); } public void log(Timer timer, String activity, String jobId) { assert !Util.isEmpty(activity); log(timer, activity, Level.INFO, jobId); } /* * * private static String getDataTimeForLog() { return * DateFormat.getDateTimeInstance(DateFormat.MEDIUM, * DateFormat.SHORT).format(System.currentTimeMillis()); } * * * public static String getRemoteAddress(WebServiceContext wsContext) { * assert wsContext != null : "WS context injection failed!"; MessageContext * msContext = wsContext.getMessageContext(); HttpServletRequest request = * (HttpServletRequest) msContext .get(MessageContext.SERVLET_REQUEST); * return request == null ? "127.0.0.1" : request.getRemoteAddr(); } */ public String getRemoteAddress() { assert wsContext != null : "WS context injection failed!"; MessageContext msContext = wsContext.getMessageContext(); HttpServletRequest request = (HttpServletRequest) msContext .get(MessageContext.SERVLET_REQUEST); return request == null ? "127.0.0.1" : request.getRemoteAddr(); } }