GH-437 Pass ExecutionContext via MessageHeader
Caching it as part of ApplicationContext was not the right idea so this changes it
This commit is contained in:
@@ -16,14 +16,14 @@
|
||||
|
||||
package example;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Map;
|
||||
import java.util.function.Function;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.cloud.function.json.JsonMapper;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.messaging.Message;
|
||||
|
||||
import com.microsoft.azure.functions.ExecutionContext;
|
||||
|
||||
@@ -35,12 +35,12 @@ public class Config {
|
||||
}
|
||||
|
||||
@Bean
|
||||
public Function<String, String> uppercase(ExecutionContext context) {
|
||||
return value -> {
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
|
||||
public Function<Message<String>, String> uppercase(JsonMapper mapper) {
|
||||
return message -> {
|
||||
String value = message.getPayload();
|
||||
ExecutionContext context = (ExecutionContext) message.getHeaders().get("executionContext");
|
||||
try {
|
||||
Map<String, String> map = mapper.readValue(value, Map.class);
|
||||
Map<String, String> map = mapper.fromJson(value, Map.class);
|
||||
|
||||
if(map != null)
|
||||
map.forEach((k, v) -> map.put(k, v != null ? v.toUpperCase() : null));
|
||||
@@ -48,8 +48,9 @@ public class Config {
|
||||
if(context != null)
|
||||
context.getLogger().info(new StringBuilder().append("Function: ").append(context.getFunctionName()).append(" is uppercasing ").append(value.toString()).toString());
|
||||
|
||||
return mapper.writeValueAsString(map);
|
||||
} catch (IOException e) {
|
||||
return mapper.toString(map);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
if(context != null)
|
||||
context.getLogger().severe("Function could not parse incoming request");
|
||||
|
||||
|
||||
Reference in New Issue
Block a user