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
19 changes: 19 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,24 @@
## Release Notes

`1.3.2`

- Added `Strings.nonBlankOrDefault(String, String)` to return a default when the value is blank.
- Added `Strings.nonBlankOrGet(String, Supplier)` to return a supplied default when the value is blank.
- Changed `Headers.of` to use `CaseInsensitiveLinkedHashMap` from MorphiX.
- Updated `ApacheHC5ExchangeClient` to use `CaseInsensitiveLinkedHashMap` from MorphiX.
- Updated `OkHttpExchangeClient` to use `CaseInsensitiveLinkedHashMap` from MorphiX.
- Upgraded `morphix-all` to `1.1.3`.
- Upgraded Spring Boot to `4.1.3` for `apiphany-spring`.
- Upgraded Spring to `7.0.11` for `apiphany-spring`.
- Upgraded Spring Security to `7.2.0`.
- Upgraded OkHttp to `5.5.1`, Maven users now resolve the JVM artifact as `okhttp-jvm`.
- Upgraded Micrometer to `1.17.3`.
- Upgraded `oauth2-oidc-sdk` to `11.39`.
- Upgraded `logback-core` to `1.6.8`.
- Upgraded `pitest-maven` to `1.30.2`.

---

`1.3.1`

- Preserved header insertion order in `Headers.of()`.
Expand Down
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ Support is being developed for other HTTP clients like Netty, Jersey, etc. If yo

### Releases

Current release `1.3.1`
Current release `1.3.2`

### Getting Started

Expand All @@ -62,7 +62,7 @@ Maven: add this dependency to your `pom.xml`
<dependency>
<groupId>io.github.raduking</groupId>
<artifactId>apiphany</artifactId>
<version>1.3.1</version>
<version>1.3.2</version>
</dependency>
```

Expand Down Expand Up @@ -146,7 +146,7 @@ By default Apiphany uses the JDK `java.net.http` client. You can switch to anoth

#### Apache HttpClient5

Add the `apiphany-httpclient5` dependency, then:
Add the `apiphany-httpclient5` and `org.apache.httpcomponents.client5:httpclient5` dependencies, then:

```java
import org.apiphany.client.http.ApacheHC5HttpExchangeClient;
Expand All @@ -162,7 +162,7 @@ String name = http(client)

#### OkHttp

Add the `apiphany-okhttp` dependency, then:
Add the `apiphany-okhttp` and `com.squareup.okhttp3:okhttp-jvm` dependencies, then:

```java
import org.apiphany.client.http.OkHttpExchangeClient;
Expand All @@ -176,6 +176,8 @@ String name = http(client)
.orRethrow();
```

If you want to use the most used OkHttp version `4.12.x` you need to add `com.squareup.okhttp3:okhttp` dependency.

#### Spring `RestClient`

Add the `apiphany-spring` dependency, then:
Expand Down
2 changes: 1 addition & 1 deletion apiphany-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<parent>
<groupId>io.github.raduking</groupId>
<artifactId>apiphany-parent</artifactId>
<version>1.3.1</version>
<version>1.3.2</version>
</parent>

<artifactId>apiphany</artifactId>
Expand Down
18 changes: 8 additions & 10 deletions apiphany-core/src/main/java/org/apiphany/RequestParameter.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
import org.apiphany.lang.Strings;
import org.morphix.convert.ArrayConversions;
import org.morphix.lang.JavaArrays;
import org.morphix.lang.JavaObjects;
import org.morphix.lang.Nullables;
import org.morphix.lang.collections.Iterables;

