wsdl11toaxisservicebuilder.java
来自「开源的axis2框架的源码。用于开发WEBSERVER」· Java 代码 · 共 1,531 行 · 第 1/5 页
JAVA
1,531 行
/*
* 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.description;
import com.ibm.wsdl.util.xml.DOM2Writer;
import org.apache.axis2.AxisFault;
import org.apache.axis2.addressing.AddressingConstants;
import org.apache.axis2.addressing.AddressingHelper;
import org.apache.axis2.addressing.wsdl.WSDL11ActionHelper;
import org.apache.axis2.transport.http.HTTPConstants;
import org.apache.axis2.transport.http.util.RESTUtil;
import org.apache.axis2.util.PolicyUtil;
import org.apache.axis2.util.XMLUtils;
import org.apache.axis2.wsdl.SOAPHeaderMessage;
import org.apache.axis2.wsdl.WSDLConstants;
import org.apache.axis2.wsdl.WSDLUtil;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.neethi.Constants;
import org.apache.neethi.Policy;
import org.apache.neethi.PolicyReference;
import org.apache.ws.commons.schema.utils.NamespaceMap;
import org.apache.axiom.soap.SOAP12Constants;
import org.apache.axiom.soap.SOAP11Constants;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.xml.sax.SAXException;
import javax.wsdl.*;
import javax.wsdl.extensions.ExtensibilityElement;
import javax.wsdl.extensions.UnknownExtensibilityElement;
import javax.wsdl.extensions.mime.MIMEMultipartRelated;
import javax.wsdl.extensions.mime.MIMEPart;
import javax.wsdl.extensions.http.HTTPAddress;
import javax.wsdl.extensions.http.HTTPBinding;
import javax.wsdl.extensions.http.HTTPOperation;
import javax.wsdl.extensions.schema.Schema;
import javax.wsdl.extensions.soap.SOAPAddress;
import javax.wsdl.extensions.soap.SOAPBinding;
import javax.wsdl.extensions.soap.SOAPBody;
import javax.wsdl.extensions.soap.SOAPHeader;
import javax.wsdl.extensions.soap.SOAPOperation;
import javax.wsdl.extensions.soap12.SOAP12Address;
import javax.wsdl.extensions.soap12.SOAP12Binding;
import javax.wsdl.extensions.soap12.SOAP12Body;
import javax.wsdl.extensions.soap12.SOAP12Header;
import javax.wsdl.extensions.soap12.SOAP12Operation;
import javax.wsdl.factory.WSDLFactory;
import javax.wsdl.xml.WSDLLocator;
import javax.wsdl.xml.WSDLReader;
import javax.xml.namespace.QName;
import javax.xml.parsers.ParserConfigurationException;
import java.io.IOException;
import java.io.InputStream;
import java.util.*;
public class WSDL11ToAxisServiceBuilder extends WSDLToAxisServiceBuilder {
protected static final Log log = LogFactory
.getLog(WSDL11ToAxisServiceBuilder.class);
private static final boolean isTraceEnabled = log.isTraceEnabled();
protected String portName;
private static final String BINDING = "Binding";
private static final String SERVICE = "Service";
private static final String PORT = "Port";
private static final String PORT_TYPE = "PortType";
private static final String PORT_TYPE_OPERATION = "PortType.Operation";
private static final String PORT_TYPE_OPERATION_INPUT = "PortType.Operation.Input";
private static final String PORT_TYPE_OPERATION_OUTPUT = "PortType.Operation.Output";
private static final String PORT_TYPE_OPERATION_FAULT = "PortType.Operation.Fault";
private static final String BINDING_OPERATION = "Binding.Operation";
private static final String BINDING_OPERATION_INPUT = "Binding.Operation.Input";
private static final String BINDING_OPERATION_OUTPUT = "Binding.Operation.Output";
protected Definition wsdl4jDefinition = null;
private WSDLLocator customWSLD4JResolver;
public static final String RPC_STYLE = "rpc";
public static final String DOCUMENT_STYLE = "document";
public static final String ENCODED_USE = "encoded";
/**
* Keeps a list of processable operations initiate to an empty list
*/
private List wrappableOperations = new ArrayList();
// used to keep the binding type of the selected binding
private String bindingType;
public static final String WRAPPED_OUTPUTNAME_SUFFIX = "Response";
public static final String XML_NAMESPACE_URI = "http://www.w3.org/2000/xmlns/";
public static final String NAMESPACE_DECLARATION_PREFIX = "xmlns:";
private static int prefixCounter = 0;
public static final String NAMESPACE_URI = "namespace";
public static final String TRAGET_NAMESPACE = "targetNamespace";
public static final String BINDING_TYPE_SOAP = "soap";
public static final String BINDING_TYPE_HTTP = "http";
/**
* keep track of whether setup code related to the entire wsdl is complete.
* Note that WSDL11ToAllAxisServices will call setup multiple times, so this
* field is used to make subsequent calls no-ops.
*/
private boolean setupComplete = false;
private Map schemaMap = null;
private static final String JAVAX_WSDL_VERBOSE_MODE_KEY = "javax.wsdl.verbose";
// As bindings are processed add it to this array so that we dont process the same binding twice
private Map processedBindings;
private boolean isAllPorts;
/**
* constructor taking in the service name and the port name
*
* @param in
* @param serviceName
* @param portName
*/
public WSDL11ToAxisServiceBuilder(InputStream in, QName serviceName,
String portName) {
super(in, serviceName);
this.portName = portName;
}
/**
* @param def
* @param serviceName
* @param portName
*/
public WSDL11ToAxisServiceBuilder(Definition def, QName serviceName,
String portName) {
super(null, serviceName);
this.wsdl4jDefinition = def;
this.portName = portName;
this.isAllPorts = false;
}
/**
* @param def
* @param serviceName
* @param portName
*/
public WSDL11ToAxisServiceBuilder(Definition def,
QName serviceName,
String portName,
boolean isAllPorts) {
this(def, serviceName, portName);
this.isAllPorts = isAllPorts;
}
/**
* @param in
* @param service
*/
public WSDL11ToAxisServiceBuilder(InputStream in, AxisService service) {
super(in, service);
}
/**
* @param in
*/
public WSDL11ToAxisServiceBuilder(InputStream in) {
this(in, null, null);
}
/**
* sets a custem WSDL4J locator
*
* @param customWSLD4JResolver
*/
public void setCustomWSLD4JResolver(WSDLLocator customWSLD4JResolver) {
this.customWSLD4JResolver = customWSLD4JResolver;
}
/**
* populates a given service This is the only publicly accessible method in
* this class
*
* @throws AxisFault
*/
public AxisService populateService() throws AxisFault {
try {
setup();
// Setting wsdl4jdefintion to axisService , so if some one want
// to play with it he can do that by getting the parameter
Parameter wsdlDefinitionParameter = new Parameter();
wsdlDefinitionParameter.setName(WSDLConstants.WSDL_4_J_DEFINITION);
wsdlDefinitionParameter.setValue(wsdl4jDefinition);
axisService.addParameter(wsdlDefinitionParameter);
axisService.setWsdlFound(true);
axisService.setCustomWsdl(true);
if (wsdl4jDefinition == null) {
return null;
}
// setting target name space
axisService.setTargetNamespace(wsdl4jDefinition.getTargetNamespace());
axisService.setNameSpacesMap(new NamespaceMap(wsdl4jDefinition.getNamespaces()));
Service wsdl4jService = findService(wsdl4jDefinition);
Binding binding = findBinding(wsdl4jDefinition, wsdl4jService);
PortType portType = getPortType(binding.getPortType().getQName(), wsdl4jDefinition);
if (portType == null) {
throw new AxisFault("There is no port type associated with the binding");
}
// create new Schema extensions element for wrapping
// (if its present)
Element[] schemaElements = generateWrapperSchema(schemaMap, binding, portType);
// we might have modified the schemas by now so the addition should
// happen here
// Types wsdl4jTypes = wsdl4jDefinition.getTypes();
// if (null != wsdl4jTypes) {
// this.copyExtensibleElements(wsdl4jTypes
// .getExtensibilityElements(), wsdl4jDefinition,
// axisService, TYPES);
// }
processTypes(wsdl4jDefinition, axisService);
// add the newly created schemas
if (schemaElements != null && schemaElements.length > 0) {
for (int i = 0; i < schemaElements.length; i++) {
Element schemaElement = schemaElements[i];
if (schemaElement != null) {
axisService.addSchema(getXMLSchema(schemaElement, null));
}
}
}
// copy the documentation element content to the description
Element documentationElement = wsdl4jDefinition.getDocumentationElement();
addDocumentation(axisService, documentationElement);
axisService.setName(wsdl4jService.getQName().getLocalPart());
populateEndpoints(binding, wsdl4jService, portType);
processPoliciesInDefintion(wsdl4jDefinition);
axisService.getPolicyInclude().setPolicyRegistry(registry);
return axisService;
} catch (WSDLException e) {
log.error(e.getMessage(), e);
throw AxisFault.makeFault(e);
} catch (Exception e) {
log.error(e.getMessage(), e);
throw AxisFault.makeFault(e);
}
}
private void processTypes(Definition wsdlDefinition, AxisService axisService)
throws AxisFault {
processTypes(wsdlDefinition, axisService, new Stack());
}
private void processTypes(Definition wsdlDefinition, AxisService axisService, Stack stack)
throws AxisFault {
stack.push(wsdlDefinition);
// process all the types in all the wsdls
Types types = wsdlDefinition.getTypes();
if (types != null) {
copyExtensibleElements(types.getExtensibilityElements(),
wsdlDefinition,
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?