@@ -606,48 +606,19 @@ private MethodInvocationGateway createGatewayForMethod(Method method) {
606606 if (!CollectionUtils .isEmpty (this .methodMetadataMap )) {
607607 methodMetadata = this .methodMetadataMap .get (method .getName ());
608608 }
609- Map <String , Expression > headerExpressions = new HashMap <>();
610- Expression requestTimeout = this .defaultRequestTimeout ;
611- Expression replyTimeout = this .defaultReplyTimeout ;
612609 Expression payloadExpression =
613610 extractPayloadExpressionFromAnnotationOrMetadata (gatewayAnnotation , methodMetadata );
614611 String requestChannelName = extractRequestChannelFromAnnotationOrMetadata (gatewayAnnotation , methodMetadata );
615612 String replyChannelName = extractReplyChannelFromAnnotationOrMetadata (gatewayAnnotation , methodMetadata );
616- if (gatewayAnnotation != null ) {
617- /*
618- * INT-2636 Unspecified annotation attributes should not
619- * override the default values supplied by explicit configuration.
620- * There is a small risk that someone has used Long.MIN_VALUE explicitly
621- * to indicate an indefinite timeout on a gateway method and that will
622- * no longer work as expected; they will need to use, say, -1 instead.
623- */
624- if (requestTimeout == null || gatewayAnnotation .requestTimeout () != Long .MIN_VALUE ) {
625- requestTimeout = new ValueExpression <>(gatewayAnnotation .requestTimeout ());
626- }
627- if (StringUtils .hasText (gatewayAnnotation .requestTimeoutExpression ())) {
628- requestTimeout = ExpressionUtils .longExpression (gatewayAnnotation .requestTimeoutExpression ());
629- }
630- if (replyTimeout == null || gatewayAnnotation .replyTimeout () != Long .MIN_VALUE ) {
631- replyTimeout = new ValueExpression <>(gatewayAnnotation .replyTimeout ());
632- }
633- if (StringUtils .hasText (gatewayAnnotation .replyTimeoutExpression ())) {
634- replyTimeout = ExpressionUtils .longExpression (gatewayAnnotation .replyTimeoutExpression ());
635- }
613+ Expression requestTimeout = extractRequestTimeoutFromAnnotationOrMetadata (gatewayAnnotation , methodMetadata );
614+ Expression replyTimeout = extractReplyTimeoutFromAnnotationOrMetadata (gatewayAnnotation , methodMetadata );
636615
616+ Map <String , Expression > headerExpressions = new HashMap <>();
617+ if (gatewayAnnotation != null ) {
637618 annotationHeaders (gatewayAnnotation , headerExpressions );
638619 }
639- else if (methodMetadata != null ) {
640- if (!CollectionUtils .isEmpty (methodMetadata .getHeaderExpressions ())) {
620+ else if (methodMetadata != null && !CollectionUtils .isEmpty (methodMetadata .getHeaderExpressions ())) {
641621 headerExpressions .putAll (methodMetadata .getHeaderExpressions ());
642- }
643- String reqTimeout = methodMetadata .getRequestTimeout ();
644- if (StringUtils .hasText (reqTimeout )) {
645- requestTimeout = ExpressionUtils .longExpression (reqTimeout );
646- }
647- String repTimeout = methodMetadata .getReplyTimeout ();
648- if (StringUtils .hasText (repTimeout )) {
649- replyTimeout = ExpressionUtils .longExpression (repTimeout );
650- }
651622 }
652623
653624 return doCreateMethodInvocationGateway (method , payloadExpression , headerExpressions ,
@@ -664,14 +635,19 @@ private Expression extractPayloadExpressionFromAnnotationOrMetadata(@Nullable Ga
664635 : null ;
665636
666637 if (gatewayAnnotation != null ) {
638+ /*
639+ * INT-2636 Unspecified annotation attributes should not
640+ * override the default values supplied by explicit configuration.
641+ * There is a small risk that someone has used Long.MIN_VALUE explicitly
642+ * to indicate an indefinite timeout on a gateway method and that will
643+ * no longer work as expected; they will need to use, say, -1 instead.
644+ */
667645 if (payloadExpression == null && StringUtils .hasText (gatewayAnnotation .payloadExpression ())) {
668646 payloadExpression = PARSER .parseExpression (gatewayAnnotation .payloadExpression ());
669647 }
670648 }
671- else if (methodMetadata != null ) {
672- if (methodMetadata .getPayloadExpression () != null ) {
673- payloadExpression = methodMetadata .getPayloadExpression ();
674- }
649+ else if (methodMetadata != null && methodMetadata .getPayloadExpression () != null ) {
650+ payloadExpression = methodMetadata .getPayloadExpression ();
675651 }
676652
677653 return payloadExpression ;
@@ -703,6 +679,68 @@ else if (methodMetadata != null) {
703679 return null ;
704680 }
705681
682+ @ Nullable
683+ private Expression extractRequestTimeoutFromAnnotationOrMetadata (@ Nullable Gateway gatewayAnnotation ,
684+ @ Nullable GatewayMethodMetadata methodMetadata ) {
685+
686+ Expression requestTimeout = this .defaultRequestTimeout ;
687+
688+ if (gatewayAnnotation != null ) {
689+ /*
690+ * INT-2636 Unspecified annotation attributes should not
691+ * override the default values supplied by explicit configuration.
692+ * There is a small risk that someone has used Long.MIN_VALUE explicitly
693+ * to indicate an indefinite timeout on a gateway method and that will
694+ * no longer work as expected; they will need to use, say, -1 instead.
695+ */
696+ if (requestTimeout == null || gatewayAnnotation .requestTimeout () != Long .MIN_VALUE ) {
697+ requestTimeout = new ValueExpression <>(gatewayAnnotation .requestTimeout ());
698+ }
699+ if (StringUtils .hasText (gatewayAnnotation .requestTimeoutExpression ())) {
700+ requestTimeout = ExpressionUtils .longExpression (gatewayAnnotation .requestTimeoutExpression ());
701+ }
702+
703+ }
704+ else if (methodMetadata != null ) {
705+ String reqTimeout = methodMetadata .getRequestTimeout ();
706+ if (StringUtils .hasText (reqTimeout )) {
707+ requestTimeout = ExpressionUtils .longExpression (reqTimeout );
708+ }
709+ }
710+ return requestTimeout ;
711+ }
712+
713+ @ Nullable
714+ private Expression extractReplyTimeoutFromAnnotationOrMetadata (@ Nullable Gateway gatewayAnnotation ,
715+ @ Nullable GatewayMethodMetadata methodMetadata ) {
716+
717+ Expression replyTimeout = this .defaultReplyTimeout ;
718+
719+ if (gatewayAnnotation != null ) {
720+ /*
721+ * INT-2636 Unspecified annotation attributes should not
722+ * override the default values supplied by explicit configuration.
723+ * There is a small risk that someone has used Long.MIN_VALUE explicitly
724+ * to indicate an indefinite timeout on a gateway method and that will
725+ * no longer work as expected; they will need to use, say, -1 instead.
726+ */
727+ if (replyTimeout == null || gatewayAnnotation .replyTimeout () != Long .MIN_VALUE ) {
728+ replyTimeout = new ValueExpression <>(gatewayAnnotation .replyTimeout ());
729+ }
730+ if (StringUtils .hasText (gatewayAnnotation .replyTimeoutExpression ())) {
731+ replyTimeout = ExpressionUtils .longExpression (gatewayAnnotation .replyTimeoutExpression ());
732+ }
733+
734+ }
735+ else if (methodMetadata != null ) {
736+ String repTimeout = methodMetadata .getReplyTimeout ();
737+ if (StringUtils .hasText (repTimeout )) {
738+ replyTimeout = ExpressionUtils .longExpression (repTimeout );
739+ }
740+ }
741+ return replyTimeout ;
742+ }
743+
706744 private void annotationHeaders (Gateway gatewayAnnotation , Map <String , Expression > headerExpressions ) {
707745 if (!ObjectUtils .isEmpty (gatewayAnnotation .headers ())) {
708746 for (GatewayHeader gatewayHeader : gatewayAnnotation .headers ()) {
@@ -725,7 +763,7 @@ private void annotationHeaders(Gateway gatewayAnnotation, Map<String, Expression
725763 private MethodInvocationGateway doCreateMethodInvocationGateway (Method method ,
726764 @ Nullable Expression payloadExpression , Map <String , Expression > headerExpressions ,
727765 @ Nullable String requestChannelName , @ Nullable String replyChannelName ,
728- Expression requestTimeout , Expression replyTimeout ) {
766+ @ Nullable Expression requestTimeout , @ Nullable Expression replyTimeout ) {
729767
730768 GatewayMethodInboundMessageMapper messageMapper = createGatewayMessageMapper (method , headerExpressions );
731769 MethodInvocationGateway gateway = new MethodInvocationGateway (messageMapper );
0 commit comments