axisservice.java
来自「开源的axis2框架的源码。用于开发WEBSERVER」· Java 代码 · 共 1,682 行 · 第 1/5 页
JAVA
1,682 行
}
}
}
/**
* change the schema Location in the elemment
* @param element
*/
private void changeLocations(Element element) {
NodeList nodeList = element.getChildNodes();
String tagName;
for (int i = 0; i < nodeList.getLength(); i++) {
tagName = nodeList.item(i).getLocalName();
if (IMPORT_TAG.equals(tagName) || INCLUDE_TAG.equals(tagName)) {
processImport(nodeList.item(i));
}
}
}
private void processImport(Node importNode) {
NamedNodeMap nodeMap = importNode.getAttributes();
Node attribute;
String attributeValue;
for (int i = 0; i < nodeMap.getLength(); i++) {
attribute = nodeMap.item(i);
if (attribute.getNodeName().equals("schemaLocation")) {
attributeValue = attribute.getNodeValue();
attribute.setNodeValue(this.name + "?xsd=" + attributeValue);
}
}
}
/**
* Produces a WSDL for this AxisService and prints it to the specified OutputStream.
*
* @param out destination stream. The WSDL will be sent here.
* @param requestIP the hostname the WSDL request was directed at. This should be the address
* that appears in the generated WSDL.
* @throws AxisFault if an error occurs
*/
public void printWSDL(OutputStream out, String requestIP) throws AxisFault {
// If we're looking for pre-existing WSDL, use that.
if (isUseUserWSDL()) {
printUserWSDL(out, null);
return;
}
// If we find a WSDLSupplier, use that
WSDLSupplier supplier = (WSDLSupplier)getParameterValue("WSDLSupplier");
if (supplier != null) {
try {
Definition definition = supplier.getWSDL(this);
if (definition != null) {
printDefinitionObject(getWSDLDefinition(definition, null), out);
}
} catch (Exception e) {
printWSDLError(out, e);
}
return;
}
// Otherwise, generate WSDL ourselves
String[] eprArray = requestIP == null ? new String[] { this.endpointName } :
calculateEPRs(requestIP);
getWSDL(out, eprArray);
}
/**
* Print the WSDL with a default URL. This will be called only during codegen time.
*
* @param out
* @throws AxisFault
*/
public void printWSDL(OutputStream out) throws AxisFault {
printWSDL(out, null);
}
private void setPortAddress(Definition definition) throws AxisFault {
setPortAddress(definition, null);
}
private void setPortAddress(Definition definition, String requestIP) throws AxisFault {
Iterator serviceItr = definition.getServices().values().iterator();
while (serviceItr.hasNext()) {
Service serviceElement = (Service) serviceItr.next();
Iterator portItr = serviceElement.getPorts().values().iterator();
while (portItr.hasNext()) {
Port port = (Port) portItr.next();
List list = port.getExtensibilityElements();
for (int i = 0; i < list.size(); i++) {
Object extensibilityEle = list.get(i);
if (extensibilityEle instanceof SOAPAddress) {
if (requestIP == null) {
((SOAPAddress) extensibilityEle).setLocationURI(getEPRs()[0]);
} else {
((SOAPAddress) extensibilityEle).setLocationURI(calculateEPRs(requestIP)[0]);
}
} else if (extensibilityEle instanceof SOAP12Address){
if (requestIP == null) {
((SOAP12Address) extensibilityEle).setLocationURI(getEPRs()[0]);
} else {
((SOAP12Address) extensibilityEle).setLocationURI(calculateEPRs(requestIP)[0]);
}
} else if (extensibilityEle instanceof HTTPAddress){
if (requestIP == null) {
((HTTPAddress) extensibilityEle).setLocationURI(getEPRs()[0]);
} else {
((HTTPAddress) extensibilityEle).setLocationURI(calculateEPRs(requestIP)[0]);
}
}
//TODO : change the Endpoint refrence addess as well.
}
}
}
}
private void getWSDL(OutputStream out, String[] serviceURL) throws AxisFault {
// Retrieve WSDL using the same data retrieval path for GetMetadata request.
DataRetrievalRequest request = new DataRetrievalRequest();
request.putDialect(DRConstants.SPEC.DIALECT_TYPE_WSDL);
request.putOutputForm(OutputForm.INLINE_FORM);
MessageContext context = new MessageContext();
context.setAxisService(this);
context.setTo(new EndpointReference(serviceURL[0]));
Data[] result = getData(request, context);
OMElement wsdlElement;
if (result != null && result.length > 0) {
wsdlElement = (OMElement) (result[0].getData());
try {
XMLPrettyPrinter.prettify(wsdlElement, out);
out.flush();
out.close();
} catch (Exception e) {
throw AxisFault.makeFault(e);
}
}
}
private void printWSDLError(OutputStream out) throws AxisFault {
printWSDLError(out, null);
}
private void printWSDLError(OutputStream out, Exception e) throws AxisFault {
try {
String wsdlntfound = "<error>" +
"<description>Unable to generate WSDL 1.1 for this service</description>" +
"<reason>If you wish Axis2 to automatically generate the WSDL 1.1, then please +" +
"set useOriginalwsdl as false in your services.xml</reason>";
out.write(wsdlntfound.getBytes());
if (e != null) {
PrintWriter pw = new PrintWriter(out);
e.printStackTrace(pw);
pw.flush();
}
out.write("</error>".getBytes());
out.flush();
out.close();
} catch (IOException ex) {
throw AxisFault.makeFault(ex);
}
}
/**
* Print the WSDL2.0 with a default URL. This will be called only during codegen time.
*
* @param out
* @throws AxisFault
*/
public void printWSDL2(OutputStream out) throws AxisFault {
printWSDL2(out, null);
}
public void printWSDL2(OutputStream out, String requestIP) throws AxisFault {
AxisService2WSDL20 axisService2WSDL2 = new AxisService2WSDL20(this);
try {
if(requestIP != null) {
axisService2WSDL2.setEPRs(calculateEPRs(requestIP));
}
OMElement wsdlElement = axisService2WSDL2.generateOM();
wsdlElement.serialize(out);
out.flush();
out.close();
} catch (Exception e) {
throw AxisFault.makeFault(e);
}
}
/**
* Gets the description about the service which is specified in services.xml.
*
* @return Returns String.
* @deprecated Use getDocumentation() instead
*/
public String getServiceDescription() {
return getDocumentation();
}
/**
* Method getClassLoader.
*
* @return Returns ClassLoader.
*/
public ClassLoader getClassLoader() {
return this.serviceClassLoader;
}
/**
* Gets the control operation which are added by module like RM.
*/
public ArrayList getControlOperations() {
Iterator op_itr = getOperations();
ArrayList operationList = new ArrayList();
while (op_itr.hasNext()) {
AxisOperation operation = (AxisOperation) op_itr.next();
if (operation.isControlOperation()) {
operationList.add(operation);
}
}
return operationList;
}
public URL getFileName() {
return fileName;
}
public long getLastupdate() {
return lastupdate;
}
public ModuleConfiguration getModuleConfig(String moduleName) {
return (ModuleConfiguration) moduleConfigmap.get(moduleName);
}
public ArrayList getModules() {
return moduleRefs;
}
public String getName() {
return name;
}
/**
* Method getOperation.
*
* @param operationName
* @return Returns AxisOperation.
*/
public AxisOperation getOperation(QName operationName) {
AxisOperation axisOperation = (AxisOperation) getChild(operationName);
if (axisOperation == null) {
axisOperation = (AxisOperation) getChild(
new QName(getTargetNamespace(), operationName.getLocalPart()));
}
if (axisOperation == null) {
axisOperation = (AxisOperation) operationsAliasesMap.get(
operationName.getLocalPart());
}
return axisOperation;
}
/**
* Returns the AxisOperation which has been mapped to the given action.
*
* @param action the action key
* @return Returns the corresponding AxisOperation or null if it isn't found.
*/
public AxisOperation getOperationByAction(String action) {
return (AxisOperation) operationsAliasesMap.get(action);
}
/**
* Returns the operation given a SOAP Action. This
* method should be called if only one Endpoint is defined for
* this Service. If more than one Endpoint exists, one of them will be
* picked. If more than one Operation is found with the given SOAP Action;
* null will be returned. If no particular Operation is found with the given
* SOAP Action; null will be returned.
*
* @param soapAction SOAP Action defined for the particular Operation
* @return Returns an AxisOperation if a unique Operation can be found with the given
* SOAP Action otherwise will return null.
*/
public AxisOperation getOperationBySOAPAction(String soapAction) {
if ((soapAction == null) || soapAction.length() == 0) {
return null;
}
AxisOperation operation = (AxisOperation) getChild(new QName(soapAction));
if (operation != null) {
return operation;
}
operation = (AxisOperation) operationsAliasesMap.get(soapAction);
return operation;
}
/**
* Method getOperations.
*
* @return Returns HashMap
*/
public Iterator getOperations() {
return getChildren();
}
/*
* (non-Javadoc)
*
* @see org.apache.axis2.description.ParameterInclude#getParameter(java.lang.String)
*/
/**
* Gets only the published operations.
*/
public ArrayList getPublishedOperations() {
Iterator op_itr = getOperations();
ArrayList operationList = new ArrayList();
while (op_itr.hasNext()) {
AxisOperation operation = (AxisOperation) op_itr.next();
if (!operation.isControlOperation()) {
operationList.add(operation);
}
}
return operationList;
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?