mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-24 17:32:48 +00:00
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:
@@ -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)
|
||||
|
@@ -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)));
|
||||
|
Reference in New Issue
Block a user