Skip to content

Commit

Permalink
Fixed handling of methods which return "void". Reduced a couple log l…
Browse files Browse the repository at this point in the history
…evels.

git-svn-id: http://red5.googlecode.com/svn/java/server/trunk@4367 1b6495e4-3631-0410-8e05-8f51eee8b9cc
  • Loading branch information
mondain committed May 18, 2012
1 parent 4c905e3 commit 436438a
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 23 deletions.
6 changes: 3 additions & 3 deletions src/org/red5/server/net/rtmp/RTMPMinaIoHandler.java
Expand Up @@ -155,14 +155,14 @@ protected void rawBufferRecieved(IoBuffer in, IoSession session) {
/** {@inheritDoc} */
@Override
public void messageReceived(IoSession session, Object message) throws Exception {
log.debug("messageReceived");
log.trace("messageReceived");
if (message instanceof IoBuffer) {
rawBufferRecieved((IoBuffer) message, session);
} else {
log.debug("Setting connection local");
log.trace("Setting connection local");
Red5.setConnectionLocal((IConnection) session.getAttribute(RTMPConnection.RTMP_CONNECTION_KEY));
handler.messageReceived(message, session);
log.debug("Removing connection local");
log.trace("Removing connection local");
Red5.setConnectionLocal(null);
}
}
Expand Down
22 changes: 9 additions & 13 deletions src/org/red5/server/service/ServiceInvoker.java
Expand Up @@ -120,7 +120,7 @@ public boolean invoke(IServiceCall call, Object service) {
IConnection conn = Red5.getConnectionLocal();
String methodName = call.getServiceMethodName();
log.debug("Service: {} name: {} method: {}", new Object[] { service, call.getServiceName(), methodName });
//pull off the prefixes since java doesnt allow this on a method name
// pull off the prefixes since java doesnt allow this on a method name
if (methodName.charAt(0) == '@') {
log.debug("Method name contained an illegal prefix, it will be removed: {}", methodName);
methodName = methodName.substring(1);
Expand Down Expand Up @@ -177,21 +177,19 @@ public boolean invoke(IServiceCall call, Object service) {
if (method.isAnnotationPresent(DeclarePrivate.class)) {
// Method may not be called by clients.
log.debug("Method {} is declared private.", method);
throw new NotAllowedException("you are not allowed to execute this method");
throw new NotAllowedException("Access denied, method is private");
}

final DeclareProtected annotation = method.getAnnotation(DeclareProtected.class);
if (annotation != null) {
if (!conn.getClient().hasPermission(conn, annotation.permission())) {
// Client doesn't have required permission
// client doesn't have required permission
log.debug("Client {} doesn't have required permission {} to call {}", new Object[] { conn.getClient(), annotation.permission(), method });
throw new NotAllowedException("you are not allowed to execute this method");
throw new NotAllowedException("Access denied, method is protected");
}
}

log.debug("Invoking method: {}", method.toString());

if (method.getReturnType() == Void.class) {
if (method.getReturnType().equals(Void.TYPE)) {
log.debug("result: void");
method.invoke(service, params);
call.setStatus(Call.STATUS_SUCCESS_VOID);
} else {
Expand All @@ -216,16 +214,14 @@ public boolean invoke(IServiceCall call, Object service) {
call.setException(invocationEx);
call.setStatus(Call.STATUS_INVOCATION_EXCEPTION);
if (!(invocationEx.getCause() instanceof ClientDetailsException)) {
// Only log if not handled by client
log.error("Error executing call: {}", call);
log.error("Service invocation error", invocationEx);
// only log if not handled by client
log.error("Error executing call: {}", call, invocationEx);
}
return false;
} catch (Exception ex) {
call.setException(ex);
call.setStatus(Call.STATUS_GENERAL_EXCEPTION);
log.error("Error executing call: {}", call);
log.error("Service invocation error", ex);
log.error("Error executing call: {}", call, ex);
return false;
}
return true;
Expand Down
12 changes: 5 additions & 7 deletions src/org/red5/server/service/ServiceUtils.java
Expand Up @@ -65,8 +65,7 @@ public static Object[] findMethodWithExactParameters(Object service, String meth
int numParams = (args == null) ? 0 : args.length;
Method method = null;
try {
//try to skip the listing of all the methods by checking for exactly what
//we want first
//try to skip the listing of all the methods by checking for exactly what we want first
Class<?>[] params = ConversionUtils.convertParams(args);
if (log.isDebugEnabled()) {
for (Class<?> clazz : params) {
Expand All @@ -86,11 +85,10 @@ public static Object[] findMethodWithExactParameters(Object service, String meth
} else if (methods.size() == 1 && args == null) {
return new Object[] { methods.get(0), null };
} else if (methods.size() > 1) {
log.debug("Multiple methods found with same name and parameter count.");
log.debug("Parameter conversion will be attempted in order.");
log.debug("Multiple methods found with same name and parameter count. Parameter conversion will be attempted in order.");
}
Object[] params = null;
// First search for method with exact parameters
// search for method with exact parameters
for (int i = 0; i < methods.size(); i++) {
method = methods.get(i);
boolean valid = true;
Expand All @@ -105,13 +103,13 @@ public static Object[] findMethodWithExactParameters(Object service, String meth
return new Object[] { method, args };
}
}
// Then try to convert parameters
// try to convert parameters
for (int i = 0; i < methods.size(); i++) {
try {
method = methods.get(i);
params = ConversionUtils.convertParams(args, method.getParameterTypes());
if (args.length > 0 && (args[0] instanceof IConnection) && (!(params[0] instanceof IConnection))) {
// Don't convert first IConnection parameter
// don't convert first IConnection parameter
continue;
}
return new Object[] { method, params };
Expand Down

0 comments on commit 436438a

Please sign in to comment.