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
Original file line number Diff line number Diff line change
Expand Up @@ -125,14 +125,12 @@ Mono<Response<CreateCallResult>> createCallWithResponseInternal(CreateCallOption
try {
context = context == null ? Context.NONE : context;
CreateCallRequestInternal request = getCreateCallRequestInternal(createCallOptions);
if (createCallOptions.getRepeatabilityHeaders() == null) {
RepeatabilityHeaders autoRepeatabilityHeaders = new RepeatabilityHeaders(UUID.randomUUID(), Instant.now());
createCallOptions.setRepeatabilityHeaders(autoRepeatabilityHeaders);
}

createCallOptions.setRepeatabilityHeaders(handleApiIdempotency(createCallOptions.getRepeatabilityHeaders()));

return serverCallingInternal.createCallWithResponseAsync(request,
createCallOptions.getRepeatabilityHeaders().getRepeatabilityRequestId(),
createCallOptions.getRepeatabilityHeaders().getRepeatabilityFirstSentInHttpDateFormat(),
createCallOptions.getRepeatabilityHeaders() != null ? createCallOptions.getRepeatabilityHeaders().getRepeatabilityRequestId() : null,
createCallOptions.getRepeatabilityHeaders() != null ? createCallOptions.getRepeatabilityHeaders().getRepeatabilityFirstSentInHttpDateFormat() : null,
context)
.onErrorMap(HttpResponseException.class, ErrorConstructorProxy::create)
.map(response -> {
Expand Down Expand Up @@ -227,10 +225,7 @@ Mono<Response<AnswerCallResult>> answerCallWithResponseInternal(AnswerCallOption
.setIncomingCallContext(answerCallOptions.getIncomingCallContext())
.setCallbackUri(answerCallOptions.getCallbackUrl());

if (answerCallOptions.getRepeatabilityHeaders() == null) {
RepeatabilityHeaders autoRepeatabilityHeaders = new RepeatabilityHeaders(UUID.randomUUID(), Instant.now());
answerCallOptions.setRepeatabilityHeaders(autoRepeatabilityHeaders);
}
answerCallOptions.setRepeatabilityHeaders(handleApiIdempotency(answerCallOptions.getRepeatabilityHeaders()));

if (answerCallOptions.getMediaStreamingConfiguration() != null) {
MediaStreamingConfigurationInternal mediaStreamingConfigurationInternal =
Expand All @@ -241,8 +236,8 @@ Mono<Response<AnswerCallResult>> answerCallWithResponseInternal(AnswerCallOption


return serverCallingInternal.answerCallWithResponseAsync(request,
answerCallOptions.getRepeatabilityHeaders().getRepeatabilityRequestId(),
answerCallOptions.getRepeatabilityHeaders().getRepeatabilityFirstSentInHttpDateFormat(),
answerCallOptions.getRepeatabilityHeaders() != null ? answerCallOptions.getRepeatabilityHeaders().getRepeatabilityRequestId() : null,
answerCallOptions.getRepeatabilityHeaders() != null ? answerCallOptions.getRepeatabilityHeaders().getRepeatabilityFirstSentInHttpDateFormat() : null,
context)
.onErrorMap(HttpResponseException.class, ErrorConstructorProxy::create)
.map(response -> {
Expand Down Expand Up @@ -296,14 +291,11 @@ Mono<Response<Void>> redirectCallWithResponseInternal(RedirectCallOptions redire
.setIncomingCallContext(redirectCallOptions.getIncomingCallContext())
.setTarget(CommunicationIdentifierConverter.convert(redirectCallOptions.getTarget()));

if (redirectCallOptions.getRepeatabilityHeaders() == null) {
RepeatabilityHeaders autoRepeatabilityHeaders = new RepeatabilityHeaders(UUID.randomUUID(), Instant.now());
redirectCallOptions.setRepeatabilityHeaders(autoRepeatabilityHeaders);
}
redirectCallOptions.setRepeatabilityHeaders(handleApiIdempotency(redirectCallOptions.getRepeatabilityHeaders()));

return serverCallingInternal.redirectCallWithResponseAsync(request,
redirectCallOptions.getRepeatabilityHeaders().getRepeatabilityRequestId(),
redirectCallOptions.getRepeatabilityHeaders().getRepeatabilityFirstSentInHttpDateFormat(),
redirectCallOptions.getRepeatabilityHeaders() != null ? redirectCallOptions.getRepeatabilityHeaders().getRepeatabilityRequestId() : null,
redirectCallOptions.getRepeatabilityHeaders() != null ? redirectCallOptions.getRepeatabilityHeaders().getRepeatabilityFirstSentInHttpDateFormat() : null,
context)
.onErrorMap(HttpResponseException.class, ErrorConstructorProxy::create);
} catch (RuntimeException ex) {
Expand Down Expand Up @@ -348,14 +340,11 @@ Mono<Response<Void>> rejectCallWithResponseInternal(RejectCallOptions rejectCall
request.setCallRejectReason(CallRejectReasonInternal.fromString(rejectCallOptions.getCallRejectReason().toString()));
}

if (rejectCallOptions.getRepeatabilityHeaders() == null) {
RepeatabilityHeaders autoRepeatabilityHeaders = new RepeatabilityHeaders(UUID.randomUUID(), Instant.now());
rejectCallOptions.setRepeatabilityHeaders(autoRepeatabilityHeaders);
}
rejectCallOptions.setRepeatabilityHeaders(handleApiIdempotency(rejectCallOptions.getRepeatabilityHeaders()));

return serverCallingInternal.rejectCallWithResponseAsync(request,
rejectCallOptions.getRepeatabilityHeaders().getRepeatabilityRequestId(),
rejectCallOptions.getRepeatabilityHeaders().getRepeatabilityFirstSentInHttpDateFormat(),
rejectCallOptions.getRepeatabilityHeaders() != null ? rejectCallOptions.getRepeatabilityHeaders().getRepeatabilityRequestId() : null,
rejectCallOptions.getRepeatabilityHeaders() != null ? rejectCallOptions.getRepeatabilityHeaders().getRepeatabilityFirstSentInHttpDateFormat() : null,
context)
.onErrorMap(HttpResponseException.class, ErrorConstructorProxy::create);
} catch (RuntimeException ex) {
Expand Down Expand Up @@ -387,4 +376,24 @@ public CallRecordingAsync getCallRecordingAsync() {
contentDownloader, httpPipelineInternal, resourceEndpoint);
}
//endregion

//region helper functions
/***
* Make sure repeatability headers of the request are correctly set.
*
* @return a verified RepeatabilityHeaders object.
*/
static RepeatabilityHeaders handleApiIdempotency(RepeatabilityHeaders repeatabilityHeaders) {
// This case means user did not disable idempotency
if (repeatabilityHeaders != null) {
// This means user never set the repeatability headers manually.
if (repeatabilityHeaders.getRepeatabilityRequestId().equals(UUID.fromString("0-0-0-0-0"))
&& repeatabilityHeaders.getRepeatabilityFirstSent() == Instant.MIN) {
repeatabilityHeaders = new RepeatabilityHeaders(UUID.randomUUID(), Instant.now());
} // Else do nothing, use the repeatability headers that user specified.
} // Else do nothing, since the user disabled idempotency. Leave it as null.

return repeatabilityHeaders;
}
//endregion
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,7 @@
import reactor.core.publisher.Mono;

import java.net.URISyntaxException;
import java.time.Instant;
import java.util.List;
import java.util.UUID;
import java.util.stream.Collectors;

import static com.azure.core.util.FluxUtil.monoError;
Expand Down Expand Up @@ -142,14 +140,11 @@ Mono<Response<Void>> hangUpWithResponseInternal(HangUpOptions hangUpOptions, Con
try {
context = context == null ? Context.NONE : context;

if (hangUpOptions.getRepeatabilityHeaders() == null) {
RepeatabilityHeaders autoRepeatabilityHeaders = new RepeatabilityHeaders(UUID.randomUUID(), Instant.now());
hangUpOptions.setRepeatabilityHeaders(autoRepeatabilityHeaders);
}
hangUpOptions.setRepeatabilityHeaders(handleApiIdempotency(hangUpOptions.getRepeatabilityHeaders()));

return (hangUpOptions.getIsForEveryone() ? callConnectionInternal.terminateCallWithResponseAsync(callConnectionId,
hangUpOptions.getRepeatabilityHeaders().getRepeatabilityRequestId(),
hangUpOptions.getRepeatabilityHeaders().getRepeatabilityFirstSentInHttpDateFormat(),
hangUpOptions.getRepeatabilityHeaders() != null ? hangUpOptions.getRepeatabilityHeaders().getRepeatabilityRequestId() : null,
hangUpOptions.getRepeatabilityHeaders() != null ? hangUpOptions.getRepeatabilityHeaders().getRepeatabilityFirstSentInHttpDateFormat() : null,
context)
: callConnectionInternal.hangupCallWithResponseAsync(callConnectionId, context))
.onErrorMap(HttpResponseException.class, ErrorConstructorProxy::create);
Expand Down Expand Up @@ -272,14 +267,11 @@ Mono<Response<TransferCallResult>> transferToParticipantCallWithResponseInternal
.setUserToUserInformation(transferToParticipantCallOptions.getUserToUserInformation())
.setOperationContext(transferToParticipantCallOptions.getOperationContext());

if (transferToParticipantCallOptions.getRepeatabilityHeaders() == null) {
RepeatabilityHeaders autoRepeatabilityHeaders = new RepeatabilityHeaders(UUID.randomUUID(), Instant.now());
transferToParticipantCallOptions.setRepeatabilityHeaders(autoRepeatabilityHeaders);
}
transferToParticipantCallOptions.setRepeatabilityHeaders(handleApiIdempotency(transferToParticipantCallOptions.getRepeatabilityHeaders()));

return callConnectionInternal.transferToParticipantWithResponseAsync(callConnectionId, request,
transferToParticipantCallOptions.getRepeatabilityHeaders().getRepeatabilityRequestId(),
transferToParticipantCallOptions.getRepeatabilityHeaders().getRepeatabilityFirstSentInHttpDateFormat(),
transferToParticipantCallOptions.getRepeatabilityHeaders() != null ? transferToParticipantCallOptions.getRepeatabilityHeaders().getRepeatabilityRequestId() : null,
transferToParticipantCallOptions.getRepeatabilityHeaders() != null ? transferToParticipantCallOptions.getRepeatabilityHeaders().getRepeatabilityFirstSentInHttpDateFormat() : null,
context)
.onErrorMap(HttpResponseException.class, ErrorConstructorProxy::create)
.map(response ->
Expand Down Expand Up @@ -332,14 +324,11 @@ Mono<Response<AddParticipantsResult>> addParticipantsWithResponseInternal(AddPar
request.setInvitationTimeoutInSeconds((int) addParticipantsOptions.getInvitationTimeout().getSeconds());
}

if (addParticipantsOptions.getRepeatabilityHeaders() == null) {
RepeatabilityHeaders autoRepeatabilityHeaders = new RepeatabilityHeaders(UUID.randomUUID(), Instant.now());
addParticipantsOptions.setRepeatabilityHeaders(autoRepeatabilityHeaders);
}
addParticipantsOptions.setRepeatabilityHeaders(handleApiIdempotency(addParticipantsOptions.getRepeatabilityHeaders()));

return callConnectionInternal.addParticipantWithResponseAsync(callConnectionId, request,
addParticipantsOptions.getRepeatabilityHeaders().getRepeatabilityRequestId(),
addParticipantsOptions.getRepeatabilityHeaders().getRepeatabilityFirstSentInHttpDateFormat(),
addParticipantsOptions.getRepeatabilityHeaders() != null ? addParticipantsOptions.getRepeatabilityHeaders().getRepeatabilityRequestId() : null,
addParticipantsOptions.getRepeatabilityHeaders() != null ? addParticipantsOptions.getRepeatabilityHeaders().getRepeatabilityFirstSentInHttpDateFormat() : null,
context)
.onErrorMap(HttpResponseException.class, ErrorConstructorProxy::create)
.map(response -> new SimpleResponse<>(response, AddParticipantsResponseConstructorProxy.create(response.getValue())));
Expand Down Expand Up @@ -380,18 +369,15 @@ Mono<Response<RemoveParticipantsResult>> removeParticipantsWithResponseInternal(
List<CommunicationIdentifierModel> participantModels = removeParticipantsOptions.getParticipants()
.stream().map(CommunicationIdentifierConverter::convert).collect(Collectors.toList());

if (removeParticipantsOptions.getRepeatabilityHeaders() == null) {
RepeatabilityHeaders autoRepeatabilityHeaders = new RepeatabilityHeaders(UUID.randomUUID(), Instant.now());
removeParticipantsOptions.setRepeatabilityHeaders(autoRepeatabilityHeaders);
}
removeParticipantsOptions.setRepeatabilityHeaders(handleApiIdempotency(removeParticipantsOptions.getRepeatabilityHeaders()));

RemoveParticipantsRequestInternal request = new RemoveParticipantsRequestInternal()
.setParticipantsToRemove(participantModels)
.setOperationContext(removeParticipantsOptions.getOperationContext());

return callConnectionInternal.removeParticipantsWithResponseAsync(callConnectionId, request,
removeParticipantsOptions.getRepeatabilityHeaders().getRepeatabilityRequestId(),
removeParticipantsOptions.getRepeatabilityHeaders().getRepeatabilityFirstSentInHttpDateFormat(),
removeParticipantsOptions.getRepeatabilityHeaders() != null ? removeParticipantsOptions.getRepeatabilityHeaders().getRepeatabilityRequestId() : null,
removeParticipantsOptions.getRepeatabilityHeaders() != null ? removeParticipantsOptions.getRepeatabilityHeaders().getRepeatabilityFirstSentInHttpDateFormat() : null,
context)
.onErrorMap(HttpResponseException.class, ErrorConstructorProxy::create)
.map(response -> new SimpleResponse<>(response, RemoveParticipantsResponseConstructorProxy.create(response.getValue())));
Expand All @@ -411,4 +397,15 @@ public CallMediaAsync getCallMediaAsync() {
return new CallMediaAsync(callConnectionId, contentsInternal);
}
//endregion

//region helper functions
/***
* Make sure repeatability headers of the request are correctly set.
*
* @return a verified RepeatabilityHeaders object.
*/
private RepeatabilityHeaders handleApiIdempotency(RepeatabilityHeaders repeatabilityHeaders) {
return CallAutomationAsyncClient.handleApiIdempotency(repeatabilityHeaders);
}
//endregion
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,10 @@
import java.nio.file.Path;
import java.nio.file.StandardOpenOption;
import java.security.InvalidParameterException;
import java.time.Instant;
import java.util.HashSet;
import java.util.List;
import java.util.Objects;
import java.util.Set;
import java.util.UUID;
import java.util.stream.Collectors;

import static com.azure.core.util.FluxUtil.monoError;
Expand Down Expand Up @@ -123,18 +121,15 @@ Mono<Response<RecordingStateResult>> startRecordingWithResponseInternal(StartRec
}
StartCallRecordingRequestInternal request = getStartCallRecordingRequest(options);

if (options.getRepeatabilityHeaders() == null) {
RepeatabilityHeaders autoRepeatabilityHeaders = new RepeatabilityHeaders(UUID.randomUUID(), Instant.now());
options.setRepeatabilityHeaders(autoRepeatabilityHeaders);
}
options.setRepeatabilityHeaders(handleApiIdempotency(options.getRepeatabilityHeaders()));

return withContext(contextValue -> {
contextValue = context == null ? contextValue : context;
return contentsInternal
.recordingWithResponseAsync(
request,
options.getRepeatabilityHeaders().getRepeatabilityRequestId(),
options.getRepeatabilityHeaders().getRepeatabilityFirstSentInHttpDateFormat(),
options.getRepeatabilityHeaders() != null ? options.getRepeatabilityHeaders().getRepeatabilityRequestId() : null,
options.getRepeatabilityHeaders() != null ? options.getRepeatabilityHeaders().getRepeatabilityFirstSentInHttpDateFormat() : null,
contextValue)
.onErrorMap(HttpResponseException.class, ErrorConstructorProxy::create)
.map(response ->
Expand Down Expand Up @@ -577,4 +572,15 @@ private URL getUrlToSignRequestWith(String endpoint) {
throw logger.logExceptionAsError(new IllegalArgumentException(ex));
}
}

//region helper functions
/***
* Make sure repeatability headers of the request are correctly set.
*
* @return a verified RepeatabilityHeaders object.
*/
private RepeatabilityHeaders handleApiIdempotency(RepeatabilityHeaders repeatabilityHeaders) {
return CallAutomationAsyncClient.handleApiIdempotency(repeatabilityHeaders);
}
//endregion
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
import com.azure.core.annotation.Fluent;

import java.time.Duration;
import java.time.Instant;
import java.util.List;
import java.util.UUID;

/**
* The options for adding participants.
Expand Down Expand Up @@ -50,6 +52,7 @@ public final class AddParticipantsOptions {
*/
public AddParticipantsOptions(List<CommunicationIdentifier> participants) {
this.participants = participants;
this.repeatabilityHeaders = new RepeatabilityHeaders(UUID.fromString("0-0-0-0-0"), Instant.MIN);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@

import com.azure.core.annotation.Fluent;

import java.time.Instant;
import java.util.UUID;

/**
* The options for creating a call.
*/
Expand Down Expand Up @@ -39,6 +42,7 @@ public class AnswerCallOptions {
public AnswerCallOptions(String incomingCallContext, String callbackUrl) {
this.incomingCallContext = incomingCallContext;
this.callbackUrl = callbackUrl;
this.repeatabilityHeaders = new RepeatabilityHeaders(UUID.fromString("0-0-0-0-0"), Instant.MIN);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
import com.azure.communication.common.CommunicationIdentifier;
import com.azure.core.annotation.Fluent;

import java.time.Instant;
import java.util.List;
import java.util.UUID;

/**
* The options for creating a call.
Expand Down Expand Up @@ -60,6 +62,7 @@ public CreateCallOptions(CommunicationIdentifier source, List<CommunicationIdent
this.source = source;
this.targets = targets;
this.callbackUrl = callbackUrl;
this.repeatabilityHeaders = new RepeatabilityHeaders(UUID.fromString("0-0-0-0-0"), Instant.MIN);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@

import com.azure.core.annotation.Fluent;

import java.time.Instant;
import java.util.UUID;

/**
* The options for creating a call.
*/
Expand All @@ -27,6 +30,7 @@ public class HangUpOptions {
*/
public HangUpOptions(boolean isForEveryone) {
this.isForEveryone = isForEveryone;
this.repeatabilityHeaders = new RepeatabilityHeaders(UUID.fromString("0-0-0-0-0"), Instant.MIN);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
import com.azure.communication.common.CommunicationIdentifier;
import com.azure.core.annotation.Fluent;

import java.time.Instant;
import java.util.UUID;

/**
* The options for creating a call.
*/
Expand Down Expand Up @@ -35,6 +38,7 @@ public class RedirectCallOptions {
public RedirectCallOptions(String incomingCallContext, CommunicationIdentifier target) {
this.incomingCallContext = incomingCallContext;
this.target = target;
this.repeatabilityHeaders = new RepeatabilityHeaders(UUID.fromString("0-0-0-0-0"), Instant.MIN);
}

/**
Expand Down
Loading