private Object doIntercept(final Method method, final Object[] objects, final MethodProxy methodProxy) throws Throwable {
final int index = methodProxy.getSuperIndex();
final OperationInfo operationInfo = operations[index];
if (operationInfo == null) {
throw new ServerRuntimeException("Operation not mapped: " + method.getName() + " index: " + index + "\n OperationInfos: " + Arrays.asList(operations));
}
stub.checkCachedEndpoint();
final Call call = stub.createCall();
operationInfo.prepareCall(call);
stub.setUpCall(call);
if (credentialsName != null) {
throw new UnsupportedOperationException("Client side auth is not implementd");
// Subject subject = ContextManager.getNextCaller();
// 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;
final List parameterDescs = operationInfo.getOperationDesc().getParameters();
final Object[] unwrapped = extractFromHolders(objects, parameterDescs, operationInfo.getOperationDesc().getNumInParams());
if (operationInfo.getOperationDesc().getMep() == OperationType.REQUEST_RESPONSE) {
try {
response = call.invoke(unwrapped);
} catch (final RemoteException e) {
throw operationInfo.unwrapFault(e);
}
if (response instanceof RemoteException) {
throw operationInfo.unwrapFault((RemoteException) response);
} else {
stub.extractAttachments(call);
final Map outputParameters = call.getOutputParams();
putInHolders(outputParameters, objects, parameterDescs);
final 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 ServerRuntimeException("Invalid messaging style: " + operationInfo.getOperationDesc().getMep());
}
}