rubenlagus / TelegramBots

Java library to create bots using Telegram Bots API
https://telegram.me/JavaBotsApi
MIT License
4.68k stars 1.18k forks source link

Strange Exception including the jar in a Spring MVC Project #32

Closed montalbano closed 8 years ago

montalbano commented 8 years ago

Hi, I'm developing a Spring MVC Application and I have included your library in my POM with Maven:

<dependency>
  <groupId>com.github.rubenlagus</groupId>
  <artifactId>TelegramBots</artifactId>
  <version>v1.0</version>
  <type>jar</type>
</dependency>

It works fine (I tested sendMessage and LongPolling), but I have a very strange behavior when glassfish hot redeploy my application after a manual save to apply a code modification in my java classes. This is the stacktrace of the exception:

Warning:   Error invoking requestInitialized method on ServletRequestListener org.jboss.weld.servlet.WeldListener
org.jboss.weld.exceptions.IllegalStateException: WELD-000227: Bean identifier index inconsistency detected - the distributed container probably does not work with identical applications
Expected hash: 422265265
Current index: BeanIdentifierIndex [hash=-141639221, indexed=20]:
   0: WELD%AbstractBuiltInBean%WEB-INF/lib/hk2-api-2.4.0-b31%HttpSession
   1: WELD%AbstractBuiltInBean%WEB-INF/lib/hk2-locator-2.4.0-b31%HttpSession
   2: WELD%AbstractBuiltInBean%WEB-INF/lib/jersey-common-2.22.1%HttpSession
   3: WELD%AbstractBuiltInBean%WEB-INF/lib/jersey-entity-filtering-2.22.1%HttpSession
   4: WELD%AbstractBuiltInBean%WEB-INF/lib/jersey-media-jaxb-2.22.1%HttpSession
   5: WELD%AbstractBuiltInBean%WEB-INF/lib/jersey-media-json-jackson-2.22.1%HttpSession
   6: WELD%AbstractBuiltInBean%WEB-INF/lib/jersey-server-2.22.1%HttpSession
   7: WELD%AbstractBuiltInBean%acceleratori%HttpSession
   8: WELD%AbstractBuiltInBean%com.ibm.jbatch.container.cdi.BatchCDIInjectionExtension%HttpSession
   9: WELD%AbstractBuiltInBean%com.sun.faces.flow.FlowDiscoveryCDIExtension%HttpSession
  10: WELD%AbstractBuiltInBean%com.sun.jersey.server.impl.cdi.CDIExtension%HttpSession
  11: WELD%AbstractBuiltInBean%org.glassfish.cdi.transaction.TransactionalExtension%HttpSession
  12: WELD%AbstractBuiltInBean%org.glassfish.jersey.ext.cdi1x.internal.CdiComponentProvider%HttpSession
  13: WELD%AbstractBuiltInBean%org.glassfish.jersey.ext.cdi1x.servlet.internal.CdiExternalRequestScopeExtension%HttpSession
  14: WELD%AbstractBuiltInBean%org.glassfish.jersey.ext.cdi1x.transaction.internal.TransactionalExceptionInterceptorProvider%HttpSession
  15: WELD%AbstractBuiltInBean%org.glassfish.jms.injection.JMSCDIExtension%HttpSession
  16: WELD%AbstractBuiltInBean%org.glassfish.osgicdi.impl.OSGiServiceExtension%HttpSession
  17: WELD%AbstractBuiltInBean%org.glassfish.sse.impl.ServerSentEventCdiExtension%HttpSession
  18: WELD%AbstractBuiltInBean%org.hibernate.validator.internal.cdi.ValidationExtension%HttpSession
  19: WELD%AbstractBuiltInBean%root_acceleratori%HttpSession
    at org.jboss.weld.context.http.HttpSessionContextImpl.checkBeanIdentifierIndexConsistency(HttpSessionContextImpl.java:88)
    at org.jboss.weld.context.http.HttpSessionContextImpl.associate(HttpSessionContextImpl.java:42)
    at org.jboss.weld.context.http.HttpSessionContextImpl.associate(HttpSessionContextImpl.java:19)
    at org.jboss.weld.servlet.HttpContextLifecycle.requestInitialized(HttpContextLifecycle.java:217)
    at org.jboss.weld.servlet.WeldInitialListener.requestInitialized(WeldInitialListener.java:167)
    at org.apache.catalina.core.StandardContext.fireRequestInitializedEvent(StandardContext.java:5257)
    at org.apache.catalina.core.StandardHostValve.preInvoke(StandardHostValve.java:655)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:166)
    at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:416)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:283)
    at com.sun.enterprise.v3.services.impl.ContainerMapper$HttpHandlerCallable.call(ContainerMapper.java:459)
    at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:167)
    at org.glassfish.grizzly.http.server.HttpHandler.runService(HttpHandler.java:206)
    at org.glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.java:180)
    at org.glassfish.grizzly.http.server.HttpServerFilter.handleRead(HttpServerFilter.java:235)
    at org.glassfish.grizzly.filterchain.ExecutorResolver$9.execute(ExecutorResolver.java:119)
    at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:283)
    at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:200)
    at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:132)
    at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:111)
    at org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:77)
    at org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:536)
    at org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:112)
    at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(WorkerThreadIOStrategy.java:117)
    at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access$100(WorkerThreadIOStrategy.java:56)
    at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy$WorkerThreadRunnable.run(WorkerThreadIOStrategy.java:137)
    at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:591)
    at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:571)
    at java.lang.Thread.run(Thread.java:745)

