if (operationInfo == null) {
throw new RuntimeException("Operation not mapped: " + method.getName() + " index: " + index + "\n OperationInfos: " + Arrays.asList(operations));
}
stub.checkCachedEndpoint();
Call call = stub.createCall();
operationInfo.prepareCall(call);
stub.setUpCall(call);
if (credentialsName != null) {
Subject subject = ContextManager.getCurrentCaller();
if (subject == null) {
throw new IllegalStateException("Subject missing but authentication turned on");
} else {
Set creds = subject.getPrivateCredentials(NamedUsernamePasswordCredential.class);
boolean found = false;
for (Iterator iterator = creds.iterator(); iterator.hasNext();) {
NamedUsernamePasswordCredential namedUsernamePasswordCredential = (NamedUsernamePasswordCredential) iterator.next();
if (credentialsName.equals(namedUsernamePasswordCredential.getName())) {
call.setUsername(namedUsernamePasswordCredential.getUsername());
call.setPassword(new String(namedUsernamePasswordCredential.getPassword()));
found = true;
break;
}
}
if (!found) {
throw new IllegalStateException("no NamedUsernamePasswordCredential found for name " + credentialsName);
}
}
}
Object response = null;
List parameterDescs = operationInfo.getOperationDesc().getParameters();
Object[] unwrapped = extractFromHolders(objects, parameterDescs, operationInfo.getOperationDesc().getNumInParams());
if (operationInfo.getOperationDesc().getMep() == OperationType.REQUEST_RESPONSE) {
try {
response = call.invoke(unwrapped);
} catch (RemoteException e) {
throw operationInfo.unwrapFault(e);
}
if (response instanceof RemoteException) {
throw operationInfo.unwrapFault((RemoteException) response);
} else {
stub.extractAttachments(call);
Map outputParameters = call.getOutputParams();
putInHolders(outputParameters, objects, parameterDescs);
Class returnType = operationInfo.getOperationDesc().getReturnClass();
//return type should never be null... but we are not objecting if wsdl-return-value-mapping is not set.
if (response == null || returnType == null || returnType.isAssignableFrom(response.getClass())) {
return response;
} else {
return JavaUtils.convert(response, returnType);
}
}
} else if (operationInfo.getOperationDesc().getMep() == OperationType.ONE_WAY) {
//one way
call.invokeOneWay(unwrapped);
return null;
} else {
throw new RuntimeException("Invalid messaging style: " + operationInfo.getOperationDesc().getMep());
}
}