@@ -1548,10 +1548,10 @@ private void handleSubResourceMethod(List<JaxrsClientReactiveEnricherBuildItem>
1548
1548
for (int i = 0 ; i < method .getParameters ().length ; i ++) {
1549
1549
MethodParameter param = method .getParameters ()[i ];
1550
1550
if (param .parameterType != ParameterType .PATH ) {
1551
- FieldDescriptor paramField = subContext .classCreator .getFieldCreator ("param" + i , param .type )
1551
+ FieldDescriptor paramField = subContext .classCreator .getFieldCreator ("param" + i , param .declaredType )
1552
1552
.setModifiers (Modifier .PUBLIC )
1553
1553
.getFieldDescriptor ();
1554
- subParamFields .add (new SubResourceParameter (method .getParameters ()[i ], param .type ,
1554
+ subParamFields .add (new SubResourceParameter (method .getParameters ()[i ], param .declaredType ,
1555
1555
jandexMethod .parameterType (i ), paramField , methodParamAnnotationsField ,
1556
1556
methodGenericParametersField ,
1557
1557
i ));
@@ -1690,6 +1690,19 @@ private void handleSubResourceMethod(List<JaxrsClientReactiveEnricherBuildItem>
1690
1690
// just store the index of parameter used to create the body, we'll use it later
1691
1691
bodyParameterValue = paramValue ;
1692
1692
} else if (param .parameterType == ParameterType .HEADER ) {
1693
+ Type paramType = jandexSubMethod .parameterType (subParamField .paramIndex );
1694
+ String effectiveParamTypeStr = paramType .name ().toString ();
1695
+ boolean isOptional = isOptional (paramType , index );
1696
+ if (isOptional ) {
1697
+ effectiveParamTypeStr = DotNames .OBJECT .toString ();
1698
+ if (paramType .kind () == PARAMETERIZED_TYPE ) {
1699
+ Type objectType = paramType .asParameterizedType ().arguments ().get (0 );
1700
+ if ((objectType .kind () == CLASS ) || (objectType .kind () == PARAMETERIZED_TYPE )) {
1701
+ effectiveParamTypeStr = objectType .name ().toString ();
1702
+ }
1703
+ }
1704
+ }
1705
+
1693
1706
// headers are added at the invocation builder level
1694
1707
MethodDescriptor handleHeaderDescriptor = MethodDescriptor .ofMethod (subName ,
1695
1708
subMethod .getName () + "$$" + subMethodIndex + "$$handleHeader$$param"
@@ -1702,9 +1715,15 @@ private void handleSubResourceMethod(List<JaxrsClientReactiveEnricherBuildItem>
1702
1715
AssignableResultHandle invocationBuilderRef = handleHeaderMethod
1703
1716
.createVariable (Invocation .Builder .class );
1704
1717
handleHeaderMethod .assign (invocationBuilderRef , handleHeaderMethod .getMethodParam (0 ));
1718
+ ResultHandle headerValue = handleHeaderMethod .getMethodParam (1 );
1705
1719
addHeaderParam (handleHeaderMethod , invocationBuilderRef , param .name ,
1706
- handleHeaderMethod .getMethodParam (1 ),
1707
- param .type ,
1720
+ isOptional
1721
+ ? handleHeaderMethod .invokeVirtualMethod (
1722
+ MethodDescriptor .ofMethod (Optional .class , "orElse" , Object .class ,
1723
+ Object .class ),
1724
+ headerValue , handleHeaderMethod .loadNull ())
1725
+ : headerValue ,
1726
+ effectiveParamTypeStr ,
1708
1727
handleHeaderMethod .readInstanceField (clientField , handleHeaderMethod .getThis ()),
1709
1728
getGenericTypeFromArray (handleHeaderMethod , subParamField .genericsParametersField ,
1710
1729
subParamField .paramIndex ),
@@ -1816,6 +1835,19 @@ private void handleSubResourceMethod(List<JaxrsClientReactiveEnricherBuildItem>
1816
1835
// just store the index of parameter used to create the body, we'll use it later
1817
1836
bodyParameterValue = subMethodCreator .getMethodParam (paramIdx );
1818
1837
} else if (param .parameterType == ParameterType .HEADER ) {
1838
+ Type paramType = jandexSubMethod .parameterType (paramIdx );
1839
+ String effectiveParamTypeStr = paramType .name ().toString ();
1840
+ boolean isOptional = isOptional (paramType , index );
1841
+ if (isOptional ) {
1842
+ effectiveParamTypeStr = DotNames .OBJECT .toString ();
1843
+ if (paramType .kind () == PARAMETERIZED_TYPE ) {
1844
+ Type objectType = paramType .asParameterizedType ().arguments ().get (0 );
1845
+ if ((objectType .kind () == CLASS ) || (objectType .kind () == PARAMETERIZED_TYPE )) {
1846
+ effectiveParamTypeStr = objectType .name ().toString ();
1847
+ }
1848
+ }
1849
+ }
1850
+
1819
1851
// headers are added at the invocation builder level
1820
1852
MethodDescriptor handleHeaderDescriptor = MethodDescriptor .ofMethod (subName ,
1821
1853
subMethod .getName () + "$$" + subMethodIndex + "$$handleHeader$$" + paramIdx ,
@@ -1826,9 +1858,16 @@ private void handleSubResourceMethod(List<JaxrsClientReactiveEnricherBuildItem>
1826
1858
1827
1859
AssignableResultHandle invocationBuilderRef = handleHeaderMethod
1828
1860
.createVariable (Invocation .Builder .class );
1861
+ ResultHandle headerValue = handleHeaderMethod .getMethodParam (1 );
1829
1862
handleHeaderMethod .assign (invocationBuilderRef , handleHeaderMethod .getMethodParam (0 ));
1830
1863
addHeaderParam (handleHeaderMethod , invocationBuilderRef , param .name ,
1831
- handleHeaderMethod .getMethodParam (1 ), param .type ,
1864
+ isOptional
1865
+ ? handleHeaderMethod .invokeVirtualMethod (
1866
+ MethodDescriptor .ofMethod (Optional .class , "orElse" , Object .class ,
1867
+ Object .class ),
1868
+ headerValue , handleHeaderMethod .loadNull ())
1869
+ : headerValue ,
1870
+ effectiveParamTypeStr ,
1832
1871
handleHeaderMethod .readInstanceField (clientField , handleHeaderMethod .getThis ()),
1833
1872
getGenericTypeFromArray (handleHeaderMethod , subMethodGenericParametersField , paramIdx ),
1834
1873
getAnnotationsFromArray (handleHeaderMethod , subMethodParamAnnotationsField , paramIdx ));
@@ -2018,7 +2057,7 @@ private void generateSubResourceLocatorOwnerMethod(String name, ClassRestClientC
2018
2057
for (int i = 0 ; i < method .getParameters ().length ; i ++) {
2019
2058
MethodParameter param = method .getParameters ()[i ];
2020
2059
if (param .parameterType != ParameterType .PATH ) {
2021
- FieldDescriptor paramField = FieldDescriptor .of (subName , "param" + i , param .type );
2060
+ FieldDescriptor paramField = FieldDescriptor .of (subName , "param" + i , param .declaredType );
2022
2061
ownerMethod .writeInstanceField (paramField , subInstance , ownerMethod .getMethodParam (i ));
2023
2062
}
2024
2063
0 commit comments