Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,17 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/).

### Removed

## [v6.0.2]

### Fixed
- Correctly handle empty 'Local-Tenant-Id' header values by @mlakov https://github.com/cap-java/cds-feature-ord/pull/39

### Changed
- Bump actions/setup-java in the minor-patch group by @dependabot https://github.com/cap-java/cds-feature-ord/pull/36
- Bump the minor-patch group across 1 directory with 5 updates by @dependabot https://github.com/cap-java/cds-feature-ord/pull/35
- Bump com.github.spotbugs:spotbugs-maven-plugin by @dependabot https://github.com/cap-java/cds-feature-ord/pull/37
- Bump org.apache.maven.plugins:maven-deploy-plugin by @dependabot https://github.com/cap-java/cds-feature-ord/pull/38

## [v6.0.1]

### Added
Expand All @@ -24,7 +35,6 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/).
### Fixed
- Use EDMX providers for loading OData API definitions by @mlakov https://github.com/cap-java/cds-feature-ord/pull/32


### Changed
- Bump the minor-patch group across 1 directory with 4 updates by @dependabot https://github.com/cap-java/cds-feature-ord/pull/23
- Improve GH workflows by @mlakov https://github.com/cap-java/cds-feature-ord/pull/8
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import com.sap.cds.services.environment.CdsProperties.Security.Authentication;
import com.sap.cds.services.runtime.CdsRuntime;
import com.sap.cds.services.utils.ErrorStatusException;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.InputStream;
Expand All @@ -40,6 +41,12 @@ public class Utils {
@UtilityClass
public static class Http {

public static String header(HttpServletRequest request, String header) {
String value = request.getHeader(header);

return (value == null || value.isBlank()) ? null : value;
}

public static void respondWith(HttpServletResponse response, String payload) {
try (PrintWriter writer = response.getWriter()) {
writer.write(payload);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import static com.sap.cds.feature.ord.common.Constants.HEADER_LOCAL_TENANT_ID;
import static com.sap.cds.feature.ord.common.Utils.Http.handleException;
import static com.sap.cds.feature.ord.common.Utils.Http.header;
import static jakarta.servlet.http.HttpServletResponse.SC_NOT_FOUND;
import static jakarta.servlet.http.HttpServletResponse.SC_OK;
import static org.apache.commons.io.FilenameUtils.getExtension;
Expand Down Expand Up @@ -47,7 +48,7 @@ private void process(HttpServletRequest request, HttpServletResponse response) {

cdsRuntime
.requestContext()
.systemUser(request.getHeader(HEADER_LOCAL_TENANT_ID))
.systemUser(header(request, HEADER_LOCAL_TENANT_ID))
.run(rc -> {
try {
processDocument(request, response);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import static com.sap.cds.feature.ord.common.Constants.PERSPECTIVE_SYSTEM_VERSION;
import static com.sap.cds.feature.ord.common.Utils.CdsRuntimeProperties.getOrdProperties;
import static com.sap.cds.feature.ord.common.Utils.Http.handleException;
import static com.sap.cds.feature.ord.common.Utils.Http.header;
import static com.sap.cds.feature.ord.common.Utils.Http.respondWith;
import static com.sap.cds.services.ErrorStatuses.NOT_FOUND;
import static jakarta.servlet.http.HttpServletResponse.SC_OK;
Expand Down Expand Up @@ -57,7 +58,7 @@ private void process(HttpServletRequest request, HttpServletResponse response) {

cdsRuntime
.requestContext()
.systemUser(request.getHeader(HEADER_LOCAL_TENANT_ID))
.systemUser(header(request, HEADER_LOCAL_TENANT_ID))
.run(rc -> {
response.setStatus(SC_OK);
response.setContentType(APPLICATION_JSON.getMimeType());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,26 +23,46 @@
import com.sap.cds.services.runtime.CdsRuntime;
import com.sap.cds.services.runtime.CdsRuntimeConfigurer;
import com.sap.cds.services.utils.ErrorStatusException;
import jakarta.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.util.List;
import lombok.SneakyThrows;
import org.apache.commons.io.IOUtils;
import org.apache.hc.core5.http.ClassicHttpResponse;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.NullAndEmptySource;
import org.junit.jupiter.params.provider.ValueSource;

class UtilsTest {

private CdsRuntime cdsRuntime;
private HttpServletRequest httpServletRequest;
private ClassicHttpResponse classicHttpResponse;

@BeforeEach
void setUp() {
cdsRuntime = CdsRuntimeConfigurer.create().complete();
httpServletRequest = mock(HttpServletRequest.class);
classicHttpResponse = mock(ClassicHttpResponse.class);
}

@SneakyThrows
@ParameterizedTest
@NullAndEmptySource
@ValueSource(strings = {" ", "value"})
void whenHttpHeaderIsCalled_thenCorrectResultIsReturned(String input) {
doReturn(input).when(httpServletRequest).getHeader("header");

assertEquals(
(input == null || input.isBlank()) ? null : input, //
Utils.Http.header(httpServletRequest, "header"));

verify(httpServletRequest).getHeader("header");
verifyNoMoreInteractions(httpServletRequest);
}

@Test
void whenHttpAssertSuccessfulIsCalled_thenNoExceptionIsThrown() {
doReturn(200).when(classicHttpResponse).getCode();
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
</distributionManagement>

<properties>
<revision>6.0.1</revision>
<revision>6.0.2</revision>
<jdk.version>17</jdk.version>
<cds4j.version>5.1.1</cds4j.version>
<slf4j.version>2.0.19</slf4j.version>
Expand Down
Loading