从jboss seam调用私有方法

时间:2013-05-29 03:48:20

标签: java reflection jboss-seam

我想从Servlet类调用Seam组件私有方法。我使用servlet类作为ContextualHttpServletRequest,因此我可以访问组件bean。检查代码示例。

protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException,
        IOException {
    String userId = "U00001";
    String userGroupCd = "00000000";
    FacesContext facesContext = null;
    try {
        facesContext = getFacesContext(request, response);
    } catch (Exception e) {
        e.printStackTrace();
    }
    loginUtility = (ClientUtility) Component.getInstance("utility");
    Method clientInfoMethod = null;
    try {
        clientInfoMethod = getDeclaredMethod(loginUtility, "createClientInfo", String.class, String.class);
        clientInfoMethod.setAccessible(true);
        clientInfoMethod.invoke(loginUtility, userId, userGroupCd);

    } catch (IllegalArgumentException e1) {
        // TODO 自動生成された catch ブロック
        e1.printStackTrace();
    } catch (SecurityException e1) {
        // TODO 自動生成された catch ブロック
        e1.printStackTrace();
    } catch (IllegalAccessException e1) {
        // TODO 自動生成された catch ブロック
        e1.printStackTrace();
    } catch (InvocationTargetException e1) {
        // TODO 自動生成された catch ブロック
        e1.printStackTrace();
        // } catch (NoSuchMethodException e1) {
        // // TODO 自動生成された catch ブロック
        // e1.printStackTrace();
    } finally {
        clientInfoMethod.setAccessible(false);
    }
}

private <T extends Object> Method getDeclaredMethod(T obj, String name, Class<?>... parameters) {
    Method declaredMethod = null;
    Method[] methods = Component.forName("loginUtility").getBeanClass().getDeclaredMethods();
    for (Method var : methods) {
        if (var.getName().contains(name) && parameters.length == var.getParameterTypes().length) {
            declaredMethod = var;
            return declaredMethod;
        }
    }
    return declaredMethod;
}

接缝组件结构如下:

@Name("utility")
@Scope(ScopeType.SESSION)
public class ClientUtility implements IfFlowUtility, Serializable {
  private void createClientInfo(String userId, String userGroupCd) {

    InternalClientInfo info = (InternalClientInfo) Contexts.getSessionContext().get(SESSION_KEY_CLIENT_INFO);
    if (info == null) {
        info = new InternalClientInfo();
    }

    info.setUserId(userId);
    info.setUserGroupCd(userGroupCd);

    HttpServletRequestUtil util = new HttpServletRequestUtil();
    info.setClientINetAddr(util.getClientINetAddr());
    HttpSession session = util.getSession();

    Conversation conv = (Conversation) Contexts.getConversationContext().get(CONTEXT_NAME_CONVERSATION);

    if (conv != null) {
        info.setConvasationId(conv.getId());
        info.setViewName(conv.getViewId());

    }

    info.setSessionId(session.getId());
    info.setAuthToken(loginStatusManager.getAuthToken(userId, userGroupCd));
    this.setSessionId(info.getSessionId());
    this.clientInfo = info;
    this.accessor.setSessionAttribute(SESSION_KEY_CLIENT_INFO, clientInfo);
  }
}  

但是当调用clientInfoMethod.invoke()方法时出现以下错误:

