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

normalize whitespace in log messages outputting user-provided parameters #418

Merged
merged 2 commits into from
Mar 7, 2024
Merged
Show file tree
Hide file tree
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 @@ -9,6 +9,7 @@
import jakarta.validation.constraints.Min;
import org.antlr.v4.runtime.NoViableAltException;
import org.antlr.v4.runtime.misc.ParseCancellationException;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
Expand Down Expand Up @@ -78,11 +79,11 @@ protected ResponseEntity<Object> processs(EndpointHandler handler, URIParameters
return new ResponseEntity<Object>(this.errorMessageFactory.get(e),
HttpStatus.INTERNAL_SERVER_ERROR);
} catch (LidVidMismatchException e) {
log.warn("The lid(vid) '" + parameters.getIdentifier()
+ "' in the data base type does not match given type '" + parameters.getGroup() + "'");
log.warn("The lid(vid) (whitespace-normalized) '" + StringUtils.normalizeSpace(parameters.getIdentifier().toString())
+ "' in the data base type does not match given type '" + StringUtils.normalizeSpace(parameters.getGroup()) + "'");
return new ResponseEntity<Object>(this.errorMessageFactory.get(e), HttpStatus.NOT_FOUND);
} catch (LidVidNotFoundException e) {
log.warn("Could not find lid(vid) in database: " + parameters.getIdentifier());
log.warn("Could not find lid(vid) in database (whitespace-normalized): " + StringUtils.normalizeSpace(parameters.getIdentifier().toString()));
return new ResponseEntity<Object>(this.errorMessageFactory.get(e), HttpStatus.NOT_FOUND);
} catch (MembershipException e) {
log.warn("The given lid(vid) does not support the requested membership.");
Expand All @@ -91,7 +92,7 @@ protected ResponseEntity<Object> processs(EndpointHandler handler, URIParameters
log.warn("Could not find any matching reference(s) in database.");
return new ResponseEntity<Object>(this.errorMessageFactory.get(e), HttpStatus.NOT_FOUND);
} catch (NoViableAltException | ParseCancellationException e) {
log.warn("The given search string '" + parameters.getQuery() + "' cannot be parsed.");
log.warn("The given search string (whitespace-normalized) '" + StringUtils.normalizeSpace(parameters.getQuery()) + "' cannot be parsed.");
ParseCancellationException forwarded_exception = new ParseCancellationException(
"The given search string '" + parameters.getQuery() + "' cannot be parsed.");
return new ResponseEntity<Object>(this.errorMessageFactory.get(forwarded_exception),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.commons.lang3.StringUtils;
import org.opensearch.action.search.SearchRequest;
import org.opensearch.action.search.SearchResponse;
import org.opensearch.client.RequestOptions;
Expand Down Expand Up @@ -256,19 +258,19 @@ public Object getResponse() throws NothingFoundException {

if (response == null) {
log.warn("Could not find any data given these conditions");
log.warn(" fields: " + String.valueOf(this.getFields().size()));
log.warn(" fields (whitespace-normalized): " + String.valueOf(this.getFields().size()));
for (String field : this.getFields())
log.warn(" " + field);
log.warn(" keyword: " + String.valueOf(this.getKeywords().size()));
log.warn(" " + StringUtils.normalizeSpace(field));
log.warn(" keyword (whitespace-normalized): " + String.valueOf(this.getKeywords().size()));
for (String keyword : this.getKeywords())
log.warn(" " + keyword);
log.warn(" lidvid: " + this.getProductIdentifierString());
log.warn(" " + StringUtils.normalizeSpace(keyword));
log.warn(" lidvid (whitespace-normalized): " + StringUtils.normalizeSpace(this.getProductIdentifierString()));
log.warn(" limit: " + String.valueOf(this.getLimit()));
log.warn(" query string: " + String.valueOf(this.getQueryString()));
log.warn(" selector: " + String.valueOf(this.getSelector()));
log.warn(" sorting: " + String.valueOf(this.getSort().size()));
log.warn(" sorting (whitespace-normalized): " + String.valueOf(this.getSort().size()));
for (String sort : this.getSort())
log.warn(" " + sort);
log.warn(" " + StringUtils.normalizeSpace(sort));
log.warn(" searchAfter: " + String.valueOf(this.getSearchAfter()));
throw new NothingFoundException();
}
Expand Down
Loading