use of org.apache.axis2.jaxws.description.AttachmentDescription in project axis-axis2-java-core by apache.
the class DocLitBareMethodMarshaller method demarshalResponse.
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 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
ParameterDescription[] pds = operationDesc.getParameterDescriptions();
MarshalServiceRuntimeDescription marshalDesc = MethodMarshallerUtils.getMarshalDesc(endpointDesc);
TreeSet<String> packages = marshalDesc.getPackages();
// the next time.
if (shouldRegisterUnmarshalInfo(operationDesc, message.getMessageContext())) {
MethodMarshallerUtils.registerUnmarshalInfo(message.getMessageContext(), packages, marshalDesc.getPackagesKey());
}
// Get the return value.
Class returnType = operationDesc.getResultActualType();
Object returnValue = null;
boolean hasReturnInBody = false;
if (returnType != void.class) {
AttachmentDescription attachmentDesc = operationDesc.getResultAttachmentDescription();
if (attachmentDesc != null) {
if (attachmentDesc.getAttachmentType() == AttachmentType.SWA) {
String cid = message.getAttachmentID(0);
returnValue = message.getDataHandler(cid);
} else {
throw ExceptionFactory.makeWebServiceException(Messages.getMessage("pdElementErr"));
}
} else {
// 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, null, false, true, operationDesc.getResultTargetNamespace(), operationDesc.getResultName(), MethodMarshallerUtils.numOutputBodyParams(pds) > 0);
} else {
returnElement = MethodMarshallerUtils.getReturnElement(packages, message, null, false, false, null, null, MethodMarshallerUtils.numOutputBodyParams(pds) > 0);
hasReturnInBody = true;
}
returnValue = returnElement.getTypeValue();
}
if (ConvertUtils.isConvertable(returnValue, returnType)) {
returnValue = ConvertUtils.convert(returnValue, returnType);
}
}
// Unmarshall the ParamValues from the Message
List<PDElement> pvList = MethodMarshallerUtils.getPDElements(pds, message, packages, // output
false, hasReturnInBody, // always unmarshal with "by element" mode
null);
// Populate the response Holders
MethodMarshallerUtils.updateResponseSignatureArgs(pds, pvList, signatureArgs);
return returnValue;
} catch (Exception e) {
throw ExceptionFactory.makeWebServiceException(e);
}
}
use of org.apache.axis2.jaxws.description.AttachmentDescription in project axis-axis2-java-core by apache.
the class DocLitBareMethodMarshaller method marshalResponse.
public Message marshalResponse(Object returnObject, Object[] signatureArgs, OperationDescription operationDesc, Protocol protocol) throws WebServiceException {
EndpointInterfaceDescription ed = operationDesc.getEndpointInterfaceDescription();
EndpointDescription endpointDesc = ed.getEndpointDescription();
// 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) {
AttachmentDescription attachmentDesc = operationDesc.getResultAttachmentDescription();
if (attachmentDesc != null) {
if (attachmentDesc.getAttachmentType() == AttachmentType.SWA) {
// Create an Attachment object with the signature value
Attachment attachment = new Attachment(returnObject, returnType, attachmentDesc, operationDesc.getResultPartName());
m.addDataHandler(attachment.getDataHandler(), attachment.getContentID());
m.setDoingSWA(true);
} else {
throw ExceptionFactory.makeWebServiceException(Messages.getMessage("pdElementErr"));
}
} else {
Element returnElement = null;
QName returnQName = new QName(operationDesc.getResultTargetNamespace(), operationDesc.getResultName());
if (marshalDesc.getAnnotationDesc(returnType).hasXmlRootElement()) {
returnElement = new Element(returnObject, returnQName);
} else {
/* when a schema defines a SimpleType with xsd list jaxws tooling generates art-effects with array rather than a java.util.List
* However the ObjectFactory definition uses a List and thus marshalling fails. Lets convert the Arrays to List.
*/
if (operationDesc.isListType()) {
List list = new ArrayList();
if (returnType.isArray()) {
for (int count = 0; count < Array.getLength(returnObject); count++) {
Object obj = Array.get(returnObject, count);
list.add(obj);
}
returnElement = new Element(list, returnQName, List.class);
}
} else {
returnElement = new Element(returnObject, returnQName, returnType);
}
}
MethodMarshallerUtils.toMessage(returnElement, returnType, operationDesc.isListType(), marshalDesc, m, // always marshal using "by element" mode
null, operationDesc.isResultHeader());
}
}
// Convert the holder objects into a list of JAXB objects for marshalling
List<PDElement> pvList = MethodMarshallerUtils.getPDElements(marshalDesc, pds, signatureArgs, // output
false, false, false);
// Put values onto the message
MethodMarshallerUtils.toMessage(pvList, m, packages, null);
// Enable SWA for nested SwaRef attachments
if (operationDesc.hasResponseSwaRefAttachments()) {
m.setDoingSWA(true);
}
return m;
} catch (Exception e) {
throw ExceptionFactory.makeWebServiceException(e);
}
}
use of org.apache.axis2.jaxws.description.AttachmentDescription in project axis-axis2-java-core by apache.
the class DocLitBareMinimalMethodMarshaller method marshalResponse.
public Message marshalResponse(Object returnObject, Object[] signatureArgs, OperationDescription operationDesc, Protocol protocol) throws WebServiceException {
EndpointInterfaceDescription ed = operationDesc.getEndpointInterfaceDescription();
EndpointDescription endpointDesc = ed.getEndpointDescription();
// 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) {
AttachmentDescription attachmentDesc = operationDesc.getResultAttachmentDescription();
if (attachmentDesc != null) {
if (attachmentDesc.getAttachmentType() == AttachmentType.SWA) {
// Create an Attachment object with the signature value
Attachment attachment = new Attachment(returnObject, returnType, attachmentDesc, operationDesc.getResultPartName());
m.addDataHandler(attachment.getDataHandler(), attachment.getContentID());
m.setDoingSWA(true);
} else {
throw ExceptionFactory.makeWebServiceException(Messages.getMessage("pdElementErr"));
}
} else {
// 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, // output
false, false, false);
// 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, null);
// Enable SWA for nested SwaRef attachments
if (operationDesc.hasResponseSwaRefAttachments()) {
m.setDoingSWA(true);
}
return m;
} catch (Exception e) {
throw ExceptionFactory.makeWebServiceException(e);
}
}
use of org.apache.axis2.jaxws.description.AttachmentDescription in project axis-axis2-java-core by apache.
the class DocLitBareMinimalMethodMarshaller method demarshalResponse.
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 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
ParameterDescription[] pds = operationDesc.getParameterDescriptions();
MarshalServiceRuntimeDescription marshalDesc = MethodMarshallerUtils.getMarshalDesc(endpointDesc);
TreeSet<String> packages = marshalDesc.getPackages();
// Get the return value.
Class returnType = operationDesc.getResultActualType();
Object returnValue = null;
boolean hasReturnInBody = false;
if (returnType != void.class) {
AttachmentDescription attachmentDesc = operationDesc.getResultAttachmentDescription();
if (attachmentDesc != null) {
if (attachmentDesc.getAttachmentType() == AttachmentType.SWA) {
String cid = message.getAttachmentID(0);
returnValue = message.getDataHandler(cid);
} else {
throw ExceptionFactory.makeWebServiceException(Messages.getMessage("pdElementErr"));
}
} else {
// Use "byJavaType" unmarshalling if necessary
Class byJavaType = null;
if (MethodMarshallerUtils.isNotJAXBRootElement(returnType, marshalDesc)) {
byJavaType = returnType;
}
// 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, byJavaType, operationDesc.isListType(), true, operationDesc.getResultTargetNamespace(), operationDesc.getResultName(), MethodMarshallerUtils.numOutputBodyParams(pds) > 0);
} else {
returnElement = MethodMarshallerUtils.getReturnElement(packages, message, byJavaType, operationDesc.isListType(), false, null, null, MethodMarshallerUtils.numOutputBodyParams(pds) > 0);
hasReturnInBody = true;
}
// 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.
returnValue = returnElement.getTypeValue();
}
if (ConvertUtils.isConvertable(returnValue, returnType)) {
returnValue = ConvertUtils.convert(returnValue, returnType);
}
}
// We want to use "by Java Type" unmarshalling for
// allall non-JAXB objects
Class[] javaTypes = new Class[pds.length];
for (int i = 0; i < pds.length; i++) {
ParameterDescription pd = pds[i];
Class type = pd.getParameterActualType();
if (MethodMarshallerUtils.isNotJAXBRootElement(type, marshalDesc)) {
javaTypes[i] = type;
}
}
// Unmarshall the ParamValues from the Message
List<PDElement> pvList = MethodMarshallerUtils.getPDElements(pds, message, packages, // output
false, hasReturnInBody, // byJavaType unmarshalling
javaTypes);
// Populate the response Holders
MethodMarshallerUtils.updateResponseSignatureArgs(pds, pvList, signatureArgs);
return returnValue;
} catch (Exception e) {
throw ExceptionFactory.makeWebServiceException(e);
}
}
use of org.apache.axis2.jaxws.description.AttachmentDescription in project axis-axis2-java-core by apache.
the class MethodMarshallerUtils method getPDElements.
/**
* Return the list of PDElements that is unmarshalled from the wire
*
* @param params ParameterDescription for this operation
* @param message Message
* @param packages set of packages needed to unmarshal objects for this operation
* @param isInput indicates if input or output params (input on server, output on client)
* @param hasReturnInBody if isInput=false, then this parameter indicates whether a
* return value is expected in the body.
* @param unmarshalByJavaType in most scenarios this is null.
* Only use this in the scenarios that require unmarshalling by java type
* @see getPDElementsWithMissingElements
* @return ParamValues
*/
static List<PDElement> getPDElements(ParameterDescription[] params, Message message, TreeSet<String> packages, boolean isInput, boolean hasReturnInBody, Class[] unmarshalByJavaType) throws XMLStreamException {
List<PDElement> pdeList = new ArrayList<PDElement>();
// Count
int totalBodyBlocks = 0;
for (int i = 0; i < params.length; i++) {
ParameterDescription pd = params[i];
if (pd.getMode() == Mode.IN && isInput || pd.getMode() == Mode.INOUT || pd.getMode() == Mode.OUT && !isInput) {
if (!pd.isHeader() && !isSWAAttachment(pd)) {
totalBodyBlocks++;
}
}
}
if (!isInput && hasReturnInBody) {
totalBodyBlocks++;
}
int index = (!isInput && hasReturnInBody) ? 1 : 0;
// TODO What if return is an swa attachment, then this should start
// at 1 not 0.
int swaIndex = 0;
for (int i = 0; i < params.length; i++) {
ParameterDescription pd = params[i];
if (pd.getMode() == Mode.IN && isInput || pd.getMode() == Mode.INOUT || pd.getMode() == Mode.OUT && !isInput) {
// Don't consider async handlers, they are are not represented on the wire,
// thus they don't have a PDElement
// TODO
// if (isAsyncHandler(param)) {
// continue;
// }
Block block = null;
JAXBBlockContext context = new JAXBBlockContext(packages);
AttachmentDescription attachmentDesc = pd.getAttachmentDescription();
if (attachmentDesc == null) {
// Trigger unmarshal by java type if necessary
if (unmarshalByJavaType != null && unmarshalByJavaType[i] != null) {
context.setProcessType(unmarshalByJavaType[i]);
context.setIsxmlList(pd.isListType());
}
boolean consume = true;
// Unmarshal the object into a JAXB object or JAXBElement
if (pd.isHeader()) {
// Get the Block from the header
// NOTE The parameter name is always used to get the header
// element...even if the style is RPC.
String localName = pd.getParameterName();
block = message.getHeaderBlock(pd.getTargetNamespace(), localName, context, factory);
consume = false;
} else {
if (totalBodyBlocks > 1) {
// You must use this method if there are more than one body block
// This method may cause OM expansion
block = message.getBodyBlock(index, context, factory);
} else {
// Use this method if you know there is only one body block.
// This method prevents OM expansion.
block = message.getBodyBlock(context, factory);
}
index++;
}
Element element;
if (block != null) {
element = new Element(block.getBusinessObject(true), block.getQName());
} else {
// The block could be null if the header is missing (which is allowed)
QName qName = new QName(pd.getTargetNamespace(), pd.getParameterName());
if (log.isDebugEnabled()) {
log.debug("There is no value in the incoming message for " + qName);
}
element = new Element(null, qName, pd.getParameterActualType());
}
PDElement pde = new PDElement(pd, element, unmarshalByJavaType == null ? null : unmarshalByJavaType[i]);
pdeList.add(pde);
} else {
// Attachment Processing
if (attachmentDesc.getAttachmentType() == AttachmentType.SWA) {
String partName = pd.getPartName();
String cid = null;
if (log.isDebugEnabled()) {
log.debug("Getting the attachment dataHandler for partName=" + partName);
}
if (partName != null && partName.length() > 0) {
// Compliant WS-I behavior
cid = message.getAttachmentID(partName);
}
if (cid == null) {
if (log.isDebugEnabled()) {
log.debug("Attachment dataHandler was not found. Fallback to use attachment " + swaIndex);
}
// Toleration mode for non-compliant attachment names
cid = message.getAttachmentID(swaIndex);
}
DataHandler dh = message.getDataHandler(cid);
Attachment attachment = new Attachment(dh, cid);
PDElement pde = new PDElement(pd, null, null, attachment);
pdeList.add(pde);
swaIndex++;
} else {
throw ExceptionFactory.makeWebServiceException(Messages.getMessage("pdElementErr"));
}
}
}
}
return pdeList;
}
Aggregations