Uploaded image for project: 'camunda BPM'
  1. camunda BPM
  2. CAM-9971

SpringBootProcessApplication attribute resolves to Optiona<Optional<String>>

    • Icon: Bug Report Bug Report
    • Resolution: Cannot Reproduce
    • Icon: L3 - Default L3 - Default
    • None
    • 7.10.3
    • spring-boot
    • None

      Hello,
      In order to use my own task and execution listener i had to remove @EnableProcessApplication annotation from my springboot application and define my own configuration extending SpringBootProcessApplication like:

      @Configuration
      public class EngineConfiguration extends SpringBootProcessApplication {
      
          @Override
          public TaskListener getTaskListener() {
              System.out.println("I am here!");
              return super.getTaskListener();
          }
      
          @Override
          public ExecutionListener getExecutionListener() {
              System.out.println("I am here!");
              return super.getExecutionListener();
          }
      
      }
      

      the issue is this below exception:

      java.lang.IllegalStateException: Failed to load ApplicationContext
      
      	at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:125)
      	at org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:108)
      	at org.springframework.test.context.web.ServletTestExecutionListener.setUpRequestContextIfNecessary(ServletTestExecutionListener.java:190)
      	at org.springframework.test.context.web.ServletTestExecutionListener.prepareTestInstance(ServletTestExecutionListener.java:132)
      	at org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:246)
      	at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.createTest(SpringJUnit4ClassRunner.java:227)
      	at org.springframework.test.context.junit4.SpringJUnit4ClassRunner$1.runReflectiveCall(SpringJUnit4ClassRunner.java:289)
      	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
      	at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.methodBlock(SpringJUnit4ClassRunner.java:291)
      	at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:246)
      	at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:97)
      	at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
      	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
      	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
      	at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
      	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
      	at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
      	at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)
      	at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
      	at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:190)
      	at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
      	at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
      	at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
      	at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
      	at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
      Caused by: java.lang.RuntimeException: java.lang.ClassCastException: java.util.Optional cannot be cast to java.lang.String
      	at org.camunda.bpm.engine.spring.application.SpringProcessApplication.onApplicationEvent(SpringProcessApplication.java:104)
      	at org.camunda.bpm.engine.spring.application.SpringProcessApplication.onApplicationEvent(SpringProcessApplication.java:51)
      	at com.td.tds.veritas.security.rivendell.engine.EngineConfiguration$$EnhancerBySpringCGLIB$$a0dde9c7.onApplicationEvent(<generated>)
      	at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:172)
      	at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:165)
      	at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:139)
      	at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:398)
      	at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:355)
      	at org.springframework.context.support.AbstractApplicationContext.finishRefresh(AbstractApplicationContext.java:882)
      	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:549)
      	at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:775)
      	at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397)
      	at org.springframework.boot.SpringApplication.run(SpringApplication.java:316)
      	at org.springframework.boot.test.context.SpringBootContextLoader.loadContext(SpringBootContextLoader.java:127)
      	at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.java:99)
      	at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:117)
      	... 24 more
      Caused by: java.lang.ClassCastException: java.util.Optional cannot be cast to java.lang.String
      	at java.util.Optional.ifPresent(Optional.java:159)
      	at org.camunda.bpm.spring.boot.starter.SpringBootProcessApplication.afterPropertiesSet(SpringBootProcessApplication.java:85)
      	at org.camunda.bpm.engine.spring.application.SpringProcessApplication.onApplicationEvent(SpringProcessApplication.java:95)
      	... 39 more
      

      looks like that the attribute springApplicationName in SpringBootProcessApplication class resolves to Optional<Optional<String>> instead of Optional<String> which causes the above exception, i am not sure whether this is the spring issue or not, but i workaround it by reassigning the springApplicationName:

      @Configuration
      public class EngineConfiguration extends SpringBootProcessApplication {
         ...
          @Override
          public void afterPropertiesSet() throws Exception {
              springApplicationName = Optional.empty();
              super.afterPropertiesSet();
          }
      }
      

      setting application-name in application.properties didn't help.
      my fix is not the best fix so i'd appreciate if you could look into this.

      Thank you,
      Hazhir

        This is the controller panel for Smart Panels app

            [CAM-9971] SpringBootProcessApplication attribute resolves to Optiona<Optional<String>>

            Hi hazhir,

            Thank you for the provided information.

            Have you been able to discover where exactly the springApplicationName resolves to Optional<Optional<String>>?

            It's strange that this happens only when the SpringBootProcessApplication class is extended.

            Best,
            Nikola

            Nikola Koevski added a comment - Hi hazhir , Thank you for the provided information. Have you been able to discover where exactly the springApplicationName resolves to Optional<Optional<String>>? It's strange that this happens only when the SpringBootProcessApplication class is extended. Best, Nikola

            Hi hazhir,

            In the latest snapshot of the Camunda Spring Boot Starter, you can use the camunda.bpm.generate-unique-process-application-name=true to generate a unique name for the Process Application. I believe that the logic there will override the Optional<Optional<String>> problem you are facing.

            Does this fix your problem?

            Best,
            Nikola

            Nikola Koevski added a comment - Hi hazhir , In the latest snapshot of the Camunda Spring Boot Starter, you can use the camunda.bpm.generate-unique-process-application-name=true to generate a unique name for the Process Application. I believe that the logic there will override the Optional<Optional<String>> problem you are facing. Does this fix your problem? Best, Nikola

            Hi Nikola,

            Thank you for your response.

            I haven't had a chance to do more debugging on this issue, but it seems that @Value is resolved by Spring, unless Camunda is overriding the functionality which you should know better
            I tried the proposed approach and got the same class cast exception.

            Any other idea?

            Regards,
            Hazhir

            Hazhir Haghshenas added a comment - Hi Nikola, Thank you for your response. I haven't had a chance to do more debugging on this issue, but it seems that @Value is resolved by Spring, unless Camunda is overriding the functionality which you should know better I tried the proposed approach and got the same class cast exception. Any other idea? Regards, Hazhir

            Hi hazhir,

            Sorry for the long delay.

            I have been trying to replicate your issue but without success. Do you happen to have an example project that you can provide so that I can reproduce the problem and test it?

            Best,
            Nikola

            Nikola Koevski added a comment - Hi hazhir , Sorry for the long delay. I have been trying to replicate your issue but without success. Do you happen to have an example project that you can provide so that I can reproduce the problem and test it? Best, Nikola

            I'm closing this ticket due to inactivity. Feel free to re-open it if you have some new data.

            Nikola Koevski added a comment - I'm closing this ticket due to inactivity. Feel free to re-open it if you have some new data.

              Unassigned Unassigned
              hazhir Hazhir Haghshenas
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Created:
                Updated:
                Resolved: