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
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Changed

Changed OkHttpRequestAdapter dependency from OkHttpClient to Call.Factory (parent interface implemented by OkHttpClient).
## [0.9.0] - 2023-11-10

### Changed

- Kiota-Java has moved away from Async/Completable futures, thus Async components are no longer utilized and have been removed. Furthermore, requestAdapter methods no longer use the async suffix. [#175](https://github.com/microsoft/kiota-java/issues/175)
- ApiException class now extends RuntimeException instead of Exception.
- Changed OkHttpRequestAdapter dependency from OkHttpClient to Call.Factory (parent interface implemented by OkHttpClient).

## [0.8.0] - 2023-10-31

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import jakarta.annotation.Nonnull;

/** Parent type for exceptions thrown by the client when receiving failed responses to its requests. */
public class ApiException extends Exception {
public class ApiException extends RuntimeException {
/** {@inheritDoc} */
public ApiException() {
super();
Expand All @@ -30,7 +30,6 @@ public ApiException(@Nonnull final Throwable cause) {
* Gets the HTTP response status code
* @return The response status code from the failed response.
*/
@Nonnull
public int getResponseStatusCode() {
return responseStatusCode;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public ApiExceptionBuilder(@Nonnull final Supplier<Parsable> builder) {
value = (ApiException) error;
} else {
value = new ApiExceptionBuilder()
.withMessage("\"unexpected error type \" + error.getClass().getName()")
.withMessage("\"unexpected error type \"" + error.getClass().getName())
.build();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public abstract class BaseRequestBuilder {
* @param urlTemplate Url template to use to build the URL for the current request builder
*/
protected BaseRequestBuilder(@Nonnull final RequestAdapter requestAdapter, @Nonnull final String urlTemplate) {
this(requestAdapter, urlTemplate, new HashMap<String, Object>());
this(requestAdapter, urlTemplate, new HashMap<>());
}
/**
* Instantiates a new BaseRequestBuilder and sets the default values.
Expand All @@ -33,7 +33,7 @@ protected BaseRequestBuilder(@Nonnull final RequestAdapter requestAdapter, @Nonn
protected BaseRequestBuilder(@Nonnull final RequestAdapter requestAdapter, @Nonnull final String urlTemplate, @Nonnull final HashMap<String, Object> pathParameters) {
this.requestAdapter = Objects.requireNonNull(requestAdapter);
this.urlTemplate = Objects.requireNonNull(urlTemplate);
this.pathParameters = new HashMap<String, Object>(Objects.requireNonNull(pathParameters));
this.pathParameters = new HashMap<>(Objects.requireNonNull(pathParameters));
}
/**
* Instantiates a new BaseRequestBuilder and sets the default values.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@

/** Base class for request configuration */
public abstract class BaseRequestConfiguration {
/**
* Default constructor
*/
public BaseRequestConfiguration() {
// default empty constructor
}
/** Request headers */
@Nullable
public RequestHeaders headers = new RequestHeaders();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,15 @@
import jakarta.annotation.Nullable;

/**
* A map that is case insensitive on the keys
* A map that is case-insensitive on the keys
*/
public class CaseInsensitiveMap implements Map<String, Set<String>>{
/**
* Default constructor
*/
public CaseInsensitiveMap() {
// default constructor
}
private final HashMap<String, HashSet<String>> internalMap = new HashMap<>();

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import java.io.InputStream;

import jakarta.annotation.Nonnull;
import jakarta.annotation.Nullable;

/**
* Compatibility methods for android
*/
Expand All @@ -30,4 +32,12 @@ public static byte[] readAllBytes(@Nonnull final InputStream inputStream) throws
return outputStream.toByteArray();
}
}
/** INTERNAL METHOD, DO NOT USE DIRECTLY
* Checks if the string is null or empty or blank
* @param str the string to check
* @return true if the string is null or empty or blank
*/
public static boolean isBlank(@Nullable final String str) {
return str == null || str.trim().isEmpty();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,12 @@

import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import java.util.Objects;
import java.util.UUID;
import java.util.*;
Comment thread
ramsessanchez marked this conversation as resolved.
import java.util.function.Consumer;

import jakarta.annotation.Nonnull;
import jakarta.annotation.Nullable;

import com.google.common.base.Strings;
import com.microsoft.kiota.serialization.Parsable;
import com.microsoft.kiota.serialization.ParseNode;
import com.microsoft.kiota.serialization.SerializationWriter;
Expand All @@ -22,9 +17,18 @@
* Represents a multipart body for a request or a response.
*/
public class MultipartBody implements Parsable {
/**
* Creates a new instance of the MultipartBody class.
*/
public MultipartBody() {
// default empty constructor
}
@Nonnull
private final String boundary = UUID.randomUUID().toString().replace("-", "");
/** @return the boundary string for the multipart body. */
/**
* Gets the boundary string for the multipart body.
* @return the boundary string for the multipart body.
*/
@Nonnull
public String getBoundary() {
return boundary;
Expand All @@ -43,14 +47,14 @@ public String getBoundary() {
*/
public <T> void addOrReplacePart(@Nonnull final String name, @Nonnull final String contentType, @Nonnull final T value) {
Objects.requireNonNull(value);
if (Strings.isNullOrEmpty(contentType) || contentType.isBlank())
if (Compatibility.isBlank(contentType))
throw new IllegalArgumentException("contentType cannot be blank or empty");
if (Strings.isNullOrEmpty(name) || name.isBlank())
if (Compatibility.isBlank(name))
throw new IllegalArgumentException("name cannot be blank or empty");

final String normalizedName = normalizePartName(name);
originalNames.put(normalizedName, name);
parts.put(normalizedName, Map.entry(contentType, value));
parts.put(normalizedName, new AbstractMap.SimpleEntry<>(contentType, value));
}
private final Map<String, Map.Entry<String, Object>> parts = new HashMap<>();
private final Map<String, String> originalNames = new HashMap<>();
Expand All @@ -66,7 +70,7 @@ private String normalizePartName(@Nonnull final String original)
@Nullable
public Object getPartValue(@Nonnull final String partName)
{
if (Strings.isNullOrEmpty(partName) || partName.isBlank())
if (Compatibility.isBlank(partName))
throw new IllegalArgumentException("partName cannot be blank or empty");
final String normalizedName = normalizePartName(partName);
final Map.Entry<String, Object> candidate = parts.get(normalizedName);
Expand All @@ -81,7 +85,7 @@ public Object getPartValue(@Nonnull final String partName)
*/
public boolean removePart(@Nonnull final String partName)
{
if (Strings.isNullOrEmpty(partName) || partName.isBlank())
if (Compatibility.isBlank(partName))
throw new IllegalArgumentException("partName cannot be blank or empty");
final String normalizedName = normalizePartName(partName);
final Object candidate = parts.remove(normalizedName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.CompletableFuture;

import jakarta.annotation.Nonnull;
import jakarta.annotation.Nullable;
Expand All @@ -14,15 +13,20 @@
* The {@code ResponseHandler} implementation to handle native response objects
*/
public class NativeResponseHandler implements ResponseHandler {
/**
* Default constructor
*/
public NativeResponseHandler() {
// default empty constructor
}
private Object value;
private HashMap<String, ParsableFactory<? extends Parsable>> errorMappings;
@Override
@Nonnull
public <NativeResponseType, ModelType> CompletableFuture<ModelType> handleResponseAsync(@Nonnull NativeResponseType response, @Nullable HashMap<String, ParsableFactory<? extends Parsable>> errorMappings) {
public <NativeResponseType, ModelType> ModelType handleResponse(@Nonnull NativeResponseType response, @Nullable HashMap<String, ParsableFactory<? extends Parsable>> errorMappings) {
this.value = response;
if(errorMappings != null)
this.errorMappings = new HashMap<>(errorMappings);
return CompletableFuture.completedFuture(null);
return null;
}
/**
* Set the error mappings for the response to use when deserializing failed responses bodies.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ public static PeriodAndDuration ofPeriodAndDuration(@Nonnull PeriodAndDuration p
return new PeriodAndDuration(periodAndDuration.getPeriod(), periodAndDuration.getDuration());
}
/**
* Parses a string to produce a {@code PeriodAndDuration}.
* @param stringValue the {@code String} parse from.
* @return parsed instance of {@code PeriodAndDuration}
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.microsoft.kiota;

import java.util.concurrent.CompletableFuture;
import java.util.HashMap;
import java.util.List;

Expand Down Expand Up @@ -31,64 +30,64 @@ public interface RequestAdapter {
* @param factory the factory to create the parsable object from the type discriminator.
* @param errorMappings the error factories mapping to use in case of a failed request.
* @param <ModelType> the type of the response model to deserialize the response into.
* @return a {@link CompletableFuture} with the deserialized response model.
* @return the deserialized response model.
*/
@Nullable
@SuppressWarnings("LambdaLast")
<ModelType extends Parsable> CompletableFuture<ModelType> sendAsync(@Nonnull final RequestInformation requestInfo, @Nonnull final ParsableFactory<ModelType> factory, @Nullable final HashMap<String, ParsableFactory<? extends Parsable>> errorMappings);
<ModelType extends Parsable> ModelType send(@Nonnull final RequestInformation requestInfo, @Nonnull final ParsableFactory<ModelType> factory, @Nullable final HashMap<String, ParsableFactory<? extends Parsable>> errorMappings);
/**
* Executes the HTTP request specified by the given RequestInformation and returns the deserialized response model collection.
* @param requestInfo the request info to execute.
* @param factory the factory to create the parsable object from the type discriminator.
* @param errorMappings the error factories mapping to use in case of a failed request.
* @param <ModelType> the type of the response model to deserialize the response into.
* @return a {@link CompletableFuture} with the deserialized response model collection.
* @return the deserialized response model collection.
*/
@Nullable
@SuppressWarnings("LambdaLast")
<ModelType extends Parsable> CompletableFuture<List<ModelType>> sendCollectionAsync(@Nonnull final RequestInformation requestInfo, @Nonnull final ParsableFactory<ModelType> factory, @Nullable final HashMap<String, ParsableFactory<? extends Parsable>> errorMappings);
<ModelType extends Parsable> List<ModelType> sendCollection(@Nonnull final RequestInformation requestInfo, @Nonnull final ParsableFactory<ModelType> factory, @Nullable final HashMap<String, ParsableFactory<? extends Parsable>> errorMappings);
/**
* Executes the HTTP request specified by the given RequestInformation and returns the deserialized primitive response model.
* @param requestInfo the request info to execute.
* @param targetClass the class of the response model to deserialize the response into.
* @param errorMappings the error factories mapping to use in case of a failed request.
* @param <ModelType> the type of the response model to deserialize the response into.
* @return a {@link CompletableFuture} with the deserialized primitive response model.
* @return the deserialized primitive response model.
*/
@Nullable
<ModelType> CompletableFuture<ModelType> sendPrimitiveAsync(@Nonnull final RequestInformation requestInfo, @Nonnull final Class<ModelType> targetClass, @Nullable final HashMap<String, ParsableFactory<? extends Parsable>> errorMappings);
<ModelType> ModelType sendPrimitive(@Nonnull final RequestInformation requestInfo, @Nonnull final Class<ModelType> targetClass, @Nullable final HashMap<String, ParsableFactory<? extends Parsable>> errorMappings);
/**
* Executes the HTTP request specified by the given RequestInformation and returns the deserialized primitive collection response model.
* @param requestInfo the request info to execute.
* @param targetClass the class of the response model to deserialize the response into.
* @param errorMappings the error factories mapping to use in case of a failed request.
* @param <ModelType> the type of the response model to deserialize the response into.
* @return a {@link CompletableFuture} with the deserialized primitive collection response model.
* @return the deserialized primitive collection response model.
*/
@Nullable
<ModelType> CompletableFuture<List<ModelType>> sendPrimitiveCollectionAsync(@Nonnull final RequestInformation requestInfo, @Nonnull final Class<ModelType> targetClass, @Nullable final HashMap<String, ParsableFactory<? extends Parsable>> errorMappings);
<ModelType> List<ModelType> sendPrimitiveCollection(@Nonnull final RequestInformation requestInfo, @Nonnull final Class<ModelType> targetClass, @Nullable final HashMap<String, ParsableFactory<? extends Parsable>> errorMappings);

/**
Executes the HTTP request specified by the given RequestInformation and returns the deserialized enum value.
* @param requestInfo the request info to execute.
* @param targetClass the class of the response model to deserialize the response into.
* @param errorMappings the error factories mapping to use in case of a failed request.
* @param <ModelType> the type of the response model to deserialize the response into.
* @return a {@link CompletableFuture} with the deserialized primitive response model.
* @return the deserialized primitive response model.
*/
@Nullable
<ModelType extends Enum<ModelType>> CompletableFuture<ModelType> sendEnumAsync(@Nonnull final RequestInformation requestInfo, @Nonnull final Class<ModelType> targetClass, @Nullable final HashMap<String, ParsableFactory<? extends Parsable>> errorMappings);
<ModelType extends Enum<ModelType>> ModelType sendEnum(@Nonnull final RequestInformation requestInfo, @Nonnull final Class<ModelType> targetClass, @Nullable final HashMap<String, ParsableFactory<? extends Parsable>> errorMappings);

/**
Executes the HTTP request specified by the given RequestInformation and returns the deserialized enum collection value.
* @param requestInfo the request info to execute.
* @param targetClass the class of the response model to deserialize the response into.
* @param errorMappings the error factories mapping to use in case of a failed request.
* @param <ModelType> the type of the response model to deserialize the response into.
* @return a {@link CompletableFuture} with the deserialized primitive response model.
* @return the deserialized primitive response model.
*/
@Nullable
<ModelType extends Enum<ModelType>> CompletableFuture<List<ModelType>> sendEnumCollectionAsync(@Nonnull final RequestInformation requestInfo, @Nonnull final Class<ModelType> targetClass, @Nullable final HashMap<String, ParsableFactory<? extends Parsable>> errorMappings);
<ModelType extends Enum<ModelType>> List<ModelType> sendEnumCollection(@Nonnull final RequestInformation requestInfo, @Nonnull final Class<ModelType> targetClass, @Nullable final HashMap<String, ParsableFactory<? extends Parsable>> errorMappings);
/**
* Sets The base url for every request.
* @param baseUrl The base url for every request.
Expand All @@ -107,5 +106,5 @@ public interface RequestAdapter {
* @return the native HTTP request.
*/
@Nonnull
<T> CompletableFuture<T> convertToNativeRequestAsync(@Nonnull final RequestInformation requestInfo);
<T> T convertToNativeRequest(@Nonnull final RequestInformation requestInfo);
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.microsoft.kiota;

import java.util.HashMap;
import java.util.concurrent.CompletableFuture;

import jakarta.annotation.Nonnull;
import jakarta.annotation.Nullable;
Expand All @@ -13,12 +12,13 @@
public interface ResponseHandler {
/**
* Callback method that is invoked when a response is received.
* @param response The native response object.
* @param errorMappings the error mappings for the response to use when deserializing failed responses bodies. Where an error code like 401 applies specifically to that status code, a class code like 4XX applies to all status codes within the range if an the specific error code is not present.
*
* @param response The native response object.
* @param errorMappings the error mappings for the response to use when deserializing failed responses bodies. Where an error code like 401 applies specifically to that status code, a class code like 4XX applies to all status codes within the range if an the specific error code is not present.
* @param <NativeResponseType> The type of the native response object.
* @param <ModelType> The type of the response model object.
* @return A CompletableFuture that represents the asynchronous operation and contains the deserialized response.
* @param <ModelType> The type of the response model object.
* @return The deserialized response model object.
*/
@Nonnull
<NativeResponseType, ModelType> CompletableFuture<ModelType> handleResponseAsync(@Nonnull final NativeResponseType response, @Nullable final HashMap<String, ParsableFactory<? extends Parsable>> errorMappings);
@Nullable
<NativeResponseType, ModelType> ModelType handleResponse(@Nonnull final NativeResponseType response, @Nullable final HashMap<String, ParsableFactory<? extends Parsable>> errorMappings);
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
public class ResponseHandlerOption implements RequestOption {
/** Creates a new instance of the option */
public ResponseHandlerOption() {
// default constructor
}
private ResponseHandler responseHandler;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import java.net.URI;
import java.util.Map;
import java.util.concurrent.CompletableFuture;

import jakarta.annotation.Nonnull;
import jakarta.annotation.Nullable;
Expand All @@ -13,10 +12,10 @@ public interface AccessTokenProvider {
* This method returns the access token for the provided url.
* @param uri The target URI to get an access token for.
* @param additionalAuthenticationContext Additional authentication context to pass to the authentication library.
* @return A CompletableFuture that holds the access token.
* @return the access token.
*/
@Nonnull
CompletableFuture<String> getAuthorizationToken(@Nonnull final URI uri, @Nullable final Map<String, Object> additionalAuthenticationContext);
String getAuthorizationToken(@Nonnull final URI uri, @Nullable final Map<String, Object> additionalAuthenticationContext);
/**
* Returns the allowed hosts validator.
* @return The allowed hosts validator.
Expand Down
Loading