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

Update servlet to handle param keys with multiple values #25

Merged
merged 1 commit into from
Apr 11, 2024
Merged
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 @@ -10,6 +10,7 @@
import java.net.http.HttpResponse;
import java.net.http.HttpResponse.BodyHandlers;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Enumeration;
import java.util.List;
import java.util.logging.Logger;
Expand Down Expand Up @@ -38,6 +39,10 @@ public class RegistryLegacyServlet extends HttpServlet {

private static List<String> SOLR_QUERY_PARAMS =
new ArrayList<String>(List.of("q", "sort", "start", "rows", "fq", "fl", "wt"));
private static List<String> SOLR_FACET_FIELDS =
new ArrayList<String>(List.of("facet_agency", "facet_instrument", "facet_investigation",
"facet_target", "facet_type", "facet_pds_model_version", "facet_primary_result_purpose",
"facet_primary_result_processing_level"));
private static List<String> REQUEST_HANDLERS =
new ArrayList<String>(List.of("search", "archive-filter", "select"));
private static String REQUEST_HANDLER_PARAM = "qt";
Expand Down Expand Up @@ -147,9 +152,10 @@ private String getQueryString(HttpServletRequest request) throws UnsupportedEnco
this.solrRequestHandler = value;
}
} else if (SOLR_QUERY_PARAMS.contains(paramKey)) {
value = URLDecoder.decode(request.getParameter(paramKey), "UTF-8");
queryString +=
String.format("%s=%s&", paramKey, URLEncoder.encode(value, "UTF-8"));
queryString += appendQueryParameters(paramKey, request.getParameterValues(paramKey));
} else if (paramKey.endsWith(".facet.prefix")
&& SOLR_FACET_FIELDS.contains(paramKey.split("\\.")[1])) {
queryString += appendQueryParameters(paramKey, request.getParameterValues(paramKey));
}
}

Expand All @@ -160,6 +166,18 @@ private String getQueryString(HttpServletRequest request) throws UnsupportedEnco
return queryString;
}

private String appendQueryParameters(String key, String[] parameterValues)
throws UnsupportedEncodingException {
String value = "";
String queryString = "";
for (String v : Arrays.asList(parameterValues)) {
value = URLDecoder.decode(v, "UTF-8");
LOG.info(v);
nutjob4life marked this conversation as resolved.
Show resolved Hide resolved
queryString += String.format("%s=%s&", key, URLEncoder.encode(value, "UTF-8"));
}
return queryString;
}

private void setResponseHeader(String wt, HttpServletResponse response) {
String contentType = "text/html; charset=UTF-8";
if (wt != null) {
Expand Down