StreamBridge null pointer with Spring 3

GreenRover
GreenRover Member Posts: 22 ✭✭

I try to get "spring-cloud-starter-stream-solace" version 3.0.0 with spring 3.1.0 running.

But every time i use the "StreamBridge" i get this error message:

2023-06-01T14:38:25.602+0200 ERROR Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed: java.lang.NullPointerException: Cannot load from object array because "contentType" is null] with root cause
java.lang.NullPointerException: Cannot load from object array because "contentType" is null
	at org.springframework.cloud.function.context.catalog.SimpleFunctionRegistry$FunctionInvocationWrapper.convertOutputIfNecessary(SimpleFunctionRegistry.java:1170) ~[spring-cloud-function-context-4.0.2.jar:4.0.2]
	at org.springframework.cloud.function.context.catalog.SimpleFunctionRegistry$FunctionInvocationWrapper.doApply(SimpleFunctionRegistry.java:708) ~[spring-cloud-function-context-4.0.2.jar:4.0.2]
	at org.springframework.cloud.function.context.catalog.SimpleFunctionRegistry$FunctionInvo

Didt some one else tried to use spring 3 and get it run?

The sample code:

@GetMapping(value = "/temperature/publish/dynamic_topic/{location}/{temperature}")
public void publishTemperatureDynamicTopic(
        @PathVariable("location") final String location,
        @PathVariable("temperature") final double temperature
) {
    SensorReading reading = new SensorReading();
    reading.setSensorID(location);
    reading.setTemperature(temperature);
    reading.setBaseUnit(BaseUnit.CELSIUS);

    log.info("Emitting " + reading);

    Message<SensorReading> message = MessageBuilder
            .withPayload(reading)
            .setHeader(
                    BinderHeaders.TARGET_DESTINATION,
                    baseDestination + "/" + location)
            .build();
    streamBridge.send("emitTemperatureSensorDynamic-out-0", message);
}

My pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>3.1.0</version>
        <relativePath /> <!-- lookup parent from repository -->
    </parent>




    <properties>
        <java.version>17</java.version>


        <solace-spring-cloud.version>3.0.0</solace-spring-cloud.version>
        <spring-cloud.version>2022.0.2</spring-cloud.version>
    </properties>




    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>${spring-cloud.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
            <dependency>
                <groupId>com.solace.spring.cloud</groupId>
                <artifactId>solace-spring-cloud-bom</artifactId>
                <version>${solace-spring-cloud.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>


    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
            <exclusions>
                <exclusion>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-starter-logging</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-stream</artifactId>
        </dependency>
        <dependency>
            <groupId>com.solace.spring.cloud</groupId>
            <artifactId>spring-cloud-starter-stream-solace</artifactId>
        </dependency>
    </dependencies>


</project>
cationWrapper.lambda$andThen$0(SimpleFunctionRegistry.java:619) ~[spring-cloud-function-context-4.0.2.jar:4.0.2]

Answers

  • marc
    marc Member, Administrator, Moderator, Employee Posts: 898 admin

    Hi @GreenRover ,

    I wasn't able to reproduce your issue. It seems to be working for me.

    I uploaded a sample project here for you: https://github.com/Mrc0113/CloudStreamV3RestController. Can you see if it works for you? Seems like there is something weird going on.

    Sample request from browser: http://localhost:8094/temperature/publish/dynamic_topic/orlando/99

    Received the output in try-me:


    Note I'm using Java: openjdk version "17.0.4" 2022-07-19

    Hope that helps!

  • GreenRover
    GreenRover Member Posts: 22 ✭✭
    edited June 2023 #3

    Hi Marc, thank you very much. Your sample leads me on the correct way.

    To reproduce you need to add to your application.yaml

    spring:
      cloud:
        function:
          configuration:
            streamBridge:
              output-header-mapping-expression:
                solace_timeToLive: 23000L
                solace_senderId: @project.artifactId@_${HOSTNAME}
    

    The configuration for "streamBridge" was in spring 2.7 necessary to add custom header configuration based to outbound header.

    But with spring 3. I can not get this feature working at all.

    I tried:

    spring:
      cloud:
        function:
          configuration:
            emitTemperatureSensorDynamic:
              output-header-mapping-expression:
                solace_timeToLive: 23000L
                solace_senderId: @project.artifactId@_${HOSTNAME}
    

    Than my application stops crashing but i am unable to put those additional outbound header to the message. Because "emitTemperatureSensorDynamic" is not in function registry.

    But "streamBridge" is still in function registry.

    Do you remember the original issue for this feature. I want to link it when creating a bug report for oleg.

  • marc
    marc Member, Administrator, Moderator, Employee Posts: 898 admin

    @GreenRover, I'm glad that helped! I believe this is the issue that kicked off the header mapping expression creation: https://github.com/spring-cloud/spring-cloud-function/issues/676

  • GreenRover
    GreenRover Member Posts: 22 ✭✭

    @marc I created a bug report: https://github.com/spring-cloud/spring-cloud-function/issues/1044

    May be you want to join the discussions