doclitbareminimalmethodmarshaller.java
来自「开源的axis2框架的源码。用于开发WEBSERVER」· Java 代码 · 共 403 行 · 第 1/2 页
JAVA
403 行
OperationDescription operationDesc, Protocol protocol)
throws WebServiceException {
EndpointInterfaceDescription ed = operationDesc.getEndpointInterfaceDescription();
EndpointDescription endpointDesc = ed.getEndpointDescription();
// We want to respond with the same protocol as the request,
// It the protocol is null, then use the Protocol defined by the binding
if (protocol == null) {
protocol = Protocol.getProtocolForBinding(endpointDesc.getBindingType());
}
// Note all exceptions are caught and rethrown with a WebServiceException
try {
// Sample Document message
// ..
// <soapenv:body>
// <m:return ... >...</m:param>
// </soapenv:body>
//
// Important points.
// 1) There is no operation element in the message
// 2) The data blocks are located underneath the operation element.
// 3) The name of the data blocks (m:param) are defined by the schema.
// (SOAP indicates that the name of the element is not important, but
// for document processing, we will assume that the name corresponds to
// a schema root element)
// 4) The type of the data block is defined by schema; thus in most cases
// an xsi:type will not be present
// Get the operation information
ParameterDescription[] pds = operationDesc.getParameterDescriptions();
MarshalServiceRuntimeDescription marshalDesc =
MethodMarshallerUtils.getMarshalDesc(endpointDesc);
TreeSet<String> packages = marshalDesc.getPackages();
// Create the message
MessageFactory mf = (MessageFactory)FactoryRegistry.getFactory(MessageFactory.class);
Message m = mf.create(protocol);
// Put the return object onto the message
Class returnType = operationDesc.getResultActualType();
if (returnType != void.class) {
// Use byJavaType marshalling if necessary
Class byJavaType = null;
if (MethodMarshallerUtils.isNotJAXBRootElement(returnType, marshalDesc)) {
byJavaType = returnType;
}
Element returnElement = null;
QName returnQName = new QName(operationDesc.getResultTargetNamespace(),
operationDesc.getResultName());
if (marshalDesc.getAnnotationDesc(returnType).hasXmlRootElement()) {
returnElement = new Element(returnObject, returnQName);
} else {
returnElement = new Element(returnObject, returnQName, returnType);
}
MethodMarshallerUtils.toMessage(returnElement, returnType, operationDesc.isListType(),
marshalDesc, m,
byJavaType,
operationDesc.isResultHeader());
}
// Convert the holder objects into a list of JAXB objects for marshalling
List<PDElement> pdeList = MethodMarshallerUtils.getPDElements(marshalDesc,
pds,
signatureArgs,
false, // output
false, false);
// We want to use "by Java Type" marshalling for
// all body elements and all non-JAXB objects
for (PDElement pde : pdeList) {
ParameterDescription pd = pde.getParam();
Class type = pd.getParameterActualType();
if (MethodMarshallerUtils.isNotJAXBRootElement(type, marshalDesc)) {
pde.setByJavaTypeClass(type);
}
}
// Put values onto the message
MethodMarshallerUtils.toMessage(pdeList, m, packages);
return m;
} catch (Exception e) {
throw ExceptionFactory.makeWebServiceException(e);
}
}
public Message marshalRequest(Object[] signatureArguments, OperationDescription operationDesc)
throws WebServiceException {
EndpointInterfaceDescription ed = operationDesc.getEndpointInterfaceDescription();
EndpointDescription endpointDesc = ed.getEndpointDescription();
Protocol protocol = Protocol.getProtocolForBinding(endpointDesc.getClientBindingID());
// Note all exceptions are caught and rethrown with a WebServiceException
try {
// Sample Document message
// ..
// <soapenv:body>
// <m:param .. >...</m:param>
// </soapenv:body>
//
// Important points.
// 1) There is no operation element under the body.
// 2) The data blocks are located underneath the body.
// 3) The name of the data blocks (m:param) are defined by the schema
// 4) The type of the data block (data:foo) is defined by schema (and probably
// is not present in the message
// Get the operation information
ParameterDescription[] pds = operationDesc.getParameterDescriptions();
MarshalServiceRuntimeDescription marshalDesc =
MethodMarshallerUtils.getMarshalDesc(endpointDesc);
TreeSet<String> packages = marshalDesc.getPackages();
// Create the message
MessageFactory mf = (MessageFactory)FactoryRegistry.getFactory(MessageFactory.class);
Message m = mf.create(protocol);
// The input object represent the signature arguments.
// Signature arguments are both holders and non-holders
// Convert the signature into a list of JAXB objects for marshalling
List<PDElement> pdeList = MethodMarshallerUtils.getPDElements(marshalDesc,
pds,
signatureArguments,
true, // input
false, false);
// We want to use "by Java Type" marshalling for
// all body elements and all non-JAXB objects
for (PDElement pde : pdeList) {
ParameterDescription pd = pde.getParam();
Class type = pd.getParameterActualType();
if (MethodMarshallerUtils.isNotJAXBRootElement(type, marshalDesc)) {
pde.setByJavaTypeClass(type);
}
}
// Put values onto the message...marshalling by type
MethodMarshallerUtils.toMessage(pdeList, m, packages);
return m;
} catch (Exception e) {
throw ExceptionFactory.makeWebServiceException(e);
}
}
public Message marshalFaultResponse(Throwable throwable, OperationDescription operationDesc,
Protocol protocol) throws WebServiceException {
EndpointInterfaceDescription ed = operationDesc.getEndpointInterfaceDescription();
EndpointDescription endpointDesc = ed.getEndpointDescription();
MarshalServiceRuntimeDescription marshalDesc =
MethodMarshallerUtils.getMarshalDesc(endpointDesc);
// We want to respond with the same protocol as the request,
// It the protocol is null, then use the Protocol defined by the binding
if (protocol == null) {
protocol = Protocol.getProtocolForBinding(endpointDesc.getBindingType());
}
// Note all exceptions are caught and rethrown with a WebServiceException
try {
// Create the message
MessageFactory mf = (MessageFactory)FactoryRegistry.getFactory(MessageFactory.class);
Message m = mf.create(protocol);
// Put the fault onto the message
MethodMarshallerUtils.marshalFaultResponse(throwable,
marshalDesc,
operationDesc,
m);
return m;
} catch (Exception e) {
throw ExceptionFactory.makeWebServiceException(e);
}
}
public Throwable demarshalFaultResponse(Message message, OperationDescription operationDesc)
throws WebServiceException {
EndpointInterfaceDescription ed = operationDesc.getEndpointInterfaceDescription();
EndpointDescription endpointDesc = ed.getEndpointDescription();
MarshalServiceRuntimeDescription marshalDesc =
MethodMarshallerUtils.getMarshalDesc(endpointDesc);
// Note all exceptions are caught and rethrown with a WebServiceException
try {
Throwable t = MethodMarshallerUtils
.demarshalFaultResponse(operationDesc, marshalDesc, message);
return t;
} catch (Exception e) {
throw ExceptionFactory.makeWebServiceException(e);
}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?