Skip to content

Commit

Permalink
Merge pull request #329 from wultra/develop
Browse files Browse the repository at this point in the history
Merge develop to master
  • Loading branch information
banterCZ authored Oct 2, 2024
2 parents ff06131 + 5501c78 commit 1134422
Show file tree
Hide file tree
Showing 12 changed files with 61 additions and 17 deletions.
2 changes: 1 addition & 1 deletion annotations/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>io.getlime.core</groupId>
<artifactId>lime-java-core-parent</artifactId>
<version>1.10.0</version>
<version>1.11.0</version>
</parent>

<artifactId>annotations</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion audit-base/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>io.getlime.core</groupId>
<artifactId>lime-java-core-parent</artifactId>
<version>1.10.0</version>
<version>1.11.0</version>
</parent>

<artifactId>audit-base</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion bom/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>io.getlime.core</groupId>
<artifactId>lime-java-core-parent</artifactId>
<version>1.10.0</version>
<version>1.11.0</version>
</parent>

<artifactId>core-bom</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion http-common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>io.getlime.core</groupId>
<artifactId>lime-java-core-parent</artifactId>
<version>1.10.0</version>
<version>1.11.0</version>
</parent>

<artifactId>http-common</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@
@Slf4j
public final class UserAgent {

/**
* Device information.
*/
@Data
public static class Device {
private String networkVersion;
Expand Down
10 changes: 5 additions & 5 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<description>Wultra - Core Java Libraries</description>
<groupId>io.getlime.core</groupId>
<artifactId>lime-java-core-parent</artifactId>
<version>1.10.0</version>
<version>1.11.0</version>
<packaging>pom</packaging>

<inceptionYear>2017</inceptionYear>
Expand Down Expand Up @@ -57,11 +57,11 @@
<maven.compiler.release>${java.version}</maven.compiler.release>

<maven-compiler-plugin.version>3.13.0</maven-compiler-plugin.version>
<maven-surefire-plugin.version>3.3.1</maven-surefire-plugin.version>
<maven-surefire-plugin.version>3.5.0</maven-surefire-plugin.version>
<maven-enforcer-plugin.version>3.5.0</maven-enforcer-plugin.version>

<!-- Dependencies -->
<spring-boot.version>3.3.2</spring-boot.version>
<spring-boot.version>3.3.4</spring-boot.version>
</properties>

<dependencyManagement>
Expand Down Expand Up @@ -119,7 +119,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.8.0</version>
<version>3.10.0</version>
<configuration>
<failOnError>false</failOnError>
</configuration>
Expand All @@ -135,7 +135,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<version>3.1.2</version>
<version>3.1.3</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
Expand Down
2 changes: 1 addition & 1 deletion rest-client-base/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>io.getlime.core</groupId>
<artifactId>lime-java-core-parent</artifactId>
<version>1.10.0</version>
<version>1.11.0</version>
</parent>

<artifactId>rest-client-base</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
import java.net.URISyntaxException;
import java.time.Duration;
import java.util.*;
import java.util.concurrent.atomic.AtomicReference;
import java.util.function.Consumer;

/**
Expand Down Expand Up @@ -839,7 +840,17 @@ private WebClient.RequestBodySpec buildUri(WebClient.RequestBodyUriSpec uriSpec,
private WebClient.RequestHeadersSpec<?> buildRequest(WebClient.RequestBodySpec requestSpec, Object request) {
if (request != null) {
if (request instanceof MultiValueMap) {
return requestSpec.body(BodyInserters.fromMultipartData(((MultiValueMap<String, ?>) request)));
final AtomicReference<MediaType> contentTypeReference = new AtomicReference<>();
requestSpec.headers(httpHeaders -> contentTypeReference.set(httpHeaders.getContentType()));
final MediaType contentType = contentTypeReference.get();

if (MediaType.APPLICATION_FORM_URLENCODED.equals(contentType)) {
return requestSpec.body(BodyInserters.fromFormData((MultiValueMap<String, String>) request));
} else if (MediaType.MULTIPART_FORM_DATA.equals(contentType)) {
return requestSpec.body(BodyInserters.fromMultipartData(((MultiValueMap<String, ?>) request)));
} else {
throw new IllegalArgumentException("Unsupported content type: %s for request type of MultiValueMap".formatted(contentType));
}
} else if (request instanceof Publisher) {
return requestSpec.body(BodyInserters.fromDataBuffers((Publisher<DataBuffer>) request));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@
import org.springframework.http.client.MultipartBodyBuilder;
import org.springframework.test.context.junit.jupiter.SpringExtension;
import org.springframework.test.util.ReflectionTestUtils;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.util.ResourceUtils;
import reactor.core.publisher.Flux;

Expand Down Expand Up @@ -662,6 +664,26 @@ void testPostWithMultipartData() throws RestClientException {
assertEquals(requestData, responseEntity.getBody().getResponseObject().getResponse());
}

@Test
void testPostFormData() throws Exception {
final HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);

final MultiValueMap<String, String> map = new LinkedMultiValueMap<>();
map.add("grant_type", "authorization_code");
map.add("client_id", "wultra");
map.add("client_secret", "top-secret");

final ResponseEntity<ObjectResponse<TestResponse>> responseEntity =
restClient.post("/form-data-request-response", map, null, headers, new ParameterizedTypeReference<>(){});

assertNotNull(responseEntity);
assertNotNull(responseEntity.getBody());
assertNotNull(responseEntity.getBody().getResponseObject());
assertEquals("OK", responseEntity.getBody().getStatus());
assertEquals("form-data: [authorization_code, wultra, top-secret]", responseEntity.getBody().getResponseObject().getResponse());
}

@Test
void testPostOctetStream() throws Exception {
final byte[] request = {1, 2};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configurers.AbstractHttpConfigurer;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.web.SecurityFilterChain;
Expand Down Expand Up @@ -53,13 +54,14 @@ private DigestAuthenticationFilter digestAuthenticationFilter() {

@Bean
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
return http.csrf().disable()
return http
.csrf(AbstractHttpConfigurer::disable)
.exceptionHandling(e -> e.authenticationEntryPoint(authenticationEntryPoint()))
.addFilter(digestAuthenticationFilter())
.authorizeHttpRequests()
.requestMatchers("/private/**").authenticated()
.anyRequest().permitAll()
.and().build();
.authorizeHttpRequests(authorize -> authorize
.requestMatchers("/private/**").authenticated()
.anyRequest().permitAll()
).build();
}

@Bean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import java.net.URI;
import java.util.Arrays;
import java.util.Enumeration;
import java.util.List;

/**
* Rest controller for tests.
Expand Down Expand Up @@ -85,6 +86,11 @@ public ObjectResponse<TestResponse> testPostWithMultipartRequestAndResponse(@Req
return new ObjectResponse<>(testResponse);
}

@PostMapping(value = "/form-data-request-response", consumes = { MediaType.APPLICATION_FORM_URLENCODED_VALUE })
public ObjectResponse<TestResponse> testPostFormDataRequestAndResponse(@RequestParam("grant_type") final String grantType, @RequestParam("client_id") final String clientId, @RequestParam("client_secret") final String clientSecret) {
return new ObjectResponse<>(new TestResponse("form-data: " + List.of(grantType, clientId, clientSecret)));
}

@PostMapping(value = "/octet-stream", consumes = MediaType.APPLICATION_OCTET_STREAM_VALUE)
public ObjectResponse<TestResponse> testPostOctetStream(@RequestBody byte[] request) {
final TestResponse testResponse = new TestResponse("length: " + request.length);
Expand Down
2 changes: 1 addition & 1 deletion rest-model-base/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>io.getlime.core</groupId>
<artifactId>lime-java-core-parent</artifactId>
<version>1.10.0</version>
<version>1.11.0</version>
</parent>

<artifactId>rest-model-base</artifactId>
Expand Down

0 comments on commit 1134422

Please sign in to comment.