axisconfiguration.java
来自「开源的axis2框架的源码。用于开发WEBSERVER」· Java 代码 · 共 1,099 行 · 第 1/3 页
JAVA
1,099 行
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.axis2.engine;
import org.apache.axis2.AxisFault;
import org.apache.axis2.builder.Builder;
import org.apache.axis2.clustering.ClusterManager;
import org.apache.axis2.context.MessageContext;
import org.apache.axis2.dataretrieval.AxisDataLocator;
import org.apache.axis2.deployment.DeploymentException;
import org.apache.axis2.deployment.ModuleDeployer;
import org.apache.axis2.deployment.repository.util.DeploymentFileData;
import org.apache.axis2.deployment.util.PhasesInfo;
import org.apache.axis2.description.*;
import org.apache.axis2.description.java2wsdl.Java2WSDLConstants;
import org.apache.axis2.i18n.Messages;
import org.apache.axis2.phaseresolver.PhaseResolver;
import org.apache.axis2.transport.MessageFormatter;
import org.apache.axis2.util.TargetResolver;
import org.apache.axis2.util.Utils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import javax.xml.namespace.QName;
import java.io.File;
import java.net.URL;
import java.security.PrivilegedAction;
import java.util.*;
/**
* Class AxisConfiguration
*/
public class AxisConfiguration extends AxisDescription {
private static final Log log = LogFactory.getLog(AxisConfiguration.class);
/*
* To store configured data locators
*/
private HashMap dataLocators = new HashMap();
private HashMap dataLocatorClassNames = new HashMap();
/**
* This is a Map of String name -> AxisModule for all available Modules.
*/
private final HashMap allModules = new HashMap();
// To store mapping between default version and module name
private final HashMap nameToversionMap = new HashMap();
// private final HashMap serviceGroups = new HashMap();
private final HashMap transportsIn = new HashMap();
private final HashMap transportsOut = new HashMap();
private final HashMap policySupportedModules = new HashMap();
/**
* Stores the QNames of local policy assertions
*/
private final ArrayList localPolicyAssertions = new ArrayList();
// to store AxisObserver Objects
private ArrayList observersList = null;
private URL axis2Repository = null;
private HashMap allServices = new HashMap();
private HashMap allEndpoints = new HashMap();
/**
* Stores the module specified in the server.xml at the document parsing time.
*/
private List globalModuleList;
private Hashtable faultyModules;
/**
* To store faulty services
*/
private Hashtable faultyServices;
private ArrayList inFaultPhases;
private ArrayList inPhasesUptoAndIncludingPostDispatch;
private HashMap messageReceivers;
private HashMap messageBuilders;
private HashMap messageFormatters;
private ClassLoader moduleClassLoader;
private HashMap moduleConfigmap;
private ArrayList outFaultPhases;
private ArrayList outPhases;
protected PhasesInfo phasesinfo;
private ClassLoader serviceClassLoader;
private ClassLoader systemClassLoader;
//To keep track of whether the system has started or not
private boolean start;
private ArrayList targetResolvers;
private ClusterManager clusterManager;
private AxisConfigurator configurator;
/**
* Constructor AxisConfiguration.
*/
public AxisConfiguration() {
moduleConfigmap = new HashMap();
globalModuleList = new ArrayList();
messageReceivers = new HashMap();
messageBuilders = new HashMap();
messageFormatters = new HashMap();
outPhases = new ArrayList();
inFaultPhases = new ArrayList();
outFaultPhases = new ArrayList();
faultyServices = new Hashtable();
faultyModules = new Hashtable();
observersList = new ArrayList();
inPhasesUptoAndIncludingPostDispatch = new ArrayList();
systemClassLoader = (ClassLoader) org.apache.axis2.java.security.AccessController
.doPrivileged(new PrivilegedAction() {
public Object run() {
return Thread.currentThread().getContextClassLoader();
}
});
serviceClassLoader = systemClassLoader;
moduleClassLoader = systemClassLoader;
this.phasesinfo = new PhasesInfo();
targetResolvers = new ArrayList();
}
public void addMessageReceiver(String mepURL,
MessageReceiver messageReceiver) {
messageReceivers.put(mepURL, messageReceiver);
}
/**
* Register a messageBuilder implementation against a content type.
* This is used by Axis2 to support different message formats.
*
* @param contentType the relevant content-type (i.e. "text/xml")
* @param messageBuilder a Builder implementation
*/
public void addMessageBuilder(String contentType,
Builder messageBuilder) {
messageBuilders.put(contentType, messageBuilder);
}
/**
* Register a messageFormatter implementation against a content type.
* This is used by Axis2 to support serialization of messages to different
* message formats. (Eg: JSON)
*
* @param contentType the relevant content-type (i.e. "text/xml")
* @param messageFormatter a MessageFormatter implementation
*/
public void addMessageFormatter(String contentType,
MessageFormatter messageFormatter) {
messageFormatters.put(contentType, messageFormatter);
}
/**
* Add an available Module to this configuration
*
* @param module an AxisModule
* @throws AxisFault in case of error
*/
public void addModule(AxisModule module) throws AxisFault {
module.setParent(this);
if (module.getVersion() == null) {
if (module.getName().endsWith(AxisModule.VERSION_SNAPSHOT)) {
allModules.put(module.getName(), module);
String moduleName =
module.getName().substring(0,
module.getName().indexOf(AxisModule.VERSION_SNAPSHOT) - 1);
module.setName(moduleName);
module.setVersion(AxisModule.VERSION_SNAPSHOT);
} else {
allModules.put(module.getName(), module);
}
} else { // Calculate the module version from the name
allModules.put(Utils.getModuleName(module.getName(), module.getVersion()), module);
}
notifyObservers(AxisEvent.MODULE_DEPLOY, module);
// Registering the policy namespaces that the module understand
registerModulePolicySupport(module);
// Registering the policy assertions that are local to the system
registerLocalPolicyAssertions(module);
}
public void deployModule(String moduleFileName) throws DeploymentException {
File moduleFile = new File(moduleFileName);
if (!moduleFile.exists()) {
throw new DeploymentException("Module archive '" + moduleFileName + "' doesn't exist");
}
DeploymentFileData dfd = new DeploymentFileData(moduleFile, new ModuleDeployer(this));
dfd.deploy();
}
/**
* To remove a given module from the system
*
* @param module name of module to remove
* @deprecated Use {@link #removeModule(String,String)}
*/
public void removeModule(String module) {
allModules.remove(module);
// TODO disengage has to be done here
}
/**
* Remove a module with moduleName & moduleVersion
*
* @param moduleName
* @param moduleVersion
*/
public void removeModule(String moduleName, String moduleVersion) {
allModules.remove(Utils.getModuleName(moduleName, moduleVersion));
// TODO disengage has to be done here
}
/**
* Adds module configuration, if there is a moduleConfig tag in service.
*
* @param moduleConfiguration a ModuleConfiguration to remember
*/
public void addModuleConfig(ModuleConfiguration moduleConfiguration) {
moduleConfigmap.put(moduleConfiguration.getModuleName(),
moduleConfiguration);
}
public void addObservers(AxisObserver axisObserver) {
observersList.add(axisObserver);
}
/**
* Method addService.
*
* @param service
* @throws AxisFault
*/
public synchronized void addService(AxisService service) throws AxisFault {
AxisServiceGroup axisServiceGroup = new AxisServiceGroup();
axisServiceGroup.setServiceGroupName(service.getName());
axisServiceGroup.setParent(this);
axisServiceGroup.addService(service);
addServiceGroup(axisServiceGroup);
}
public synchronized void addServiceGroup(AxisServiceGroup axisServiceGroup)
throws AxisFault {
axisServiceGroup.setParent(this);
notifyObservers(AxisEvent.SERVICE_DEPLOY, axisServiceGroup);
AxisService axisService;
Iterator services = axisServiceGroup.getServices();
while (services.hasNext()) {
axisService = (AxisService) services.next();
if (axisService.getSchematargetNamespace() == null) {
axisService.setSchemaTargetNamespace(Java2WSDLConstants.AXIS2_XSD);
}
}
services = axisServiceGroup.getServices();
while (services.hasNext()) {
axisService = (AxisService) services.next();
if (axisService.isUseDefaultChains()) {
Iterator operations = axisService.getOperations();
while (operations.hasNext()) {
AxisOperation operation = (AxisOperation) operations.next();
phasesinfo.setOperationPhases(operation);
}
}
}
Iterator enModule = getEngagedModules().iterator();
while (enModule.hasNext()) {
axisServiceGroup.engageModule((AxisModule) enModule.next());
}
services = axisServiceGroup.getServices();
ArrayList servicesIAdded = new ArrayList();
while (services.hasNext()) {
axisService = (AxisService) services.next();
Map endpoints = axisService.getEndpoints();
String serviceName = axisService.getName();
try {
addToAllServicesMap(axisService);
} catch (AxisFault axisFault) {
// Whoops, must have been a duplicate! If we had a problem here, we have to
// remove all the ones we added...
for (Iterator i = servicesIAdded.iterator(); i.hasNext();) {
AxisService service = (AxisService) i.next();
allServices.remove(service.getName());
}
// And toss this in case anyone wants it?
throw axisFault;
}
servicesIAdded.add(axisService);
if (endpoints != null) {
Iterator endpointNameIter = endpoints.keySet().iterator();
while (endpointNameIter.hasNext()) {
String endpointName = (String) endpointNameIter.next();
allEndpoints.put(serviceName + "." + endpointName, axisService);
}
}
if (!axisService.isClientSide()) {
notifyObservers(AxisEvent.SERVICE_DEPLOY, axisService);
}
}
// serviceGroups.put(axisServiceGroup.getServiceGroupName(),
// axisServiceGroup);
addChild(axisServiceGroup);
}
public void addToAllServicesMap(AxisService axisService) throws AxisFault {
String serviceName = axisService.getName();
AxisService oldService = (AxisService) allServices.get(serviceName);
if (oldService == null) {
allServices.put(serviceName, axisService);
} else {
// If we were already there, that's fine. If not, fault!
if (oldService != axisService) {
throw new AxisFault(Messages.getMessage("twoservicecannothavesamename",
axisService.getName()));
}
}
}
public AxisServiceGroup removeServiceGroup(String serviceGroupName) throws AxisFault {
AxisServiceGroup axisServiceGroup = (AxisServiceGroup) getChild(serviceGroupName);
if (axisServiceGroup == null) {
throw new AxisFault(Messages.getMessage("invalidservicegroupname",
serviceGroupName));
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?