Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIX: Editing ChangeLog and Readme for CallingServer. #23167

Merged
2 commits merged into from
Jul 27, 2021
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 @@ -608,5 +608,5 @@ the main ServiceBusClientBuilder. -->

<!-- Checkstyle suppressions to keep HttpPipelinePolicy in implementation folder. -->
<suppress checks="com.azure.tools.checkstyle.checks.HttpPipelinePolicyCheck"
files="com.azure.communication.common.implementation.RedirectPolicy.java"/>
files="com.azure.communication.callingserver.implementation.RedirectPolicy.java"/>
</suppressions>
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# Release History

## 1.0.0-beta.3 (Unreleased)

## 1.0.0-beta.3 (2021-07-26)
### Features Added
- Added RedirectPolicy as a new HttpPolicy to redirect requests based on the HttpResponse.

## 1.0.0-beta.2 (2021-06-25)
- Updated sdk and apis documentation.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ This package contains a Java SDK for Azure Communication CallingServer Service.
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-communication-callingserver</artifactId>
<version>1.0.0-beta.2</version>
<version>1.0.0-beta.3</version>
</dependency>
```
[//]: # ({x-version-update-end})
Expand Down
23 changes: 23 additions & 0 deletions sdk/communication/azure-communication-callingserver/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -176,4 +176,27 @@
</plugin>
</plugins>
</build>

<profiles>
<profile>
<id>is.jdk.11</id>
<activation>
<jdk>[9,)</jdk>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M3</version> <!-- {x-version-update;org.apache.maven.plugins:maven-surefire-plugin;external_dependency} -->
<configuration>
<argLine>
--add-opens com.azure.communication.callingserver/com.azure.communication.callingserver.implementation=ALL-UNNAMED
</argLine>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import com.azure.communication.callingserver.implementation.AzureCommunicationCallingServerServiceImpl;
import com.azure.communication.callingserver.implementation.AzureCommunicationCallingServerServiceImplBuilder;
import com.azure.communication.common.implementation.RedirectPolicy;
import com.azure.communication.callingserver.implementation.RedirectPolicy;
import com.azure.communication.common.implementation.CommunicationConnectionString;
import com.azure.communication.common.implementation.HmacAuthenticationPolicy;
import com.azure.core.annotation.ServiceClientBuilder;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
package com.azure.communication.callingserver.implementation;

import com.azure.core.http.HttpPipelineCallContext;
import com.azure.core.http.HttpPipelineNextPolicy;
import com.azure.core.http.HttpRequest;
import com.azure.core.http.HttpResponse;
import com.azure.core.http.policy.HttpPipelinePolicy;
import com.azure.core.util.logging.ClientLogger;
import reactor.core.publisher.Mono;

import java.util.HashSet;
import java.util.Set;

/**
* HttpPipelinePolicy to redirect requests when a redirect response (Http codes 301 or 302) is received to the
* new location marked by the Location header.
*/
public final class RedirectPolicy implements HttpPipelinePolicy {
private static final int MAX_REDIRECTS = 10;
private static final String LOCATION_HEADER_NAME = "Location";
private static final int SC_MOVED_PERMANENTLY = 301;
private static final int SC_MOVED_TEMPORARILY = 302;

private final ClientLogger logger = new ClientLogger(RedirectPolicy.class);

@Override
public Mono<HttpResponse> process(HttpPipelineCallContext context, HttpPipelineNextPolicy next) {
return attemptRedirection(context, next, 0, new HashSet<>());
}

private Mono<HttpResponse> attemptRedirection(HttpPipelineCallContext context, HttpPipelineNextPolicy next,
int redirectNumber, Set<String> attemptedRedirectLocations) {
return next.clone().process().flatMap(httpResponse -> {
if (isRedirectResponse(httpResponse)
&& shouldRedirect(httpResponse, context, redirectNumber, attemptedRedirectLocations)) {
String newLocation = httpResponse.getHeaderValue(LOCATION_HEADER_NAME);
attemptedRedirectLocations.add(newLocation);

HttpRequest newRequest = context.getHttpRequest().copy();
newRequest.setUrl(newLocation);
context.setHttpRequest(newRequest);

return attemptRedirection(context, next, redirectNumber + 1, attemptedRedirectLocations);
}
return Mono.just(httpResponse);
});
}

private boolean isRedirectResponse(HttpResponse response) {
return response.getStatusCode() == SC_MOVED_TEMPORARILY || response.getStatusCode() == SC_MOVED_PERMANENTLY;
}

private boolean shouldRedirect(HttpResponse response, HttpPipelineCallContext context, int retryCount,
Set<String> attemptedRedirectLocations) {
if (retryCount > MAX_REDIRECTS) {
logger.error(String.format("Request to %s has been redirected more than %s times.",
context.getHttpRequest().getUrl(), MAX_REDIRECTS));
return false;
}
if (attemptedRedirectLocations.contains(response.getHeaderValue(LOCATION_HEADER_NAME))) {
logger.error(String.format("Request to %s was redirected more than once to: %s",
context.getHttpRequest().getUrl(), response.getHeaderValue(LOCATION_HEADER_NAME)));
return false;
}
return true;
}

}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

package com.azure.communication.common.implementation;
package com.azure.communication.callingserver.implementation;

import com.azure.core.http.HttpClient;
import com.azure.core.http.HttpMethod;
Expand Down
2 changes: 1 addition & 1 deletion sdk/communication/azure-communication-common/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,4 @@ Check out other client libraries for Azure communication service
[cla]: https://cla.microsoft.com
[coc]: https://opensource.microsoft.com/codeofconduct/
[coc_faq]: https://opensource.microsoft.com/codeofconduct/faq/
[coc_contact]: mailto:[email protected]
[coc_contact]: mailto:[email protected]
35 changes: 0 additions & 35 deletions sdk/communication/azure-communication-common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -84,40 +84,5 @@
<version>3.4.8</version> <!-- {x-version-update;io.projectreactor:reactor-test;external_dependency} -->
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>3.9.0</version> <!-- {x-version-update;org.mockito:mockito-core;external_dependency} -->
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-all</artifactId>
<version>1.3</version> <!-- {x-version-update;org.hamcrest:hamcrest-all;external_dependency} -->
<scope>test</scope>
</dependency>
</dependencies>

<profiles>
<profile>
<id>java-lts</id>
<activation>
<jdk>[11,)</jdk>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M3</version> <!-- {x-version-update;org.apache.maven.plugins:maven-surefire-plugin;external_dependency} -->
<configuration>
<argLine>
--add-opens com.azure.communication.common/com.azure.communication.common.implementation=ALL-UNNAMED
</argLine>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>

This file was deleted.