IllegalArgumentException在servlet中调用EJB

时间:2016-02-16 05:55:53

标签: java servlets java-ee glassfish ejb

我有一个带有EJB模块和WAR模块的企业应用程序。在EJB模块中,我有一个用于执行基本启动/关闭过程(套接字连接等)的单例:

@Singleton
@Startup
public class ExecutionBean {
  @EJB
  private TServerLocal tServer;
  @PostConstruct
  private void atStartup() {
    this.startup();
  }
  @PreDestroy
  private void atShutdown() {
    this.shutdown();
  }
  public void startup() {
    [...]
  }
  public void shutdown() {
    [...]
  } 
}

在WAR模块中,我可以使用一组servlet来关闭,启动和重启应用程序,只需调用ExecutionBean的shutdown和startup方法,如下所示:

public class shutdown extends HttpServlet {
  @EJB
  private ExecutionBean execBean;

  protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    response.setContentType("text/html;charset=UTF-8");
    try (PrintWriter out = response.getWriter()) {
      out.println("<!DOCTYPE html>");
      out.println("<html>");
      out.println("<head>");
      out.println("<title>Servlet shutdown</title>");      
      out.println("</head>");
      out.println("<body>");
      execBean.shutdown();
      out.println("shutdown done");
      out.println("</body>");
      out.println("</html>");
    }
  }
  [...]
}

有时,经过一些部署周期(使用热部署或取消部署和部署,无关紧要),glassfish开始将我的servlet标记为不可用,并出现此类错误:

[2016-02-16T02:29:30.201-0300] [glassfish 4.0] [WARNING] [] [javax.enterprise.web] [tid: _ThreadID=22 _ThreadName=http-listener-1(3)] [timeMillis: 1455600570201] [levelValue: 900] [[
  StandardWrapperValve[shutdown]: Allocate exception for servlet shutdown
java.lang.IllegalArgumentException: Can not set com.tecytal.tyterisk.ExecutionBean field com.tecytal.tyterisk.servlets.shutdown.execBean to com.tecytal.tyterisk.servlets.shutdown
    at sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:167)
    at sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:171)
    at sun.reflect.UnsafeFieldAccessorImpl.ensureObj(UnsafeFieldAccessorImpl.java:58)
    at sun.reflect.UnsafeObjectFieldAccessorImpl.set(UnsafeObjectFieldAccessorImpl.java:75)
    at java.lang.reflect.Field.set(Field.java:764)
    at com.sun.enterprise.container.common.impl.util.InjectionManagerImpl._inject(InjectionManagerImpl.java:665)
    at com.sun.enterprise.container.common.impl.util.InjectionManagerImpl.inject(InjectionManagerImpl.java:484)
    at com.sun.enterprise.container.common.impl.util.InjectionManagerImpl.injectInstance(InjectionManagerImpl.java:141)
    at com.sun.enterprise.container.common.impl.util.InjectionManagerImpl.injectInstance(InjectionManagerImpl.java:127)
    at com.sun.enterprise.container.common.impl.util.InjectionManagerImpl.createManagedObject(InjectionManagerImpl.java:324)
    at com.sun.enterprise.web.WebContainer.createServletInstance(WebContainer.java:983)
    at com.sun.enterprise.web.WebModule.createServletInstance(WebModule.java:2130)
    at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1404)
    at org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:1211)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:237)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:160)
    at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:734)
    at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:673)
    at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:99)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:174)
    at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:357)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:260)
    at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:188)
    at org.glassfish.grizzly.http.server.HttpHandler.runService(HttpHandler.java:191)
    at org.glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.java:168)
    at org.glassfish.grizzly.http.server.HttpServerFilter.handleRead(HttpServerFilter.java:189)
    at org.glassfish.grizzly.filterchain.ExecutorResolver$9.execute(ExecutorResolver.java:119)
    at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:288)
    at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:206)
    at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:136)
    at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:114)
    at org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:77)
    at org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:838)
    at org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:113)
    at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(WorkerThreadIOStrategy.java:115)
    at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access$100(WorkerThreadIOStrategy.java:55)
    at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy$WorkerThreadRunnable.run(WorkerThreadIOStrategy.java:135)
    at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:564)
    at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:544)
    at java.lang.Thread.run(Thread.java:745)

如果我重新开始使用glassfish,那么就能正常工作。 这个错误对我来说没有意义,execBean不是一个字段,我不是设置任何东西,只调用一个方法。我做了一些非法的事情,所以在一些执行玻璃鱼疯了之后调用reflect.Field.set,或者这是一个知道错误?我的代码中有什么“奇怪的”证明这种行为吗? 我在论坛等搜索过,但我什么都没找到。

0 个答案:

没有答案