List of usage examples for java.lang IllegalAccessException getCause
public synchronized Throwable getCause()
From source file:com.mani.cucumber.ReflectionUtils.java
/** * Uses reflection to set the value of the given property on the target * object.//from www .j a v a 2s . co m * * @param target the object to reflect on * @param field the name of the property to set * @param value the new value of the property */ private static void setValue(Object target, String field, Object value) { // TODO: Should we do this for all numbers, not just '0'? if ("0".equals(field)) { if (!(target instanceof Collection)) { throw new IllegalArgumentException("Cannot evaluate '0' on object " + target); } @SuppressWarnings("unchecked") Collection<Object> collection = (Collection<Object>) target; collection.add(value); } else { Method setter = findMethod(target, "set" + field, value.getClass()); try { setter.invoke(target, value); } catch (IllegalAccessException exception) { throw new IllegalStateException("Unable to access setter method", exception); } catch (InvocationTargetException exception) { if (exception.getCause() instanceof RuntimeException) { throw (RuntimeException) exception.getCause(); } throw new IllegalStateException("Checked exception thrown from setter method", exception); } } }
From source file:org.spring4gwt.server.RpcHelper.java
/** * Invoke the method on targeted object and encode received response. * * @param target the target object * @param serviceMethod the service method * @param args the args of method * @param serializationPolicy the serialization policy * @param flags the flags// ww w . j a va 2s. c om * @throws SerializationException the serialization exception */ public static String invokeAndEncodeResponse(Object target, Method serviceMethod, Object[] args, SerializationPolicy serializationPolicy, int flags) throws SerializationException { if (serviceMethod == null) { throw new NullPointerException("serviceMethod"); } if (serializationPolicy == null) { throw new NullPointerException("serializationPolicy"); } String responsePayload; try { Object result = serviceMethod.invoke(target, args); responsePayload = RPC.encodeResponseForSuccess(serviceMethod, result, serializationPolicy, flags); } catch (IllegalAccessException ex) { SecurityException securityException = new SecurityException( formatIllegalAccessErrorMessage(target, serviceMethod)); securityException.initCause(ex); throw securityException; } catch (IllegalArgumentException ex) { SecurityException securityException = new SecurityException( formatIllegalArgumentErrorMessage(target, serviceMethod, args)); securityException.initCause(ex); throw securityException; } catch (InvocationTargetException ex) { // Try to encode the caught exception // Throwable cause = ex.getCause(); LOG.error("Unexpected exception occured while invoking service method - " + serviceMethod.getName(), ex); responsePayload = RPC.encodeResponseForFailure(serviceMethod, cause, serializationPolicy, flags); } return responsePayload; }
From source file:org.apache.chemistry.opencmis.server.shared.Dispatcher.java
/** * Find the appropriate method an call it. * * @return/*from w w w . j a v a 2 s. c o m*/ * <code>true</code> if the method was found, * <code>false</code> otherwise. */ public boolean dispatch(String resource, String httpMethod, CallContext context, CmisService service, String repositoryId, HttpServletRequest request, HttpServletResponse response) { Method m = methodMap.get(getKey(resource, httpMethod)); if (m == null) { return false; } if (LOG.isDebugEnabled()) { LOG.debug(repositoryId + " / " + resource + ", " + httpMethod + " -> " + m.getName()); } try { m.invoke(null, context, service, repositoryId, request, response); } catch (IllegalAccessException e) { throw new CmisRuntimeException("Internal error!", e); } catch (InvocationTargetException e) { if (e.getCause() instanceof CmisBaseException) { throw (CmisBaseException) e.getCause(); } else { throw new CmisRuntimeException(e.getMessage(), e); } } return true; }
From source file:org.sipfoundry.sipxconfig.bulk.csv.Index.java
public String getProperty(Object bean) { try {/*from w w w .j a va 2 s . com*/ return BeanUtils.getProperty(bean, m_name); } catch (IllegalAccessException e) { throw new RuntimeException(e); } catch (InvocationTargetException e) { throw new RuntimeException(e.getCause()); } catch (NoSuchMethodException e) { throw new RuntimeException(e); } }
From source file:org.sipfoundry.sipxconfig.bulk.csv.Index.java
public void setProperty(Object bean, String[] row) { String value = get(row);// w w w. ja v a 2s. c o m if (value.length() == 0) { return; } try { BeanUtils.setProperty(bean, m_name, value); } catch (IllegalAccessException e) { throw new RuntimeException(e); } catch (InvocationTargetException e) { throw new RuntimeException(e.getCause()); } }
From source file:org.apache.sling.testing.mock.osgi.OsgiServiceUtil.java
private static void invokeMethod(Object target, Method method, Object[] args) { try {//ww w . j a v a 2 s . c om method.setAccessible(true); method.invoke(target, args); } catch (IllegalAccessException ex) { throw new RuntimeException( "Unable to invoke method '" + method.getName() + "' for class " + target.getClass().getName(), ex); } catch (IllegalArgumentException ex) { throw new RuntimeException( "Unable to invoke method '" + method.getName() + "' for class " + target.getClass().getName(), ex); } catch (InvocationTargetException ex) { throw new RuntimeException( "Unable to invoke method '" + method.getName() + "' for class " + target.getClass().getName(), ex.getCause()); } }
From source file:org.apache.qpid.disttest.client.MessageProvider.java
protected void setStandardProperty(Message message, String property, Object propertyValue) throws JMSException { String propertyName = "JMS" + StringUtils.capitalize(property); try {/*from ww w . j a va2s .c om*/ BeanUtils.setProperty(message, propertyName, propertyValue); } catch (IllegalAccessException e) { throw new DistributedTestException("Unable to set property " + propertyName + " :" + e.getMessage(), e); } catch (InvocationTargetException e) { if (e.getCause() instanceof JMSException) { throw ((JMSException) e.getCause()); } else { throw new DistributedTestException("Unable to set property " + propertyName + " :" + e.getMessage(), e); } } }
From source file:org.apache.struts.tiles.TilesUtilImpl.java
/** * Do an include using PageContext.include(). * * This method is used by the Tiles package when an include is required. * The Tiles package can use indifferently any form of this method. * @param uri Uri or Definition name to forward. * @param pageContext Current page context. * @param flush If the writer should be flushed before the include */// w w w. j av a2s.c om public void doInclude(String uri, PageContext pageContext, boolean flush) throws IOException, ServletException { try { // perform include with new JSP 2.0 method that supports flushing if (include != null) { include.invoke(pageContext, new Object[] { uri, Boolean.valueOf(flush) }); return; } } catch (IllegalAccessException e) { log.debug("Could not find JSP 2.0 include method. Using old one.", e); } catch (InvocationTargetException e) { if (e.getCause() instanceof ServletException) { throw ((ServletException) e.getCause()); } else if (e.getCause() instanceof IOException) { throw ((IOException) e.getCause()); } else { throw new ServletException(e); } } pageContext.include(uri); }
From source file:nu.staldal.lsp.wrapper.ReadonlyBeanMap.java
public Object get(Object key) { Member member = getMember((String) key); if (member == null) { return null; }/*from ww w . ja va2s.c o m*/ try { if (member instanceof Method) { return ((Method) member).invoke(bean); } else if (member instanceof Field) { return ((Field) member).get(bean); } else { throw new Error("Unknown Member: " + member.getClass().getName()); } } catch (IllegalAccessException e) { throw new RuntimeException(e); } catch (IllegalArgumentException e) { throw new RuntimeException(e); } catch (InvocationTargetException e) { Throwable ee = e.getCause(); if (ee instanceof RuntimeException) { throw (RuntimeException) ee; } else { throw new RuntimeException(ee); } } }
From source file:org.echocat.jomon.spring.BeanProvider.java
@Nonnull protected <T> T createInstanceOf(@Nonnull Class<T> type) { try {/*from w ww . j a v a 2 s. co m*/ return type.newInstance(); } catch (final IllegalAccessException e) { throw new RuntimeException("Could not create new instance of " + type.getName() + ".", e); } catch (final InstantiationException e) { final Throwable cause = e.getCause(); if (cause instanceof RuntimeException) { //noinspection ThrowInsideCatchBlockWhichIgnoresCaughtException throw (RuntimeException) cause; } else if (cause instanceof Error) { //noinspection ThrowInsideCatchBlockWhichIgnoresCaughtException throw (Error) cause; } else { throw new RuntimeException("Could not create new instance of " + type.getName() + ".", cause != null ? cause : e); } } }