doclitwrappedmethodmarshaller.java
来自「开源的axis2框架的源码。用于开发WEBSERVER」· Java 代码 · 共 525 行 · 第 1/2 页
JAVA
525 行
}
pvList.add(new PDElement(pd, element, null));
}
// Build the signature arguments
Object[] sigArguments = MethodMarshallerUtils.createRequestSignatureArgs(pds, pvList);
return sigArguments;
} catch (Exception e) {
throw ExceptionFactory.makeWebServiceException(e);
}
}
public Message marshalResponse(Object returnObject, Object[] signatureArgs,
OperationDescription operationDesc, Protocol protocol)
throws WebServiceException {
EndpointInterfaceDescription ed = operationDesc.getEndpointInterfaceDescription();
EndpointDescription endpointDesc = ed.getEndpointDescription();
MarshalServiceRuntimeDescription marshalDesc =
MethodMarshallerUtils.getMarshalDesc(endpointDesc);
TreeSet<String> packages = marshalDesc.getPackages();
String packagesKey = marshalDesc.getPackagesKey();
// 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:operationResponse ... >
// <param>hello</param>
// </m:operationResponse>
// </soapenv:body>
//
// Important points.
// 1) There is no operation element in the message
// 2) The data blocks are located underneath the body element.
// 3) The name of the data block (m:operationResponse) is defined by the schema.
// It matches the operation name + "Response", and it has a corresponding JAXB element.
// This element is called the wrapper element
// 4) The parameters are (param) are child elements of the wrapper element.
// Get the operation information
ParameterDescription[] pds = operationDesc.getParameterDescriptions();
// Create the message
MessageFactory mf = marshalDesc.getMessageFactory();
Message m = mf.create(protocol);
// In usage=WRAPPED, there will be a single block in the body.
// The signatureArguments represent the child elements of that block
// The first step is to convert the signature arguments into a list
// of parameter values
List<PDElement> pdeList =
MethodMarshallerUtils.getPDElements(marshalDesc,
pds,
signatureArgs,
false, // output
true, false);
// Now we want to create a single JAXB element that contains the
// ParameterValues. We will use the wrapper tool to do this.
// Create the inputs to the wrapper tool
ArrayList<String> nameList = new ArrayList<String>();
Map<String, Object> objectList = new HashMap<String, Object>();
for (PDElement pde : pdeList) {
String name = pde.getParam().getParameterName();
// The object list contains type rendered objects
Object value = pde.getElement().getTypeValue();
nameList.add(name);
objectList.put(name, value);
}
// Add the return object to the nameList and objectList
Class returnType = operationDesc.getResultActualType();
if (returnType != void.class) {
String name = operationDesc.getResultName();
nameList.add(name);
objectList.put(name, returnObject);
}
// Now create the single JAXB element
String wrapperName = marshalDesc.getResponseWrapperClassName(operationDesc);
Class cls = MethodMarshallerUtils.loadClass(wrapperName);
JAXBWrapperTool wrapperTool = new JAXBWrapperToolImpl();
Object object = wrapperTool.wrap(cls, nameList, objectList,
marshalDesc.getPropertyDescriptorMap(cls));
QName wrapperQName = new QName(operationDesc.getResponseWrapperTargetNamespace(),
operationDesc.getResponseWrapperLocalName());
// Make sure object can be rendered as an element
if (!marshalDesc.getAnnotationDesc(cls).hasXmlRootElement()) {
object = new JAXBElement(wrapperQName, cls, object);
}
// Put the object into the message
JAXBBlockFactory factory =
(JAXBBlockFactory)FactoryRegistry.getFactory(JAXBBlockFactory.class);
Block block = factory.createFrom(object,
new JAXBBlockContext(packages, packagesKey),
wrapperQName);
m.setBodyBlock(block);
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());
MarshalServiceRuntimeDescription marshalDesc =
MethodMarshallerUtils.getMarshalDesc(endpointDesc);
TreeSet<String> packages = marshalDesc.getPackages();
String packagesKey = marshalDesc.getPackagesKey();
// Note all exceptions are caught and rethrown with a WebServiceException
try {
// Sample Document message
// ..
// <soapenv:body>
// <m:operation>
// <param>hello</param>
// </m:operation>
// </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 block (m:operation) is defined by the schema and match the name of the operation.
// This is called the wrapper element. The wrapper element has a corresponding JAXB element pojo.
// 4) The parameters (m:param) are child elements of the wrapper element.
// Get the operation information
ParameterDescription[] pds = operationDesc.getParameterDescriptions();
// Create the message
MessageFactory mf = marshalDesc.getMessageFactory();
Message m = mf.create(protocol);
// In usage=WRAPPED, there will be a single block in the body.
// The signatureArguments represent the child elements of that block
// The first step is to convert the signature arguments into list
// of parameter values
List<PDElement> pvList = MethodMarshallerUtils.getPDElements(marshalDesc,
pds,
signatureArguments,
true, // input
true, false);
// Now we want to create a single JAXB element that contains the
// ParameterValues. We will use the wrapper tool to do this.
// Create the inputs to the wrapper tool
ArrayList<String> nameList = new ArrayList<String>();
Map<String, Object> objectList = new HashMap<String, Object>();
for (PDElement pv : pvList) {
String name = pv.getParam().getParameterName();
// The object list contains type rendered objects
Object value = pv.getElement().getTypeValue();
nameList.add(name);
objectList.put(name, value);
}
// Now create the single JAXB element
String wrapperName = marshalDesc.getRequestWrapperClassName(operationDesc);
Class cls = MethodMarshallerUtils.loadClass(wrapperName);
JAXBWrapperTool wrapperTool = new JAXBWrapperToolImpl();
Object object = wrapperTool.wrap(cls, nameList, objectList,
marshalDesc.getPropertyDescriptorMap(cls));
QName wrapperQName = new QName(operationDesc.getRequestWrapperTargetNamespace(),
operationDesc.getRequestWrapperLocalName());
// Make sure object can be rendered as an element
if (!marshalDesc.getAnnotationDesc(cls).hasXmlRootElement()) {
object = new JAXBElement(wrapperQName, cls, object);
}
// Put the object into the message
JAXBBlockFactory factory =
(JAXBBlockFactory)FactoryRegistry.getFactory(JAXBBlockFactory.class);
Block block = factory.createFrom(object,
new JAXBBlockContext(packages, packagesKey),
wrapperQName);
m.setBodyBlock(block);
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);
TreeSet<String> packages = marshalDesc.getPackages();
// 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 + -
显示快捷键?