MNT-24346 Fix "0" return status code when SORL unavailable (#2942)

* MNT-24346: Fix 0 status code in Search API when Solr is unavailable.

* MNT-24346: Fixing PMD issues.

* MNT-24346: Fixing formatting.

* MNT-24346: Reverting accidental method name change.

* MNT-24346: Fixing spotless issues.

* MNT-24346: Fixing spotless issues.

* MNT-24346: Fixing spotless issues.

* MNT-24346 Fix line endings.

---------

Co-authored-by: Tom Page <tom.page@alfresco.com>
This commit is contained in:
Maciej Pichura
2024-09-25 15:27:06 +02:00
committed by GitHub
parent 837fb0cccd
commit 0f6950a72e
2 changed files with 186 additions and 186 deletions

View File

@@ -2,7 +2,7 @@
* #%L
* Alfresco Repository
* %%
* Copyright (C) 2005 - 2023 Alfresco Software Limited
* Copyright (C) 2005 - 2024 Alfresco Software Limited
* %%
* This file is part of the Alfresco software.
* If the software was purchased under a paid Alfresco license, the terms of
@@ -30,11 +30,8 @@ import java.io.IOException;
import java.io.InputStreamReader;
import java.io.Reader;
import java.util.List;
import jakarta.servlet.http.HttpServletResponse;
import org.alfresco.httpclient.HttpClientException;
import org.alfresco.repo.search.QueryParserException;
import org.apache.commons.httpclient.Header;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpStatus;
@@ -48,6 +45,9 @@ import org.json.JSONException;
import org.json.JSONObject;
import org.json.JSONTokener;
import org.alfresco.httpclient.HttpClientException;
import org.alfresco.repo.search.QueryParserException;
public abstract class AbstractSolrQueryHTTPClient
{
/** Logger for the class. */
@@ -99,7 +99,7 @@ public abstract class AbstractSolrQueryHTTPClient
try
{
httpClient.executeMethod(post);
if(post.getStatusCode() == HttpStatus.SC_MOVED_PERMANENTLY || post.getStatusCode() == HttpStatus.SC_MOVED_TEMPORARILY)
if (post.getStatusCode() == HttpStatus.SC_MOVED_PERMANENTLY || post.getStatusCode() == HttpStatus.SC_MOVED_TEMPORARILY)
{
Header locationHeader = post.getResponseHeader("location");
if (locationHeader != null)

View File

@@ -2,7 +2,7 @@
* #%L
* Alfresco Repository
* %%
* Copyright (C) 2005 - 2023 Alfresco Software Limited
* Copyright (C) 2005 - 2024 Alfresco Software Limited
* %%
* This file is part of the Alfresco software.
* If the software was purchased under a paid Alfresco license, the terms of
@@ -36,12 +36,10 @@ import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import static org.mockito.MockitoAnnotations.openMocks;
import jakarta.servlet.http.HttpServletResponse;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import jakarta.servlet.http.HttpServletResponse;
import org.alfresco.httpclient.HttpClientException;
import org.alfresco.repo.search.QueryParserException;
import org.apache.commons.httpclient.Header;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.URI;
@@ -51,6 +49,9 @@ import org.junit.Before;
import org.junit.Test;
import org.mockito.Mock;
import org.alfresco.httpclient.HttpClientException;
import org.alfresco.repo.search.QueryParserException;
/** Tests for the {@link AbstractSolrQueryHTTPClient}. */
public class AbstractSolrQueryHTTPClientTest
{
@@ -158,8 +159,7 @@ public class AbstractSolrQueryHTTPClientTest
String messageFromHttp = "Some IO Exception";
when(httpClient.executeMethod(any())).thenThrow(new IOException(messageFromHttp));
HttpClientException expectedException =
assertThrows(HttpClientException.class, () -> abstractSolrQueryHTTPClient.postQuery(httpClient, URL, body));
HttpClientException expectedException = assertThrows(HttpClientException.class, () -> abstractSolrQueryHTTPClient.postQuery(httpClient, URL, body));
String exceptionMessage = expectedException.getMessage();
assertTrue(exceptionMessage.endsWith("[%s] %s".formatted(abstractSolrQueryHTTPClient.getClass().getSimpleName(), messageFromHttp)));