wsdl11defaultactionpatternhelper.java
来自「开源的axis2框架的源码。用于开发WEBSERVER」· Java 代码 · 共 397 行 · 第 1/2 页
JAVA
397 行
// Get the portType name (as a string to be included in the action)
String portTypeName = wsdl4jPortType.getQName().getLocalPart();
// Get the name of the output element (and generate one if none explicitly specified)
String outputName = getNameFromOutputElement(op, output);
// Append the bits together
StringBuffer sb = new StringBuffer();
sb.append(targetNamespace);
// Deal with the problem that the targetNamespace may or may not have a trailing delimiter
if (!targetNamespace.endsWith(delimiter)) {
sb.append(delimiter);
}
sb.append(portTypeName);
sb.append(delimiter);
sb.append(outputName);
// Resolve the action from the StringBuffer
String result = sb.toString();
if (log.isTraceEnabled()) {
log.trace("generateActionFromOutputElement result: " + result);
}
return result;
}
/**
* Get the name of the specified Output element using the rules defined in WSDL 1.1
* Section 2.4.5 http://www.w3.org/TR/wsdl#_names
*/
private static String getNameFromOutputElement(Operation op, Output output) {
// Get the name from the output element if specified.
String result = output.getName();
// If not we'll have to generate it.
if (result == null) {
// If Request-Response or Solicit-Response do something special per
// WSDL 1.1 Section 2.4.5
OperationType operationType = op.getStyle();
if (null != operationType) {
if (operationType.equals(OperationType.REQUEST_RESPONSE)) {
return op.getName() + RESPONSE;
} else if (operationType.equals(OperationType.SOLICIT_RESPONSE)) {
return op.getName() + SOLICIT;
}
}
// If the OperationType was not available for some reason, assume on-way or notification
if (result == null) {
result = op.getName();
}
}
return result;
}
protected static String getOutputActionFromStringInformation(String messageExchangePattern,
String targetNamespace,
String portTypeName,
String operationName,
String outputName) {
if (messageExchangePattern == null && outputName == null) {
throw new IllegalArgumentException(
"One of messageExchangePattern or outputName must the non-null to generate an action.");
}
// Determine the delimiter. Per the spec: 'is ":" when the [target namespace] is a URN, otherwise "/".
// Note that for IRI schemes other than URNs which aren't path-based (i.e. those that outlaw the "/"
// character), the default action value may not conform to the rules of the IRI scheme. Authors
// are advised to specify explicit values in the WSDL in this case.'
String delimiter = SLASH;
if (targetNamespace.toLowerCase().startsWith(URN)) {
delimiter = COLON;
}
if (outputName == null) {
outputName = operationName;
if (messageExchangePattern.indexOf("in-out") >= 0) {
outputName += RESPONSE;
}
}
// Append the bits together
StringBuffer sb = new StringBuffer();
sb.append(targetNamespace);
// Deal with the problem that the targetNamespace may or may not have a trailing delimiter
if (!targetNamespace.endsWith(delimiter)) {
sb.append(delimiter);
}
sb.append(portTypeName);
sb.append(delimiter);
sb.append(outputName);
// Resolve the action from the StringBuffer
String result = sb.toString();
if (log.isTraceEnabled()) {
log.trace("getOutputActionFromStringInformation result: " + result);
}
return result;
}
/**
* Generate the Action for a Fault using the Default Action Pattern
* <p/>
* Pattern is defined as [target namespace][delimiter][port type name][delimiter][operation name][delimiter]Fault[delimiter][fault name]
*
* @param def is required to obtain the targetNamespace
* @param wsdl4jPortType is required to obtain the portType name
* @param op is required to obtain the operation name
* @param fault is required to obtain the fault name
* @return a wsa:Action value based on the Default Action Pattern and the provided objects
*/
public static String generateActionFromFaultElement(Definition def, PortType wsdl4jPortType,
Operation op, Fault fault) {
// Get the targetNamespace of the wsdl:definition
String targetNamespace = def.getTargetNamespace();
// Determine the delimiter. Per the spec: 'is ":" when the [target namespace] is a URN, otherwise "/".
// Note that for IRI schemes other than URNs which aren't path-based (i.e. those that outlaw the "/"
// character), the default action value may not conform to the rules of the IRI scheme. Authors
// are advised to specify explicit values in the WSDL in this case.'
String delimiter = SLASH;
if (targetNamespace.toLowerCase().startsWith(URN)) {
delimiter = COLON;
}
// Get the portType name (as a string to be included in the action)
String portTypeName = wsdl4jPortType.getQName().getLocalPart();
// Get the operation name (as a string to be included in the action)
String operationName = op.getName();
// Get the name of the fault element (name is mandatory on fault elements)
String faultName = fault.getName();
// Append the bits together
StringBuffer sb = new StringBuffer();
sb.append(targetNamespace);
// Deal with the problem that the targetNamespace may or may not have a trailing delimiter
if (!targetNamespace.endsWith(delimiter)) {
sb.append(delimiter);
}
sb.append(portTypeName);
sb.append(delimiter);
sb.append(operationName);
sb.append(delimiter);
sb.append(FAULT);
sb.append(delimiter);
sb.append(faultName);
// Resolve the action from the StringBuffer
String result = sb.toString();
if (log.isTraceEnabled()) {
log.trace("generateActionFromFaultElement result: " + result);
}
return result;
}
protected static String getFaultActionFromStringInformation(String targetNamespace,
String portTypeName,
String operationName,
String faultName) {
// Determine the delimiter. Per the spec: 'is ":" when the [target namespace] is a URN, otherwise "/".
// Note that for IRI schemes other than URNs which aren't path-based (i.e. those that outlaw the "/"
// character), the default action value may not conform to the rules of the IRI scheme. Authors
// are advised to specify explicit values in the WSDL in this case.'
String delimiter = SLASH;
if (targetNamespace.toLowerCase().startsWith(URN)) {
delimiter = COLON;
}
// Append the bits together
StringBuffer sb = new StringBuffer();
sb.append(targetNamespace);
// Deal with the problem that the targetNamespace may or may not have a trailing delimiter
if (!targetNamespace.endsWith(delimiter)) {
sb.append(delimiter);
}
sb.append(portTypeName);
sb.append(delimiter);
sb.append(operationName);
sb.append(delimiter);
sb.append(FAULT);
sb.append(delimiter);
sb.append(faultName);
// Resolve the action from the StringBuffer
String result = sb.toString();
if (log.isTraceEnabled()) {
log.trace("getFaultActionFromStringInformation result: " + result);
}
return result;
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?