List of usage examples for org.springframework.http HttpHeaders setLocation
public void setLocation(@Nullable URI location)
From source file:net.es.sense.rm.api.SenseRmController.java
/** * *********************************************************************** * POST /api/sense/v1/models/{id}/deltas * * *********************************************************************** @param accept * @param accept// w ww . ja v a2s .c om * @param deltaRequest * @param model * @param id * @return */ @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 = "/models/{" + HttpConstants.ID_NAME + "}/deltas", method = RequestMethod.POST, consumes = { MediaType.APPLICATION_JSON_VALUE }, produces = { MediaType.APPLICATION_JSON_VALUE }) public ResponseEntity<?> propagateModelDelta( @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, @PathVariable(HttpConstants.ID_NAME) @ApiParam(value = HttpConstants.ID_MSG, required = true) String id, @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) { log.info("propagateModelDelta: {}", deltaRequest); DeltaResource delta = new DeltaResource(); delta.setId("922f4388-c8f6-4014-b6ce-5482289b0200"); delta.setHref("http://localhost:8080/sense/v1/deltas/922f4388-c8f6-4014-b6ce-5482289b0200"); delta.setLastModified("2016-07-26T13:45:21.001Z"); delta.setModelId("922f4388-c8f6-4014-b6ce-5482289b02ff"); delta.setResult( "H4sIACKIo1cAA+1Y32/aMBB+56+I6NtUx0loVZEV1K6bpkm0m5Y+7NWNTbCa2JEdCP3vZydULYUEh0CnQXlC+O6+O/ u7X1ylgozp3BJ4LH3rcpJlqQ9hnud23rO5iKDnOA50XKgEgAwnJEEnQ8vuXC30eB5XqXnQuYDqfEl+LnGVvAv/3I6CVQiFv FbF7ff7UKF4Hiice2IZmgMml5RZ8sq/0n9p82hcWFCHCtjtQacHH5AkS5qJkNWa6rDUdD2Y8ZTHPHoqtDudy6lgvpLzGclyL h59zBNE2YBIW/0y7FhvPqjw8X5h5LS40TuUEPyDYTqjeIpi6/OKltZ5IDFnkbzn1gqmxMxO0DyiEUp5qoGfj4YVxiZIfqGYCh JmlDMU/+IiW7W7FIvPOCYDOWUMhOLcT5XG4AJ60PVjyh4HKPbk8NTIBmIxSIRXmpgT4EAXOqWVT4YmwgkNX9w4V wZeu1EddEDEjIZkE4YyktNMgbCoyhhTj2Z1vwVK3PoZ3Fz/DqyvN3ddTYoq49o3bd6mLCNCffFsgqeHwZH1sS04gxmQua 3fbI1I8YIkm5xDr3xCInXmVPPAAEqztAaqtwQFtHQ7vBzJiQmeeoAW5KxwxJisP57VrOuRF2xB1ZZ37M9ixIBALCLrSG9ct 0dI8fy74NN02CQ5Yq2WPaVkE5KqaQ5UIRRRnWinq+51huIpkVbXA2dO/6ztjTZhUUXRWEnYHVUPcwY2zaOafHh553fKz dcErXCLyuuYIlnpEBYo4quVVvtzezO6K2Fd0AMG/arMWuoBLQTcWnqZ9tcNOahhX679/8muNX27IrrgWWBRbZvESFjIsV LdXYhHOYcVVAlylKb6LrtjFEvStnY2Gi4ONAn2Mxh9dJr3mYi2bDjmRWHHXaYe7N+wZk0b2FTH2rHC+EJ28NL7Se9aVp Ry9ZwwyNTDa8Uf627LdXcfM8CWk/4BTQBblaMDjb92ND2C+Gun+yNsz6ZbcdPuLBSQfLvwJ1QggDPmF6Uo5IyVt+rnCq es+AaNt7cbsh/jaxtn//6GsWYDgAEdvHddkj8Wv/3/+bCDnW+rf2DW7Xx/ASQO0KQcHgAA"); URI deltaURI; try { deltaURI = new URI("http://localhost:8080/sense/v1/deltas/922f4388-c8f6-4014-b6ce-5482289b0200"); } catch (URISyntaxException ex) { Error error = new Error(HttpStatus.INTERNAL_SERVER_ERROR.toString(), ex.getLocalizedMessage(), null); return new ResponseEntity<>(error, null, HttpStatus.INTERNAL_SERVER_ERROR); } final URI location = ServletUriComponentsBuilder.fromCurrentRequestUri().build().toUri(); log.error("URL: " + location.toASCIIString()); //return Response.created(deltaURI).entity(getProxy().serialize(delta)).build(); final HttpHeaders headers = new HttpHeaders(); headers.setLocation(deltaURI); return new ResponseEntity<>(delta, headers, HttpStatus.CREATED); }
From source file:org.ambraproject.rhino.rest.controller.ContentRepoController.java
private static ResponseEntity<?> serveFromRemoteRepo(URI contentRepoAddress, String bucket, String key, String version) {/* w ww .ja v a 2 s .c o m*/ URI location = URI.create(String.format("%s/objects/%s?key=%s", // TODO Use version contentRepoAddress, bucket, key)); HttpHeaders headers = new HttpHeaders(); headers.setLocation(location); return new ResponseEntity<Object>(headers, HttpStatus.FOUND); }
From source file:org.fao.geonet.services.inspireatom.AtomPredefinedFeed.java
private HttpEntity<byte[]> redirectResponse(String location) throws Exception { HttpHeaders header = new HttpHeaders(); // TODO: character-set encoding ? header.setContentType(new MediaType("text", "plain", Charset.forName(Constants.ENCODING))); header.setContentLength(0);/*from www. java2 s. c om*/ header.setLocation(new URI(location)); return new HttpEntity<>(header); }
From source file:org.geoserver.importer.rest.ImportTransformController.java
@PostMapping(path = { "/tasks/{taskId}/transforms" }) public ResponseEntity postTransform(@PathVariable Long importId, @PathVariable Integer taskId, @RequestParam(value = "expand", required = false) String expand, @RequestBody ImportTransform importTransform, UriComponentsBuilder builder) { ImportTransform tx = importTransform; ImportTask task = task(importId, taskId); task.getTransform().add(tx);/*from w w w.j ava2 s.c o m*/ HttpHeaders headers = new HttpHeaders(); headers.setLocation(builder.path("/imports/{importId}/tasks/{taskId}/transforms/{transformId}") .buildAndExpand(importId.toString(), taskId.toString(), task.getTransform().getTransforms().size() - 1) .toUri()); return new ResponseEntity<String>("", headers, HttpStatus.CREATED); }
From source file:org.geoserver.opensearch.rest.CollectionsController.java
private ResponseEntity<String> returnCreatedCollectionReference(HttpServletRequest request, String eoId) throws URISyntaxException { String baseURL = ResponseUtils.baseURL(request); String newCollectionLocation = ResponseUtils.buildURL(baseURL, "/rest/oseo/collections/" + eoId, null, URLType.RESOURCE);/*www. j a va2 s . c o m*/ HttpHeaders headers = new HttpHeaders(); headers.setLocation(new URI(newCollectionLocation)); return new ResponseEntity<>(eoId, headers, HttpStatus.CREATED); }
From source file:org.geoserver.opensearch.rest.ProductsController.java
private ResponseEntity<String> returnCreatedProductReference(String collection, HttpServletRequest request, String productId) throws URISyntaxException { String baseURL = ResponseUtils.baseURL(request); String newCollectionLocation = ResponseUtils.buildURL(baseURL, "/rest/oseo/collections/" + collection + "/products/" + productId, null, URLType.RESOURCE); HttpHeaders headers = new HttpHeaders(); headers.setLocation(new URI(newCollectionLocation)); return new ResponseEntity<>(productId, headers, HttpStatus.CREATED); }
From source file:org.geoserver.rest.catalog.StyleController.java
@PostMapping(value = { "/styles", "/workspaces/{workspaceName}/styles" }, consumes = { SLDHandler.MIMETYPE_11, SLDHandler.MIMETYPE_10 })/*w w w.j a v a2 s. c om*/ public ResponseEntity<String> styleSLDPost(@RequestBody Style style, @PathVariable(required = false) String workspaceName, @RequestParam(required = false) String name, @RequestHeader("Content-Type") String contentType, UriComponentsBuilder builder) { if (workspaceName != null && catalog.getWorkspaceByName(workspaceName) == null) { throw new ResourceNotFoundException("Workspace " + workspaceName + " not found"); } checkFullAdminRequired(workspaceName); StyleHandler handler = org.geoserver.catalog.Styles.handler(contentType); if (name == null) { name = findNameFromObject(style); } //ensure that the style does not already exist if (catalog.getStyleByName(workspaceName, name) != null) { throw new RestException("Style " + name + " already exists.", HttpStatus.FORBIDDEN); } StyleInfo sinfo = catalog.getFactory().createStyle(); sinfo.setName(name); sinfo.setFilename(name + "." + handler.getFileExtension()); sinfo.setFormat(handler.getFormat()); sinfo.setFormatVersion(handler.versionForMimeType(contentType)); if (workspaceName != null) { sinfo.setWorkspace(catalog.getWorkspaceByName(workspaceName)); } // ensure that a existing resource does not already exist, because we may not want to overwrite it GeoServerDataDirectory dataDir = new GeoServerDataDirectory(catalog.getResourceLoader()); if (dataDir.style(sinfo).getType() != Resource.Type.UNDEFINED) { String msg = "Style resource " + sinfo.getFilename() + " already exists."; throw new RestException(msg, HttpStatus.FORBIDDEN); } ResourcePool resourcePool = catalog.getResourcePool(); try { if (style instanceof Style) { resourcePool.writeStyle(sinfo, (Style) style); } else { resourcePool.writeStyle(sinfo, (InputStream) style); } } catch (IOException e) { throw new RestException("Error writing style", HttpStatus.INTERNAL_SERVER_ERROR, e); } catalog.add(sinfo); LOGGER.info("POST Style " + name); //build the new path UriComponents uriComponents = getUriComponents(name, workspaceName, builder); HttpHeaders headers = new HttpHeaders(); headers.setLocation(uriComponents.toUri()); return new ResponseEntity<String>(name, headers, HttpStatus.CREATED); }
From source file:org.geoserver.rest.catalog.StyleController.java
@PostMapping(value = { "/styles", "/workspaces/{workspaceName}/styles" }, consumes = { MediaTypeExtensions.APPLICATION_ZIP_VALUE }) public ResponseEntity<String> stylePost(InputStream stream, @RequestParam(required = false) String name, @PathVariable(required = false) String workspaceName, UriComponentsBuilder builder) throws IOException { if (workspaceName != null && catalog.getWorkspaceByName(workspaceName) == null) { throw new ResourceNotFoundException("Workspace " + workspaceName + " not found"); }//from w w w .j a va 2s . c om checkFullAdminRequired(workspaceName); File directory = unzipSldPackage(stream); File uploadedFile = retrieveSldFile(directory); Style styleSld = parseSld(uploadedFile); if (name == null) { name = findNameFromObject(styleSld); } //ensure that the style does not already exist if (catalog.getStyleByName(workspaceName, name) != null) { throw new RestException("Style " + name + " already exists.", HttpStatus.FORBIDDEN); } // save image resources saveImageResources(directory, workspaceName); //create a style info object StyleInfo styleInfo = catalog.getFactory().createStyle(); styleInfo.setName(name); styleInfo.setFilename(name + ".sld"); if (workspaceName != null) { styleInfo.setWorkspace(catalog.getWorkspaceByName(workspaceName)); } Resource style = dataDir.style(styleInfo); // ensure that a existing resource does not already exist, because we may not want to overwrite it if (dataDir.style(styleInfo).getType() != Resource.Type.UNDEFINED) { String msg = "Style resource " + styleInfo.getFilename() + " already exists."; throw new RestException(msg, HttpStatus.FORBIDDEN); } serializeSldFileInCatalog(style, uploadedFile); catalog.add(styleInfo); LOGGER.info("POST Style Package: " + name + ", workspace: " + workspaceName); UriComponents uriComponents = getUriComponents(name, workspaceName, builder); HttpHeaders headers = new HttpHeaders(); headers.setLocation(uriComponents.toUri()); return new ResponseEntity<>(name, headers, HttpStatus.CREATED); }
From source file:org.jasig.cas.support.rest.TicketsResource.java
/** * Create new ticket granting ticket.//from w ww. j a v a 2s . c o m * * @param requestBody username and password application/x-www-form-urlencoded values * @param request raw HttpServletRequest used to call this method * @return ResponseEntity representing RESTful response */ @RequestMapping(value = "/tickets", method = RequestMethod.POST, consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE) public final ResponseEntity<String> createTicketGrantingTicket( @RequestBody final MultiValueMap<String, String> requestBody, final HttpServletRequest request) { Formatter fmt = null; try { final String tgtId = this.cas.createTicketGrantingTicket(obtainCredential(requestBody)); final URI ticketReference = new URI(request.getRequestURL().toString() + "/" + tgtId); final HttpHeaders headers = new HttpHeaders(); headers.setLocation(ticketReference); headers.setContentType(MediaType.TEXT_HTML); fmt = new Formatter(); fmt.format("<!DOCTYPE HTML PUBLIC \\\"-//IETF//DTD HTML 2.0//EN\\\"><html><head><title>"); fmt.format("%s %s", HttpStatus.CREATED, HttpStatus.CREATED.getReasonPhrase()) .format("</title></head><body><h1>TGT Created</h1><form action=\"%s", ticketReference.toString()) .format("\" method=\"POST\">Service:<input type=\"text\" name=\"service\" value=\"\">") .format("<br><input type=\"submit\" value=\"Submit\"></form></body></html>"); return new ResponseEntity<String>(fmt.toString(), headers, HttpStatus.CREATED); } catch (final Throwable e) { LOGGER.error(e.getMessage(), e); return new ResponseEntity<String>(e.getMessage(), HttpStatus.BAD_REQUEST); } finally { IOUtils.closeQuietly(fmt); } }
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); }//from w ww . j a v a 2s . c om } 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>)"); } } }