GH-349 Added support for raw input to AWS adapter

Resolves #349
This commit is contained in:
Oleg Zhurakousky
2019-04-08 14:18:19 +02:00
parent 6644130297
commit bd094bef39
2 changed files with 75 additions and 6 deletions

View File

@@ -30,7 +30,6 @@ import reactor.core.publisher.Flux;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.function.context.AbstractSpringFunctionAdapterInitializer;
/**
* @author Dave Syer
* @author Oleg Zhurakousky
@@ -50,15 +49,13 @@ public class SpringBootStreamHandler extends AbstractSpringFunctionAdapterInitia
}
@Override
public void handleRequest(InputStream input, OutputStream output, Context context)
throws IOException {
public void handleRequest(InputStream input, OutputStream output, Context context) throws IOException {
initialize(context);
Object value = convertStream(input);
Publisher<?> flux = apply(extract(value));
this.mapper.writeValue(output, result(value, flux));
}
@Override
protected void initialize(Context context) {
super.initialize(context);
@@ -74,13 +71,22 @@ public class SpringBootStreamHandler extends AbstractSpringFunctionAdapterInitia
return Flux.just(input);
}
/*
* Will convert to POJOP or generic map unless user
* explicitly requests InputStream (e.g., Function<InputStream, ?>).
*/
private Object convertStream(InputStream input) {
Object convertedResult = input;
try {
return this.mapper.readValue(input, getInputType());
Class<?> inputType = getInputType();
if (!InputStream.class.isAssignableFrom(inputType)) {
convertedResult = this.mapper.readValue(input, inputType);
}
}
catch (Exception e) {
throw new IllegalStateException("Cannot convert event", e);
throw new IllegalStateException("Cannot convert event stream", e);
}
return convertedResult;
}
}