44
55import com .amazonaws .services .lambda .runtime .ClientContext ;
66import com .amazonaws .services .lambda .runtime .Context ;
7+ import com .amazonaws .services .lambda .runtime .LambdaRuntimeInternal ;
78import com .amazonaws .services .lambda .runtime .RequestHandler ;
89import com .amazonaws .services .lambda .runtime .RequestStreamHandler ;
9- import com .amazonaws .services .lambda .runtime .LambdaRuntimeInternal ;
10-
10+ import com .amazonaws .services .lambda .runtime .api .client .LambdaRequestHandler .UserFaultHandler ;
1111import com .amazonaws .services .lambda .runtime .api .client .api .LambdaClientContext ;
1212import com .amazonaws .services .lambda .runtime .api .client .api .LambdaCognitoIdentity ;
1313import com .amazonaws .services .lambda .runtime .api .client .api .LambdaContext ;
14+ import com .amazonaws .services .lambda .runtime .api .client .runtimeapi .InvocationRequest ;
1415import com .amazonaws .services .lambda .runtime .api .client .util .UnsafeUtil ;
1516import com .amazonaws .services .lambda .runtime .serialization .PojoSerializer ;
1617import com .amazonaws .services .lambda .runtime .serialization .events .LambdaEventSerializers ;
1718import com .amazonaws .services .lambda .runtime .serialization .factories .GsonFactory ;
1819import com .amazonaws .services .lambda .runtime .serialization .factories .JacksonFactory ;
1920import com .amazonaws .services .lambda .runtime .serialization .util .Functions ;
2021import com .amazonaws .services .lambda .runtime .serialization .util .ReflectUtil ;
21- import com .amazonaws .services .lambda .runtime .api .client .LambdaRequestHandler .UserFaultHandler ;
22- import com .amazonaws .services .lambda .runtime .api .client .runtimeapi .InvocationRequest ;
2322
2423import java .io .ByteArrayOutputStream ;
2524import java .io .IOException ;
4241import java .util .Map ;
4342import java .util .Optional ;
4443
45- import static com .amazonaws .services .lambda .runtime .api .client .UserFault .filterStackTrace ;
46- import static com .amazonaws .services .lambda .runtime .api .client .UserFault .makeUserFault ;
47- import static com .amazonaws .services .lambda .runtime .api .client .UserFault .trace ;
44+ import static com .amazonaws .services .lambda .runtime .api .client .UserFault .*;
4845
4946public final class EventHandlerLoader {
5047 private static final byte [] _JsonNull = new byte []{'n' , 'u' , 'l' , 'l' };
@@ -57,12 +54,14 @@ private enum Platform {
5754
5855 private static final EnumMap <Platform , Map <Type , PojoSerializer <Object >>> typeCache = new EnumMap <>(Platform .class );
5956
60- private EventHandlerLoader () { }
57+ private EventHandlerLoader () {
58+ }
6159
6260 /**
6361 * returns the appropriate serializer for the class based on platform and whether the class is a supported event
62+ *
6463 * @param platform enum platform
65- * @param type Type of object used
64+ * @param type Type of object used
6665 * @return PojoSerializer
6766 * @see Platform for which platforms are used
6867 * @see LambdaEventSerializers for how mixins and modules are added to the serializer
@@ -76,7 +75,7 @@ private static PojoSerializer<Object> getSerializer(Platform platform, Type type
7675
7776 // if serializing a Class that is a Lambda supported event, use Jackson with customizations
7877 if (type instanceof Class ) {
79- Class <Object > clazz = ((Class )type );
78+ Class <Object > clazz = ((Class ) type );
8079 if (LambdaEventSerializers .isLambdaSupportedEvent (clazz .getName ())) {
8180 return LambdaEventSerializers .serializerFor (clazz , AWSLambda .customerClassLoader );
8281 }
@@ -150,7 +149,7 @@ private static Platform getPlatform(Context context) {
150149 }
151150
152151 private static boolean isVoid (Type type ) {
153- return Void .TYPE .equals (type ) || (type instanceof Class ) && Void .class .isAssignableFrom ((Class <?>)type );
152+ return Void .TYPE .equals (type ) || (type instanceof Class ) && Void .class .isAssignableFrom ((Class <?>) type );
154153 }
155154
156155 /**
@@ -393,7 +392,7 @@ public void handleRequest(InputStream inputStream, OutputStream outputStream, Co
393392 }
394393 }
395394
396- public static <T > Constructor <T > getConstructor (Class <T > clazz ) throws Exception {
395+ private static <T > Constructor <T > getConstructor (Class <T > clazz ) throws Exception {
397396 final Constructor <T > constructor ;
398397 try {
399398 constructor = clazz .getConstructor ();
@@ -409,7 +408,7 @@ public static <T> Constructor<T> getConstructor(Class<T> clazz) throws Exception
409408 return constructor ;
410409 }
411410
412- public static <T > T newInstance (Constructor <? extends T > constructor ) {
411+ private static <T > T newInstance (Constructor <? extends T > constructor ) {
413412 try {
414413 return constructor .newInstance ();
415414 } catch (UserFault e ) {
@@ -458,15 +457,15 @@ public ClassContext(ParameterizedType type, ClassContext curContext) {
458457 for (int i = 0 ; i < types .length ; i ++) {
459458 Type t = types [i ];
460459 if (t instanceof TypeVariable ) {
461- types [i ] = curContext .resolveTypeVariable ((TypeVariable )t );
460+ types [i ] = curContext .resolveTypeVariable ((TypeVariable ) t );
462461 }
463462 }
464463
465464 Type t = type .getRawType ();
466465 if (t instanceof Class ) {
467- this .clazz = (Class )t ;
466+ this .clazz = (Class ) t ;
468467 } else if (t instanceof TypeVariable ) {
469- this .clazz = (Class )((TypeVariable )t ).getGenericDeclaration ();
468+ this .clazz = (Class ) ((TypeVariable ) t ).getGenericDeclaration ();
470469 } else {
471470 throw new RuntimeException ("Type " + t + " is of unexpected type " + t .getClass ());
472471 }
@@ -499,30 +498,30 @@ private TypeVariable[] getTypeParameters() {
499498 *
500499 * @return null of no type found. Otherwise the type found.
501500 */
502- public static Type [] findInterfaceParameters (Class <?> clazz , Class <?> iface ) {
501+ private static Type [] findInterfaceParameters (Class <?> clazz , Class <?> iface ) {
503502 LinkedList <ClassContext > clazzes = new LinkedList <>();
504- clazzes .addFirst (new ClassContext (clazz , (Type [])null ));
503+ clazzes .addFirst (new ClassContext (clazz , (Type []) null ));
505504 while (!clazzes .isEmpty ()) {
506505 final ClassContext curContext = clazzes .removeLast ();
507506 Type [] interfaces = curContext .clazz .getGenericInterfaces ();
508507
509508 for (Type type : interfaces ) {
510509 if (type instanceof ParameterizedType ) {
511- ParameterizedType candidate = (ParameterizedType )type ;
510+ ParameterizedType candidate = (ParameterizedType ) type ;
512511 Type rawType = candidate .getRawType ();
513512 if (!(rawType instanceof Class )) {
514513 //should be impossible
515514 System .err .println ("raw type is not a class: " + rawType );
516515 continue ;
517516 }
518- Class <?> rawClass = (Class <?>)rawType ;
517+ Class <?> rawClass = (Class <?>) rawType ;
519518 if (iface .isAssignableFrom (rawClass )) {
520519 return new ClassContext (candidate , curContext ).actualTypeArguments ;
521520 } else {
522521 clazzes .addFirst (new ClassContext (candidate , curContext ));
523522 }
524523 } else if (type instanceof Class ) {
525- clazzes .addFirst (new ClassContext ((Class <?>)type , curContext ));
524+ clazzes .addFirst (new ClassContext ((Class <?>) type , curContext ));
526525 } else {
527526 //should never happen?
528527 System .err .println ("Unexpected type class " + type .getClass ().getName ());
@@ -531,17 +530,17 @@ public static Type[] findInterfaceParameters(Class<?> clazz, Class<?> iface) {
531530
532531 final Type superClass = curContext .clazz .getGenericSuperclass ();
533532 if (superClass instanceof ParameterizedType ) {
534- clazzes .addFirst (new ClassContext ((ParameterizedType )superClass , curContext ));
533+ clazzes .addFirst (new ClassContext ((ParameterizedType ) superClass , curContext ));
535534 } else if (superClass != null ) {
536- clazzes .addFirst (new ClassContext ((Class <?>)superClass , curContext ));
535+ clazzes .addFirst (new ClassContext ((Class <?>) superClass , curContext ));
537536 }
538537 }
539538 return null ;
540539 }
541540
542541
543542 @ SuppressWarnings ({"rawtypes" })
544- public static LambdaRequestHandler wrapRequestHandlerClass (final Class <? extends RequestHandler > clazz ) {
543+ private static LambdaRequestHandler wrapRequestHandlerClass (final Class <? extends RequestHandler > clazz ) {
545544 Type [] ptypes = findInterfaceParameters (clazz , RequestHandler .class );
546545 if (ptypes == null ) {
547546 return new UserFaultHandler (makeUserFault ("Class "
@@ -555,7 +554,7 @@ public static LambdaRequestHandler wrapRequestHandlerClass(final Class<? extends
555554
556555 for (Type t : ptypes ) {
557556 if (t instanceof TypeVariable ) {
558- Type [] bounds = ((TypeVariable )t ).getBounds ();
557+ Type [] bounds = ((TypeVariable ) t ).getBounds ();
559558 boolean foundBound = false ;
560559 if (bounds != null ) {
561560 for (Type bound : bounds ) {
@@ -588,7 +587,7 @@ public static LambdaRequestHandler wrapRequestHandlerClass(final Class<? extends
588587 }
589588 }
590589
591- public static LambdaRequestHandler wrapRequestStreamHandlerClass (final Class <? extends RequestStreamHandler > clazz ) {
590+ private static LambdaRequestHandler wrapRequestStreamHandlerClass (final Class <? extends RequestStreamHandler > clazz ) {
592591 final Constructor <? extends RequestStreamHandler > constructor ;
593592 try {
594593 constructor = getConstructor (clazz );
@@ -600,7 +599,7 @@ public static LambdaRequestHandler wrapRequestStreamHandlerClass(final Class<? e
600599 }
601600 }
602601
603- public static LambdaRequestHandler loadStreamingRequestHandler (Class <?> clazz ) {
602+ private static LambdaRequestHandler loadStreamingRequestHandler (Class <?> clazz ) {
604603 if (RequestStreamHandler .class .isAssignableFrom (clazz )) {
605604 return wrapRequestStreamHandlerClass (clazz .asSubclass (RequestStreamHandler .class ));
606605 } else if (RequestHandler .class .isAssignableFrom (clazz )) {
@@ -730,10 +729,9 @@ private static final boolean lastParameterIsContext(Class<?>[] params) {
730729 public int compare (Method lhs , Method rhs ) {
731730
732731 //1. Non bridge methods are preferred over bridge methods.
733- if (! lhs .isBridge () && rhs .isBridge ()) {
732+ if (!lhs .isBridge () && rhs .isBridge ()) {
734733 return -1 ;
735- }
736- else if (!rhs .isBridge () && lhs .isBridge ()) {
734+ } else if (!rhs .isBridge () && lhs .isBridge ()) {
737735 return 1 ;
738736 }
739737
@@ -828,13 +826,13 @@ private static LambdaRequestHandler loadEventPojoHandler(HandlerInfo handlerInfo
828826 }
829827
830828 @ SuppressWarnings ({"rawtypes" })
831- public static LambdaRequestHandler wrapPojoHandler (RequestHandler instance , Type pType , Type rType ) {
829+ private static LambdaRequestHandler wrapPojoHandler (RequestHandler instance , Type pType , Type rType ) {
832830 return wrapRequestStreamHandler (new PojoHandlerAsStreamHandler (instance , Optional .ofNullable (pType ),
833831 isVoid (rType ) ? Optional .<Type >empty () : Optional .of (rType )
834832 ));
835833 }
836834
837- public static String exceptionToString (Throwable t ) {
835+ private static String exceptionToString (Throwable t ) {
838836 StringWriter writer = new StringWriter (65536 );
839837 try (PrintWriter wrapped = new PrintWriter (writer )) {
840838 t .printStackTrace (wrapped );
@@ -849,7 +847,7 @@ public static String exceptionToString(Throwable t) {
849847 return buffer .toString ();
850848 }
851849
852- public static LambdaRequestHandler wrapRequestStreamHandler (final RequestStreamHandler handler ) {
850+ private static LambdaRequestHandler wrapRequestStreamHandler (final RequestStreamHandler handler ) {
853851 return new LambdaRequestHandler () {
854852 private final ByteArrayOutputStream output = new ByteArrayOutputStream (1024 );
855853 private Functions .V2 <String , String > log4jContextPutMethod = null ;
@@ -860,14 +858,15 @@ private void safeAddRequestIdToLog4j(String log4jContextClassName,
860858 Class <?> log4jContextClass = ReflectUtil .loadClass (AWSLambda .customerClassLoader , log4jContextClassName );
861859 log4jContextPutMethod = ReflectUtil .loadStaticV2 (log4jContextClass , "put" , false , String .class , contextMapValueClass );
862860 log4jContextPutMethod .call ("AWSRequestId" , request .getId ());
863- } catch (Exception e ) {}
861+ } catch (Exception e ) {
862+ }
864863 }
865864
866865 public ByteArrayOutputStream call (InvocationRequest request ) throws Error , Exception {
867866 output .reset ();
868867
869868 LambdaCognitoIdentity cognitoIdentity = null ;
870- if (request .getCognitoIdentity () != null && !request .getCognitoIdentity ().isEmpty ()) {
869+ if (request .getCognitoIdentity () != null && !request .getCognitoIdentity ().isEmpty ()) {
871870 cognitoIdentity = getCognitoSerializer ().fromJson (request .getCognitoIdentity ());
872871 }
873872
0 commit comments