descriptionutils.java
来自「开源的axis2框架的源码。用于开发WEBSERVER」· Java 代码 · 共 540 行 · 第 1/2 页
JAVA
540 行
/**
* This is a helper method that will open a stream to an @HandlerChain configuration file.
*
* @param configFile - The path to the file
* @param className - The class in which the annotation was declared. This is used in case the
* file path is relative.
* @param classLoader - ClassLoader used to load relative file paths.
* @return
*/
public static InputStream openHandlerConfigStream(String configFile, String className,
ClassLoader
classLoader) {
InputStream configStream = null;
URL configURL;
if (log.isDebugEnabled()) {
log.debug("Attempting to load @HandlerChain configuration file: " + configFile +
" relative to class: " + className);
}
try {
configURL = new URL(configFile);
if (configURL != null) {
if (log.isDebugEnabled()) {
log.debug("Found absolute @HandlerChain configuration file: " + configFile);
}
configStream = configURL.openStream();
}
}
catch (MalformedURLException e) {
// try another method to obtain a stream to the configuration file
}
catch (IOException e) {
// report this since it was a valid URL but the openStream caused a problem
ExceptionFactory.makeWebServiceException(Messages.getMessage("hcConfigLoadFail",
configFile, className,
e.toString()));
}
if (configStream == null) {
if (log.isDebugEnabled()) {
log.debug("@HandlerChain.file attribute referes to a relative location: "
+ configFile);
}
className = className.replace(".", "/");
try {
if (log.isDebugEnabled()) {
log.debug("Resolving @HandlerChain configuration file: " + configFile +
" relative to class file: " + className);
}
URI uri = new URI(className);
uri = uri.resolve(configFile);
String resolvedPath = uri.toString();
if (log.isDebugEnabled()) {
log.debug("@HandlerChain.file resolved file path location: " + resolvedPath);
}
configStream = classLoader.getResourceAsStream(resolvedPath);
}
catch (URISyntaxException e) {
ExceptionFactory.makeWebServiceException(Messages.getMessage("hcConfigLoadFail",
configFile, className,
e.toString()));
}
}
if (configStream == null) {
ExceptionFactory.makeWebServiceException(Messages.getMessage("handlerChainNS",
configFile, className));
} else {
if (log.isDebugEnabled()) {
log.debug("@HandlerChain configuration file: " + configFile + " in class: " +
className + " was successfully loaded.");
}
}
return configStream;
}
/**
* Determine is this method is an async method
* @param method - The method to examine
* @return
*/
public static boolean isAsync(Method method) {
if (method == null) {
return false;
}
String methodName = method.getName();
Class returnType = method.getReturnType();
if (methodName.endsWith("Async")
&& (returnType.isAssignableFrom(javax.xml.ws.Response.class) || returnType
.isAssignableFrom(java.util.concurrent.Future.class))) {
return true;
} else {
return false;
}
}
public static HandlerChainsType loadHandlerChains(InputStream is) {
try {
// All the classes we need should be part of this package
JAXBContext jc = JAXBContext
.newInstance("org.apache.axis2.jaxws.description.xml.handler",
EndpointDescriptionImpl.class.getClassLoader());
Unmarshaller u = jc.createUnmarshaller();
JAXBElement<?> o = (JAXBElement<?>)u.unmarshal(is);
return (HandlerChainsType)o.getValue();
} catch (Exception e) {
throw ExceptionFactory
.makeWebServiceException(
"EndpointDescriptionImpl: loadHandlerList: thrown when attempting to unmarshall JAXB content");
}
}
/**
* This method will loop through a list of extensibility elements looking for one
* of four objects: SOAPBody, SOAP12Body, SOAPHeader, SOAP12Header. If any of these
* objects are found the namespace URI from this object will be returned.
*/
public static String getNamespaceFromSOAPElement(List extElements) {
Iterator extIter = extElements.iterator();
while (extIter.hasNext()) {
Object extObj = extIter.next();
if (extObj instanceof SOAPBody) {
if (log.isDebugEnabled()) {
log.debug("Returning SOAPBody namespace: "
+ ((SOAPBody) extObj).getNamespaceURI());
}
return ((SOAPBody) extObj).getNamespaceURI();
} else if (extObj instanceof SOAP12Body) {
if (log.isDebugEnabled()) {
log.debug("Returning SOAP12Body namespace: "
+ ((SOAP12Body) extObj).getNamespaceURI());
}
return ((SOAP12Body) extObj).getNamespaceURI();
} else if (extObj instanceof SOAPHeader) {
if (log.isDebugEnabled()) {
log.debug("Returning SOAPHeader namespace: "
+ ((SOAPHeader) extObj).getNamespaceURI());
}
return ((SOAPHeader) extObj).getNamespaceURI();
} else if (extObj instanceof SOAP12Header) {
if (log.isDebugEnabled()) {
log.debug("Returning SOAP12Header namespace: "
+ ((SOAP12Header) extObj).getNamespaceURI());
}
return ((SOAP12Header) extObj).getNamespaceURI();
}
}
return null;
}
/**
* This method will process a WSDL Binding and build AttachmentDescription objects if the
* WSDL dicatates attachments.
*/
public static void getAttachmentFromBinding(OperationDescriptionImpl opDesc, Binding binding) {
if (binding != null) {
Iterator bindingOpIter = binding.getBindingOperations().iterator();
while (bindingOpIter.hasNext()) {
BindingOperation bindingOp = (BindingOperation) bindingOpIter.next();
// found the BindingOperation that matches the current OperationDescription
if (bindingOp.getName().equals(opDesc.getName().getLocalPart())) {
if (bindingOp.getBindingInput() != null) {
if (log.isDebugEnabled()) {
log.debug("Processing binding input");
}
processBindingForMIME(bindingOp.getBindingInput()
.getExtensibilityElements(),
opDesc,
bindingOp.getOperation());
}
if (bindingOp.getBindingOutput() != null) {
if (log.isDebugEnabled()) {
log.debug("Processing binding output");
}
processBindingForMIME(bindingOp.getBindingOutput()
.getExtensibilityElements(),
opDesc,
bindingOp.getOperation());
}
}
}
}
}
/**
* This method will loop through the extensibility elements for a given BindingInput or
* BindingOutput element and determine if it has any MIMEMultipartRelated content. If it
* does it will build up the appropriate AttachmentDescription objects.
*/
private static void processBindingForMIME(List extensibilityElements,
OperationDescriptionImpl opDesc, Operation operation) {
Iterator extensibilityIter = extensibilityElements.iterator();
while (extensibilityIter.hasNext()) {
Object obj = extensibilityIter.next();
if (obj instanceof MIMEMultipartRelated) {
// Found mime information now process it and determine if we need to
// create an AttachmentDescription
MIMEMultipartRelated mime = (MIMEMultipartRelated) obj;
Iterator partIter = mime.getMIMEParts().iterator();
while (partIter.hasNext()) {
MIMEPart mimePart = (MIMEPart) partIter.next();
Iterator mExtIter = mimePart.getExtensibilityElements().iterator();
// Process each mime part to determine if there is mime content
while (mExtIter.hasNext()) {
Object obj2 = mExtIter.next();
// For mime content we need to potentially create an AttachmentDescription
if (obj2 instanceof MIMEContent) {
MIMEContent mimeContent = (MIMEContent) obj2;
String part = mimeContent.getPart();
String type = mimeContent.getType();
// if we have not already processed this part for the operation
if (opDesc.getPartAttachmentDescription(part) == null) {
if (log.isDebugEnabled()) {
log.debug("Adding new AttachmentDescription for part: " + part
+ " on operation: " + opDesc.getOperationName());
}
AttachmentDescription attachmentDesc =
new AttachmentDescriptionImpl(AttachmentType.SWA,
new String[] { type });
opDesc.addPartAttachmentDescription(part, attachmentDesc);
} else {
if (log.isDebugEnabled()) {
log.debug("Already created AttachmentDescription for part: "
+ part + " of type: " + type);
}
}
}
}
}
}
}
}
public static void registerHandlerHeaders(AxisService axisService, List<Handler> handlers) {
if (handlers == null || axisService == null) {
return;
}
ArrayList<QName> understoodHeaderQNames = new ArrayList<QName>();
for (Handler handler : handlers) {
if (handler instanceof SOAPHandler) {
SOAPHandler soapHandler = (SOAPHandler) handler;
Set<QName> headers = soapHandler.getHeaders();
if (headers != null) {
for (QName header : headers) {
if (!understoodHeaderQNames.contains(header)) {
understoodHeaderQNames.add(header);
}
}
}
}
}
if (!understoodHeaderQNames.isEmpty()) {
Parameter headerQNParameter =
new Parameter(EndpointDescription.HANDLER_PARAMETER_QNAMES, understoodHeaderQNames);
try {
axisService.addParameter(headerQNParameter);
} catch (AxisFault e) {
// TODO: RAS
log.warn("Unable to add Parameter for header QNames to AxisService " + axisService, e);
}
}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?