Skip to content

Commit

Permalink
to be more consistent, log the Exception and move on
Browse files Browse the repository at this point in the history
  • Loading branch information
nitram509 committed Jun 29, 2015
1 parent 0569d0a commit e4bb419
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
import io.searchbox.action.GenericResultAbstractAction;

import java.io.*;
import java.net.URLEncoder;
import java.nio.charset.Charset;

import static io.searchbox.indices.script.ScriptLanguage.GROOVY;
import static java.net.URLEncoder.encode;

public class CreateIndexedScript extends GenericResultAbstractAction {

Expand All @@ -26,11 +26,15 @@ protected CreateIndexedScript(Builder builder) {
}

protected String buildURI() {
String finalUri = super.buildURI() + "/_scripts/" + scriptLanguage.pathParameterName + "/";
try {
return super.buildURI() + "/_scripts/" + scriptLanguage.pathParameterName + "/" + URLEncoder.encode(scriptName, CHARSET);
finalUri += encode(scriptName, CHARSET);
} catch (UnsupportedEncodingException e) {
throw new RuntimeException(e);
// unless CHARSET is overridden with a wrong value in a subclass,
// this exception won't be thrown.
log.error("Error occurred while adding parameters to uri.", e);
}
return finalUri;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
import io.searchbox.action.GenericResultAbstractAction;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;

import static io.searchbox.indices.script.ScriptLanguage.GROOVY;
import static java.net.URLEncoder.encode;

public class DeleteIndexedScript extends GenericResultAbstractAction {

Expand All @@ -21,11 +21,15 @@ protected DeleteIndexedScript(Builder builder) {
}

protected String buildURI() {
String finalUri = super.buildURI() + "/_scripts/" + scriptLanguage.pathParameterName + "/";
try {
return super.buildURI() + "/_scripts/" + scriptLanguage.pathParameterName + "/" + URLEncoder.encode(scriptName, CHARSET);
finalUri += encode(scriptName, CHARSET);
} catch (UnsupportedEncodingException e) {
throw new RuntimeException(e);
// unless CHARSET is overridden with a wrong value in a subclass,
// this exception won't be thrown.
log.error("Error occurred while adding parameters to uri.", e);
}
return finalUri;
}

@Override
Expand Down

0 comments on commit e4bb419

Please sign in to comment.