I have a rest controller
@RestController
@RequestMapping(APIConstants.API_BASE_URI + APIConstants.MYCONTROLLER)
public class MyController extends APIRESTResource {
@Context
UriInfo uriInfo;
@GetMapping({"/activate"})
public ResponseEntity<String> activateAccount(@PathVariable("service") String srvc, @Context UriInfo info) {
HttpStatus status = HttpStatus.OK;
MediaType type = MediaType.TEXT_PLAIN;
String payload = "Activated";
try {
List<Long> accountIdList = extractAccountIdsAsList(info);
String datasource = getDatasourceForService(srvc);
AccountsServiceImpl mgr = new AccountsServiceImpl(datasource);
mgr.activateAccounts(accIdList);
HttpHeaders headers = new HttpHeaders();
headers.setContentType(type);
return new ResponseEntity<>(payload, headers, status);
}
catch (Exception ex) {
return new ResponseEntity<>(ex.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR);
}
}
}
where
private List<Long> extractAccountIdsAsList(UriInfo info) throws Exception {
String fieldName = "accId";
String accIdStr = info.getQueryParameters().getFirst(fieldName);
validateRequiredField(fieldName, accIdStr);
accIdStr = accIdStr.replace(" ", ""); // remove any spaces...
String[] accIds = null;
if (accIdStr.contains(",")) {
accIds = accIdStr.split("\\,");
}
else {
accIds = new String[1];
accIds[0] = accIdStr;
}
List<Long> accIdList = new ArrayList<Long>();
for (int i = 0; i < accIds.length; i++) {
validateFieldValueType(fieldName, accIds[i], Long.TYPE);
Long accId = new Long(accIds[i]);
accIdList.add(accId);
}
return accIdList;
}
but that will fail with an error
No primary or single public constructor found for interface javax.ws.rs.core.UriInfo - and no default constructor found either
not even making it to that controller. Any other controller for @GetMapping
works fine but only that one with @Context
is failing.