From 436438a262b80a6408adc23e53660dd853c98193 Mon Sep 17 00:00:00 2001 From: mondain Date: Fri, 18 May 2012 15:27:38 +0000 Subject: [PATCH] Fixed handling of methods which return "void". Reduced a couple log levels. git-svn-id: http://red5.googlecode.com/svn/java/server/trunk@4367 1b6495e4-3631-0410-8e05-8f51eee8b9cc --- .../server/net/rtmp/RTMPMinaIoHandler.java | 6 ++--- .../red5/server/service/ServiceInvoker.java | 22 ++++++++----------- src/org/red5/server/service/ServiceUtils.java | 12 +++++----- 3 files changed, 17 insertions(+), 23 deletions(-) diff --git a/src/org/red5/server/net/rtmp/RTMPMinaIoHandler.java b/src/org/red5/server/net/rtmp/RTMPMinaIoHandler.java index 454f37a5..a67e627a 100644 --- a/src/org/red5/server/net/rtmp/RTMPMinaIoHandler.java +++ b/src/org/red5/server/net/rtmp/RTMPMinaIoHandler.java @@ -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); } } diff --git a/src/org/red5/server/service/ServiceInvoker.java b/src/org/red5/server/service/ServiceInvoker.java index ad1cf107..ff349a8f 100644 --- a/src/org/red5/server/service/ServiceInvoker.java +++ b/src/org/red5/server/service/ServiceInvoker.java @@ -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); @@ -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 { @@ -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; diff --git a/src/org/red5/server/service/ServiceUtils.java b/src/org/red5/server/service/ServiceUtils.java index 669aabf7..f34da88f 100644 --- a/src/org/red5/server/service/ServiceUtils.java +++ b/src/org/red5/server/service/ServiceUtils.java @@ -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) { @@ -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; @@ -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 };