6
6
import com .google .common .base .Strings ;
7
7
import com .google .common .io .ByteStreams ;
8
8
import in .erail .glue .Glue ;
9
+ import in .erail .glue .common .Util ;
9
10
import in .erail .model .Event ;
10
11
import in .erail .service .RESTService ;
11
12
import io .reactivex .Single ;
32
33
public class AWSLambda implements RequestStreamHandler {
33
34
34
35
protected Logger log = LogManager .getLogger (AWSLambda .class .getCanonicalName ());
35
- private static final String SERVICE_ENV = "SERVICE" ;
36
- private static final String SERVICE_SYS_PROP = "service" ;
36
+ private static final String SERVICE_ENV = "service" ;
37
37
private final RESTService mService ;
38
38
private final List <String > allowedFields = new ArrayList <>();
39
39
@@ -45,17 +45,18 @@ public AWSLambda() {
45
45
allowedFields .add ("multiValueHeaders" );
46
46
allowedFields .add ("body" );
47
47
48
- String component = System .getenv (SERVICE_ENV );
49
- if (Strings .isNullOrEmpty (component )) {
50
- component = System .getProperty (SERVICE_SYS_PROP );
51
- }
48
+ String component = Util .getEnvironmentValue (SERVICE_ENV );
52
49
50
+ if (Strings .isNullOrEmpty (component )) {
51
+ throw new RuntimeException ("Service not defined in lambda environment" );
52
+ }
53
+
53
54
mService = Glue .instance ().resolve (component );
54
55
}
55
56
56
57
@ Override
57
58
public void handleRequest (InputStream inputStream , OutputStream outputStream , Context context ) throws IOException {
58
- try (OutputStreamWriter writer = new OutputStreamWriter (outputStream , "UTF-8" )) {
59
+ try ( OutputStreamWriter writer = new OutputStreamWriter (outputStream , "UTF-8" )) {
59
60
JsonObject requestJson = new JsonObject (Buffer .buffer (ByteStreams .toByteArray (inputStream )));
60
61
log .debug (() -> requestJson .toString ());
61
62
String resp = handleMessage (requestJson ).blockingGet ();
0 commit comments