You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@juddi.apache.org by sv...@apache.org on 2003/11/11 14:49:38 UTC
cvs commit: ws-juddi/src/java/org/apache/juddi/monitor Monitor.java MonitorAdapter.java MonitorData.java MonitorFactory.java
sviens 2003/11/11 05:49:38
Added: src/java/org/apache/juddi/monitor Monitor.java
MonitorAdapter.java MonitorData.java
MonitorFactory.java
Log:
Moved from jUDDI CVS at SourceForge
Revision Changes Path
1.1 ws-juddi/src/java/org/apache/juddi/monitor/Monitor.java
Index: Monitor.java
===================================================================
/*
* The Apache Software License, Version 1.1
*
*
* Copyright (c) 2001-2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "jUDDI" and "Apache Software Foundation" must
* not be used to endorse or promote products derived from this
* software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* nor may "Apache" appear in their name, without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.juddi.monitor;
import org.apache.axis.MessageContext;
import org.apache.juddi.datatype.RegistryObject;
import org.w3c.dom.Element;
/**
* @author Anou Mana (anou_mana@users.sourceforge.net)
*/
public interface Monitor
{
void inspectMessageContext(MessageContext messageContext);
void inspectUDDIRequest(Element request);
void inspectRegistryObject(RegistryObject registryObject);
void addMonitorFault( String faultString );
void log();
}
1.1 ws-juddi/src/java/org/apache/juddi/monitor/MonitorAdapter.java
Index: MonitorAdapter.java
===================================================================
/*
* The Apache Software License, Version 1.1
*
*
* Copyright (c) 2001-2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "jUDDI" and "Apache Software Foundation" must
* not be used to endorse or promote products derived from this
* software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* nor may "Apache" appear in their name, without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.juddi.monitor;
import org.apache.axis.Constants;
import org.apache.axis.MessageContext;
import org.apache.axis.transport.http.AxisServlet;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.juddi.datatype.RegistryObject;
import org.apache.juddi.datatype.request.AuthInfo;
import org.apache.juddi.datatype.request.DiscardAuthToken;
import org.apache.juddi.datatype.request.Publish;
import org.apache.juddi.registry.Registry;
import org.w3c.dom.Element;
/**
* @author Anou Mana (anou_mana@users.sourceforge.net)
*/
public abstract class MonitorAdapter implements Monitor
{
// private reference to the jUDDI logger
private static Log log = LogFactory.getLog(MonitorAdapter.class);
protected MonitorData data = null;
public MonitorAdapter()
{
init();
}
protected void init()
{
data = new MonitorData();
}
public void inspectMessageContext(MessageContext messageContext)
{
String remoteHost = messageContext.getProperty(Constants.MC_REMOTE_ADDR).toString();
String requestedURI = messageContext.getProperty(Constants.MC_RELATIVE_PATH).toString();
log.debug("RequestedURI: " + requestedURI +",RemoteHost: " + remoteHost);
data.setRequestURI( requestedURI );
data.setRemoteHost( remoteHost );
// inspect the called Servlet value now since to obtain
// this object is a simple 'getProperty' call from
// MessageContext.
AxisServlet axisServlet =
(AxisServlet)messageContext.getProperty("transport.http.servlet");
}
public void inspectUDDIRequest(Element request)
{
if(request != null)
{
data.setCalledFunction(request.getLocalName());
String generic = request.getAttribute("generic");
if (generic == null)
generic = Registry.UDDI_V2_GENERIC;
data.setUddiVersion(generic);
}
}
public void inspectRegistryObject(RegistryObject registryObject)
{
AuthInfo authInfo = null;
// As of UDDI v3.0 get_authToken and discard_authToken are
// no longer part of the Publish API (they are part of the
// new SecurityPolicy API) so the associated request classes
// do not implement "Publish".
// Since the DiscardAuthToken doesn't implement Publish we
// need to check it specifically (we never cared about the
// GetAuthToken requests here so we now ignore them).
if (registryObject instanceof Publish)
authInfo = ((Publish)registryObject).getAuthInfo();
else if (registryObject instanceof DiscardAuthToken)
authInfo = ((DiscardAuthToken)registryObject).getAuthInfo();
if (authInfo != null)
data.setAuthToken(authInfo.getValue());
}
public void addMonitorFault( String faultString )
{
String fault = data.getFault();
if(fault != "")
{
faultString = "; " + faultString;
}
data.setFault(fault + faultString);
}
public abstract void log();
}
1.1 ws-juddi/src/java/org/apache/juddi/monitor/MonitorData.java
Index: MonitorData.java
===================================================================
/*
* The Apache Software License, Version 1.1
*
*
* Copyright (c) 2001-2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "jUDDI" and "Apache Software Foundation" must
* not be used to endorse or promote products derived from this
* software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* nor may "Apache" appear in their name, without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.juddi.monitor;
import org.apache.juddi.datatype.RegistryObject;
/**
* @author Anou Mana (anou_mana@users.sourceforge.net)
*/
public class MonitorData implements RegistryObject
{
String requestURI = ""; // initialize to empty string to avoid log db failure
String remoteHost = "";
String calledFunction = "";
String authToken = "";
String uddiVersion = "";
String logTime = null;
String fault = "";
/**
* Construct a new initialized MonitorData instance.
*/
public MonitorData()
{
}
/**
* Construct a new MonitorData with a given user IP and the function called.
*
* @param number The number of the new MonitorData.
* @param useType The usetype of the new MonitorData.
*/
public MonitorData(String remoteHost, String calledFunction)
{
this.remoteHost = remoteHost;
this.calledFunction = calledFunction;
}
/**
* @return The UDDI or jUDDI function invoked by this request.
*/
public String getCalledFunction()
{
return calledFunction;
}
/**
* @return The fault generated by the request (if it was unsuccessful)
*/
public String getFault()
{
return fault;
}
/**
* @return The time the request was logged
*/
public String getLogTime()
{
return logTime;
}
/**
* @return Version of the UDDI or jUDDI API used to make the request.
*/
public String getVersion()
{
return uddiVersion;
}
/**
* @return The AuthToken (if any) used to make the request.
*/
public String getAuthToken()
{
return authToken;
}
/**
* @param string
*/
public void setCalledFunction(String string)
{
calledFunction = string;
}
/**
* @param string
*/
public void setFault(String string)
{
fault = string;
}
/**
* @param string
*/
public void setLogTime(String string)
{
logTime = string;
}
/**
* @param string
*/
public void setUddiVersion(String string)
{
uddiVersion = string;
}
/**
* @param string
*/
public void setAuthToken(String authToken)
{
this.authToken = authToken;
}
/**
* @return the name of the Host which made the request
*/
public String getRemoteHost()
{
return remoteHost;
}
/**
* @param string
*/
public void setRemoteHost(String string)
{
remoteHost = string;
}
/**
* @return the UDDI uri used to make the request
*/
public String getRequestURI()
{
return requestURI;
}
/**
* @param string
*/
public void setRequestURI(String string)
{
requestURI = string;
}
public String toString()
{
StringBuffer buff = new StringBuffer();
buff.append(" RequestURI :" + requestURI);
buff.append(" RemoteHost :" + remoteHost);
buff.append(" CalledFunction :" + calledFunction);
buff.append(" AuthToken :" + authToken);
buff.append(" LogTime :" + logTime);
buff.append(" Fault in uddi :" + fault);
return buff.toString();
}
}
1.1 ws-juddi/src/java/org/apache/juddi/monitor/MonitorFactory.java
Index: MonitorFactory.java
===================================================================
/*
* The Apache Software License, Version 1.1
*
*
* Copyright (c) 2001-2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "jUDDI" and "Apache Software Foundation" must
* not be used to endorse or promote products derived from this
* software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* nor may "Apache" appear in their name, without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.juddi.monitor;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.juddi.util.Config;
import org.apache.juddi.util.Loader;
/**
* @author Anou Mana (anou_mana@users.sourceforge.net)
*/
public class MonitorFactory
{
// private reference to the jUDDI logger
private static Log log = LogFactory.getLog(MonitorFactory.class);
private static Class monitorClass = null;
/**
* Returns a new instance of a DefaultMonitor.
*
* @return DefaultMonitor
*/
public static Monitor getMonitor()
{
//see if monitor is needed
String needsMonitor = Config.getMonitor();
Monitor monitor = null;
if(needsMonitor.equals("true"))
{
getMonitorClass();
if(monitorClass != null)
{
try
{
// try to instantiate the Monitor
monitor = (Monitor)monitorClass.newInstance();
}
catch(java.lang.Exception e)
{
log.error("Exception while attempting to instantiate subclass of " +
"Monitor: " + "\n" + e.getMessage());
log.error(e);
}
}
}
return monitor;
}
private static synchronized void getMonitorClass()
{
if(monitorClass == null)
{
// obtain the name of the DefaultMonitor to create
String className = Config.getMonitorClass();
// write DefaultMonitor Property to the log for good measure
log.debug(className);
try
{
// instruct class loader to load the Monitor
monitorClass = Loader.getClassForName(className);
}
catch(ClassNotFoundException e)
{
log.error("The specified DefaultMonitor class '" + className +
"' was not found in classpath.");
log.error(e);
}
}
}
}