Skip to content

Commit

Permalink
AgsClient fixed to properly encode spaces in URL's.
Browse files Browse the repository at this point in the history
  • Loading branch information
pandzel committed Dec 11, 2020
1 parent d4fb2db commit 5fef814
Showing 1 changed file with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,13 @@
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.net.InetAddress;
import java.net.MalformedURLException;
import java.net.URISyntaxException;
import java.net.URL;
import java.net.URLEncoder;
import java.util.HashMap;
import java.util.stream.Collectors;
import org.apache.commons.codec.net.URLCodec;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.http.HttpEntity;
Expand All @@ -44,6 +45,7 @@
* ArcGIS Server client.
*/
public class AgsClient implements Closeable {
private static final URLCodec URL_CODEC = new URLCodec("UTF-8");

private final URL rootUrl;
private final CloseableHttpClient httpClient;
Expand Down Expand Up @@ -135,7 +137,11 @@ public ContentResponse listContent(String folder) throws URISyntaxException, IOE
* @throws IOException if accessing token fails
*/
public ServerResponse readServiceInformation(String folder, ServiceInfo si) throws URISyntaxException, IOException {
String url = rootUrl.toURI().resolve("rest/services/").resolve(StringUtils.stripToEmpty(folder)).resolve(si.name + "/" + si.type).toASCIIString();
String url = rootUrl.toURI()
.resolve("rest/services/")
.resolve(URLEncoder.encode(StringUtils.stripToEmpty(folder), "UTF-8").replaceAll("\\+", "%20"))
.resolve(URLEncoder.encode(si.name, "UTF-8").replaceAll("\\+", "%20") + "/" + si.type)
.toASCIIString();
return readServiceInformation(new URL(url));
}

Expand Down

1 comment on commit 5fef814

@pandzel-zz
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed #133

Please sign in to comment.