doclitwrappedminimalmethodmarshaller.java
来自「开源的axis2框架的源码。用于开发WEBSERVER」· Java 代码 · 共 537 行 · 第 1/2 页
JAVA
537 行
// put the data blocks underneath the operation element
m.setStyle(Style.DOCUMENT);
m.setIndirection(1);
QName responseOp = getResponseWrapperQName(operationDesc);
m.setOperationElement(responseOp);
// Put the return object onto the message
Class returnType = operationDesc.getResultActualType();
String returnNS = null;
String returnLocalPart = null;
if (operationDesc.isResultHeader()) {
returnNS = operationDesc.getResultTargetNamespace();
returnLocalPart = operationDesc.getResultName();
} else {
returnNS = operationDesc.getResultTargetNamespace();
returnLocalPart = operationDesc.getResultPartName();
}
if (returnType != void.class) {
// TODO should we allow null if the return is a header?
//Validate input parameters for operation and make sure no input parameters are null.
//As per JAXWS Specification section 3.6.2.3 if a null value is passes as an argument
//to a method then an implementation MUST throw WebServiceException.
if (returnObject == null) {
throw ExceptionFactory.makeWebServiceException(Messages.getMessage(
"NullParamErr1", "Return", operationDesc.getJavaMethodName(),
"rpc/lit"));
}
Element returnElement = null;
QName returnQName = new QName(returnNS, returnLocalPart);
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,
returnType, // force marshal by type
operationDesc.isResultHeader());
}
// Convert the holder objects into a list of JAXB objects for marshalling
List<PDElement> pdeList =
MethodMarshallerUtils.getPDElements(marshalDesc,
pds,
signatureArgs,
false, // output
true, // doc/lit wrapped
false); // not rpc
// We want to use "by Java Type" marshalling for
// all objects
for (PDElement pde : pdeList) {
ParameterDescription pd = pde.getParam();
Class type = pd.getParameterActualType();
pde.setByJavaTypeClass(type);
}
// TODO Should we check for null output body values? Should we check for null output header values ?
// Put values onto the message
MethodMarshallerUtils.toMessage(pdeList, m, packages);
return m;
} catch (Exception e) {
throw ExceptionFactory.makeWebServiceException(e);
}
}
public Object demarshalResponse(Message message, Object[] signatureArgs,
OperationDescription operationDesc)
throws WebServiceException {
EndpointInterfaceDescription ed = operationDesc.getEndpointInterfaceDescription();
EndpointDescription endpointDesc = ed.getEndpointDescription();
// Note all exceptions are caught and rethrown with a WebServiceException
try {
// Sample RPC message
// ..
// <soapenv:body>
// <m:opResponse xmlns:m="urn://api">
// <param xsi:type="data:foo" >...</param>
// </m:op>
// </soapenv:body>
//
// Important points.
// 1) RPC has an operation element under the body. This is the name of the
// wsdl operation.
// 2) The data blocks are located underneath the operation element. (In doc/lit
// the data elements are underneath the body.
// 3) The name of the data blocks (param) are defined by the wsdl:part not the
// schema. Note that it is unqualified per WSI-BP
// 4) The type of the data block (data:foo) is defined by schema (thus there is
// JAXB type rendering.
// 5) We always send an xsi:type, but other vendor's may not.
// Get the operation information
ParameterDescription[] pds = operationDesc.getParameterDescriptions();
MarshalServiceRuntimeDescription marshalDesc =
MethodMarshallerUtils.getMarshalDesc(endpointDesc);
TreeSet<String> packages = marshalDesc.getPackages();
// Indicate that the style is Document.
message.setStyle(Style.DOCUMENT);
message.setIndirection(1);
// Get the return value.
Class returnType = operationDesc.getResultActualType();
Object returnValue = null;
boolean hasReturnInBody = false;
if (returnType != void.class) {
// If the webresult is in the header, we need the name of the header so that we can find it.
Element returnElement = null;
if (operationDesc.isResultHeader()) {
returnElement = MethodMarshallerUtils.getReturnElement(packages,
message,
returnType,
operationDesc.isListType(),
true, // is a header
operationDesc.getResultTargetNamespace(),
// header ns
operationDesc.getResultPartName(), // header local part
MethodMarshallerUtils.numOutputBodyParams(pds) > 0);
} else {
returnElement = MethodMarshallerUtils.getReturnElement(packages,
message,
returnType,
operationDesc.isListType(),
false,
null,
null,
MethodMarshallerUtils.numOutputBodyParams(pds) > 0);
hasReturnInBody = true;
}
returnValue = returnElement.getTypeValue();
// TODO should we allow null if the return is a header?
//Validate input parameters for operation and make sure no input parameters are null.
//As per JAXWS Specification section 3.6.2.3 if a null value is passes as an argument
//to a method then an implementation MUST throw WebServiceException.
if (returnValue == null) {
throw ExceptionFactory.makeWebServiceException(Messages.getMessage(
"NullParamErr1", "Return", operationDesc.getJavaMethodName(),
"rpc/lit"));
}
}
// We want to use "by Java Type" unmarshalling for
// all objects
Class[] javaTypes = new Class[pds.length];
for (int i = 0; i < pds.length; i++) {
ParameterDescription pd = pds[i];
Class type = pd.getParameterActualType();
javaTypes[i] = type;
}
// Unmarshall the ParamValues from the Message
List<PDElement> pvList = MethodMarshallerUtils.getPDElements(pds,
message,
packages,
false, // output
hasReturnInBody,
javaTypes); // unmarshal by type
// TODO Should we check for null output body values? Should we check for null output header values ?
// Populate the response Holders
MethodMarshallerUtils.updateResponseSignatureArgs(pds, pvList, signatureArgs);
return returnValue;
} 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);
}
}
/**
* @param opDesc
* @return request wrapper qname
*/
private static QName getRequestWrapperQName(OperationDescription opDesc) {
QName qName = opDesc.getName();
String localPart = opDesc.getRequestWrapperLocalName();
String uri = opDesc.getRequestWrapperTargetNamespace();
String prefix = "dlwmin"; // Prefer using an actual prefix
qName = new QName(uri, localPart, prefix);
return qName;
}
/**
* @param opDesc
* @return request wrapper qname
*/
private static QName getResponseWrapperQName(OperationDescription opDesc) {
QName qName = opDesc.getName();
String localPart = opDesc.getResponseWrapperLocalName();
String uri = opDesc.getResponseWrapperTargetNamespace();
String prefix = "dlwmin"; // Prefer using an actual prefix
qName = new QName(uri, localPart, prefix);
return qName;
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?