return new WebServiceException(ex);
}
@SuppressWarnings("unchecked")
public T invoke(T obj, boolean isOneWay) {
StaxSource createdSource = null;
checkError();
try {
if (obj instanceof SOAPMessage) {
SOAPMessage msg = (SOAPMessage)obj;
if (msg.countAttachments() > 0) {
client.getRequestContext().put(AttachmentOutInterceptor.WRITE_ATTACHMENTS, Boolean.TRUE);
}
} else if (context != null) {
Boolean unwrapProperty = obj instanceof JAXBElement ? Boolean.FALSE : Boolean.TRUE;
getRequestContext().put("unwrap.jaxb.element", unwrapProperty);
}
QName opName = (QName)getRequestContext().get(MessageContext.WSDL_OPERATION);
boolean findDispatchOp = Boolean.TRUE.equals(getRequestContext().get("find.dispatch.operation"));
boolean hasOpName;
if (opName == null) {
hasOpName = false;
opName = isOneWay ? INVOKE_ONEWAY_QNAME : INVOKE_QNAME;
} else {
hasOpName = true;
BindingOperationInfo bop = client.getEndpoint().getBinding()
.getBindingInfo().getOperation(opName);
if (bop == null) {
addInvokeOperation(opName, isOneWay);
}
}
//CXF-2836 : find the operation for the dispatched object
// if findDispatchOp is already true, skip the addressing feature lookup.
// if the addressing feature is enabled, set findDispatchOp to true
if (!findDispatchOp) {
// the feature list to be searched is the endpoint and the bus's lists
List<Feature> endpointFeatures
= ((JaxWsClientEndpointImpl)client.getEndpoint()).getFeatures();
List<Feature> allFeatures;
if (client.getBus().getFeatures() != null) {
allFeatures = new ArrayList<Feature>(endpointFeatures.size()
+ client.getBus().getFeatures().size());
allFeatures.addAll(endpointFeatures);
allFeatures.addAll(client.getBus().getFeatures());
} else {
allFeatures = endpointFeatures;
}
for (Feature feature : allFeatures) {
if (feature instanceof WSAddressingFeature) {
findDispatchOp = true;
}
}
}
Map<String, QName> payloadOPMap = createPayloadEleOpNameMap(
client.getEndpoint().getBinding().getBindingInfo(), hasOpName);
if (findDispatchOp && !payloadOPMap.isEmpty()) {
QName payloadElementName = null;
if (obj instanceof javax.xml.transform.Source) {
XMLStreamReader reader = null;
try {
reader = StaxUtils.createXMLStreamReader((javax.xml.transform.Source)obj);
Document document = StaxUtils.read(reader);
createdSource = new StaxSource(StaxUtils.createXMLStreamReader(document));
payloadElementName = getPayloadElementName(document.getDocumentElement());
} catch (Exception e) {
// ignore, we are trying to get the operation name
} finally {
StaxUtils.close(reader);