User: cgjung
Date: 01/10/03 06:20:31
Added: jboss.net/src/main/org/jboss/net/axis/server
AxisService.java AxisServiceMBean.java
AxisServiceServlet.java
ClassLoaderAwareAxisServer.java
ClassLoaderAwareMessageContext.java Constants.java
package.html
Log:
restructured server/client parts, invocationhandler support.
MBeanProvider for exposing MBeans as web-services.
JMXConnector.
Revision Changes Path
1.1
contrib/jboss.net/src/main/org/jboss/net/axis/server/AxisService.java
Index: AxisService.java
===================================================================
/*
* JBoss, the OpenSource J2EE webOS
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
// $Id: AxisService.java,v 1.1 2001/10/03 13:20:31 cgjung Exp $
package org.jboss.net.axis.server;
import org.jboss.net.axis.XMLResourceProvider;
import org.jboss.net.DefaultResourceBundle;
import org.jboss.deployment.DeploymentException;
import org.jboss.deployment.DeployerMBeanSupport;
import org.jboss.web.WebApplication;
import org.apache.log4j.Category;
import org.apache.log4j.Priority;
import org.apache.axis.MessageContext;
import org.apache.axis.utils.XMLUtils;
import org.apache.axis.utils.Admin;
import org.apache.axis.AxisFault;
import org.apache.axis.server.AxisServer;
import org.apache.axis.configuration.FileProvider;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import javax.management.MBeanRegistration;
import javax.management.MBeanServer;
import javax.management.MBeanServerFactory;
import javax.management.ObjectName;
import javax.management.MalformedObjectNameException;
import java.io.FilenameFilter;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.FileOutputStream;
import java.net.URL;
import java.net.URLClassLoader;
import java.net.MalformedURLException;
import java.util.HashMap;
import java.util.Map;
/**
* A deployer service that installs and manages Axis within JMX.
* @created 27. September 2001
* @author <a href="mailto:[EMAIL PROTECTED]">Christoph G. Jung</a>
* @version $Revision: 1.1 $
*/
public class AxisService extends DeployerMBeanSupport implements AxisServiceMBean,
MBeanRegistration, Constants {
/** the name registered */
ObjectName _name=null;
/** this is where the axis "web-application" has been installed */
String myUrl=null;
/** Axis administration helper, keeps no state, i think */
final Admin admin=new Admin();
/** the axis engines */
final static Map axisServerMap=new HashMap();
/** default */
public AxisService() {
// we fake internationalisation if it is not globally catered
if(category.getResourceBundle()==null)
category.setResourceBundle(new DefaultResourceBundle());
}
//----------------------------------------------------------------------------
// 'name' interface
//----------------------------------------------------------------------------
public ObjectName getObjectName(MBeanServer server, ObjectName name)
throws MalformedObjectNameException {
// accept name proposal from JMX in order
// to allow several instances
if(name==null) {
_name=new ObjectName(DOMAIN+":"+TYPE+"="+getName());
} else {
_name=name;
}
return _name;
}
/** return just the proper name part */
public String getName() {
return NAME;
}
//----------------------------------------------------------------------------
// 'service' interface
//----------------------------------------------------------------------------
/** some status methods*/
boolean initialised=false;
protected boolean isInitialised() {
return initialised;
}
protected void setInitialised(boolean flag) {
initialised=flag;
}
/** starts the associated AxisEngine */
protected void ensureService() throws Exception {
synchronized(AxisService.class) {
// each engine must have a different context
if(axisServerMap.get(rootContext)!=null)
throw new Exception(AXIS_SERVER_CONTEXT_OCCUPIED);
// find the global config file in classpath
URL resource=getClass().
getClassLoader().getResource(AXIS_CONFIGURATION_FILE);
if(resource==null) {
category.l7dlog(Priority.WARN,COULD_NOT_FIND_AXIS_CONFIGURATION_0,
new Object[]{AXIS_CONFIGURATION_FILE},null);
throw new Exception(COULD_NOT_FIND_AXIS_CONFIGURATION_0);
}
// Set the base path for the AxisServer to our WEB-INF directory
axisServerMap.put(getRootContext(),new ClassLoaderAwareAxisServer(new
XMLResourceProvider(resource)));
}
}
/** initialise service */
public void initService() throws Exception {
if (!isInitialised()) {
ensureService();
super.initService();
setInitialised(true);
} else
category.warn(AXIS_ALREADY_INITIALIZED);
}
/** start service = register Axis servlet in WebContainer */
public void startService() throws Exception {
super.startService();
// we find out through which URLClassLoader we have been loaded
ClassLoader myLoader=getClass().getClassLoader();
// there must be also the servlet spec as a resource somewhere
URL web_descriptor=myLoader.getResource(AXIS_DEPLOYMENT_DESCRIPTOR);
if(web_descriptor==null)
throw new Exception(AXIS_DEPLOYMENT_DESCRIPTOR_NOT_FOUND);
// its there, so we open it prophylactically
InputStream input=web_descriptor.openStream();
try{
//next we build the deployment structure that should
//persuade the web-server to run the axis servlet under
//our root context
File appDir=
new File(getDeployDir()+AXIS_DEPLOY_DIR+"/"+getRootContext()+"/");
// and this is how it looks in stringified URL notation
myUrl=appDir.toURL().toString();
// the target where the deployemnt descriptor goes to
File target=
new File(appDir+WEB_DEPLOYMENT_DESCRIPTOR);
// create intermediate directories if not yet existing
target.getParentFile().mkdirs();
// this is the output stream for writing the descriptor into
FileOutputStream output=new FileOutputStream(target);
try {
copy(input, output);
} finally {
output.close();
}
} finally {
input.close();
}
// we use the root context as URL infix
String rootContext="/"+getRootContext()+"/*";
category.l7dlog(Priority.INFO,ABOUT_TO_DEPLOY_0_UNDER_CONTEXT_1,new
Object[] {myUrl,rootContext},null);
// Call the appropriate deployer through the JMX server
Object webApplication=
getServer().invoke(new ObjectName(getWarDeployerName()),
DEPLOY_METHOD_NAME, new Object[]{rootContext,myUrl},
new String[] {STRING_CLASS_NAME,STRING_CLASS_NAME});
}
/** what to do to stop axis temporarily --> undeploy the servlet */
public void stopService() {
super.stopService();
try {
// undeploy axis servlet
category.l7dlog(Priority.INFO,ABOUT_TO_UNDEPLOY_0,new
Object[]{myUrl},null);
// Call the appropriate deployer through the JMX server
Object webApplication=
getServer().invoke(new ObjectName(getWarDeployerName()),
UNDEPLOY_METHOD_NAME, new Object[]{myUrl},new String[]
{STRING_CLASS_NAME});
} catch (Exception e) {
category.error(COULD_NOT_STOP_AXIS, e);
} finally {
myUrl=null;
}
}
/** take the complete engine down */
public void destroyService() {
if (isInitialised()) {
super.destroyService();
synchronized(AxisService.class) {
((AxisServer) axisServerMap.get(getRootContext())).stop();
axisServerMap.remove(getRootContext());
}
// who knows what to do here
setInitialised(false);
}
else
category.warn(AXIS_ALREADY_DESTROYED);
}
//----------------------------------------------------------------------------
// static helper that relates contexts and axis engines
//----------------------------------------------------------------------------
/** return the engine if initialised */
public static synchronized AxisServer getAxisServer(String context) {
return (AxisServer) axisServerMap.get(context);
}
//----------------------------------------------------------------------------
// war deployer plug
//----------------------------------------------------------------------------
protected String warDeployerName=null;
public String getWarDeployerName() {
return warDeployerName;
}
public void setWarDeployerName(String name) {
category.l7dlog(Priority.INFO,SET_WAR_DEPLOYER_0,new Object[]{name},null);
warDeployerName=name;
}
//----------------------------------------------------------------------------
// root context plug
//----------------------------------------------------------------------------
protected String rootContext=DEFAULT_ROOT_CONTEXT;
public String getRootContext() {
return rootContext;
}
/** the root context must be constant for the lifetime of the service */
public void setRootContext(String name) throws Exception {
if(isInitialised())
throw new Exception(CANNOT_CHANGE_ROOT_CONTEXT);
category.l7dlog(Priority.INFO,SET_ROOT_CONTEXT_0,new Object[]{name},null);
rootContext=name;
}
//----------------------------------------------------------------------------
// Deployer interface
//----------------------------------------------------------------------------
/** we accept .wsr files */
public FilenameFilter getDeployableFilter() {
return new FilenameFilter() {
public boolean accept(File dir, String filename) {
filename=filename.toLowerCase();
return filename.endsWith(WSR_FILE_EXTENSION);
}
};
}
/** deploys a given descriptor file, we & axis expect the classes
* needed to do this in the context classloader of the
* calling thread
*/
protected Element deployDescriptor(URL url) throws DeploymentException {
category.l7dlog(Priority.INFO,ABOUT_TO_DEPLOY_AXIS_0,new Object[]
{url},null);
try{
// we create a new message context
// connected to our singleton servlet
MessageContext msgContext = new MessageContext((AxisServer)
axisServerMap.get(getRootContext()));
// parse the stuff into a dom
Document doc = XMLUtils.newDocument( url.openStream() );
// the original command
Element root=doc.getDocumentElement();
// the deployment command document
Document deployDoc=XMLUtils.newDocument();
// create command
Element deploy=deployDoc.createElementNS("m","deploy");
deploy.setAttributeNS("xmlns","m","AdminService");
// and insert the nodes from the original document
NodeList children=root.getChildNodes();
for(int count=0;count<children.getLength();count++) {
Node actNode=children.item(count);
deploy.appendChild(deployDoc.importNode(actNode,true));
}
// insert command into document
deployDoc.appendChild(deploy);
try {
// and run the axis administrator
admin.AdminService(msgContext, deployDoc);
return root;
} catch(AxisFault e) {
throw new DeploymentException(COULD_NOT_DEPLOY_DESCRIPTOR,e);
}
} catch(IOException e) {
throw new DeploymentException(COULD_NOT_DEPLOY_DESCRIPTOR,e);
}
}
/** undeploys a given app */
protected void undeploy(URL url, Object info)
throws DeploymentException {
// we create a new message context
MessageContext msgContext = new MessageContext((AxisServer)
axisServerMap.get(getRootContext()));
// this was the deployment command
Element root=(Element) info;
// from which we extract an undeployment counterpart
Document undeployDoc=XMLUtils.newDocument();
Element undeploy=undeployDoc.createElementNS("m","undeploy");
undeploy.setAttributeNS("xmlns","m","AdminService");
// all service and handler entries are copied for
// that purpose
NodeList children=root.getElementsByTagName("service");
for(int count=0;count<children.getLength();count++) {
Node actNode=children.item(count);
undeploy.appendChild(undeployDoc.importNode(actNode,true));
}
children=root.getElementsByTagName("handler");
for(int count=0;count<children.getLength();count++) {
Node actNode=children.item(count);
undeploy.appendChild(undeployDoc.importNode(actNode,true));
}
// put command into document
undeployDoc.appendChild(undeploy);
try{
// and call the administrator
admin.AdminService(msgContext,undeployDoc);
} catch(AxisFault e) {
throw new DeploymentException(COULD_NOT_UNDEPLOY,e);
}
}
/** deploys a given file/directory/descriptor */
protected Object deploy(URL url) throws DeploymentException {
if(url.getFile().toLowerCase().endsWith(XML_FILE_EXTENSION)) {
// pure file deployment
return deployDescriptor(url);
} else
if(url.toString().toLowerCase().endsWith(WSR_FILE_EXTENSION)) {
// wsr archive deployment
try{
// copy the archive
URL copy=getLocalCopy(url,null).toURL();
// remember classloader
ClassLoader
previous=Thread.currentThread().getContextClassLoader();
// and install new classloader apartment
URLClassLoader newClassLoader=new URLClassLoader(new URL[]
{copy},
previous);
// enter the apartment
Thread.currentThread().setContextClassLoader(newClassLoader);
try{
// extract the deployment descriptor from the file
URL
deploymentDescriptor=newClassLoader.getResource(WEB_SERVICE_DESCRIPTOR);
// and deploy the pure descriptor
if(deploymentDescriptor!=null)
return deployDescriptor(deploymentDescriptor);
else
throw new
DeploymentException(NO_VALID_WEB_SERVICE_DESCRIPTOR);
} finally {
Thread.currentThread().setContextClassLoader(previous);
}
} catch(IOException e) {
throw new DeploymentException(COULD_NOT_COPY_URL);
}
}
throw new DeploymentException(COULD_NOT_DEPLOY);
}
}
1.1
contrib/jboss.net/src/main/org/jboss/net/axis/server/AxisServiceMBean.java
Index: AxisServiceMBean.java
===================================================================
/*
* JBoss, the OpenSource J2EE webOS
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
// $Id: AxisServiceMBean.java,v 1.1 2001/10/03 13:20:31 cgjung Exp $
package org.jboss.net.axis.server;
/**
* Mbean interface to the AxisService
* @author <a href="mailto:[EMAIL PROTECTED]">Christoph G. Jung</a>
* @created 27. September 2001
* @version $Revision: 1.1 $
*/
public interface AxisServiceMBean extends org.jboss.deployment.DeployerMBean {
// P-------------------------------------------------------
public String getWarDeployerName();
public void setWarDeployerName(String name);
public String getRootContext();
public void setRootContext(String name) throws Exception;
}
1.1
contrib/jboss.net/src/main/org/jboss/net/axis/server/AxisServiceServlet.java
Index: AxisServiceServlet.java
===================================================================
/*
* JBoss, the OpenSource J2EE webOS
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
package org.jboss.net.axis.server;
import org.apache.axis.transport.http.AxisServlet;
import org.apache.axis.server.AxisServer;
import org.apache.axis.AxisEngine;
import org.apache.axis.MessageContext;
import java.util.StringTokenizer;
import java.util.ArrayList;
import java.io.File;
/**
* An AxisServlet that is able to extract the corresponding AxisEngine
* from its installation context and builds the right message contexts for the
* JBoss classloading and deployment architecture.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Christoph G. Jung</a>
* @created 7. September 2001, 19:17
* @version $Revision: 1.1 $
*/
public class AxisServiceServlet extends AxisServlet implements Constants {
/** Creates new AxisServlet */
public AxisServiceServlet() {
}
/** override AxisServlet.getEngine() in order to redirect to
* the corresponding AxisEngine
*/
public AxisServer getEngine() {
if (getServletContext().getAttribute(AXIS_ENGINE_ATTRIBUTE) == null) {
// we need to extract the engine from the
// rootcontext
String installation=getServletContext().getRealPath("");
if(installation.indexOf(File.separator)!=-1)
installation=installation.substring(installation.lastIndexOf(File.separator)+1);
// call the static service method to find the installed engine
getServletContext().setAttribute(AXIS_ENGINE_ATTRIBUTE,
AxisService.getAxisServer(installation));
}
return
(AxisServer)getServletContext().getAttribute(AXIS_ENGINE_ATTRIBUTE);
}
/** return only special message contexts*/
public MessageContext createMessageContext(AxisEngine engine) {
return new ClassLoaderAwareMessageContext(engine);
}
}
1.1
contrib/jboss.net/src/main/org/jboss/net/axis/server/ClassLoaderAwareAxisServer.java
Index: ClassLoaderAwareAxisServer.java
===================================================================
/*
* JBoss, the OpenSource J2EE webOS
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
// $Id: ClassLoaderAwareAxisServer.java,v 1.1 2001/10/03 13:20:31 cgjung Exp $
package org.jboss.net.axis.server;
import org.apache.axis.server.AxisServer;
import org.apache.axis.ConfigurationProvider;
import org.apache.axis.handlers.soap.SOAPService;
import org.apache.axis.utils.AxisClassLoader;
import java.util.Map;
import java.util.HashMap;
/**
* This AxisServer is able to store also classloading information
* for each service such that the message processing will look
* in the right part of the VM.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Christoph G. Jung</a>
* @created 29. September 2001, 15:32
* @version $Revision: 1.1 $
*/
public class ClassLoaderAwareAxisServer extends AxisServer {
/** The classloader registry this Engine uses. */
protected Map loaderRegistry = new HashMap();
/** Creates new ClassloaderAwareAxisServer */
public ClassLoaderAwareAxisServer() {
}
/** Creates new ClassloaderAwareAxisServer with a given config provider */
public ClassLoaderAwareAxisServer(ConfigurationProvider provider)
{
super(provider);
}
/**
* Deploy a Service into our service registry, will
* register the corresponding classloader, too
*/
public void deployService(String key, SOAPService service)
{
loaderRegistry.put(key,AxisClassLoader.getClassLoader());
super.deployService(key,service);
}
/**
* Undeploy (remove) a Service from the handler registry
* will unregister the corresponding classloader, too
*/
public void undeployService(String key)
{
loaderRegistry.remove(key);
super.undeployService(key);
}
}
1.1
contrib/jboss.net/src/main/org/jboss/net/axis/server/ClassLoaderAwareMessageContext.java
Index: ClassLoaderAwareMessageContext.java
===================================================================
/*
* JBoss, the OpenSource J2EE webOS
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
// $Id: ClassLoaderAwareMessageContext.java,v 1.1 2001/10/03 13:20:31 cgjung Exp $
package org.jboss.net.axis.server;
import org.apache.axis.AxisEngine;
import org.apache.axis.MessageContext;
import org.apache.axis.utils.AxisClassLoader;
import java.util.Map;
/**
* This MessageContext is able to install the right classloader
* for its target services as being configured by a JBoss aware
* AxisServer.
* @author <a href="mailto:[EMAIL PROTECTED]">Christoph G. Jung</a>
* @created 29. September 2001, 15:36
* @version $Revision: 1.1 $
*/
public class ClassLoaderAwareMessageContext extends MessageContext {
/** Creates new ClassLoaderAwareMessageContext in the given engine */
public ClassLoaderAwareMessageContext(AxisEngine engine) {
super(engine);
}
/**
* Set the target service for this message.
*
* If running against our special server, will lookup the
* service->classloader table to find the right VM apartment, before
* delegating to the super class.
*
* @param tServ the name of the target service.
*/
public void setTargetService(String tServ) {
if(getAxisEngine() instanceof ClassLoaderAwareAxisServer) {
Map loaders=((ClassLoaderAwareAxisServer) getAxisEngine()).
loaderRegistry;
setClassLoader((AxisClassLoader) loaders.get(tServ));
}
super.setTargetService(tServ);
}
}
1.1
contrib/jboss.net/src/main/org/jboss/net/axis/server/Constants.java
Index: Constants.java
===================================================================
/*
* JBoss, the OpenSource J2EE webOS
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
// $Id: Constants.java,v 1.1 2001/10/03 13:20:31 cgjung Exp $
package org.jboss.net.axis.server;
/**
* Some Constants for the axis package
* @author <a href="mailto:[EMAIL PROTECTED]">Christoph G. Jung</a>
* @created 28. September 2001
* @version $Revision: 1.1 $
*/
public interface Constants {
static final String DOMAIN="JBOSS-SYSTEM";
static final String NAME = "Axis";
static final String TYPE="service";
static final String
SERVER_DELEGATE_NAME="JMImplementation:type=MBeanServerDelegate";
static final String SERVER_ID_ATTRIBUTE="MBeanServerId";
static final String AXIS_DEPLOYMENT_DESCRIPTOR="META-INF/install-axis.xml";
static final String AXIS_DEPLOY_DIR="/_axis_/";
static final String WEB_DEPLOYMENT_DESCRIPTOR="/WEB-INF/web.xml";
static final String DEPLOY_METHOD_NAME="deploy";
static final String UNDEPLOY_METHOD_NAME="undeploy";
static final String STRING_CLASS_NAME="java.lang.String";
static final String DEFAULT_ROOT_CONTEXT="axis";
static final String WSR_FILE_EXTENSION=".wsr";
static final String XML_FILE_EXTENSION=".xml";
static final String AXIS_ENGINE_ATTRIBUTE="AxisEngine";
static final String GET_AXIS_SERVER_METHOD_NAME="getAxisServer";
static final String AXIS_CONFIGURATION_FILE="axis-config.xml";
static final String WEB_SERVICE_DESCRIPTOR="META-INF/web-service.xml";
static final String AXIS_ALREADY_INITIALIZED="Axis has already been
initialised.";
static final String AXIS_DEPLOYMENT_DESCRIPTOR_NOT_FOUND="The axis deployment
descriptor is lacking in the service archive!";
static final String ABOUT_TO_DEPLOY_0_UNDER_CONTEXT_1="About to deploy axis web
application from {0} under context {1}.";
static final String AXIS_ALREADY_STARTED="Axis has already been started.";
static final String ABOUT_TO_UNDEPLOY_0="About to undeploy axis web application
from {0}.";
static final String COULD_NOT_STOP_AXIS="Could not correctly stop Axis.";
static final String AXIS_ALREADY_STOPPED="Axis has already been stopped.";
static final String AXIS_ALREADY_DESTROYED="Axis has already been destroyed.";
static final String SET_WAR_DEPLOYER_0="Seting WarDeployerName to {0}.";
static final String SET_ROOT_CONTEXT_0="Seting RootContext to {0}.";
static final String ABOUT_TO_DEPLOY_AXIS_0="About to deploy axis descriptor
{0}.";
static final String COULD_NOT_DEPLOY_DESCRIPTOR="Could not deploy axis
descriptor.";
static final String COULD_NOT_FIND_AXIS_CONFIGURATION_0="Could not find the axis
configuration file {0}.";
static final String NO_VALID_WEB_SERVICE_DESCRIPTOR="Could not find a valid web
service descriptor.";
static final String COULD_NOT_DEPLOY="Could not deploy url.";
static final String COULD_NOT_UNDEPLOY="Could not undeploy url.";
static final String COULD_NOT_COPY_URL="Could not download url.";
static final String CANNOT_CHANGE_ROOT_CONTEXT="Cannot change root context while
service is running. Stop first.";
static final String AXIS_SERVER_CONTEXT_OCCUPIED="There is already an Axis
service running under that root context.";
}
1.1
contrib/jboss.net/src/main/org/jboss/net/axis/server/package.html
Index: package.html
===================================================================
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML>
<HEAD>
<TITLE>JBoss-Axis server package</TITLE>
</HEAD>
<BODY>
contains code to run axis as a deployer within jboss
</BODY>
</HTML>
_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-development