Skip to content
This repository has been archived by the owner on Feb 22, 2024. It is now read-only.

Commit

Permalink
fix encoding parsing in transformer client
Browse files Browse the repository at this point in the history
  • Loading branch information
andreybratus committed Sep 26, 2016
1 parent d0728d9 commit 9e12f2e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
package eu.spaziodati.batchrefine.transformer;

import com.google.refine.util.ParsingUtilities;


import eu.fusepool.p3.accept.util.AcceptPreference;
import eu.fusepool.p3.transformer.HttpRequestEntity;
import eu.fusepool.p3.transformer.Transformer;
import eu.fusepool.p3.transformer.commons.Entity;

import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.tuple.ImmutablePair;
import org.apache.http.HttpEntity;
Expand All @@ -18,13 +15,13 @@
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.log4j.Logger;
import org.eclipse.jetty.http.MimeTypes;
import org.json.JSONArray;
import org.json.JSONObject;

import javax.activation.MimeType;
import javax.activation.MimeTypeParseException;
import javax.servlet.http.HttpServletRequest;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
Expand Down Expand Up @@ -115,7 +112,11 @@ protected JSONArray fetchTransform(HttpRequestEntity request)
+ transformURI + ".");
}

String encoding = request.getRequest().getCharacterEncoding();
String encoding = null;
if (responseEntity.getContentType() != null) {
encoding = MimeTypes.getCharsetFromContentType(responseEntity.getContentType().getValue());
}

String transform = IOUtils.toString(responseEntity.getContent(),
encoding == null ? "UTF-8" : encoding);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import eu.fusepool.p3.transformer.Transformer;
import eu.fusepool.p3.transformer.server.TransformerServer;
import eu.spaziodati.batchrefine.java.EngineTest;
import org.eclipse.jetty.http.MimeTypes;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.handler.DefaultHandler;
import org.eclipse.jetty.server.handler.HandlerList;
Expand Down Expand Up @@ -52,6 +53,9 @@ private int startTransformServer() throws Exception {
Server fileServer = new Server(port);

ResourceHandler handler = new ResourceHandler();
MimeTypes mimeTypes = handler.getMimeTypes();
mimeTypes.addMimeMapping("json", "application/json; charset=UTF-8");

handler.setDirectoriesListed(true);
handler.setBaseResource(JarResource.newResource(transforms));

Expand Down

0 comments on commit 9e12f2e

Please sign in to comment.