List of usage examples for org.springframework.http HttpHeaders setLastModified
public void setLastModified(long lastModified)
From source file:net.es.sense.rm.api.SenseRmController.java
/** * Returns the delta resource identified by deltaId that is associated with model identified by id within the Resource * Manager./*from www . j av a 2s . c o m*/ * * @param accept Provides media types that are acceptable for the response. At the moment 'application/json' is the * supported response encoding. * @param ifModifiedSince The HTTP request may contain the If-Modified-Since header requesting all models with * creationTime after the specified date. The date must be specified in RFC 1123 format. * @param encode * @param model This versions detailed topology model in the requested format (TURTLE, etc.). To optimize transfer * the contents of this model element should be gzipped (contentType="application/x-gzip") and base64 encoded * (contentTransferEncoding="base64"). This will reduce the transfer size and encapsulate the original model contents. * @param id Identifier of the target topology model resource. * @param deltaId Identifier of the target delta resource. * @return A RESTful response. */ @ApiOperation(value = "Get a specific SENSE topology model resource.", notes = "Returns SENSE topology model resource corresponding to the specified resource id.", response = DeltaResource.class) @ApiResponses(value = { @ApiResponse(code = HttpConstants.OK_CODE, message = HttpConstants.OK_DELTA_MSG, response = DeltaResource.class, responseHeaders = { @ResponseHeader(name = HttpConstants.CONTENT_TYPE_NAME, description = HttpConstants.CONTENT_TYPE_DESC, response = String.class), @ResponseHeader(name = HttpConstants.LAST_MODIFIED_NAME, description = HttpConstants.LAST_MODIFIED_DESC, response = String.class) }), @ApiResponse(code = HttpConstants.NOT_MODIFIED, message = HttpConstants.NOT_MODIFIED_MSG, response = Error.class, responseHeaders = { @ResponseHeader(name = HttpConstants.CONTENT_TYPE_NAME, description = HttpConstants.CONTENT_TYPE_DESC, response = String.class), @ResponseHeader(name = HttpConstants.LAST_MODIFIED_NAME, description = HttpConstants.LAST_MODIFIED_DESC, response = String.class) }), @ApiResponse(code = HttpConstants.BAD_REQUEST_CODE, message = HttpConstants.BAD_REQUEST_MSG, response = Error.class, responseHeaders = { @ResponseHeader(name = HttpConstants.CONTENT_TYPE_NAME, description = HttpConstants.CONTENT_TYPE_DESC, response = String.class) }), @ApiResponse(code = HttpConstants.FORBIDDEN_CODE, message = HttpConstants.FORBIDDEN_MSG, response = Error.class, responseHeaders = { @ResponseHeader(name = HttpConstants.CONTENT_TYPE_NAME, description = HttpConstants.CONTENT_TYPE_DESC, response = String.class) }), @ApiResponse(code = HttpConstants.NOT_FOUND_CODE, message = HttpConstants.NOT_FOUND_MSG, response = Error.class, responseHeaders = { @ResponseHeader(name = HttpConstants.CONTENT_TYPE_NAME, description = HttpConstants.CONTENT_TYPE_DESC, response = String.class) }), @ApiResponse(code = HttpConstants.NOT_ACCEPTABLE_CODE, message = HttpConstants.NOT_ACCEPTABLE_MSG, response = Error.class, responseHeaders = { @ResponseHeader(name = HttpConstants.CONTENT_TYPE_NAME, description = HttpConstants.CONTENT_TYPE_DESC, response = String.class) }), @ApiResponse(code = HttpConstants.INTERNAL_ERROR_CODE, message = HttpConstants.INTERNAL_ERROR_MSG, response = Error.class, responseHeaders = { @ResponseHeader(name = HttpConstants.CONTENT_TYPE_NAME, description = HttpConstants.CONTENT_TYPE_DESC, response = String.class) }), }) @RequestMapping(value = "/models/{" + HttpConstants.ID_NAME + "}/deltas/{" + HttpConstants.DELTAID_NAME + "}", method = RequestMethod.GET, produces = { MediaType.APPLICATION_JSON_VALUE }) @ResponseBody public ResponseEntity<?> getModelDelta( @RequestHeader(value = HttpConstants.ACCEPT_NAME, defaultValue = MediaType.APPLICATION_JSON_VALUE) @ApiParam(value = HttpConstants.ACCEPT_MSG, required = false) String accept, @RequestHeader(value = HttpConstants.IF_MODIFIED_SINCE_NAME, defaultValue = HttpConstants.IF_MODIFIED_SINCE_DEFAULT) @ApiParam(value = HttpConstants.IF_MODIFIED_SINCE_MSG, required = false) String ifModifiedSince, @RequestParam(value = HttpConstants.MODEL_NAME, defaultValue = HttpConstants.MODEL_TURTLE) @ApiParam(value = HttpConstants.MODEL_MSG, required = false) String model, @RequestParam(value = HttpConstants.ENCODE_NAME, defaultValue = "false") @ApiParam(value = HttpConstants.ENCODE_MSG, required = false) boolean encode, @PathVariable(HttpConstants.ID_NAME) @ApiParam(value = HttpConstants.ID_MSG, required = true) String id, @PathVariable(HttpConstants.DELTAID_NAME) @ApiParam(value = HttpConstants.DELTAID_MSG, required = true) String deltaId) { // Get the requested resource URL. final URI location = ServletUriComponentsBuilder.fromCurrentRequestUri().build().toUri(); log.info( "[SenseRmController] operation = {}, id = {}, deltaId = {}, accept = {}, ifModifiedSince = {}, model = {}", location, id, deltaId, accept, ifModifiedSince, model); // Parse the If-Modified-Since header if it is present. long ifms = parseIfModfiedSince(ifModifiedSince); final HttpHeaders headers = new HttpHeaders(); headers.add("Content-Location", location.toASCIIString()); try { DeltaResponse response = driver.getDelta(deltaId, model, ifms).get(); if (response == null || response.getStatus() != Status.OK) { return toResponseEntity(headers, response); } DeltaResource d = response.getDelta().get(); log.info("[SenseRmController] deltaId = {}, lastModified = {}, If-Modified-Since = {}", d.getId(), d.getLastModified(), ifModifiedSince); long lastModified = XmlUtilities.xmlGregorianCalendar(d.getLastModified()).toGregorianCalendar() .getTimeInMillis(); d.setHref(location.toASCIIString()); if (encode) { d.setAddition(Encoder.encode(d.getAddition())); d.setReduction(Encoder.encode(d.getReduction())); d.setResult(Encoder.encode(d.getResult())); } headers.setLastModified(lastModified); log.info( "[SenseRmController] getDelta returning id = {}, creationTime = {}, queried If-Modified-Since = {}.", d.getId(), d.getLastModified(), ifModifiedSince); return new ResponseEntity<>(d, headers, HttpStatus.OK); } catch (InterruptedException | ExecutionException | IOException | DatatypeConfigurationException ex) { log.error("getDelta failed, ex = {}", ex); Error error = Error.builder().error(HttpStatus.INTERNAL_SERVER_ERROR.getReasonPhrase()) .error_description(ex.getMessage()).build(); return new ResponseEntity<>(error, HttpStatus.INTERNAL_SERVER_ERROR); } }
From source file:net.es.sense.rm.api.SenseRmController.java
/** * Returns a collection of delta resources. * * Operation: GET /api/sense/v1/deltas/*w w w. j av a 2 s. c om*/ * * @param accept Provides media types that are acceptable for the response. At the moment 'application/json' is the * supported response encoding. * @param ifModifiedSince The HTTP request may contain the If-Modified-Since header requesting all models with * creationTime after the specified date. The date must be specified in RFC 1123 format. * @param summary If summary=true then a summary collection of delta resources will be returned including the delta meta-data while excluding the addition, reduction, and m elements. Default value is summary=true. * @param encode * @param model If model=turtle then the returned addition, reduction, and m elements will contain the full topology model in a TURTLE representation. Default value is model=turtle. * @return A RESTful response. */ @ApiOperation(value = "Get a collection of accepted delta resources.", notes = "Returns a collection of available delta resources.", response = DeltaResource.class, responseContainer = "List") @ApiResponses(value = { @ApiResponse(code = HttpConstants.OK_CODE, message = HttpConstants.OK_DELTAS_MSG, response = DeltaResource.class, responseContainer = "List", responseHeaders = { @ResponseHeader(name = HttpConstants.CONTENT_TYPE_NAME, description = HttpConstants.CONTENT_TYPE_DESC, response = String.class), @ResponseHeader(name = HttpConstants.LAST_MODIFIED_NAME, description = HttpConstants.LAST_MODIFIED_DESC, response = String.class) }), @ApiResponse(code = HttpConstants.NOT_MODIFIED, message = HttpConstants.NOT_MODIFIED_MSG, response = Error.class, responseHeaders = { @ResponseHeader(name = HttpConstants.CONTENT_TYPE_NAME, description = HttpConstants.CONTENT_TYPE_DESC, response = String.class), @ResponseHeader(name = HttpConstants.LAST_MODIFIED_NAME, description = HttpConstants.LAST_MODIFIED_DESC, response = String.class) }), @ApiResponse(code = HttpConstants.BAD_REQUEST_CODE, message = HttpConstants.BAD_REQUEST_MSG, response = Error.class, responseHeaders = { @ResponseHeader(name = HttpConstants.CONTENT_TYPE_NAME, description = HttpConstants.CONTENT_TYPE_DESC, response = String.class) }), @ApiResponse(code = HttpConstants.FORBIDDEN_CODE, message = HttpConstants.FORBIDDEN_MSG, response = Error.class, responseHeaders = { @ResponseHeader(name = HttpConstants.CONTENT_TYPE_NAME, description = HttpConstants.CONTENT_TYPE_DESC, response = String.class) }), @ApiResponse(code = HttpConstants.NOT_FOUND_CODE, message = HttpConstants.NOT_FOUND_MSG, response = Error.class, responseHeaders = { @ResponseHeader(name = HttpConstants.CONTENT_TYPE_NAME, description = HttpConstants.CONTENT_TYPE_DESC, response = String.class) }), @ApiResponse(code = HttpConstants.NOT_ACCEPTABLE_CODE, message = HttpConstants.NOT_ACCEPTABLE_MSG, response = Error.class, responseHeaders = { @ResponseHeader(name = HttpConstants.CONTENT_TYPE_NAME, description = HttpConstants.CONTENT_TYPE_DESC, response = String.class) }), @ApiResponse(code = HttpConstants.INTERNAL_ERROR_CODE, message = HttpConstants.INTERNAL_ERROR_MSG, response = Error.class, responseHeaders = { @ResponseHeader(name = HttpConstants.CONTENT_TYPE_NAME, description = HttpConstants.CONTENT_TYPE_DESC, response = String.class) }), }) @RequestMapping(value = "/deltas", method = RequestMethod.GET, produces = { MediaType.APPLICATION_JSON_VALUE }) @ResponseBody @ResourceAnnotation(name = "deltas", version = "v1") public ResponseEntity<?> getDeltas( @RequestHeader(value = HttpConstants.ACCEPT_NAME, defaultValue = MediaType.APPLICATION_JSON_VALUE) @ApiParam(value = HttpConstants.ACCEPT_MSG, required = false) String accept, @RequestHeader(value = HttpConstants.IF_MODIFIED_SINCE_NAME, defaultValue = HttpConstants.IF_MODIFIED_SINCE_DEFAULT) @ApiParam(value = HttpConstants.IF_MODIFIED_SINCE_MSG, required = false) String ifModifiedSince, @RequestParam(value = HttpConstants.SUMMARY_NAME, defaultValue = "false") @ApiParam(value = HttpConstants.SUMMARY_MSG, required = false) boolean summary, @RequestParam(value = HttpConstants.MODEL_NAME, defaultValue = HttpConstants.MODEL_TURTLE) @ApiParam(value = HttpConstants.MODEL_MSG, required = false) String model, @RequestParam(value = HttpConstants.ENCODE_NAME, defaultValue = "false") @ApiParam(value = HttpConstants.ENCODE_MSG, required = false) boolean encode) { // We need the request URL to build fully qualified resource URLs. final URI location = ServletUriComponentsBuilder.fromCurrentRequestUri().build().toUri(); log.info("[SenseRmController] GET operation = {}, accept = {}, If-Modified-Since = {}, current = {}, " + "summary = {}, model = {}", location, accept, ifModifiedSince, summary, model); // Parse the If-Modified-Since header if it is present. long ifms = parseIfModfiedSince(ifModifiedSince); // Populate the content location header with our URL location. final HttpHeaders headers = new HttpHeaders(); headers.add("Content-Location", location.toASCIIString()); try { // Track matching deltas here. List<DeltaResource> deltas = new ArrayList<>(); // Keep track of the most recently updated delta date. long newest = 0; // Query the driver for a list of deltas. DeltasResponse response = driver.getDeltas(model, ifms).get(); if (response == null || response.getStatus() != Status.OK) { return toResponseEntity(headers, response); } // The requester asked for a list of models so apply any filtering criteria. for (DeltaResource d : response.getDeltas()) { long lastModified = XmlUtilities.xmlGregorianCalendar(d.getLastModified()).toGregorianCalendar() .getTimeInMillis(); log.info("[SenseRmController] delta id = {}, lastModified = {}, If-Modified-Since = {}", d.getId(), d.getLastModified(), ifModifiedSince); // Create the unique resource URL. d.setHref(UrlHelper.append(location.toASCIIString(), d.getId())); // If summary results are requested we do not return the model. if (summary) { d.setAddition(null); d.setReduction(null); d.setResult(null); } else { // If they requested an encoded transfer we will encode the model contents. if (encode) { d.setAddition(Encoder.encode(d.getAddition())); d.setReduction(Encoder.encode(d.getReduction())); d.setResult(Encoder.encode(d.getResult())); } } // Save this model and update If-Modified-Since with the creation time. deltas.add(d); if (lastModified > newest) { newest = lastModified; } } // Update the LastModified header with the value of the newest model. headers.setLastModified(newest); // We have success so return the models we have found. return new ResponseEntity<>(deltas, headers, HttpStatus.OK); } catch (InterruptedException | IOException | DatatypeConfigurationException | IllegalArgumentException | ExecutionException ex) { log.error("[SenseRmController] getDeltas failed, ex = {}", ex); Error error = Error.builder().error(HttpStatus.INTERNAL_SERVER_ERROR.getReasonPhrase()) .error_description(ex.getMessage()).build(); return new ResponseEntity<>(error, HttpStatus.INTERNAL_SERVER_ERROR); } }
From source file:net.es.sense.rm.api.SenseRmController.java
/** * Returns the delta resource identified by deltaId. * * Operation: GET /api/sense/v1/deltas/{deltaId} * * @param accept Provides media types that are acceptable for the response. At the moment 'application/json' is the * supported response encoding.//from ww w. j av a 2 s .co m * @param summary * @param ifModifiedSince The HTTP request may contain the If-Modified-Since header requesting all models with * creationTime after the specified date. The date must be specified in RFC 1123 format. * @param encode * @param model Specifies the model encoding to use (i.e. turtle, ttl, json-ld, etc). * @param deltaId Identifier of the target delta resource. * @return A RESTful response. */ @ApiOperation(value = "Get a specific SENSE topology model resource.", notes = "Returns SENSE topology model resource corresponding to the specified resource id.", response = DeltaResource.class) @ApiResponses(value = { @ApiResponse(code = HttpConstants.OK_CODE, message = HttpConstants.OK_DELTA_MSG, response = DeltaResource.class, responseHeaders = { @ResponseHeader(name = HttpConstants.CONTENT_TYPE_NAME, description = HttpConstants.CONTENT_TYPE_DESC, response = String.class), @ResponseHeader(name = HttpConstants.LAST_MODIFIED_NAME, description = HttpConstants.LAST_MODIFIED_DESC, response = String.class) }), @ApiResponse(code = HttpConstants.NOT_MODIFIED, message = HttpConstants.NOT_MODIFIED_MSG, response = Error.class, responseHeaders = { @ResponseHeader(name = HttpConstants.CONTENT_TYPE_NAME, description = HttpConstants.CONTENT_TYPE_DESC, response = String.class), @ResponseHeader(name = HttpConstants.LAST_MODIFIED_NAME, description = HttpConstants.LAST_MODIFIED_DESC, response = String.class) }), @ApiResponse(code = HttpConstants.BAD_REQUEST_CODE, message = HttpConstants.BAD_REQUEST_MSG, response = Error.class, responseHeaders = { @ResponseHeader(name = HttpConstants.CONTENT_TYPE_NAME, description = HttpConstants.CONTENT_TYPE_DESC, response = String.class) }), @ApiResponse(code = HttpConstants.FORBIDDEN_CODE, message = HttpConstants.FORBIDDEN_MSG, response = Error.class, responseHeaders = { @ResponseHeader(name = HttpConstants.CONTENT_TYPE_NAME, description = HttpConstants.CONTENT_TYPE_DESC, response = String.class) }), @ApiResponse(code = HttpConstants.NOT_FOUND_CODE, message = HttpConstants.NOT_FOUND_MSG, response = Error.class, responseHeaders = { @ResponseHeader(name = HttpConstants.CONTENT_TYPE_NAME, description = HttpConstants.CONTENT_TYPE_DESC, response = String.class) }), @ApiResponse(code = HttpConstants.NOT_ACCEPTABLE_CODE, message = HttpConstants.NOT_ACCEPTABLE_MSG, response = Error.class, responseHeaders = { @ResponseHeader(name = HttpConstants.CONTENT_TYPE_NAME, description = HttpConstants.CONTENT_TYPE_DESC, response = String.class) }), @ApiResponse(code = HttpConstants.INTERNAL_ERROR_CODE, message = HttpConstants.INTERNAL_ERROR_MSG, response = Error.class, responseHeaders = { @ResponseHeader(name = HttpConstants.CONTENT_TYPE_NAME, description = HttpConstants.CONTENT_TYPE_DESC, response = String.class) }), }) @RequestMapping(value = "/deltas/{" + HttpConstants.DELTAID_NAME + "}", method = RequestMethod.GET, produces = { MediaType.APPLICATION_JSON_VALUE }) @ResponseBody public ResponseEntity<?> getDelta( @RequestHeader(value = HttpConstants.ACCEPT_NAME, defaultValue = MediaType.APPLICATION_JSON_VALUE) @ApiParam(value = HttpConstants.ACCEPT_MSG, required = false) String accept, @RequestHeader(value = HttpConstants.IF_MODIFIED_SINCE_NAME, required = false) @ApiParam(value = HttpConstants.IF_MODIFIED_SINCE_MSG, required = false) String ifModifiedSince, @RequestParam(value = HttpConstants.SUMMARY_NAME, defaultValue = "false") @ApiParam(value = HttpConstants.SUMMARY_MSG, required = false) boolean summary, @RequestParam(value = HttpConstants.MODEL_NAME, defaultValue = HttpConstants.MODEL_TURTLE) @ApiParam(value = HttpConstants.MODEL_MSG, required = false) String model, @RequestParam(value = HttpConstants.ENCODE_NAME, defaultValue = "false") @ApiParam(value = HttpConstants.ENCODE_MSG, required = false) boolean encode, @PathVariable(HttpConstants.DELTAID_NAME) @ApiParam(value = HttpConstants.DELTAID_MSG, required = true) String deltaId) { // Get the requested resource URL. final URI location = ServletUriComponentsBuilder.fromCurrentRequestUri().build().toUri(); log.info("[SenseRmController] operation = {}, id = {}, accept = {}, ifModifiedSince = {}, model = {}", location, deltaId, accept, ifModifiedSince, model); // Parse the If-Modified-Since header if it is present. long ifms = parseIfModfiedSince(ifModifiedSince); // We need to return the current location of this resource in the response header. final HttpHeaders headers = new HttpHeaders(); headers.add("Content-Location", location.toASCIIString()); try { // Query for the requested delta. DeltaResponse response = driver.getDelta(deltaId, model, ifms).get(); if (response == null || response.getStatus() != Status.OK) { return toResponseEntity(headers, response); } DeltaResource d = response.getDelta().get(); log.info("[SenseRmController] deltaId = {}, lastModified = {}, If-Modified-Since = {}", d.getId(), d.getLastModified(), ifModifiedSince); // Determine when this was last modified. long lastModified = XmlUtilities.xmlGregorianCalendar(d.getLastModified()).toGregorianCalendar() .getTimeInMillis(); headers.setLastModified(lastModified); // Do we need to return this delta? if (lastModified <= ifms) { log.info("[SenseRmController] returning not modified, deltaId = {}", d.getId()); return new ResponseEntity<>(headers, HttpStatus.NOT_MODIFIED); } d.setHref(location.toASCIIString()); if (summary) { // If a summary resource view was requested we do not send back any models. d.setAddition(null); d.setReduction(null); d.setResult(null); } else if (encode) { // Compress and base64 encode the model contents if requested. d.setAddition(Encoder.encode(d.getAddition())); d.setReduction(Encoder.encode(d.getReduction())); d.setResult(Encoder.encode(d.getResult())); } log.info( "[SenseRmController] getDelta returning id = {}, creationTime = {}, queried If-Modified-Since = {}.", d.getId(), d.getLastModified(), ifModifiedSince); return new ResponseEntity<>(d, headers, HttpStatus.OK); } catch (InterruptedException | ExecutionException | IOException | DatatypeConfigurationException ex) { log.error("[SenseRmController] getDelta failed, deltaId = {}, ex = {}", deltaId, ex); Error error = Error.builder().error(HttpStatus.INTERNAL_SERVER_ERROR.getReasonPhrase()) .error_description(ex.getMessage()).build(); return new ResponseEntity<>(error, HttpStatus.INTERNAL_SERVER_ERROR); } }
From source file:net.es.sense.rm.api.SenseRmController.java
/** * Submits a proposed model delta to the Resource Manager based on the model * identified by modelId within the deltaRequest. * * Operation: POST /api/sense/v1/deltas//from w ww.j ava 2 s.c om * * @param accept * @param deltaRequest * @param encode * @param model * @return * @throws java.net.URISyntaxException */ @ApiOperation(value = "Submits a proposed model delta to the Resource Manager based on the model " + "identified by id.", notes = "The Resource Manager must verify the proposed model change, confirming " + "(201 Created), rejecting (500 Internal Server Error), or proposing an " + "optional counter-offer (200 OK).", response = DeltaResource.class) @ApiResponses(value = { @ApiResponse(code = HttpConstants.OK_CODE, message = HttpConstants.OK_DELTA_COUNTER_MSG, response = DeltaRequest.class, responseHeaders = { @ResponseHeader(name = HttpConstants.CONTENT_TYPE_NAME, description = HttpConstants.CONTENT_TYPE_DESC, response = String.class), @ResponseHeader(name = HttpConstants.LAST_MODIFIED_NAME, description = HttpConstants.LAST_MODIFIED_DESC, response = String.class) }), @ApiResponse(code = HttpConstants.CREATED_CODE, message = HttpConstants.CREATED_MSG, response = DeltaResource.class, responseHeaders = { @ResponseHeader(name = HttpConstants.CONTENT_TYPE_NAME, description = HttpConstants.CONTENT_TYPE_DESC, response = String.class), @ResponseHeader(name = HttpConstants.LAST_MODIFIED_NAME, description = HttpConstants.LAST_MODIFIED_DESC, response = String.class) }), @ApiResponse(code = HttpConstants.BAD_REQUEST_CODE, message = HttpConstants.BAD_REQUEST_MSG, response = Error.class, responseHeaders = { @ResponseHeader(name = HttpConstants.CONTENT_TYPE_NAME, description = HttpConstants.CONTENT_TYPE_DESC, response = String.class) }), @ApiResponse(code = HttpConstants.FORBIDDEN_CODE, message = HttpConstants.FORBIDDEN_MSG, response = Error.class, responseHeaders = { @ResponseHeader(name = HttpConstants.CONTENT_TYPE_NAME, description = HttpConstants.CONTENT_TYPE_DESC, response = String.class) }), @ApiResponse(code = HttpConstants.NOT_FOUND_CODE, message = HttpConstants.NOT_FOUND_MSG, response = Error.class, responseHeaders = { @ResponseHeader(name = HttpConstants.CONTENT_TYPE_NAME, description = HttpConstants.CONTENT_TYPE_DESC, response = String.class) }), @ApiResponse(code = HttpConstants.NOT_ACCEPTABLE_CODE, message = HttpConstants.NOT_ACCEPTABLE_MSG, response = Error.class, responseHeaders = { @ResponseHeader(name = HttpConstants.CONTENT_TYPE_NAME, description = HttpConstants.CONTENT_TYPE_DESC, response = String.class) }), @ApiResponse(code = HttpConstants.CONFLICT_CODE, message = HttpConstants.CONFLICT_MSG, response = Error.class, responseHeaders = { @ResponseHeader(name = HttpConstants.CONTENT_TYPE_NAME, description = HttpConstants.CONTENT_TYPE_DESC, response = String.class) }), @ApiResponse(code = HttpConstants.INTERNAL_ERROR_CODE, message = HttpConstants.INTERNAL_ERROR_MSG, response = Error.class, responseHeaders = { @ResponseHeader(name = HttpConstants.CONTENT_TYPE_NAME, description = HttpConstants.CONTENT_TYPE_DESC, response = String.class) }), }) @RequestMapping(value = "/deltas", method = RequestMethod.POST, consumes = { MediaType.APPLICATION_JSON_VALUE }, produces = { MediaType.APPLICATION_JSON_VALUE }) public ResponseEntity<?> propagateDelta( @RequestHeader(value = HttpConstants.ACCEPT_NAME, defaultValue = MediaType.APPLICATION_JSON_VALUE) @ApiParam(value = HttpConstants.ACCEPT_MSG, required = false) String accept, @RequestParam(value = HttpConstants.MODEL_NAME, defaultValue = HttpConstants.MODEL_TURTLE) @ApiParam(value = HttpConstants.MODEL_MSG, required = false) String model, @RequestParam(value = HttpConstants.ENCODE_NAME, defaultValue = "false") @ApiParam(value = HttpConstants.ENCODE_MSG, required = false) boolean encode, @RequestBody @ApiParam(value = "A JSON structure-containing the model reduction and/or addition " + " elements. If provided, the model reduction element is applied first, " + " followed by the model addition element.", required = true) DeltaRequest deltaRequest) throws URISyntaxException { final URI location = ServletUriComponentsBuilder.fromCurrentRequestUri().build().toUri(); log.info( "[SenseRmController] POST operation = {}, accept = {}, deltaId = {}, modelId = {}, deltaRequest = {}", location, accept, deltaRequest.getId(), model, deltaRequest); // If the requester did not specify a delta id then we need to create one. if (Strings.isNullOrEmpty(deltaRequest.getId())) { deltaRequest.setId(UuidHelper.getUUID()); log.info("[SenseRmController] assigning delta id = {}", deltaRequest.getId()); } try { if (encode) { if (!Strings.isNullOrEmpty(deltaRequest.getAddition())) { deltaRequest.setAddition(Decoder.decode(deltaRequest.getAddition())); } if (!Strings.isNullOrEmpty(deltaRequest.getReduction())) { deltaRequest.setReduction(Decoder.decode(deltaRequest.getReduction())); } } // We need to return the current location of this resource in the response header. final HttpHeaders headers = new HttpHeaders(); // Query for the requested delta. DeltaResponse response = driver.propagateDelta(deltaRequest, model).get(); if (response == null || response.getStatus() != Status.CREATED) { return toResponseEntity(headers, response); } DeltaResource delta = response.getDelta().get(); String contentLocation = UrlHelper.append(location.toASCIIString(), delta.getId()); log.info("[SenseRmController] Delta id = {}, lastModified = {}, content-location = {}", delta.getId(), delta.getLastModified(), contentLocation); long lastModified = XmlUtilities.xmlGregorianCalendar(delta.getLastModified()).toGregorianCalendar() .getTimeInMillis(); delta.setHref(contentLocation); if (encode) { if (!Strings.isNullOrEmpty(delta.getAddition())) { delta.setAddition(Encoder.encode(delta.getAddition())); } if (!Strings.isNullOrEmpty(delta.getReduction())) { delta.setReduction(Encoder.encode(delta.getReduction())); } if (!Strings.isNullOrEmpty(delta.getResult())) { delta.setResult(Encoder.encode(delta.getResult())); } } headers.add("Content-Location", contentLocation); headers.setLastModified(lastModified); log.info("[SenseRmController] Delta returning id = {}, creationTime = {}", delta.getId(), delta.getLastModified()); return new ResponseEntity<>(delta, headers, HttpStatus.CREATED); } catch (InterruptedException | ExecutionException | IOException | DatatypeConfigurationException ex) { log.error("pullModel failed", ex); Error error = Error.builder().error(HttpStatus.INTERNAL_SERVER_ERROR.getReasonPhrase()) .error_description(ex.getMessage()).build(); return new ResponseEntity<>(error, HttpStatus.INTERNAL_SERVER_ERROR); } }
From source file:org.springframework.cloud.stream.app.http.source.DefaultMixedCaseContentTypeHttpHeaderMapper.java
private void setHttpHeader(HttpHeaders target, String name, Object value) { if (ACCEPT.equalsIgnoreCase(name)) { if (value instanceof Collection<?>) { Collection<?> values = (Collection<?>) value; if (!CollectionUtils.isEmpty(values)) { List<MediaType> acceptableMediaTypes = new ArrayList<MediaType>(); for (Object type : values) { if (type instanceof MediaType) { acceptableMediaTypes.add((MediaType) type); } else if (type instanceof String) { acceptableMediaTypes.addAll(MediaType.parseMediaTypes((String) type)); } else { Class<?> clazz = (type != null) ? type.getClass() : null; throw new IllegalArgumentException( "Expected MediaType or String value for 'Accept' header value, but received: " + clazz); }/* ww w .j av a2 s . c o m*/ } target.setAccept(acceptableMediaTypes); } } else if (value instanceof MediaType) { target.setAccept(Collections.singletonList((MediaType) value)); } else if (value instanceof String[]) { List<MediaType> acceptableMediaTypes = new ArrayList<MediaType>(); for (String next : (String[]) value) { acceptableMediaTypes.add(MediaType.parseMediaType(next)); } target.setAccept(acceptableMediaTypes); } else if (value instanceof String) { target.setAccept(MediaType.parseMediaTypes((String) value)); } else { Class<?> clazz = (value != null) ? value.getClass() : null; throw new IllegalArgumentException( "Expected MediaType or String value for 'Accept' header value, but received: " + clazz); } } else if (ACCEPT_CHARSET.equalsIgnoreCase(name)) { if (value instanceof Collection<?>) { Collection<?> values = (Collection<?>) value; if (!CollectionUtils.isEmpty(values)) { List<Charset> acceptableCharsets = new ArrayList<Charset>(); for (Object charset : values) { if (charset instanceof Charset) { acceptableCharsets.add((Charset) charset); } else if (charset instanceof String) { acceptableCharsets.add(Charset.forName((String) charset)); } else { Class<?> clazz = (charset != null) ? charset.getClass() : null; throw new IllegalArgumentException( "Expected Charset or String value for 'Accept-Charset' header value, but received: " + clazz); } } target.setAcceptCharset(acceptableCharsets); } } else if (value instanceof Charset[] || value instanceof String[]) { List<Charset> acceptableCharsets = new ArrayList<Charset>(); Object[] values = ObjectUtils.toObjectArray(value); for (Object charset : values) { if (charset instanceof Charset) { acceptableCharsets.add((Charset) charset); } else if (charset instanceof String) { acceptableCharsets.add(Charset.forName((String) charset)); } } target.setAcceptCharset(acceptableCharsets); } else if (value instanceof Charset) { target.setAcceptCharset(Collections.singletonList((Charset) value)); } else if (value instanceof String) { String[] charsets = StringUtils.commaDelimitedListToStringArray((String) value); List<Charset> acceptableCharsets = new ArrayList<Charset>(); for (String charset : charsets) { acceptableCharsets.add(Charset.forName(charset.trim())); } target.setAcceptCharset(acceptableCharsets); } else { Class<?> clazz = (value != null) ? value.getClass() : null; throw new IllegalArgumentException( "Expected Charset or String value for 'Accept-Charset' header value, but received: " + clazz); } } else if (ALLOW.equalsIgnoreCase(name)) { if (value instanceof Collection<?>) { Collection<?> values = (Collection<?>) value; if (!CollectionUtils.isEmpty(values)) { Set<HttpMethod> allowedMethods = new HashSet<HttpMethod>(); for (Object method : values) { if (method instanceof HttpMethod) { allowedMethods.add((HttpMethod) method); } else if (method instanceof String) { allowedMethods.add(HttpMethod.valueOf((String) method)); } else { Class<?> clazz = (method != null) ? method.getClass() : null; throw new IllegalArgumentException( "Expected HttpMethod or String value for 'Allow' header value, but received: " + clazz); } } target.setAllow(allowedMethods); } } else { if (value instanceof HttpMethod) { target.setAllow(Collections.singleton((HttpMethod) value)); } else if (value instanceof HttpMethod[]) { Set<HttpMethod> allowedMethods = new HashSet<HttpMethod>(); Collections.addAll(allowedMethods, (HttpMethod[]) value); target.setAllow(allowedMethods); } else if (value instanceof String || value instanceof String[]) { String[] values = (value instanceof String[]) ? (String[]) value : StringUtils.commaDelimitedListToStringArray((String) value); Set<HttpMethod> allowedMethods = new HashSet<HttpMethod>(); for (String next : values) { allowedMethods.add(HttpMethod.valueOf(next.trim())); } target.setAllow(allowedMethods); } else { Class<?> clazz = (value != null) ? value.getClass() : null; throw new IllegalArgumentException( "Expected HttpMethod or String value for 'Allow' header value, but received: " + clazz); } } } else if (CACHE_CONTROL.equalsIgnoreCase(name)) { if (value instanceof String) { target.setCacheControl((String) value); } else { Class<?> clazz = (value != null) ? value.getClass() : null; throw new IllegalArgumentException( "Expected String value for 'Cache-Control' header value, but received: " + clazz); } } else if (CONTENT_LENGTH.equalsIgnoreCase(name)) { if (value instanceof Number) { target.setContentLength(((Number) value).longValue()); } else if (value instanceof String) { target.setContentLength(Long.parseLong((String) value)); } else { Class<?> clazz = (value != null) ? value.getClass() : null; throw new IllegalArgumentException( "Expected Number or String value for 'Content-Length' header value, but received: " + clazz); } } else if (MessageHeaders.CONTENT_TYPE.equalsIgnoreCase(name)) { if (value instanceof MediaType) { target.setContentType((MediaType) value); } else if (value instanceof String) { target.setContentType(MediaType.parseMediaType((String) value)); } else { Class<?> clazz = (value != null) ? value.getClass() : null; throw new IllegalArgumentException( "Expected MediaType or String value for 'Content-Type' header value, but received: " + clazz); } } else if (DATE.equalsIgnoreCase(name)) { if (value instanceof Date) { target.setDate(((Date) value).getTime()); } else if (value instanceof Number) { target.setDate(((Number) value).longValue()); } else if (value instanceof String) { try { target.setDate(Long.parseLong((String) value)); } catch (NumberFormatException e) { target.setDate(this.getFirstDate((String) value, DATE)); } } else { Class<?> clazz = (value != null) ? value.getClass() : null; throw new IllegalArgumentException( "Expected Date, Number, or String value for 'Date' header value, but received: " + clazz); } } else if (ETAG.equalsIgnoreCase(name)) { if (value instanceof String) { target.setETag((String) value); } else { Class<?> clazz = (value != null) ? value.getClass() : null; throw new IllegalArgumentException( "Expected String value for 'ETag' header value, but received: " + clazz); } } else if (EXPIRES.equalsIgnoreCase(name)) { if (value instanceof Date) { target.setExpires(((Date) value).getTime()); } else if (value instanceof Number) { target.setExpires(((Number) value).longValue()); } else if (value instanceof String) { try { target.setExpires(Long.parseLong((String) value)); } catch (NumberFormatException e) { target.setExpires(this.getFirstDate((String) value, EXPIRES)); } } else { Class<?> clazz = (value != null) ? value.getClass() : null; throw new IllegalArgumentException( "Expected Date, Number, or String value for 'Expires' header value, but received: " + clazz); } } else if (IF_MODIFIED_SINCE.equalsIgnoreCase(name)) { if (value instanceof Date) { target.setIfModifiedSince(((Date) value).getTime()); } else if (value instanceof Number) { target.setIfModifiedSince(((Number) value).longValue()); } else if (value instanceof String) { try { target.setIfModifiedSince(Long.parseLong((String) value)); } catch (NumberFormatException e) { target.setIfModifiedSince(this.getFirstDate((String) value, IF_MODIFIED_SINCE)); } } else { Class<?> clazz = (value != null) ? value.getClass() : null; throw new IllegalArgumentException( "Expected Date, Number, or String value for 'If-Modified-Since' header value, but received: " + clazz); } } else if (IF_UNMODIFIED_SINCE.equalsIgnoreCase(name)) { String ifUnmodifiedSinceValue = null; if (value instanceof Date) { ifUnmodifiedSinceValue = this.formatDate(((Date) value).getTime()); } else if (value instanceof Number) { ifUnmodifiedSinceValue = this.formatDate(((Number) value).longValue()); } else if (value instanceof String) { try { ifUnmodifiedSinceValue = this.formatDate(Long.parseLong((String) value)); } catch (NumberFormatException e) { long longValue = this.getFirstDate((String) value, IF_UNMODIFIED_SINCE); ifUnmodifiedSinceValue = this.formatDate(longValue); } } else { Class<?> clazz = (value != null) ? value.getClass() : null; throw new IllegalArgumentException( "Expected Date, Number, or String value for 'If-Unmodified-Since' header value, but received: " + clazz); } target.set(IF_UNMODIFIED_SINCE, ifUnmodifiedSinceValue); } else if (IF_NONE_MATCH.equalsIgnoreCase(name)) { if (value instanceof String) { target.setIfNoneMatch((String) value); } else if (value instanceof String[]) { String delmitedString = StringUtils.arrayToCommaDelimitedString((String[]) value); target.setIfNoneMatch(delmitedString); } else if (value instanceof Collection) { Collection<?> values = (Collection<?>) value; if (!CollectionUtils.isEmpty(values)) { List<String> ifNoneMatchList = new ArrayList<String>(); for (Object next : values) { if (next instanceof String) { ifNoneMatchList.add((String) next); } else { Class<?> clazz = (next != null) ? next.getClass() : null; throw new IllegalArgumentException( "Expected String value for 'If-None-Match' header value, but received: " + clazz); } } target.setIfNoneMatch(ifNoneMatchList); } } } else if (LAST_MODIFIED.equalsIgnoreCase(name)) { if (value instanceof Date) { target.setLastModified(((Date) value).getTime()); } else if (value instanceof Number) { target.setLastModified(((Number) value).longValue()); } else if (value instanceof String) { try { target.setLastModified(Long.parseLong((String) value)); } catch (NumberFormatException e) { target.setLastModified(this.getFirstDate((String) value, LAST_MODIFIED)); } } else { Class<?> clazz = (value != null) ? value.getClass() : null; throw new IllegalArgumentException( "Expected Date, Number, or String value for 'Last-Modified' header value, but received: " + clazz); } } else if (LOCATION.equalsIgnoreCase(name)) { if (value instanceof URI) { target.setLocation((URI) value); } else if (value instanceof String) { try { target.setLocation(new URI((String) value)); } catch (URISyntaxException e) { throw new IllegalArgumentException(e); } } else { Class<?> clazz = (value != null) ? value.getClass() : null; throw new IllegalArgumentException( "Expected URI or String value for 'Location' header value, but received: " + clazz); } } else if (PRAGMA.equalsIgnoreCase(name)) { if (value instanceof String) { target.setPragma((String) value); } else { Class<?> clazz = (value != null) ? value.getClass() : null; throw new IllegalArgumentException( "Expected String value for 'Pragma' header value, but received: " + clazz); } } else if (value instanceof String) { target.set(name, (String) value); } else if (value instanceof String[]) { for (String next : (String[]) value) { target.add(name, next); } } else if (value instanceof Iterable<?>) { for (Object next : (Iterable<?>) value) { String convertedValue = null; if (next instanceof String) { convertedValue = (String) next; } else { convertedValue = this.convertToString(value); } if (StringUtils.hasText(convertedValue)) { target.add(name, convertedValue); } else { logger.warn("Element of the header '" + name + "' with value '" + value + "' will not be set since it is not a String and no Converter is available. " + "Consider registering a Converter with ConversionService (e.g., <int:converter>)"); } } } else { String convertedValue = this.convertToString(value); if (StringUtils.hasText(convertedValue)) { target.set(name, convertedValue); } else { logger.warn("Header '" + name + "' with value '" + value + "' will not be set since it is not a String and no Converter is available. " + "Consider registering a Converter with ConversionService (e.g., <int:converter>)"); } } }
From source file:org.springframework.integration.http.support.DefaultHttpHeaderMapper.java
private void setHttpHeader(HttpHeaders target, String name, Object value) { if (ACCEPT.equalsIgnoreCase(name)) { if (value instanceof Collection<?>) { Collection<?> values = (Collection<?>) value; if (!CollectionUtils.isEmpty(values)) { List<MediaType> acceptableMediaTypes = new ArrayList<MediaType>(); for (Object type : values) { if (type instanceof MediaType) { acceptableMediaTypes.add((MediaType) type); } else if (type instanceof String) { acceptableMediaTypes.addAll(MediaType.parseMediaTypes((String) type)); } else { Class<?> clazz = (type != null) ? type.getClass() : null; throw new IllegalArgumentException( "Expected MediaType or String value for 'Accept' header value, but received: " + clazz); }//from www .jav a 2 s . com } target.setAccept(acceptableMediaTypes); } } else if (value instanceof MediaType) { target.setAccept(Collections.singletonList((MediaType) value)); } else if (value instanceof String[]) { List<MediaType> acceptableMediaTypes = new ArrayList<MediaType>(); for (String next : (String[]) value) { acceptableMediaTypes.add(MediaType.parseMediaType(next)); } target.setAccept(acceptableMediaTypes); } else if (value instanceof String) { target.setAccept(MediaType.parseMediaTypes((String) value)); } else { Class<?> clazz = (value != null) ? value.getClass() : null; throw new IllegalArgumentException( "Expected MediaType or String value for 'Accept' header value, but received: " + clazz); } } else if (ACCEPT_CHARSET.equalsIgnoreCase(name)) { if (value instanceof Collection<?>) { Collection<?> values = (Collection<?>) value; if (!CollectionUtils.isEmpty(values)) { List<Charset> acceptableCharsets = new ArrayList<Charset>(); for (Object charset : values) { if (charset instanceof Charset) { acceptableCharsets.add((Charset) charset); } else if (charset instanceof String) { acceptableCharsets.add(Charset.forName((String) charset)); } else { Class<?> clazz = (charset != null) ? charset.getClass() : null; throw new IllegalArgumentException( "Expected Charset or String value for 'Accept-Charset' header value, but received: " + clazz); } } target.setAcceptCharset(acceptableCharsets); } } else if (value instanceof Charset[] || value instanceof String[]) { List<Charset> acceptableCharsets = new ArrayList<Charset>(); Object[] values = ObjectUtils.toObjectArray(value); for (Object charset : values) { if (charset instanceof Charset) { acceptableCharsets.add((Charset) charset); } else if (charset instanceof String) { acceptableCharsets.add(Charset.forName((String) charset)); } } target.setAcceptCharset(acceptableCharsets); } else if (value instanceof Charset) { target.setAcceptCharset(Collections.singletonList((Charset) value)); } else if (value instanceof String) { String[] charsets = StringUtils.commaDelimitedListToStringArray((String) value); List<Charset> acceptableCharsets = new ArrayList<Charset>(); for (String charset : charsets) { acceptableCharsets.add(Charset.forName(charset.trim())); } target.setAcceptCharset(acceptableCharsets); } else { Class<?> clazz = (value != null) ? value.getClass() : null; throw new IllegalArgumentException( "Expected Charset or String value for 'Accept-Charset' header value, but received: " + clazz); } } else if (ALLOW.equalsIgnoreCase(name)) { if (value instanceof Collection<?>) { Collection<?> values = (Collection<?>) value; if (!CollectionUtils.isEmpty(values)) { Set<HttpMethod> allowedMethods = new HashSet<HttpMethod>(); for (Object method : values) { if (method instanceof HttpMethod) { allowedMethods.add((HttpMethod) method); } else if (method instanceof String) { allowedMethods.add(HttpMethod.valueOf((String) method)); } else { Class<?> clazz = (method != null) ? method.getClass() : null; throw new IllegalArgumentException( "Expected HttpMethod or String value for 'Allow' header value, but received: " + clazz); } } target.setAllow(allowedMethods); } } else { if (value instanceof HttpMethod) { target.setAllow(Collections.singleton((HttpMethod) value)); } else if (value instanceof HttpMethod[]) { Set<HttpMethod> allowedMethods = new HashSet<HttpMethod>(); for (HttpMethod next : (HttpMethod[]) value) { allowedMethods.add(next); } target.setAllow(allowedMethods); } else if (value instanceof String || value instanceof String[]) { String[] values = (value instanceof String[]) ? (String[]) value : StringUtils.commaDelimitedListToStringArray((String) value); Set<HttpMethod> allowedMethods = new HashSet<HttpMethod>(); for (String next : values) { allowedMethods.add(HttpMethod.valueOf(next.trim())); } target.setAllow(allowedMethods); } else { Class<?> clazz = (value != null) ? value.getClass() : null; throw new IllegalArgumentException( "Expected HttpMethod or String value for 'Allow' header value, but received: " + clazz); } } } else if (CACHE_CONTROL.equalsIgnoreCase(name)) { if (value instanceof String) { target.setCacheControl((String) value); } else { Class<?> clazz = (value != null) ? value.getClass() : null; throw new IllegalArgumentException( "Expected String value for 'Cache-Control' header value, but received: " + clazz); } } else if (CONTENT_LENGTH.equalsIgnoreCase(name)) { if (value instanceof Number) { target.setContentLength(((Number) value).longValue()); } else if (value instanceof String) { target.setContentLength(Long.parseLong((String) value)); } else { Class<?> clazz = (value != null) ? value.getClass() : null; throw new IllegalArgumentException( "Expected Number or String value for 'Content-Length' header value, but received: " + clazz); } } else if (CONTENT_TYPE.equalsIgnoreCase(name)) { if (value instanceof MediaType) { target.setContentType((MediaType) value); } else if (value instanceof String) { target.setContentType(MediaType.parseMediaType((String) value)); } else { Class<?> clazz = (value != null) ? value.getClass() : null; throw new IllegalArgumentException( "Expected MediaType or String value for 'Content-Type' header value, but received: " + clazz); } } else if (DATE.equalsIgnoreCase(name)) { if (value instanceof Date) { target.setDate(((Date) value).getTime()); } else if (value instanceof Number) { target.setDate(((Number) value).longValue()); } else if (value instanceof String) { target.setDate(Long.parseLong((String) value)); } else { Class<?> clazz = (value != null) ? value.getClass() : null; throw new IllegalArgumentException( "Expected Date, Number, or String value for 'Date' header value, but received: " + clazz); } } else if (ETAG.equalsIgnoreCase(name)) { if (value instanceof String) { target.setETag((String) value); } else { Class<?> clazz = (value != null) ? value.getClass() : null; throw new IllegalArgumentException( "Expected String value for 'ETag' header value, but received: " + clazz); } } else if (EXPIRES.equalsIgnoreCase(name)) { if (value instanceof Date) { target.setExpires(((Date) value).getTime()); } else if (value instanceof Number) { target.setExpires(((Number) value).longValue()); } else if (value instanceof String) { target.setExpires(Long.parseLong((String) value)); } else { Class<?> clazz = (value != null) ? value.getClass() : null; throw new IllegalArgumentException( "Expected Date, Number, or String value for 'Expires' header value, but received: " + clazz); } } else if (IF_MODIFIED_SINCE.equalsIgnoreCase(name)) { if (value instanceof Date) { target.setIfModifiedSince(((Date) value).getTime()); } else if (value instanceof Number) { target.setIfModifiedSince(((Number) value).longValue()); } else if (value instanceof String) { target.setIfModifiedSince(Long.parseLong((String) value)); } else { Class<?> clazz = (value != null) ? value.getClass() : null; throw new IllegalArgumentException( "Expected Date, Number, or String value for 'If-Modified-Since' header value, but received: " + clazz); } } else if (IF_NONE_MATCH.equalsIgnoreCase(name)) { if (value instanceof String) { target.setIfNoneMatch((String) value); } else if (value instanceof String[]) { String delmitedString = StringUtils.arrayToCommaDelimitedString((String[]) value); target.setIfNoneMatch(delmitedString); } else if (value instanceof Collection) { Collection<?> values = (Collection<?>) value; if (!CollectionUtils.isEmpty(values)) { List<String> ifNoneMatchList = new ArrayList<String>(); for (Object next : values) { if (next instanceof String) { ifNoneMatchList.add((String) next); } else { Class<?> clazz = (next != null) ? next.getClass() : null; throw new IllegalArgumentException( "Expected String value for 'If-None-Match' header value, but received: " + clazz); } } target.setIfNoneMatch(ifNoneMatchList); } } } else if (LAST_MODIFIED.equalsIgnoreCase(name)) { if (value instanceof Date) { target.setLastModified(((Date) value).getTime()); } else if (value instanceof Number) { target.setLastModified(((Number) value).longValue()); } else if (value instanceof String) { target.setLastModified(Long.parseLong((String) value)); } else { Class<?> clazz = (value != null) ? value.getClass() : null; throw new IllegalArgumentException( "Expected Date, Number, or String value for 'Last-Modified' header value, but received: " + clazz); } } else if (LOCATION.equalsIgnoreCase(name)) { if (value instanceof URI) { target.setLocation((URI) value); } else if (value instanceof String) { try { target.setLocation(new URI((String) value)); } catch (URISyntaxException e) { throw new IllegalArgumentException(e); } } else { Class<?> clazz = (value != null) ? value.getClass() : null; throw new IllegalArgumentException( "Expected URI or String value for 'Location' header value, but received: " + clazz); } } else if (PRAGMA.equalsIgnoreCase(name)) { if (value instanceof String) { target.setPragma((String) value); } else { Class<?> clazz = (value != null) ? value.getClass() : null; throw new IllegalArgumentException( "Expected String value for 'Pragma' header value, but received: " + clazz); } } else if (value instanceof String) { target.set(name, (String) value); } else if (value instanceof String[]) { for (String next : (String[]) value) { target.add(name, next); } } else if (value instanceof Iterable<?>) { for (Object next : (Iterable<?>) value) { String convertedValue = null; if (next instanceof String) { convertedValue = (String) next; } else { convertedValue = this.convertToString(value); } if (StringUtils.hasText(convertedValue)) { target.add(name, (String) next); } else { logger.warn("Element of the header '" + name + "' with value '" + value + "' will not be set since it is not a String and no Converter " + "is available. Consider registering a Converter with ConversionService (e.g., <int:converter>)"); } } } else { String convertedValue = this.convertToString(value); if (StringUtils.hasText(convertedValue)) { target.set(name, convertedValue); } else { logger.warn("Header '" + name + "' with value '" + value + "' will not be set since it is not a String and no Converter " + "is available. Consider registering a Converter with ConversionService (e.g., <int:converter>)"); } } }