I have a problem with reflection.
The very essence: there is a bunch of methods in the class. I find it necessary this way (it's all good here):
invokingMethod = InstanceClass.getMethod(AMethodName, AArgumentTypes);
Then I want to call him:
result = invokingMethod.invoke(AInstance, AArgumentObjects);
The number of parameters can be different. Here, simply calling the authorization method and therefore only two parameters
Signature of the method:
public abstract long userLogin(java.lang.String,java.lang.String)
Content AArgumentsTypes:
Content AArgumentObjects:
And as a result I have an error about the wrong type of parameters passed.
Works only if you explicitly pass all parameters to a function. Or I use AArgumentObjects[1] in the debug menu variable (if I change it in the code, the errors remain):
After calling from the code with AArgumentObjects[1]:
Discharges : "java.lang.IllegalArgumentException"
24-Jul-2017 14:21:08.444 SEVERE [http-nio-8081-exec-3] ru.nahodka.general.Reflection.TReflexiveClassUtils.invokeMethod java.lang.IllegalArgumentException: wrong number of arguments
24-Jul-2017 14:21:08.444 INFO [http-nio-8081-exec-3] org.directwebremoting.log.accessLog.writeExceptionToAccessLog Method execution failed:
ru.nahodka.Applications.WebApplication.TCustomizableWebApplicationAbstractBothPart$WebServiceMethodInvokedException: Не удалось произвести вызов функции UserLogin в интерфейсе ru.nahodka.Family.Constants.FamilyClientMainInterfaceConstants.FamilyIntf. Код ошибки rwsrProcedureSuccess.
at ru.nahodka.ISUpravlenie.Implementation.ClientPart.MainInterfaceServiceInvoker.ControlLowLevelMainFunctionalClass.UserLogin(ControlLowLevelMainFunctionalClass.java:118)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at ru.nahodka.general.Reflection.TReflexiveUtils.InvokeMethodWithParameters(TReflexiveUtils.java:729)
at ru.nahodka.ISUpravlenie.Implementation.ClientPart.AbstractFunctional.ControlHighLevelAbstractFunctionalClientClass.getLowLevelMethodInvokeResult(ControlHighLevelAbstractFunctionalClientClass.java:170)
at ru.nahodka.ISUpravlenie.Implementation.ClientPart.MainInterfaceServiceInvoker.ControlHighLevelMainFunctionalClass.UserLogin(ControlHighLevelMainFunctionalClass.java:208)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.directwebremoting.impl.CreatorModule$1.doFilter(CreatorModule.java:178)
at org.directwebremoting.impl.CreatorModule.executeMethod(CreatorModule.java:184)
at org.directwebremoting.impl.DefaultRemoter.execute(DefaultRemoter.java:353)
at org.directwebremoting.impl.DefaultRemoter.execute(DefaultRemoter.java:306)
at org.directwebremoting.dwrp.BaseCallHandler.handle(BaseCallHandler.java:110)
at org.directwebremoting.servlet.UrlProcessor.handle(UrlProcessor.java:211)
at org.directwebremoting.servlet.UrlProcessor.handle(UrlProcessor.java:185)
at org.directwebremoting.servlet.DwrServlet.doPost(DwrServlet.java:144)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:648)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:292)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:212)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:94)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:504)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:141)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:620)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:502)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1132)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:684)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1533)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1489)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:748)
我以这种方式解决了问题,谢谢大家:
result = invokingMethod.invoke(AInstance, ((Object[])AArgumentObjects[1]));
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.