2013-05-29 00:20:45,921 ERROR [STDERR] (http-127.0.0.1-8080-1) java.lang.reflect.InvocationTargetException
2013-05-29 00:20:45,921 ERROR [STDERR] (http-127.0.0.1-8080-1)  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
2013-05-29 00:20:45,921 ERROR [STDERR] (http-127.0.0.1-8080-1)  at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
2013-05-29 00:20:45,921 ERROR [STDERR] (http-127.0.0.1-8080-1)  at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
2013-05-29 00:20:45,921 ERROR [STDERR] (http-127.0.0.1-8080-1)  at java.lang.reflect.Method.invoke(Method.java:597)
2013-05-29 00:20:45,921 ERROR [STDERR] (http-127.0.0.1-8080-1)  at jp.co.dirbi.fast.front.comon.servlet.CommonSsoInit.processRequest(CommonSsoInit.java:73)
2013-05-29 00:20:45,921 ERROR [STDERR] (http-127.0.0.1-8080-1)  at jp.co.dirbi.fast.front.comon.servlet.AbstractFacesServlet$1.process(AbstractFacesServlet.java:48)
2013-05-29 00:20:45,921 ERROR [STDERR] (http-127.0.0.1-8080-1)  at org.jboss.seam.servlet.ContextualHttpServletRequest.run(ContextualHttpServletRequest.java:53)
2013-05-29 00:20:45,921 ERROR [STDERR] (http-127.0.0.1-8080-1)  at jp.co.dirbi.fast.front.comon.servlet.AbstractFacesServlet.service(AbstractFacesServlet.java:50)
2013-05-29 00:20:45,921 ERROR [STDERR] (http-127.0.0.1-8080-1)  at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
2013-05-29 00:20:45,921 ERROR [STDERR] (http-127.0.0.1-8080-1)  at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
2013-05-29 00:20:45,921 ERROR [STDERR] (http-127.0.0.1-8080-1)  at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
2013-05-29 00:20:45,921 ERROR [STDERR] (http-127.0.0.1-8080-1)  at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:83)
2013-05-29 00:20:45,921 ERROR [STDERR] (http-127.0.0.1-8080-1)  at jp.co.dirbi.falcon.online.component.web.seam.SystemFilter.doFilter(SystemFilter.java:253)
2013-05-29 00:20:45,921 ERROR [STDERR] (http-127.0.0.1-8080-1)  at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
2013-05-29 00:20:45,921 ERROR [STDERR] (http-127.0.0.1-8080-1)  at org.jboss.seam.web.IdentityFilter.doFilter(IdentityFilter.java:40)
2013-05-29 00:20:45,921 ERROR [STDERR] (http-127.0.0.1-8080-1)  at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
2013-05-29 00:20:45,921 ERROR [STDERR] (http-127.0.0.1-8080-1)  at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:73)
2013-05-29 00:20:45,921 ERROR [STDERR] (http-127.0.0.1-8080-1)  at org.jboss.seam.web.ExceptionFilter.doFilter(ExceptionFilter.java:64)
2013-05-29 00:20:45,921 ERROR [STDERR] (http-127.0.0.1-8080-1)  at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
2013-05-29 00:20:45,921 ERROR [STDERR] (http-127.0.0.1-8080-1)  at org.jboss.seam.web.RedirectFilter.doFilter(RedirectFilter.java:45)
2013-05-29 00:20:45,921 ERROR [STDERR] (http-127.0.0.1-8080-1)  at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
2013-05-29 00:20:45,921 ERROR [STDERR] (http-127.0.0.1-8080-1)  at org.jboss.seam.web.ContextFilter$1.process(ContextFilter.java:42)
2013-05-29 00:20:45,921 ERROR [STDERR] (http-127.0.0.1-8080-1)  at org.jboss.seam.servlet.ContextualHttpServletRequest.run(ContextualHttpServletRequest.java:53)
2013-05-29 00:20:45,921 ERROR [STDERR] (http-127.0.0.1-8080-1)  at org.jboss.seam.web.ContextFilter.doFilter(ContextFilter.java:37)
2013-05-29 00:20:45,921 ERROR [STDERR] (http-127.0.0.1-8080-1)  at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
2013-05-29 00:20:45,921 ERROR [STDERR] (http-127.0.0.1-8080-1)  at org.ajax4jsf.webapp.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:178)
2013-05-29 00:20:45,921 ERROR [STDERR] (http-127.0.0.1-8080-1)  at org.ajax4jsf.webapp.BaseFilter.handleRequest(BaseFilter.java:290)
2013-05-29 00:20:45,921 ERROR [STDERR] (http-127.0.0.1-8080-1)  at org.ajax4jsf.webapp.BaseFilter.processUploadsAndHandleRequest(BaseFilter.java:390)
2013-05-29 00:20:45,921 ERROR [STDERR] (http-127.0.0.1-8080-1)  at org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:517)
2013-05-29 00:20:45,921 ERROR [STDERR] (http-127.0.0.1-8080-1)  at org.jboss.seam.web.Ajax4jsfFilter.doFilter(Ajax4jsfFilter.java:56)
2013-05-29 00:20:45,921 ERROR [STDERR] (http-127.0.0.1-8080-1)  at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
2013-05-29 00:20:45,921 ERROR [STDERR] (http-127.0.0.1-8080-1)  at org.jboss.seam.web.LoggingFilter.doFilter(LoggingFilter.java:60)
2013-05-29 00:20:45,921 ERROR [STDERR] (http-127.0.0.1-8080-1)  at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
2013-05-29 00:20:45,921 ERROR [STDERR] (http-127.0.0.1-8080-1)  at org.jboss.seam.web.HotDeployFilter.doFilter(HotDeployFilter.java:53)
2013-05-29 00:20:45,921 ERROR [STDERR] (http-127.0.0.1-8080-1)  at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
2013-05-29 00:20:45,921 ERROR [STDERR] (http-127.0.0.1-8080-1)  at org.jboss.seam.servlet.SeamFilter.doFilter(SeamFilter.java:158)
2013-05-29 00:20:45,921 ERROR [STDERR] (http-127.0.0.1-8080-1)  at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
2013-05-29 00:20:45,921 ERROR [STDERR] (http-127.0.0.1-8080-1)  at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
2013-05-29 00:20:45,921 ERROR [STDERR] (http-127.0.0.1-8080-1)  at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
2013-05-29 00:20:45,921 ERROR [STDERR] (http-127.0.0.1-8080-1)  at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
2013-05-29 00:20:45,921 ERROR [STDERR] (http-127.0.0.1-8080-1)  at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
2013-05-29 00:20:45,921 ERROR [STDERR] (http-127.0.0.1-8080-1)  at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:235)
2013-05-29 00:20:45,921 ERROR [STDERR] (http-127.0.0.1-8080-1)  at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
2013-05-29 00:20:45,921 ERROR [STDERR] (http-127.0.0.1-8080-1)  at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:190)
2013-05-29 00:20:45,921 ERROR [STDERR] (http-127.0.0.1-8080-1)  at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:433)
2013-05-29 00:20:45,921 ERROR [STDERR] (http-127.0.0.1-8080-1)  at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:92)
2013-05-29 00:20:45,921 ERROR [STDERR] (http-127.0.0.1-8080-1)  at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.process(SecurityContextEstablishmentValve.java:126)
2013-05-29 00:20:45,921 ERROR [STDERR] (http-127.0.0.1-8080-1)  at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.invoke(SecurityContextEstablishmentValve.java:70)
2013-05-29 00:20:45,921 ERROR [STDERR] (http-127.0.0.1-8080-1)  at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
2013-05-29 00:20:45,921 ERROR [STDERR] (http-127.0.0.1-8080-1)  at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
2013-05-29 00:20:45,921 ERROR [STDERR] (http-127.0.0.1-8080-1)  at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:158)
2013-05-29 00:20:45,921 ERROR [STDERR] (http-127.0.0.1-8080-1)  at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
2013-05-29 00:20:45,921 ERROR [STDERR] (http-127.0.0.1-8080-1)  at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:330)
2013-05-29 00:20:45,921 ERROR [STDERR] (http-127.0.0.1-8080-1)  at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:829)
2013-05-29 00:20:45,921 ERROR [STDERR] (http-127.0.0.1-8080-1)  at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:598)
2013-05-29 00:20:45,921 ERROR [STDERR] (http-127.0.0.1-8080-1)  at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
2013-05-29 00:20:45,921 ERROR [STDERR] (http-127.0.0.1-8080-1)  at java.lang.Thread.run(Thread.java:662)
2013-05-29 00:20:45,921 ERROR [STDERR] (http-127.0.0.1-8080-1) Caused by: java.lang.NullPointerException
2013-05-29 00:20:45,921 ERROR [STDERR] (http-127.0.0.1-8080-1)  at jp.co.dirbi.falcon.online.component.authenticate.LoginUtility.createClientInfo(LoginUtility.java:794)
2013-05-29 00:20:45,921 ERROR [STDERR] (http-127.0.0.1-8080-1)  ... 57 more

任何人都可以帮助我或提出一些建议吗?

0 个答案:

没有答案