| Method from org.apache.axis2.util.Utils Detail: |
public static void addHandler(Flow flow,
Handler handler,
String phaseName) {
HandlerDescription handlerDesc = new HandlerDescription(handler.getName());
PhaseRule rule = new PhaseRule(phaseName);
handlerDesc.setRules(rule);
handler.init(handlerDesc);
handlerDesc.setHandler(handler);
flow.addHandler(handlerDesc);
}
|
public static void calculateDefaultModuleVersion(HashMap modules,
AxisConfiguration axisConfig) {
Iterator allModules = modules.values().iterator();
HashMap defaultModules = new HashMap();
while (allModules.hasNext()) {
AxisModule axisModule = (AxisModule) allModules.next();
String moduleName = axisModule.getName();
String moduleNameString;
String moduleVersionString;
if (AxisModule.VERSION_SNAPSHOT.equals(axisModule.getVersion())) {
moduleNameString = axisModule.getName();
moduleVersionString = axisModule.getVersion();
} else {
if (axisModule.getVersion() == null) {
moduleNameString = getModuleName(moduleName);
moduleVersionString = getModuleVersion(moduleName);
if (moduleVersionString != null) {
try {
Float.valueOf(moduleVersionString);
axisModule.setVersion(moduleVersionString);
axisModule.setName(moduleName);
} catch (NumberFormatException e) {
moduleVersionString = null;
}
}
} else {
moduleNameString = axisModule.getName();
moduleVersionString = axisModule.getVersion();
}
}
String currentDefaultVerison = (String) defaultModules.get(moduleNameString);
if (currentDefaultVerison != null) {
// if the module version is null then , that will be ignore in this case
if (!AxisModule.VERSION_SNAPSHOT.equals(currentDefaultVerison)) {
if (moduleVersionString != null &&
isLatest(moduleVersionString, currentDefaultVerison)) {
defaultModules.put(moduleNameString, moduleVersionString);
}
}
} else {
defaultModules.put(moduleNameString, moduleVersionString);
}
}
Iterator def_mod_itr = defaultModules.keySet().iterator();
while (def_mod_itr.hasNext()) {
String moduleName = (String) def_mod_itr.next();
axisConfig.addDefaultModuleVersion(moduleName, (String) defaultModules.get(moduleName));
}
}
|
public static boolean checkVersion(String module1version,
String module2version) throws AxisFault {
if ((module1version !=null && !module1version.equals(module2version)) ||
module2version !=null && !module2version.equals(module1version)) {
throw new AxisFault("trying to engage two different module versions " +
module1version + " : " + module2version);
}
return true;
}
- if he trying to engage the same module then method will returen false
- else it will return true |
public static MessageContext createOutMessageContext(MessageContext inMessageContext) throws AxisFault {
return MessageContextBuilder.createOutMessageContext(inMessageContext);
} Deprecated! ( - post1.1branch)
|
public static AxisService createSimpleInOnlyService(QName serviceName,
MessageReceiver messageReceiver,
QName opName) throws AxisFault {
AxisService service = new AxisService(serviceName.getLocalPart());
service.setClassLoader(getContextClassLoader_DoPriv());
AxisOperation axisOp = new InOnlyAxisOperation(opName);
axisOp.setMessageReceiver(messageReceiver);
axisOp.setStyle(WSDLConstants.STYLE_RPC);
service.addOperation(axisOp);
service.mapActionToOperation(Constants.AXIS2_NAMESPACE_URI + "/" + opName.getLocalPart(),
axisOp);
return service;
}
|
public static AxisService createSimpleService(QName serviceName,
String className,
QName opName) throws AxisFault {
return createSimpleService(serviceName, new RawXMLINOutMessageReceiver(), className,
opName);
}
|
public static AxisService createSimpleService(QName serviceName,
MessageReceiver messageReceiver,
String className,
QName opName) throws AxisFault {
AxisService service = new AxisService(serviceName.getLocalPart());
service.setClassLoader(getContextClassLoader_DoPriv());
service.addParameter(new Parameter(Constants.SERVICE_CLASS, className));
AxisOperation axisOp = new InOutAxisOperation(opName);
axisOp.setMessageReceiver(messageReceiver);
axisOp.setStyle(WSDLConstants.STYLE_RPC);
service.addOperation(axisOp);
service.mapActionToOperation(Constants.AXIS2_NAMESPACE_URI + "/" + opName.getLocalPart(),
axisOp);
return service;
}
|
public static AxisService createSimpleServiceforClient(QName serviceName,
String className,
QName opName) throws AxisFault {
return createSimpleServiceforClient(serviceName, new RawXMLINOutMessageReceiver(),
className,
opName);
}
|
public static AxisService createSimpleServiceforClient(QName serviceName,
MessageReceiver messageReceiver,
String className,
QName opName) throws AxisFault {
AxisService service = new AxisService(serviceName.getLocalPart());
service.setClassLoader(getContextClassLoader_DoPriv());
service.addParameter(new Parameter(Constants.SERVICE_CLASS, className));
AxisOperation axisOp = new OutInAxisOperation(opName);
axisOp.setMessageReceiver(messageReceiver);
axisOp.setStyle(WSDLConstants.STYLE_RPC);
service.addOperation(axisOp);
return service;
}
|
public static ServiceContext fillContextInformation(AxisService axisService,
ConfigurationContext configurationContext) throws AxisFault {
// 2. if null, create new opCtxt
// fill the service group context and service context info
return fillServiceContextAndServiceGroupContext(axisService, configurationContext);
}
|
public static int getAxisSpecifMEPConstant(String messageExchangePattern) {
int mepConstant = WSDLConstants.MEP_CONSTANT_INVALID;
if (WSDL2Constants.MEP_URI_IN_OUT.equals(messageExchangePattern) ||
WSDLConstants.WSDL20_2006Constants.MEP_URI_IN_OUT.equals(messageExchangePattern) ||
WSDLConstants.WSDL20_2004_Constants.MEP_URI_IN_OUT.equals(messageExchangePattern)) {
mepConstant = WSDLConstants.MEP_CONSTANT_IN_OUT;
} else if (
WSDL2Constants.MEP_URI_IN_ONLY.equals(messageExchangePattern) ||
WSDLConstants.WSDL20_2006Constants.MEP_URI_IN_ONLY.equals(messageExchangePattern) ||
WSDLConstants.WSDL20_2004_Constants.MEP_URI_IN_ONLY
.equals(messageExchangePattern)) {
mepConstant = WSDLConstants.MEP_CONSTANT_IN_ONLY;
} else if (WSDL2Constants.MEP_URI_IN_OPTIONAL_OUT
.equals(messageExchangePattern) ||
WSDLConstants.WSDL20_2006Constants.MEP_URI_IN_OPTIONAL_OUT
.equals(messageExchangePattern) ||
WSDLConstants.WSDL20_2004_Constants.MEP_URI_IN_OPTIONAL_OUT
.equals(messageExchangePattern)) {
mepConstant = WSDLConstants.MEP_CONSTANT_IN_OPTIONAL_OUT;
} else if (WSDL2Constants.MEP_URI_OUT_IN.equals(messageExchangePattern) ||
WSDLConstants.WSDL20_2006Constants.MEP_URI_OUT_IN.equals(messageExchangePattern) ||
WSDLConstants.WSDL20_2004_Constants.MEP_URI_OUT_IN
.equals(messageExchangePattern)) {
mepConstant = WSDLConstants.MEP_CONSTANT_OUT_IN;
} else if (WSDL2Constants.MEP_URI_OUT_ONLY.equals(messageExchangePattern) ||
WSDLConstants.WSDL20_2006Constants.MEP_URI_OUT_ONLY
.equals(messageExchangePattern) ||
WSDLConstants.WSDL20_2004_Constants
.MEP_URI_OUT_ONLY.equals(messageExchangePattern)) {
mepConstant = WSDLConstants.MEP_CONSTANT_OUT_ONLY;
} else if (WSDL2Constants.MEP_URI_OUT_OPTIONAL_IN.equals(messageExchangePattern) ||
WSDLConstants.WSDL20_2006Constants.MEP_URI_OUT_OPTIONAL_IN
.equals(messageExchangePattern) ||
WSDLConstants.WSDL20_2004_Constants.MEP_URI_OUT_OPTIONAL_IN
.equals(messageExchangePattern)) {
mepConstant = WSDLConstants.MEP_CONSTANT_OUT_OPTIONAL_IN;
} else if (WSDL2Constants.MEP_URI_ROBUST_IN_ONLY.equals(messageExchangePattern) ||
WSDLConstants.WSDL20_2006Constants.MEP_URI_ROBUST_IN_ONLY
.equals(messageExchangePattern) ||
WSDLConstants.WSDL20_2004_Constants.MEP_URI_ROBUST_IN_ONLY
.equals(messageExchangePattern)) {
mepConstant = WSDLConstants.MEP_CONSTANT_ROBUST_IN_ONLY;
} else if (WSDL2Constants.MEP_URI_ROBUST_OUT_ONLY.equals(messageExchangePattern) ||
WSDLConstants.WSDL20_2006Constants.MEP_URI_ROBUST_OUT_ONLY
.equals(messageExchangePattern) ||
WSDLConstants.WSDL20_2004_Constants.MEP_URI_ROBUST_OUT_ONLY
.equals(messageExchangePattern)) {
mepConstant = WSDLConstants.MEP_CONSTANT_ROBUST_OUT_ONLY;
}
if (mepConstant == WSDLConstants.MEP_CONSTANT_INVALID) {
throw new AxisError(Messages.getMessage("mepmappingerror"));
}
return mepConstant;
}
Maps the String URI of the Message exchange pattern to a integer.
Further, in the first lookup, it will cache the looked
up value so that the subsequent method calls are extremely efficient. |
public static String getHostname(AxisConfiguration axisConfiguration) {
if(axisConfiguration!=null){
Parameter param = axisConfiguration.getParameter(TransportListener.HOST_ADDRESS);
if (param != null) {
String hostAddress = ((String) param.getValue()).trim();
if(hostAddress!=null){
return hostAddress;
}
}
}
return null;
}
First check whether the hostname parameter is there in AxisConfiguration (axis2.xml) ,
if it is there then this will return that as the host name , o.w will return the IP address. |
public static AxisFault getInboundFaultFromMessageContext(MessageContext messageContext) {
// Get the fault if it's already been extracted by a handler
AxisFault result = (AxisFault) messageContext.getProperty(Constants.INBOUND_FAULT_OVERRIDE);
// Else, extract it from the SOAPBody
if (result == null) {
SOAPEnvelope envelope = messageContext.getEnvelope();
SOAPFault soapFault;
SOAPBody soapBody;
if (envelope != null && (soapBody = envelope.getBody()) != null) {
if ((soapFault = soapBody.getFault()) != null) {
return new AxisFault(soapFault, messageContext);
}
// If its a REST response the content is not a SOAP envelop and hence we will
// Have use the soap body as the exception
if (messageContext.isDoingREST() && soapBody.getFirstElement() != null) {
return new AxisFault(soapBody.getFirstElement().toString());
}
}
// Not going to be able to
throw new IllegalArgumentException(
"The MessageContext does not have an associated SOAPFault.");
}
return result;
}
Get an AxisFault object to represent the SOAPFault in the SOAPEnvelope attached
to the provided MessageContext. This first check for an already extracted AxisFault
and otherwise does a simple extract.
MUST NOT be passed a MessageContext which does not contain a SOAPFault |
public static String getIpAddress() throws SocketException {
Enumeration e = NetworkInterface.getNetworkInterfaces();
String address = "127.0.0.1";
while (e.hasMoreElements()) {
NetworkInterface netface = (NetworkInterface) e.nextElement();
Enumeration addresses = netface.getInetAddresses();
while (addresses.hasMoreElements()) {
InetAddress ip = (InetAddress) addresses.nextElement();
if (!ip.isLoopbackAddress() && isIP(ip.getHostAddress())) {
return ip.getHostAddress();
}
}
}
return address;
}
Returns the ip address to be used for the replyto epr
CAUTION:
This will go through all the available network interfaces and will try to return an ip address.
First this will try to get the first IP which is not loopback address (127.0.0.1). If none is found
then this will return this will return 127.0.0.1.
This will not consider IPv6 addresses.
TODO:
- Improve this logic to genaralize it a bit more
- Obtain the ip to be used here from the Call API |
public static String getIpAddress(AxisConfiguration axisConfiguration) throws SocketException {
if(axisConfiguration!=null){
Parameter param = axisConfiguration.getParameter(TransportListener.HOST_ADDRESS);
if (param != null) {
String hostAddress = ((String) param.getValue()).trim();
if(hostAddress!=null){
return hostAddress;
}
}
}
return getIpAddress();
}
First check whether the hostname parameter is there in AxisConfiguration (axis2.xml) ,
if it is there then this will retun that as the host name , o.w will return the IP address. |
public static String getModuleName(String moduleName) {
if (moduleName.endsWith("-SNAPSHOT")) {
return moduleName.substring(0, moduleName.indexOf("-SNAPSHOT"));
}
char delimiter = '-";
int version_index = moduleName.lastIndexOf(delimiter);
if (version_index > 0) {
String versionString = getModuleVersion(moduleName);
if (versionString == null) {
return moduleName;
} else {
return moduleName.substring(0, version_index);
}
} else {
return moduleName;
}
}
Get the name of the module , where archive name is combination of module name + its version
The format of the name is as follows:
moduleName-00.0000
Example: "addressing-01.0001.mar" would return "addressing" |
public static String getModuleName(String moduleName,
String moduleVersion) {
if (moduleVersion != null && moduleVersion.length() != 0) {
moduleName = moduleName + "-" + moduleVersion;
}
return moduleName;
}
|
public static String getModuleVersion(String moduleName) {
if (moduleName.endsWith("-SNAPSHOT")) {
return "SNAPSHOT";
}
char version_seperator = '-";
int version_index = moduleName.lastIndexOf(version_seperator);
if (version_index > 0) {
String versionString = moduleName.substring(version_index + 1, moduleName.length());
try {
Float.parseFloat(versionString);
return versionString;
} catch (NumberFormatException e) {
return null;
}
} else {
return null;
}
}
|
public static int getMtomThreshold(MessageContext msgCtxt) {
Integer value = null;
if(!msgCtxt.isServerSide()){
value = (Integer)msgCtxt.getProperty(Constants.Configuration.MTOM_THRESHOLD);
}else{
Parameter param = msgCtxt.getParameter(Constants.Configuration.MTOM_THRESHOLD);
if(param!=null){
value = (Integer)param.getValue();
}
}
int threshold = (value!=null)?value.intValue():0;
if(log.isDebugEnabled()){
log.debug("MTOM optimized Threshold value ="+threshold);
}
return threshold;
}
|
public static ConfigurationContext getNewConfigurationContext(String repositry) throws Exception {
final File file = new File(repositry);
boolean exists = exists(file);
if (!exists) {
throw new Exception("repository directory " + file.getAbsolutePath()
+ " does not exists");
}
File axis2xml = new File(file, "axis.xml");
String axis2xmlString = null;
if (exists(axis2xml)) {
axis2xmlString = axis2xml.getName();
}
String path = (String) org.apache.axis2.java.security.AccessController.doPrivileged(
new PrivilegedAction< String >() {
public String run() {
return file.getAbsolutePath();
}
}
);
return ConfigurationContextFactory
.createConfigurationContextFromFileSystem(path, axis2xmlString);
}
|
public static ClassLoader getObjectClassLoader(Object object) {
if(object == null) {
return null;
}
else {
return (ClassLoader) AccessController.doPrivileged(new PrivilegedAction() {
public Object run() {
return object.getClass().getClassLoader();
}
});
}
}
This method will provide the logic needed to retrieve an Object's classloader
in a Java 2 Security compliant manner. |
public static String getParameterValue(Parameter param) {
if (param == null) {
return null;
} else {
return (String) param.getValue();
}
}
|
public static boolean isExplicitlyTrue(MessageContext messageContext,
String propertyName) {
Object flag = messageContext.getProperty(propertyName);
return JavaUtils.isTrueExplicitly(flag);
} Deprecated! please - use MessageContext.isTrue(propertyName) instead
Check if a MessageContext property is true. |
public static boolean isLatest(String moduleVersion,
String currentDefaultVersion) {
if (AxisModule.VERSION_SNAPSHOT.equals(moduleVersion)) {
return true;
} else {
float m_version = Float.parseFloat(moduleVersion);
float m_c_vresion = Float.parseFloat(currentDefaultVersion);
return m_version > m_c_vresion;
}
}
|
public static String[] parseRequestURLForServiceAndOperation(String path,
String servicePath) {
if (log.isDebugEnabled()) {
log.debug("parseRequestURLForServiceAndOperation : [" + path + "][" + servicePath + "]");
}
if (path == null) {
return null;
}
String[] values = new String[2];
// TODO. This is kind of brittle. Any service with the name /services would cause fun.
int index = path.lastIndexOf(servicePath);
String service;
if (-1 != index) {
int serviceStart = index + servicePath.length();
if (path.length() > serviceStart + 1) {
service = path.substring(serviceStart + 1);
int queryIndex = service.indexOf('?");
if (queryIndex > 0) {
service = service.substring(0, queryIndex);
}
int operationIndex = service.indexOf('/");
if (operationIndex > 0) {
values[0] = service.substring(0, operationIndex);
values[1] = service.substring(operationIndex + 1);
operationIndex = values[1].lastIndexOf('/");
if (operationIndex > 0) {
values[1] = values[1].substring(operationIndex + 1);
}
} else {
values[0] = service;
}
}
} else {
if (log.isDebugEnabled()) {
log.debug("Unable to parse request URL [" + path + "][" + servicePath + "]");
}
}
return values;
}
Break a full path into pieces |