Skip to content

Commit

Permalink
MNT-24346 Fix "0" return status code when SORL unavailable (#2942)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
mpichura and tpage-alfresco committed Sep 25, 2024
1 parent 837fb0c commit 0f6950a
Show file tree
Hide file tree
Showing 2 changed files with 186 additions and 186 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,23 @@
* #%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
* the paid license agreement will prevail. Otherwise, the software is
* This file is part of the Alfresco software.
* If the software was purchased under a paid Alfresco license, the terms of
* the paid license agreement will prevail. Otherwise, the software is
* provided under the following open source license terms:
*
*
* Alfresco is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
*
* Alfresco is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
*
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
* #L%
Expand All @@ -30,11 +30,8 @@
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;
Expand All @@ -48,13 +45,16 @@
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. */
private static final Log LOGGER = LogFactory.getLog(AbstractSolrQueryHTTPClient.class);

public static final int DEFAULT_SAVEPOST_BUFFER = 4096;

// Constants copied from org.apache.solr.common.params.HighlightParams (solr-solrj:1.4.1)
// These values have been moved to this Alfresco class to avoid using solr-solrj library as dependency
public static final String HIGHLIGHT_PARAMS_HIGHLIGHT = "hl";
Expand Down Expand Up @@ -86,7 +86,7 @@ public abstract class AbstractSolrQueryHTTPClient

/** List of SOLR Exceptions that should be returning HTTP 501 status code in Remote API. */
private static final List<String> STATUS_CODE_501_EXCEPTIONS = List.of("java.lang.UnsupportedOperationException");

protected JSONObject postQuery(HttpClient httpClient, String url, JSONObject body) throws IOException, JSONException
{
PostMethod post = createNewPostMethod(url);
Expand All @@ -99,7 +99,7 @@ protected JSONObject postQuery(HttpClient httpClient, String url, JSONObject bod
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)
Expand Down
Loading

0 comments on commit 0f6950a

Please sign in to comment.