servicebuilder.java
来自「开源的axis2框架的源码。用于开发WEBSERVER」· Java 代码 · 共 833 行 · 第 1/3 页
JAVA
833 行
new QName(POLICY_NS_URI, TAG_POLICY_REF));
if (policyRefElements != null && policyRefElements.hasNext()) {
processPolicyRefElements(PolicyInclude.AXIS_SERVICE_POLICY,
policyRefElements, service.getPolicyInclude());
}
//processing service scope
String sessionScope = service_element.getAttributeValue(new QName(ATTRIBUTE_SCOPE));
if (sessionScope != null) {
service.setScope(sessionScope);
}
// processing service-wide modules which required to engage globally
Iterator moduleRefs = service_element.getChildrenWithName(new QName(TAG_MODULE));
processModuleRefs(moduleRefs);
//processing transports
OMElement transports = service_element.getFirstChildWithName(new QName(TAG_TRANSPORTS));
if (transports != null) {
Iterator transport_itr = transports.getChildrenWithName(new QName(TAG_TRANSPORT));
ArrayList trs = new ArrayList();
while (transport_itr.hasNext()) {
OMElement trsEle = (OMElement) transport_itr.next();
String transportName = trsEle.getText().trim();
trs.add(transportName);
if (axisConfig.getTransportIn(transportName) == null) {
throw new AxisFault("Service [ "+ service.getName() + "] is trying to expose in a transport : "
+ transports + " and which is not available in Axis2");
}
}
service.setExposedTransports(trs);
}
// processing operations
Iterator operationsIterator =
service_element.getChildrenWithName(new QName(TAG_OPERATION));
ArrayList ops = processOperations(operationsIterator);
for (int i = 0; i < ops.size(); i++) {
AxisOperation operationDesc = (AxisOperation) ops.get(i);
ArrayList wsamappings = operationDesc.getWSAMappingList();
if (wsamappings == null) {
continue;
}
if (service.getOperation(operationDesc.getName()) == null) {
service.addOperation(operationDesc);
}
for (int j = 0; j < wsamappings.size(); j++) {
String mapping = (String) wsamappings.get(j);
if (mapping.length() > 0) {
service.mapActionToOperation(mapping, operationDesc);
}
}
}
String objectSupplierValue = (String) service.getParameterValue(TAG_OBJECT_SUPPLIER);
if (objectSupplierValue != null) {
loadObjectSupplierClass(objectSupplierValue);
}
// Set the default message receiver for the operations that were
// not listed in the services.xml
setDefaultMessageReceivers();
if (!service.isUseUserWSDL()) {
// Generating schema for the service if the impl class is Java
if (!service.isWsdlFound()) {
//trying to generate WSDL for the service using JAM and Java reflection
try {
if (generateWsdl(service)) {
Utils.fillAxisService(service, axisConfig, excludeops, null);
} else {
ArrayList nonRpcOperations = getNonRPCMethods(service);
Utils.fillAxisService(service, axisConfig, excludeops,
nonRpcOperations);
}
} catch (Exception e) {
throw new DeploymentException(
Messages.getMessage("errorinschemagen", e.getMessage()), e);
}
}
}
if (service.isCustomWsdl()) {
OMElement mappingElement = service_element.getFirstChildWithName(
new QName(TAG_PACKAGE2QNAME));
if (mappingElement != null) {
processTypeMappings(mappingElement);
}
}
for (int i = 0; i < excludeops.size(); i++) {
String opName = (String) excludeops.get(i);
service.removeOperation(new QName(opName));
}
// Need to call the same logic towice
setDefaultMessageReceivers();
Iterator moduleConfigs =
service_element.getChildrenWithName(new QName(TAG_MODULE_CONFIG));
processServiceModuleConfig(moduleConfigs, service, service);
// Loading Data Locator(s) configured
OMElement dataLocatorElement =
service_element
.getFirstChildWithName(new QName(DRConstants.DATA_LOCATOR_ELEMENT));
if (dataLocatorElement != null) {
processDataLocatorConfig(dataLocatorElement, service);
}
} catch (XMLStreamException e) {
throw new DeploymentException(e);
} catch (AxisFault axisFault) {
throw new DeploymentException(axisFault);
}
return service;
}
private void setDefaultMessageReceivers() {
Iterator operations = service.getPublishedOperations().iterator();
while (operations.hasNext()) {
AxisOperation operation = (AxisOperation) operations.next();
if (operation.getMessageReceiver() == null) {
MessageReceiver messageReceiver = loadDefaultMessageReceiver(
operation.getMessageExchangePattern(), service);
if (messageReceiver == null &&
//we assume that if the MEP is ROBUST_IN_ONLY then the in-out MR can handle that
WSDL2Constants.MEP_URI_ROBUST_IN_ONLY.equals(
operation.getMessageExchangePattern())) {
messageReceiver = loadDefaultMessageReceiver(
WSDL2Constants.MEP_URI_IN_OUT, service);
}
operation.setMessageReceiver(messageReceiver);
}
}
}
private void loadObjectSupplierClass(String objectSupplierValue) throws AxisFault {
try {
ClassLoader loader = service.getClassLoader();
Class objectSupplierImpl = Loader.loadClass(loader, objectSupplierValue.trim());
ObjectSupplier objectSupplier = (ObjectSupplier) objectSupplierImpl.newInstance();
service.setObjectSupplier(
objectSupplier);
} catch (Exception e) {
throw AxisFault.makeFault(e);
}
}
/**
* Process the package name to QName mapping:
*
* <packageMapping>
* <mapping packageName="foo.bar" qname="http://foo/bar/xsd"%gt;
* ......
* ......
* </packageMapping>
*
* @param packageMappingElement OMElement for the packageMappingElement
*/
private void processTypeMappings(OMElement packageMappingElement) {
Iterator elementItr = packageMappingElement.getChildrenWithName(new QName(TAG_MAPPING));
TypeTable typeTable = service.getTypeTable();
if (typeTable == null) {
typeTable = new TypeTable();
}
while (elementItr.hasNext()) {
OMElement mappingElement = (OMElement) elementItr.next();
String packageName = mappingElement.getAttributeValue(new QName(TAG_PACKAGE_NAME));
String qName = mappingElement.getAttributeValue(new QName(TAG_QNAME));
if (packageName == null || qName == null) {
continue;
}
Iterator keys = service.getNamespaceMap().keySet().iterator();
while (keys.hasNext()) {
String key = (String) keys.next();
if (qName.equals(service.getNamespaceMap().get(key))) {
typeTable.addComplexSchema(packageName,
new QName(qName, packageName, key));
}
}
}
service.setTypeTable(typeTable);
}
private void loadServiceLifeCycleClass(String className) throws DeploymentException {
if (className != null) {
try {
ClassLoader loader = service.getClassLoader();
Class serviceLifeCycleClassImpl = Loader.loadClass(loader, className);
ServiceLifeCycle serviceLifeCycle =
(ServiceLifeCycle) serviceLifeCycleClassImpl.newInstance();
serviceLifeCycle.startUp(configCtx, service);
service.setServiceLifeCycle(
serviceLifeCycle);
} catch (Exception e) {
throw new DeploymentException(e.getMessage(), e);
}
}
}
private boolean generateWsdl(AxisService axisService) {
Iterator operatins = axisService.getOperations();
if (operatins.hasNext()) {
while (operatins.hasNext()) {
AxisOperation axisOperation = (AxisOperation) operatins
.next();
if (axisOperation.isControlOperation()) {
continue;
}
if (axisOperation.getMessageReceiver() == null) {
continue;
}
String messageReceiverClass = axisOperation
.getMessageReceiver().getClass().getName();
if (!("org.apache.axis2.rpc.receivers.RPCMessageReceiver"
.equals(messageReceiverClass)
|| "org.apache.axis2.rpc.receivers.RPCInOnlyMessageReceiver"
.equals(messageReceiverClass)
|| "org.apache.axis2.rpc.receivers.RPCInOutAsyncMessageReceiver"
.equals(messageReceiverClass)
|| "org.apache.axis2.jaxws.server.JAXWSMessageReceiver"
.equals(messageReceiverClass))) {
return false;
}
}
}
return true;
}
/**
* To get the methods which do not use RPC* MessageReceivers
*
* @param axisService the AxisService to search
* @return an ArrayList of the LOCAL PARTS of the QNames of any non-RPC operations
* TODO: Why not just return the AxisOperations themselves??
*/
private ArrayList getNonRPCMethods(AxisService axisService) {
ArrayList excludeOperations = new ArrayList();
Iterator operatins = axisService.getOperations();
if (operatins.hasNext()) {
while (operatins.hasNext()) {
AxisOperation axisOperation = (AxisOperation) operatins
.next();
if (axisOperation.getMessageReceiver() == null) {
continue;
}
String messageReceiverClass = axisOperation
.getMessageReceiver().getClass().getName();
if (!("org.apache.axis2.rpc.receivers.RPCMessageReceiver"
.equals(messageReceiverClass)
|| "org.apache.axis2.rpc.receivers.RPCInOnlyMessageReceiver"
.equals(messageReceiverClass)
|| "org.apache.axis2.rpc.receivers.RPCInOutAsyncMessageReceiver"
.equals(messageReceiverClass)
|| "org.apache.axis2.jaxws.server.JAXWSMessageReceiver"
.equals(messageReceiverClass))) {
excludeOperations.add(axisOperation.getName().getLocalPart());
}
}
}
return excludeOperations;
}
/**
* Process <excludeOperation> element in services.xml. Each operation referenced
* will be removed from the AxisService.
*
* @param excludeOperations the <excludeOperations> element from services.xml
* @return an ArrayList of the String contents of the <operation> elements
*/
private ArrayList processExcludeOperations(OMElement excludeOperations) {
ArrayList exOps = new ArrayList();
Iterator excludeOp_itr = excludeOperations.getChildrenWithName(new QName(TAG_OPERATION));
while (excludeOp_itr.hasNext()) {
OMElement opName = (OMElement) excludeOp_itr.next();
exOps.add(opName.getText().trim());
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?