Abstract implementation of Invoker.
| Method from org.apache.cxf.service.invoker.AbstractInvoker Detail: |
protected Fault createFault(Throwable ex,
Method m,
List params,
boolean checked) {
if (checked) {
return new Fault(ex);
} else {
return new Fault(new Message("EXCEPTION_INVOKING_OBJECT",
LOG,
ex.getMessage(), m.toString(), params),
ex);
}
}
|
public static Method getMostSpecificMethod(Method method,
Class targetClass) {
if (method != null && targetClass != null) {
try {
method = targetClass.getMethod(method.getName(), method.getParameterTypes());
} catch (NoSuchMethodException ex) {
// Perhaps the target class doesn't implement this method:
// that's fine, just use the original method
}
}
return method;
}
Given a method, which may come from an interface, and a targetClass used
in the current AOP invocation, find the most specific method if there is
one. E.g. the method may be IFoo.bar() and the target class may be
DefaultFoo. In this case, the method may be DefaultFoo.bar(). This
enables attributes on that method to be found. |
abstract public Object getServiceObject(Exchange context)
Creates and returns a service object depending on the scope. |
public Object[] insertExchange(Method method,
Object[] params,
Exchange context) {
Object[] newParams = params;
for (int i = 0; i < method.getParameterTypes().length; i++) {
if (method.getParameterTypes()[i].equals(Exchange.class)) {
newParams = new Object[params.length + 1];
for (int j = 0; j < newParams.length; j++) {
if (j == i) {
newParams[j] = context;
} else if (j > i) {
newParams[j] = params[j - 1];
} else {
newParams[j] = params[j];
}
}
}
}
return newParams;
}
|
public Object invoke(Exchange exchange,
Object o) {
final Object serviceObject = getServiceObject(exchange);
try {
BindingOperationInfo bop = exchange.get(BindingOperationInfo.class);
MethodDispatcher md = (MethodDispatcher)
exchange.get(Service.class).get(MethodDispatcher.class.getName());
Method m = md.getMethod(bop);
//Method m = (Method)bop.getOperationInfo().getProperty(Method.class.getName());
m = matchMethod(m, serviceObject);
List< Object > params = null;
if (o instanceof List) {
params = CastUtils.cast((List< ? >)o);
} else if (o != null) {
params = new MessageContentsList(o);
}
return invoke(exchange, serviceObject, m, params);
} finally {
releaseServiceObject(exchange, serviceObject);
}
}
|
protected Object invoke(Exchange exchange,
Object serviceObject,
Method m,
List params) {
Object res;
try {
Object[] paramArray = new Object[]{};
if (params != null) {
paramArray = params.toArray();
}
res = performInvocation(exchange, serviceObject, m, paramArray);
if (exchange.isOneWay()) {
return null;
}
return new MessageContentsList(res);
} catch (InvocationTargetException e) {
Throwable t = e.getCause();
if (t == null) {
t = e;
}
exchange.getInMessage().put(FaultMode.class, FaultMode.UNCHECKED_APPLICATION_FAULT);
for (Class< ? > cl : m.getExceptionTypes()) {
if (cl.isInstance(t)) {
exchange.getInMessage().put(FaultMode.class,
FaultMode.CHECKED_APPLICATION_FAULT);
}
}
if (t instanceof Fault) {
exchange.getInMessage().put(FaultMode.class,
FaultMode.CHECKED_APPLICATION_FAULT);
throw (Fault)t;
}
throw createFault(t, m, params, true);
} catch (Fault f) {
exchange.getInMessage().put(FaultMode.class, FaultMode.UNCHECKED_APPLICATION_FAULT);
throw f;
} catch (Exception e) {
exchange.getInMessage().put(FaultMode.class, FaultMode.UNCHECKED_APPLICATION_FAULT);
throw createFault(e, m, params, false);
}
}
|
public static boolean isJdkDynamicProxy(Object object) {
return object != null && Proxy.isProxyClass(object.getClass());
}
Return whether the given object is a J2SE dynamic proxy. |
protected Object performInvocation(Exchange exchange,
Object serviceObject,
Method m,
Object[] paramArray) throws Exception {
paramArray = insertExchange(m, paramArray, exchange);
if (LOG.isLoggable(Level.FINER)) {
LOG.log(Level.FINER, "INVOKING_METHOD", new Object[] {serviceObject,
m,
Arrays.asList(paramArray)});
}
return m.invoke(serviceObject, paramArray);
}
|
public void releaseServiceObject(Exchange context,
Object obj) {
}
Called when the invoker is done with the object. Default implementation
does nothing. |