BAEL-5054 make sure all files are added

BAEL-5054 organise packages

BAEL-5054 move project to correct folder

BAEL-5044 remove old folder
This commit is contained in:
Trixi Turny 2021-08-01 14:28:51 +01:00
parent 75e9acc874
commit 638d34924b
6 changed files with 130 additions and 78 deletions

View File

@ -133,7 +133,7 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<mainClass>com.baeldung.Spring5Application</mainClass>
<mainClass>com.baeldung.reactive.Application</mainClass>
<layout>JAR</layout>
</configuration>
</plugin>

View File

@ -0,0 +1,12 @@
package com.baeldung.reactive;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}

View File

@ -0,0 +1,47 @@
package com.baeldung.reactive.controller;
import com.baeldung.reactive.service.ReactiveUploadService;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import reactor.core.publisher.Mono;
@RestController
public class UploadController {
final ReactiveUploadService uploadService;
public UploadController(ReactiveUploadService uploadService) {
this.uploadService = uploadService;
}
@PostMapping(path = "/upload")
@ResponseBody
public Mono<HttpStatus> uploadPdf(@RequestParam("file") final MultipartFile multipartFile) {
return uploadService.uploadPdf(multipartFile.getResource());
}
@PostMapping(path = "/upload/multipart")
@ResponseBody
public Mono<HttpStatus> uploadMultipart(@RequestParam("file") final MultipartFile multipartFile) {
return uploadService.uploadMultipart(multipartFile);
}
/**
* Fake upload endpoint returning "OK" HttpStatus
* @return "OK" HttpStatus
*/
@PostMapping(path = "/external/upload")
@ResponseBody
public HttpStatus externalUpload() {
return HttpStatus.OK;
}
@GetMapping("/trixi")
public String returnTrixi() {
return "Trixi";
}
}

View File

@ -0,0 +1,69 @@
package com.baeldung.reactive.service;
import org.springframework.core.io.Resource;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.client.MultipartBodyBuilder;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.reactive.function.BodyInserters;
import org.springframework.web.reactive.function.client.WebClient;
import org.springframework.web.util.UriComponentsBuilder;
import reactor.core.publisher.Mono;
import java.net.URI;
@Service
public class ReactiveUploadService {
private final WebClient webClient;
private static final String EXTERNAL_UPLOAD_URL = "http://localhost:8080/external/upload";
public ReactiveUploadService() {
this.webClient = WebClient.create();
}
public Mono<HttpStatus> uploadPdf(final Resource resource){
final URI url = UriComponentsBuilder.fromHttpUrl(EXTERNAL_UPLOAD_URL).build().toUri();
Mono<HttpStatus> httpStatusMono = webClient.post()
.uri(url)
.contentType(MediaType.APPLICATION_PDF)
.body(BodyInserters.fromResource(resource))
.exchangeToMono(response -> {
if (response.statusCode().equals(HttpStatus.OK)) {
return response.bodyToMono(HttpStatus.class).thenReturn(response.statusCode());
} else {
System.out.println("Failed to upload pdf. " + response.statusCode());
}
return null;
});
return httpStatusMono;
}
public Mono<HttpStatus> uploadMultipart(final MultipartFile multipartFile){
final URI url = UriComponentsBuilder.fromHttpUrl(EXTERNAL_UPLOAD_URL).build().toUri();
final MultipartBodyBuilder builder = new MultipartBodyBuilder();
builder.part("file", multipartFile.getResource());
Mono<HttpStatus> httpStatusMono = webClient.post()
.uri(url)
.contentType(MediaType.MULTIPART_FORM_DATA)
.body(BodyInserters.fromMultipartData(builder.build()))
.exchangeToMono(response -> {
if (response.statusCode().equals(HttpStatus.OK)) {
return response.bodyToMono(HttpStatus.class).thenReturn(response.statusCode());
} else {
System.out.println("Failed to upload pdf. " + response.statusCode());
}
return null;
});
return httpStatusMono;
}
}

View File

@ -1,5 +1,5 @@
logging.level.root=INFO
server.port=8081
server.port=8080
logging.level.reactor.netty.http.client.HttpClient=DEBUG

View File

@ -1,76 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.baeldung</groupId>
<artifactId>webclient_upload</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.5.0</version>
</parent>
<name>webclient_upload Maven Webapp</name>
<properties>
<java.version>16</java.version>
<reactor-spring.version>1.0.1.RELEASE</reactor-spring.version>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.projectreactor</groupId>
<artifactId>reactor-spring</artifactId>
<version>${reactor-spring.version}</version>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-webflux</artifactId>
</dependency>
<dependency>
<groupId>org.projectreactor</groupId>
<artifactId>reactor-spring</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>json-schema-validator</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
</project>