After this error my application stops working and I have to restart my server. It happens also if I include only the jar in my pom, without write any code that use the library. It works properly at the first time that my server starts and it crashes after the second HOT REDEPLOY.

Can you help me please? Thank you a lot.

montalbano commented 8 years ago

This is my whole POM if it helps:

<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <modelVersion>4.0.0</modelVersion>
  <groupId>infn.lns</groupId>
  <artifactId>acceleratori</artifactId>
  <packaging>war</packaging>
  <version>1.0.0-RC2-SNAPSHOT</version>
  <name>acceleratori</name>
  <description>acceleratori webapp</description>

  <repositories>
    <repository>
      <id>shibboleth</id>
      <name>Shibboleth</name>
      <url>https://build.shibboleth.net/nexus/content/groups/public/</url>
      <layout>default</layout>
      <releases>
        <enabled>true</enabled>
      </releases>
      <snapshots>
        <enabled>false</enabled>
      </snapshots>
    </repository>
    <repository>
      <releases>
        <enabled>false</enabled>
      </releases>
      <snapshots>
        <enabled>true</enabled>
      </snapshots>
      <id>com.springsource.repository.maven.snapshot</id>
      <name>SpringSource Enterprise Bundle Maven Repository - SpringSource Snapshot Releases</name>
      <url>http://maven.springframework.org/snapshot</url>
    </repository>
    <repository>
      <releases>
        <enabled>true</enabled>
      </releases>
      <snapshots>
        <enabled>false</enabled>
      </snapshots>
      <id>com.springsource.repository.maven.milestone</id>
      <name>Spring Framework Maven Milestone Releases (Maven Central Format)</name>
      <url>http://maven.springframework.org/milestone</url>
    </repository>
    <repository>
        <id>jitpack.io</id>
        <url>https://jitpack.io</url>
    </repository>
  </repositories>

  <build>
    <finalName>acceleratori</finalName>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <configuration>
          <source>1.8</source>
          <target>1.8</target>
        </configuration>
        <version>3.5.1</version>
      </plugin>
    </plugins>
  </build>  

  <dependencies>

      <dependency>
        <groupId>org.springframework.data</groupId>
        <artifactId>spring-data-redis</artifactId>
        <version>1.6.1.RELEASE</version>
    </dependency>
      <dependency>
        <groupId>redis.clients</groupId>
        <artifactId>jedis</artifactId>
        <version>2.8.0</version>
    </dependency>

    <dependency>
        <groupId>org.codehaus.jackson</groupId>
        <artifactId>jackson-mapper-asl</artifactId>
        <version>1.9.10</version>
    </dependency>

    <dependency>
        <groupId>org.codehaus.jackson</groupId>
        <artifactId>jackson-core-asl</artifactId>
        <version>1.9.13</version>
    </dependency>

    <dependency>
        <groupId>com.fasterxml.jackson.core</groupId>
        <artifactId>jackson-core</artifactId>
        <version>2.7.2</version>
    </dependency>

    <dependency>
        <groupId>com.fasterxml.jackson.core</groupId>
        <artifactId>jackson-databind</artifactId>
        <version>2.6.3</version>
    </dependency>

    <dependency>
      <groupId>javax.servlet</groupId>
      <artifactId>jstl</artifactId>
      <version>1.2</version>
      <scope>compile</scope>
    </dependency>
    <dependency>
      <groupId>org.slf4j</groupId>
      <artifactId>slf4j-log4j12</artifactId>
      <version>1.6.3</version>
      <scope>compile</scope>
    </dependency>
    <dependency>
      <groupId>org.springframework.security.extensions</groupId>
      <artifactId>spring-security-saml2-core</artifactId>
      <version>1.0.0-RC2-SNAPSHOT</version>
      <scope>compile</scope>
    </dependency>
    <dependency>
      <groupId>org.springframework.security</groupId>
      <artifactId>spring-security-config</artifactId>
      <version>3.1.2.RELEASE</version>
      <scope>compile</scope>
    </dependency>
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-core</artifactId>
      <version>4.2.5.RELEASE</version>
      <scope>compile</scope>
    </dependency>
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-beans</artifactId>
      <version>4.2.5.RELEASE</version>
      <scope>compile</scope>
    </dependency>
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-context</artifactId>
      <version>4.2.5.RELEASE</version>
      <scope>compile</scope>
    </dependency>
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-aop</artifactId>
      <version>4.2.5.RELEASE</version>
      <scope>compile</scope>
    </dependency>
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-web</artifactId>
      <version>4.2.5.RELEASE</version>
      <scope>compile</scope>
    </dependency>
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-webmvc</artifactId>
      <version>4.2.5.RELEASE</version>
      <scope>compile</scope>
    </dependency>
    <dependency>
      <groupId>javax.servlet</groupId>
      <artifactId>jsp-api</artifactId>
      <version>2.0</version>
      <scope>provided</scope>
    </dependency>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.4</version>
      <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework.security</groupId>
        <artifactId>spring-security-taglibs</artifactId>
        <version>3.1.2.RELEASE</version>
    </dependency>

    <dependency>
        <groupId>javax.validation</groupId>
        <artifactId>validation-api</artifactId>
        <version>1.0.0.GA</version>
    </dependency>

    <dependency>
        <groupId>javax.transaction</groupId>
        <artifactId>jta</artifactId>
        <version>1.1</version>
    </dependency>

    <dependency>
        <groupId>org.eclipse.persistence</groupId>
        <artifactId>eclipselink</artifactId>
        <version>2.5.2</version>
        <scope>provided</scope>
    </dependency>
     <dependency>
      <groupId>org.eclipse.persistence</groupId>
      <artifactId>org.eclipse.persistence.jpa.modelgen.processor</artifactId>
      <version>2.5.2</version>
      <scope>provided</scope>
     </dependency>
    <dependency>
      <groupId>com.google.code.gson</groupId>
      <artifactId>gson</artifactId>
      <version>2.3.1</version>
      <type>jar</type>
    </dependency>
    <dependency>
      <groupId>org.json</groupId>
      <artifactId>json</artifactId>
      <version>20151123</version>
      <type>jar</type>
    </dependency>
    <dependency>
      <groupId>com.googlecode.json-simple</groupId>
      <artifactId>json-simple</artifactId>
      <version>1.1</version>
      <type>jar</type>
    </dependency>
    <dependency>
        <groupId>com.github.pengrad</groupId>
        <artifactId>java-telegram-bot-api</artifactId>
        <version>1.3.2</version>
      </dependency>
    <dependency>
      <groupId>com.github.rubenlagus</groupId>
      <artifactId>TelegramBots</artifactId>
      <version>v1.0</version>
      <type>jar</type>
    </dependency>
  </dependencies>
</project>
montalbano commented 8 years ago

I googled for hours and found the solution: I set a new system property in glassfish

org.jboss.weld.serialization.beanIdentifierIndexOptimization = false

to avoid the appearing inconsistencies as explained in the WELD reference here: link