List of usage examples for org.springframework.jmx.access InvalidInvocationException InvalidInvocationException
public InvalidInvocationException(String msg)
From source file:org.springframework.jmx.access.MBeanClientInterceptor.java
/** * Route the invocation to the configured managed resource. Correctly routes JavaBean property * access to {@code MBeanServerConnection.get/setAttribute} and method invocation to * {@code MBeanServerConnection.invoke}. * @param invocation the {@code MethodInvocation} to re-route * @return the value returned as a result of the re-routed invocation * @throws Throwable an invocation error propagated to the user *//*www . java 2s . co m*/ @Nullable protected Object doInvoke(MethodInvocation invocation) throws Throwable { Method method = invocation.getMethod(); try { Object result; if (this.invocationHandler != null) { result = this.invocationHandler.invoke(invocation.getThis(), method, invocation.getArguments()); } else { PropertyDescriptor pd = BeanUtils.findPropertyForMethod(method); if (pd != null) { result = invokeAttribute(pd, invocation); } else { result = invokeOperation(method, invocation.getArguments()); } } return convertResultValueIfNecessary(result, new MethodParameter(method, -1)); } catch (MBeanException ex) { throw ex.getTargetException(); } catch (RuntimeMBeanException ex) { throw ex.getTargetException(); } catch (RuntimeErrorException ex) { throw ex.getTargetError(); } catch (RuntimeOperationsException ex) { // This one is only thrown by the JMX 1.2 RI, not by the JDK 1.5 JMX code. RuntimeException rex = ex.getTargetException(); if (rex instanceof RuntimeMBeanException) { throw ((RuntimeMBeanException) rex).getTargetException(); } else if (rex instanceof RuntimeErrorException) { throw ((RuntimeErrorException) rex).getTargetError(); } else { throw rex; } } catch (OperationsException ex) { if (ReflectionUtils.declaresException(method, ex.getClass())) { throw ex; } else { throw new InvalidInvocationException(ex.getMessage()); } } catch (JMException ex) { if (ReflectionUtils.declaresException(method, ex.getClass())) { throw ex; } else { throw new InvocationFailureException("JMX access failed", ex); } } catch (IOException ex) { if (ReflectionUtils.declaresException(method, ex.getClass())) { throw ex; } else { throw new MBeanConnectFailureException("I/O failure during JMX access", ex); } } }
From source file:org.springframework.jmx.access.MBeanClientInterceptor.java
@Nullable private Object invokeAttribute(PropertyDescriptor pd, MethodInvocation invocation) throws JMException, IOException { Assert.state(this.serverToUse != null, "No MBeanServerConnection available"); String attributeName = JmxUtils.getAttributeName(pd, this.useStrictCasing); MBeanAttributeInfo inf = this.allowedAttributes.get(attributeName); // If no attribute is returned, we know that it is not defined in the // management interface. if (inf == null) { throw new InvalidInvocationException( "Attribute '" + pd.getName() + "' is not exposed on the management interface"); }// w w w.j a v a2s . co m if (invocation.getMethod().equals(pd.getReadMethod())) { if (inf.isReadable()) { return this.serverToUse.getAttribute(this.objectName, attributeName); } else { throw new InvalidInvocationException("Attribute '" + attributeName + "' is not readable"); } } else if (invocation.getMethod().equals(pd.getWriteMethod())) { if (inf.isWritable()) { this.serverToUse.setAttribute(this.objectName, new Attribute(attributeName, invocation.getArguments()[0])); return null; } else { throw new InvalidInvocationException("Attribute '" + attributeName + "' is not writable"); } } else { throw new IllegalStateException( "Method [" + invocation.getMethod() + "] is neither a bean property getter nor a setter"); } }
From source file:org.springframework.jmx.access.MBeanClientInterceptor.java
/** * Routes a method invocation (not a property get/set) to the corresponding * operation on the managed resource.//from w w w .j a va 2 s . co m * @param method the method corresponding to operation on the managed resource. * @param args the invocation arguments * @return the value returned by the method invocation. */ private Object invokeOperation(Method method, Object[] args) throws JMException, IOException { Assert.state(this.serverToUse != null, "No MBeanServerConnection available"); MethodCacheKey key = new MethodCacheKey(method.getName(), method.getParameterTypes()); MBeanOperationInfo info = this.allowedOperations.get(key); if (info == null) { throw new InvalidInvocationException( "Operation '" + method.getName() + "' is not exposed on the management interface"); } String[] signature; synchronized (this.signatureCache) { signature = this.signatureCache.get(method); if (signature == null) { signature = JmxUtils.getMethodSignature(method); this.signatureCache.put(method, signature); } } return this.serverToUse.invoke(this.objectName, method.getName(), args, signature); }