/** * Constructor. * * @param contentType content type value used to build a Content-Type header. e.g. text/csv or application/json */ DefaultResponseFormatType(String contentType) { this.fileExtension = "." + name().toLowerCase(Locale.ENGLISH); this.contentType = contentType; }
@Override public boolean accepts(String responseFormatValue) { return Objects.equals(toString(), responseFormatValue); }
/** * Generates the format in which the response data is expected. * * @param format Expects a URL format query String. * * @return Response format type (CSV or JSON). * @throws BadApiRequestException if the requested format is not found. */ protected ResponseFormatType generateAcceptFormat(String format) throws BadApiRequestException { try { return format == null ? DefaultResponseFormatType.JSON : DefaultResponseFormatType.valueOf(format.toUpperCase(Locale.ENGLISH)); } catch (IllegalArgumentException e) { LOG.error(ACCEPT_FORMAT_INVALID.logFormat(format), e); throw new BadApiRequestException(ACCEPT_FORMAT_INVALID.format(format)); } }
if (CSV.accepts(apiRequest.getFormat())) { output = new CsvResponse<>( rows,
@Override public boolean accepts(ResponseFormatType formatType) { return formatType.accepts(this.toString()); }
@Override public String toString() { return name().toLowerCase(Locale.ENGLISH); }
RequestLog.record(new JobRequest(ticket)); apiRequest = new JobsApiRequestImpl( DefaultResponseFormatType.JSON.toString(), null, "",