/**
* Represents a parameter in the API context. When constructing request parameters prefer using the
Expand Down Expand Up @@ -117,14 +119,12 @@ public void putInto(final Map<String, List<String>> map) {
* @return true if the object is multi-valued, false otherwise
*/
public static boolean isMultiValued(final Object object) {
if (null == object) {
return false;
}
return switch (object) {
case null -> false;
case Collection<?> collection -> true;
case Iterable<?> iterable -> true;
case Object[] array -> true;
case Object o when o.getClass().isArray() -> true;
case Object o when JavaObjects.isArray(o) -> true;
default -> false;
};
}
Expand All @@ -146,14 +146,12 @@ public static boolean isSingleValued(final Object object) {
* @return the string representation of the value
*/
public static List<String> toValues(final Object object) {
if (null == object) {
return NOT_PRESENT;
}
return switch (object) {
case null -> NOT_PRESENT;
case Collection<?> collection -> toValues(collection);
case Iterable<?> iterable -> toValues(iterable);
case Object[] array -> toValues(array);
case Object o when o.getClass().isArray() -> toValues(JavaArrays.toArray(o));
case Object o when JavaObjects.isArray(o) -> toValues(JavaArrays.toArray(o));
default -> toValues(String.valueOf(object));
};
}
Expand All @@ -168,7 +166,7 @@ public static List<String> toValues(final String string) {
if (null == string) {
return NOT_PRESENT;
}
List<String> list = new ArrayList<>();
List<String> list = new ArrayList<>(1);
list.add(string);
return list;
}
Expand Down Expand Up @@ -202,7 +200,7 @@ public static List<String> toValues(final Iterable<?> iterable) {
* @return the list of string representations of the values
*/
public static List<String> toValues(final Collection<?> collection) {
if (null == collection || collection.isEmpty()) {
if (Iterables.isEmpty(collection)) {
return NOT_PRESENT;
}
List<String> list = new ArrayList<>(collection.size());
Expand Down
11 changes: 3 additions & 8 deletions apiphany-core/src/main/java/org/apiphany/RequestParameters.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import org.morphix.convert.MapConversions;
import org.morphix.convert.function.SimpleConverter;
import org.morphix.lang.JavaArrays;
import org.morphix.lang.JavaObjects;
import org.morphix.lang.collections.Lists;
import org.morphix.lang.collections.Maps;
import org.morphix.lang.function.PutFunction;
Expand Down Expand Up @@ -149,12 +150,10 @@ public static Map<String, List<String>> from(final String body, final Charset en
return params;
}
String[] bodyParams = body.split(SEPARATOR);

for (String bodyParam : bodyParams) {
int index = bodyParam.indexOf(RequestParameter.NAME_VALUE_SEPARATOR);
final String decodedKey;
final String decodedValue;

if (index >= 0) {
decodedKey = URLDecoder.decode(bodyParam.substring(0, index), encoding);
decodedValue = URLDecoder.decode(bodyParam.substring(index + 1), encoding);
Expand Down Expand Up @@ -231,8 +230,7 @@ public static Map<String, List<String>> from(final Object queryParams, final Sim
}
Require.thatNot(queryParams instanceof List<?>, "Cannot convert a List into request parameters map. Expected a POJO or a Map.");
Require.thatNot(queryParams instanceof Set<?>, "Cannot convert a Set into request parameters map. Expected a POJO or a Map.");
Require.thatNot(queryParams.getClass().isArray(), "Cannot convert an Array into request parameters map. Expected a POJO or a Map.");

Require.thatNot(JavaObjects.isArray(queryParams), "Cannot convert an Array into request parameters map. Expected a POJO or a Map.");
if (queryParams instanceof Map<?, ?> map) {
return from(map, nameConverter);
}
Expand Down Expand Up @@ -273,9 +271,7 @@ public static <N, V> Map<String, List<String>> from(final Map<N, V> map, final S
* @return a map representation of the object's fields
*/
protected static Map<String, List<String>> fromObject(final Object queryParams, final SimpleConverter<String, String> nameConverter) {
List<ExtendedField> extendedFields = ExtendedFields.findAllNonStatic(queryParams,
extendedField -> null != extendedField.getFieldValue());

List<ExtendedField> extendedFields = ExtendedFields.findAllNonStatic(queryParams, ExtendedField::valueNotNull);
Map<String, List<String>> paramMap = LinkedHashMap.newLinkedHashMap(extendedFields.size());
if (Lists.isEmpty(extendedFields)) {
return paramMap;
Expand All @@ -286,7 +282,6 @@ protected static Map<String, List<String>> fromObject(final Object queryParams,
continue;
}
String paramName = nameConverter.convert(extendedField.getName());

QueryParam annotation = extendedField.getAnnotation(QueryParam.class);
MultiValueStrategy strategy = MultiValueStrategy.from(annotation);
ParameterFunction parameter = strategy.apply(paramName, paramValues);
Expand Down
5 changes: 2 additions & 3 deletions apiphany-core/src/main/java/org/apiphany/header/Headers.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.function.BiPredicate;
Expand All @@ -12,6 +11,7 @@

import org.apiphany.lang.Strings;
import org.morphix.lang.Nullables;
import org.morphix.lang.collections.CaseInsensitiveLinkedHashMap;
import org.morphix.lang.collections.Lists;
import org.morphix.lang.collections.Maps;

Expand Down Expand Up @@ -39,8 +39,7 @@ static Map<String, List<String>> of(final HeaderFunction... headerFunctions) {
if (null == headerFunctions || 0 == headerFunctions.length) {
return Collections.emptyMap();
}
// TODO: implement a case insensitive linked hash map
var map = new LinkedHashMap<String, List<String>>();
var map = new CaseInsensitiveLinkedHashMap<List<String>>();
for (HeaderFunction headerFunction : headerFunctions) {
headerFunction.addTo(map);
}
Expand Down
23 changes: 23 additions & 0 deletions apiphany-core/src/main/java/org/apiphany/lang/Strings.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import java.util.Collection;
import java.util.Objects;
import java.util.function.Consumer;
import java.util.function.Supplier;

import org.apiphany.io.IOStreams;
import org.apiphany.io.ResourceLocation;
Expand Down Expand Up @@ -543,4 +544,26 @@ static boolean equalsIgnoreCase(final String a, final String b) {
}
return null != a && a.equalsIgnoreCase(b);
}

/**
* Returns the given string if it is not blank, otherwise the default value.
*
* @param value a string
* @param defaultValue default value if value is blank
* @return the given string if it is not blank, otherwise the default value
*/
static String nonBlankOrDefault(final String value, final String defaultValue) {
return isNotBlank(value) ? value : defaultValue;
}

/**
* Returns the given string if it is not blank, otherwise the supplied default value.
*
* @param value a string
* @param defaultValue default value if value is blank
* @return the given string if it is not blank, otherwise the supplied default value
*/
static String nonBlankOrGet(final String value, final Supplier<String> defaultValue) {
return isNotBlank(value) ? value : defaultValue.get();
}
}
Loading