All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.gkutiel.flip.web.MethodInvokerCatchAll Maven / Gradle / Ivy

package com.github.gkutiel.flip.web;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.github.gkutiel.flip.web.Flipper.RedirectException;

class MethodInvokerCatchAll extends MethodInvoker {

	private final String[] args;

	MethodInvokerCatchAll(final Class clazz, final Method method, final String[] args) {
		super(clazz, method);
		this.args = args;
	}

	@Override
	Object invoke(final HttpServletRequest req, final HttpServletResponse res) {
		try {
			final Class[] parameterTypes = this.method.getParameterTypes();
			final Object[] actualParams = new Object[parameterTypes.length];
			for (int i = 0; i < actualParams.length; i++)
				actualParams[i] = ParseParamService.parse(parameterTypes[i], this.args[i]);
			final Object instance = super.getInstance(req, res);
			return this.method.invoke(instance, actualParams);
		} catch (IllegalAccessException | IllegalArgumentException e) {
			throw new RuntimeException(e);
		} catch (final InvocationTargetException e) {
			final Throwable cause = e.getCause();
			if (cause instanceof RedirectException) throw (RedirectException) cause;
			throw new RuntimeException(cause);
		}
	}

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy