27
27
import com .amazonaws .services .lambda .runtime .api .client .logging .LambdaContextLogger ;
28
28
import com .amazonaws .services .lambda .runtime .api .client .logging .LogSink ;
29
29
import com .amazonaws .services .lambda .runtime .api .client .logging .StdOutLogSink ;
30
- import com .amazonaws .services .lambda .runtime .api .client .runtimeapi .LambdaError ;
31
30
import com .amazonaws .services .lambda .runtime .api .client .runtimeapi .LambdaRuntimeApiClient ;
32
31
import com .amazonaws .services .lambda .runtime .api .client .runtimeapi .LambdaRuntimeApiClientImpl ;
33
- import com .amazonaws .services .lambda .runtime .api .client .runtimeapi .RapidErrorType ;
34
32
import com .amazonaws .services .lambda .runtime .api .client .runtimeapi .converters .LambdaErrorConverter ;
35
33
import com .amazonaws .services .lambda .runtime .api .client .runtimeapi .converters .XRayErrorCauseConverter ;
36
34
import com .amazonaws .services .lambda .runtime .api .client .runtimeapi .dto .InvocationRequest ;
35
+ import com .amazonaws .services .lambda .runtime .api .client .runtimeapi .dto .LambdaError ;
36
+ import com .amazonaws .services .lambda .runtime .api .client .runtimeapi .dto .XRayErrorCause ;
37
37
import com .amazonaws .services .lambda .runtime .api .client .util .LambdaOutputStream ;
38
38
import com .amazonaws .services .lambda .runtime .api .client .util .UnsafeUtil ;
39
39
import com .amazonaws .services .lambda .runtime .logging .LogFormat ;
54
54
*/
55
55
public class AWSLambda {
56
56
57
- protected static ClassLoader customerClassLoader ;
58
-
59
57
private static final String TRUST_STORE_PROPERTY = "javax.net.ssl.trustStore" ;
60
58
61
59
private static final String JAVA_SECURITY_PROPERTIES = "java.security.properties" ;
@@ -77,6 +75,8 @@ public class AWSLambda {
77
75
private static final String AWS_LAMBDA_INITIALIZATION_TYPE =
78
76
System .getenv (ReservedRuntimeEnvironmentVariables .AWS_LAMBDA_INITIALIZATION_TYPE );
79
77
78
+ protected static ClassLoader customerClassLoader ;
79
+
80
80
private static LambdaRuntimeApiClient runtimeClient ;
81
81
82
82
static {
@@ -215,10 +215,10 @@ private static void startRuntime(String handler, LambdaContextLogger lambdaLogge
215
215
216
216
runtimeClient = new LambdaRuntimeApiClientImpl (LambdaEnvironment .RUNTIME_API );
217
217
218
- String taskRoot = System .getProperty ("user.dir" );
219
- String libRoot = "/opt/java" ;
220
218
// Make system classloader the customer classloader's parent to ensure any aws-lambda-java-core
221
219
// classes are loaded from the system classloader.
220
+ // String taskRoot = System.getProperty("user.dir");
221
+ // String libRoot = "/opt/java";
222
222
//
223
223
// customerClassLoader =
224
224
// new CustomerClassLoader(taskRoot, libRoot, ClassLoader.getSystemClassLoader());
@@ -236,8 +236,7 @@ private static void startRuntime(String handler, LambdaContextLogger lambdaLogge
236
236
} catch (UserFault userFault ) {
237
237
lambdaLogger .log (userFault .reportableError (),
238
238
lambdaLogger .getLogFormat () == LogFormat .JSON ? LogLevel .ERROR : LogLevel .UNDEFINED );
239
- LambdaError error = new LambdaError (LambdaErrorConverter .fromUserFault (userFault ),
240
- RapidErrorType .BadFunctionCode );
239
+ LambdaError error = LambdaErrorConverter .fromUserFault (userFault );
241
240
runtimeClient .reportInitError (error );
242
241
System .exit (1 );
243
242
return ;
@@ -259,23 +258,23 @@ private static void startRuntime(String handler, LambdaContextLogger lambdaLogge
259
258
try {
260
259
payload = requestHandler .call (request );
261
260
runtimeClient .reportInvocationSuccess (request .getId (), payload .toByteArray ());
262
- // clear interrupted flag in case if it was set by user's code
263
- boolean ignored = Thread . interrupted ();
261
+ boolean ignored = Thread . interrupted (); // clear interrupted flag in case if it was set by
262
+ // user's code
264
263
} catch (UserFault f ) {
265
264
shouldExit = f .fatal ;
266
265
userFault = f ;
267
266
UserFault .filterStackTrace (f );
268
- LambdaError error =
269
- new LambdaError ( LambdaErrorConverter .fromUserFault (f ), RapidErrorType . BadFunctionCode );
267
+
268
+ LambdaError error = LambdaErrorConverter .fromUserFault (f );
270
269
runtimeClient .reportInvocationError (request .getId (), error );
271
270
} catch (Throwable t ) {
272
271
shouldExit = t instanceof VirtualMachineError || t instanceof IOError ;
273
272
UserFault .filterStackTrace (t );
274
273
userFault = UserFault .makeUserFault (t );
275
274
276
- LambdaError error = new LambdaError ( LambdaErrorConverter .fromThrowable (t ),
277
- XRayErrorCauseConverter .fromThrowable (t ), RapidErrorType . UserException );
278
- runtimeClient .reportInvocationError (request .getId (), error );
275
+ LambdaError error = LambdaErrorConverter .fromThrowable (t );
276
+ XRayErrorCause xRayErrorCause = XRayErrorCauseConverter .fromThrowable (t );
277
+ runtimeClient .reportInvocationError (request .getId (), error , xRayErrorCause );
279
278
} finally {
280
279
if (userFault != null ) {
281
280
lambdaLogger .log (userFault .reportableError (),
@@ -291,16 +290,16 @@ static void onInitComplete(final LambdaContextLogger lambdaLogger) throws IOExce
291
290
runtimeClient .restoreNext ();
292
291
} catch (Exception e1 ) {
293
292
logExceptionCloudWatch (lambdaLogger , e1 );
294
- runtimeClient . reportInitError ( new LambdaError ( LambdaErrorConverter .fromThrowable (e1 ),
295
- RapidErrorType . BeforeCheckpointError ) );
293
+ LambdaError error = LambdaErrorConverter .fromThrowable (e1 );
294
+ runtimeClient . reportInitError ( error );
296
295
System .exit (64 );
297
296
}
298
297
try {
299
298
Core .getGlobalContext ().afterRestore (null );
300
299
} catch (Exception restoreExc ) {
301
300
logExceptionCloudWatch (lambdaLogger , restoreExc );
302
- runtimeClient . reportRestoreError ( new LambdaError (
303
- LambdaErrorConverter . fromThrowable ( restoreExc ), RapidErrorType . AfterRestoreError ) );
301
+ LambdaError error = LambdaErrorConverter . fromThrowable ( restoreExc );
302
+ runtimeClient . reportRestoreError ( error );
304
303
System .exit (64 );
305
304
}
306
305
}
0 commit comments