From: Ben Soares Date: Mon, 13 Sep 2021 19:58:28 +0000 (+0100) Subject: JAL-2422 Fixed URL encoding of REST calls (broken paths in Windows due to colon) X-Git-Tag: Release_2_11_2_0~37^2~4 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=882a6c7044693a72c20f336f26e87a5fcf30fe5b;p=jalview.git JAL-2422 Fixed URL encoding of REST calls (broken paths in Windows due to colon) --- diff --git a/src/ext/edu/ucsf/rbvi/strucviz2/ChimeraManager.java b/src/ext/edu/ucsf/rbvi/strucviz2/ChimeraManager.java index d7e7937..812bfea 100644 --- a/src/ext/edu/ucsf/rbvi/strucviz2/ChimeraManager.java +++ b/src/ext/edu/ucsf/rbvi/strucviz2/ChimeraManager.java @@ -38,6 +38,9 @@ import java.io.File; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; +import java.io.UnsupportedEncodingException; +import java.net.URLEncoder; +import java.nio.charset.StandardCharsets; import java.nio.file.Paths; import java.util.ArrayList; import java.util.Collection; @@ -363,7 +366,7 @@ public class ChimeraManager * Select something in Chimera * * @param command - * the selection command to pass to Chimera + * the selection command to pass to Chimera */ public void select(String command) { @@ -509,8 +512,8 @@ public class ChimeraManager /** * Return the list of depiction presets available from within Chimera. Chimera - * will return the list as a series of lines with the format: Preset type - * number "description" + * will return the list as a series of lines with the format: Preset type number + * "description" * * @return list of presets */ @@ -551,9 +554,9 @@ public class ChimeraManager } /** - * Launch Chimera, unless an instance linked to this object is already - * running. Returns true if chimera is successfully launched, or already - * running, else false. + * Launch Chimera, unless an instance linked to this object is already running. + * Returns true if chimera is successfully launched, or already running, else + * false. * * @param chimeraPaths * @return @@ -696,7 +699,7 @@ public class ChimeraManager * Determine the color that Chimera is using for this model. * * @param model - * the ChimeraModel we want to get the Color for + * the ChimeraModel we want to get the Color for * @return the default model Color for this model in Chimera */ public Color getModelColor(ChimeraModel model) @@ -713,11 +716,11 @@ public class ChimeraManager /** * * Get information about the residues associated with a model. This uses the - * Chimera listr command. We don't return the resulting residues, but we add - * the residues to the model. + * Chimera listr command. We don't return the resulting residues, but we add the + * residues to the model. * * @param model - * the ChimeraModel to get residue information for + * the ChimeraModel to get residue information for * */ public void addResidues(ChimeraModel model) @@ -809,10 +812,10 @@ public class ChimeraManager * Send a command to Chimera. * * @param command - * Command string to be send. + * Command string to be send. * @param reply - * Flag indicating whether the method should return the reply from - * Chimera or not. + * Flag indicating whether the method should return the reply + * from Chimera or not. * @return List of Strings corresponding to the lines in the Chimera reply or * null. */ @@ -833,7 +836,7 @@ public class ChimeraManager */ int waited = 0; int pause = 25; - while (busy && waited < 1001) + while (busy && waited < 1001) { try { @@ -876,8 +879,16 @@ public class ChimeraManager String method = getHttpRequestMethod(); if ("GET".equals(method)) { - command = command.replace(" ", "+").replace("#", "%23") - .replace("|", "%7C").replace(";", "%3B"); + try + { + command = URLEncoder.encode(command, + StandardCharsets.UTF_8.toString()); + } catch (UnsupportedEncodingException e) + { + command = command.replace(" ", "+").replace("#", "%23") + .replace("|", "%7C").replace(";", "%3B") + .replace(":", "%3A"); + } } commands.add(new BasicNameValuePair("command", command));