Java Code Examples for org.springframework.http.ResponseEntity#BodyBuilder

The following examples show how to use org.springframework.http.ResponseEntity#BodyBuilder . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
private final ResponseEntity.BodyBuilder newResponse(final HttpStatus status, final String etag)
	ResponseEntity.BodyBuilder response = ResponseEntity.status(status)
			.cacheControl(CacheControl.maxAge(cacheMaxAgeSec, TimeUnit.SECONDS));

	final String adLanguage = getAdLanguage();
	if (adLanguage != null && !adLanguage.isEmpty())
		final String contentLanguage = ADLanguageList.toHttpLanguageTag(adLanguage);
		response.header(HttpHeaders.CONTENT_LANGUAGE, contentLanguage);
		response.header(HttpHeaders.VARY, HttpHeaders.ACCEPT_LANGUAGE); // advice browser to include ACCEPT_LANGUAGE in their caching key

	return response;
Example 2
@ApiOperation("Update a platform")
public ResponseEntity<PlatformIO> updatePlatform(Authentication authentication,
                                                 @PathVariable("application_name") final String applicationName,
                                                 @ApiParam(value = "Copie les propriétés du module déployé de la plateforme source avec l'ID correspondant. " +
                                                         "Si ce module ne contient pas de propriétés, à défaut on utilise les propriétés du module avec le même properties_path.")
                                                 @RequestParam(value = "copyPropertiesForUpgradedModules", required = false) final Boolean copyPropertiesForUpgradedModules,
                                                 @Valid @RequestBody final PlatformIO platformInput) {

    Platform.Key platformKey = new Platform.Key(applicationName, platformInput.getPlatformName());

            Boolean.TRUE.equals(copyPropertiesForUpgradedModules), // on traite le cas `null`
            new User(authentication)

    final ResponseEntity.BodyBuilder response = ResponseEntity.status(HttpStatus.OK);
    PlatformView platformView = platformUseCases.getPlatform(platformKey);
    return response.body(new PlatformIO(platformView));
Example 3
@Transactional(readOnly = true)
public ResponseEntity<StreamingResponseBody> download(String fileId) {
  FileMeta fileMeta = getFileMeta(fileId);

  ResponseEntity.BodyBuilder builder = ResponseEntity.ok();
  builder.header(CONTENT_TYPE, fileMeta.getContentType());
  builder.header(CONTENT_DISPOSITION, "attachment; filename=\"" + fileMeta.getFilename() + "\"");

  Long contentLength = fileMeta.getSize();
  if (contentLength != null) {

  return builder.body(
      outputStream -> {
        try (ReadableByteChannel fromChannel = blobStore.newChannel(fileId)) {
          ByteStreams.copy(fromChannel, Channels.newChannel(outputStream));
Example 4
public Mono<ResponseEntity<String>> sayHello() {
	ResponseEntity.BodyBuilder unAuthenticated = ResponseEntity.status(HttpStatus.UNAUTHORIZED);

	return ReactiveSecurityContext.getToken()
			.doOnError(throwable -> Mono.just(unAuthenticated))
			.map(token -> ResponseEntity.ok().contentType(MediaType.TEXT_PLAIN)
					.body(new Base64JwtDecoder().decode(token.getAppToken()).getPayload()));
Example 5
 * We cache names if there are more than 3 services. This helps people getting started: if we
 * cache empty results, users have more questions. We assume caching becomes a concern when zipkin
 * is in active use, and active use usually implies more than 3 services.
ResponseEntity<List<String>> maybeCacheNames(List<String> names) {
  ResponseEntity.BodyBuilder response = ResponseEntity.ok();
  if (serviceCount > 3) {
    response.cacheControl(CacheControl.maxAge(namesMaxAge, TimeUnit.SECONDS).mustRevalidate());
  return response.body(names);
Example 6
Source Project: quarkus   File:    License: Apache License 2.0 5 votes vote down vote up
public ResponseEntity<Error> handleResponseEntityException(HandledResponseEntityException e,
        HttpServletRequest request) {

    ResponseEntity.BodyBuilder bodyBuilder = ResponseEntity
            .header("custom-header", "custom-value");

    if (e.getContentType() != null) {

    return bodyBuilder.body(new Error(request.getRequestURI() + ":" + e.getMessage()));
Example 7
public ResponseEntity<byte[]> toResponseEntity(@NonNull final ResponseEntity.BodyBuilder responseBuilder)
	return responseBuilder
			.header(HttpHeaders.CONTENT_DISPOSITION, "inline; filename=\"" + getImageName() + "\"")
Example 8
public ResponseEntity<InputStreamResource> getIcon(String definitionName, DefinitionImageType imageType) {
    notNull(definitionName, "Definition name cannot be null.");
    notNull(imageType, "Definition image type cannot be null.");
    final Definition<?> definition = propertiesHelpers.getDefinition(definitionName);
    notNull(definition, "Could not find definition of name %s", definitionName);

    // Undefined and missing icon resources are simply 404.
    String imagePath = definition.getImagePath(imageType);
    if (imagePath == null) {
        return new ResponseEntity<>(HttpStatus.NOT_FOUND);
    InputStream is = definition.getClass().getResourceAsStream(imagePath);
    if (is == null) {"The image type %s should exist for %s at %s, but is missing. "
                + "The component should provide this resource.", imageType, definitionName, imagePath);
        return new ResponseEntity<>(HttpStatus.NOT_FOUND);

    // At this point, we have enough information for a correct response.
    ResponseEntity.BodyBuilder response = ResponseEntity.ok();

    // Add the content type if it can be determined.
    MimetypesFileTypeMap mimeTypesMap = new MimetypesFileTypeMap();
    String contentType = mimeTypesMap.getContentType(imagePath);
    if (contentType != null) {
        response = response.contentType(MediaType.parseMediaType(contentType));

    return response.body(new InputStreamResource(is));
Example 9
private static ResponseEntity.BodyBuilder buildStatus ( int status ) {
	return ResponseEntity.status( status );