Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Force the server responses to be treated as UTF-8

  • Loading branch information...
commit 6f9d22b8ac512c62e68671f819ae635f9df4e5f8 1 parent 35be1a7
Ian authored
10 pom.xml
@@ -88,6 +88,11 @@
88 88 <type>jar</type>
89 89 <scope>compile</scope>
90 90 </dependency>
  91 + <dependency>
  92 + <groupId>commons-io</groupId>
  93 + <artifactId>commons-io</artifactId>
  94 + <version>2.1</version>
  95 + </dependency>
91 96 <dependency>
92 97 <groupId>commons-httpclient</groupId>
93 98 <artifactId>commons-httpclient</artifactId>
@@ -148,5 +153,10 @@
148 153 <artifactId>mysql-connector-java</artifactId>
149 154 <version>5.1.13</version>
150 155 </dependency>
  156 + <dependency>
  157 + <groupId>junit</groupId>
  158 + <artifactId>junit</artifactId>
  159 + <version>4.10</version>
  160 + </dependency>
151 161 </dependencies>
152 162 </project>
9 src/main/java/uk/co/tfd/symplectic/harvester/ConcurrentHttpFetch.java
... ... @@ -1,11 +1,13 @@
1 1 package uk.co.tfd.symplectic.harvester;
2 2
3 3 import java.io.IOException;
  4 +import java.io.InputStream;
4 5 import java.net.MalformedURLException;
5 6
6 7 import org.apache.commons.httpclient.HttpClient;
7 8 import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager;
8 9 import org.apache.commons.httpclient.methods.GetMethod;
  10 +import org.apache.commons.io.IOUtils;
9 11
10 12 /**
11 13 * @author ieb
@@ -21,6 +23,11 @@ public static String get(String url) throws MalformedURLException, IOException {
21 23 GetMethod getMethod = new GetMethod(url);
22 24 getMethod.setFollowRedirects(true);
23 25 client.executeMethod(getMethod);
24   - return getMethod.getResponseBodyAsString();
  26 + InputStream in = getMethod.getResponseBodyAsStream();
  27 + // Force the input stream to be UTF-8. This is wrong, but if the Elements server is misconfigured
  28 + // With no charset defined then its the only way of getting UTF-8 data
  29 + String content = IOUtils.toString(in, "UTF-8");
  30 + in.close();
  31 + return content;
25 32 }
26 33 }

0 comments on commit 6f9d22b

Please sign in to comment.
Something went wrong with that request. Please try again.