Merge branch 'stable-3.1'

* stable-3.1:
  PullReplicationIT: simplify fetching HTTP URL

Change-Id: I473842a4fd684896bf2ac627472343b6270e8171
diff --git a/src/main/java/com/googlesource/gerrit/plugins/replication/pull/Source.java b/src/main/java/com/googlesource/gerrit/plugins/replication/pull/Source.java
index e8eae78..0f03929 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/replication/pull/Source.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/replication/pull/Source.java
@@ -28,6 +28,7 @@
 import com.google.gerrit.entities.BranchNameKey;
 import com.google.gerrit.entities.Project;
 import com.google.gerrit.entities.RefNames;
+import com.google.gerrit.exceptions.StorageException;
 import com.google.gerrit.extensions.config.FactoryModule;
 import com.google.gerrit.extensions.registration.DynamicItem;
 import com.google.gerrit.extensions.restapi.AuthException;
@@ -255,19 +256,19 @@
               new Callable<Boolean>() {
                 @Override
                 public Boolean call() throws NoSuchProjectException, PermissionBackendException {
-                  ProjectState projectState;
+                  Optional<ProjectState> projectState;
                   try {
-                    projectState = projectCache.checkedGet(project);
-                  } catch (IOException e) {
+                    projectState = projectCache.get(project);
+                  } catch (StorageException e) {
                     return false;
                   }
-                  if (projectState == null) {
+                  if (!projectState.isPresent()) {
                     throw new NoSuchProjectException(project);
                   }
-                  if (!projectState.statePermitsRead()) {
+                  if (!projectState.get().statePermitsRead()) {
                     return false;
                   }
-                  if (!shouldReplicate(projectState, userProvider.get())) {
+                  if (!shouldReplicate(projectState.get(), userProvider.get())) {
                     return false;
                   }
                   if (FetchOne.ALL_REFS.equals(ref)) {
@@ -302,16 +303,16 @@
               new Callable<Boolean>() {
                 @Override
                 public Boolean call() throws NoSuchProjectException, PermissionBackendException {
-                  ProjectState projectState;
+                  Optional<ProjectState> projectState;
                   try {
-                    projectState = projectCache.checkedGet(project);
-                  } catch (IOException e) {
+                    projectState = projectCache.get(project);
+                  } catch (StorageException e) {
                     return false;
                   }
-                  if (projectState == null) {
+                  if (!projectState.isPresent()) {
                     throw new NoSuchProjectException(project);
                   }
-                  return shouldReplicate(projectState, userProvider.get());
+                  return shouldReplicate(projectState.get(), userProvider.get());
                 }
               })
           .call();
diff --git a/src/main/java/com/googlesource/gerrit/plugins/replication/pull/api/FetchAction.java b/src/main/java/com/googlesource/gerrit/plugins/replication/pull/api/FetchAction.java
index 736fbf0..d51590d 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/replication/pull/api/FetchAction.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/replication/pull/api/FetchAction.java
@@ -74,7 +74,7 @@
         | ExecutionException
         | IllegalStateException
         | TimeoutException e) {
-      throw new RestApiException(e.getMessage(), e);
+      throw RestApiException.wrap(e.getMessage(), e);
     } catch (RemoteConfigurationMissingException e) {
       throw new UnprocessableEntityException(e.getMessage());
     }