From 8d630a595fd773c88b6d90351785a89ea12a35df Mon Sep 17 00:00:00 2001 From: gmantele <gmantele@ari.uni-heidelberg.de> Date: Thu, 2 Apr 2015 18:48:23 +0200 Subject: [PATCH] [UWS,TAP] Set UTF-8 as default character encoding for all HTTP response. --- src/tap/ADQLExecutor.java | 4 ++++ src/tap/error/DefaultTAPErrorWriter.java | 4 ++++ src/tap/metadata/TAPMetadata.java | 1 + src/tap/resource/Availability.java | 8 ++++++-- src/tap/resource/Capabilities.java | 6 +++++- src/tap/resource/HomePage.java | 7 +++++-- src/tap/resource/TAP.java | 3 +++ src/uws/UWSToolBox.java | 10 +++++++++- src/uws/service/UWSService.java | 4 ++++ src/uws/service/UWSServlet.java | 11 +++++++++++ src/uws/service/actions/AddJob.java | 4 ++-- src/uws/service/actions/DestroyJob.java | 4 ++-- src/uws/service/actions/GetJobParam.java | 9 +++++++-- src/uws/service/actions/JobSummary.java | 6 ++++-- src/uws/service/actions/ListJobs.java | 6 ++++-- src/uws/service/actions/SetJobParam.java | 4 ++-- src/uws/service/actions/SetUWSParameter.java | 4 ++-- src/uws/service/actions/ShowHomePage.java | 3 +++ src/uws/service/error/DefaultUWSErrorWriter.java | 6 ++++++ 19 files changed, 84 insertions(+), 20 deletions(-) diff --git a/src/tap/ADQLExecutor.java b/src/tap/ADQLExecutor.java index fd65069..a0ffd3e 100644 --- a/src/tap/ADQLExecutor.java +++ b/src/tap/ADQLExecutor.java @@ -37,6 +37,7 @@ import tap.parameters.DALIUpload; import tap.parameters.TAPParameters; import tap.upload.Uploader; import uws.UWSException; +import uws.UWSToolBox; import uws.job.JobThread; import uws.job.Result; import uws.service.log.UWSLog.LogLevel; @@ -610,6 +611,9 @@ public class ADQLExecutor { // Set the HTTP content type to the MIME type of the result format: response.setContentType(formatter.getMimeType()); + // Set the character encoding: + response.setCharacterEncoding(UWSToolBox.DEFAULT_CHAR_ENCODING); + // Write the formatted result in the HTTP response output: start = System.currentTimeMillis(); writeResult(queryResult, formatter, response.getOutputStream()); diff --git a/src/tap/error/DefaultTAPErrorWriter.java b/src/tap/error/DefaultTAPErrorWriter.java index 22a542c..6b390cb 100644 --- a/src/tap/error/DefaultTAPErrorWriter.java +++ b/src/tap/error/DefaultTAPErrorWriter.java @@ -41,6 +41,7 @@ import tap.formatter.VOTableFormat; import tap.log.DefaultTAPLog; import tap.log.TAPLog; import uws.UWSException; +import uws.UWSToolBox; import uws.job.ErrorSummary; import uws.job.ErrorType; import uws.job.UWSJob; @@ -193,6 +194,9 @@ public class DefaultTAPErrorWriter implements ServiceErrorWriter { // Set the MIME type of the answer (XML for a VOTable document): response.setContentType("application/xml"); + // Set the character encoding: + response.setCharacterEncoding(UWSToolBox.DEFAULT_CHAR_ENCODING); + }catch(IllegalStateException ise){ /* If it is not possible any more to reset the response header and body, * the error is anyway written in order to corrupt the HTTP response. diff --git a/src/tap/metadata/TAPMetadata.java b/src/tap/metadata/TAPMetadata.java index 77dd732..11cad6c 100644 --- a/src/tap/metadata/TAPMetadata.java +++ b/src/tap/metadata/TAPMetadata.java @@ -456,6 +456,7 @@ public class TAPMetadata implements Iterable<TAPSchema>, VOSIResource, TAPResour @Override public boolean executeResource(HttpServletRequest request, HttpServletResponse response) throws IOException{ response.setContentType("application/xml"); + response.setCharacterEncoding(UWSToolBox.DEFAULT_CHAR_ENCODING); PrintWriter writer = response.getWriter(); write(writer); diff --git a/src/tap/resource/Availability.java b/src/tap/resource/Availability.java index 003db0a..aede393 100644 --- a/src/tap/resource/Availability.java +++ b/src/tap/resource/Availability.java @@ -16,7 +16,7 @@ package tap.resource; * You should have received a copy of the GNU Lesser General Public License * along with TAPLibrary. If not, see <http://www.gnu.org/licenses/>. * - * Copyright 2012,2014 - UDS/Centre de Données astronomiques de Strasbourg (CDS), + * Copyright 2012-2015 - UDS/Centre de Données astronomiques de Strasbourg (CDS), * Astronomisches Rechen Institut (ARI) */ @@ -31,12 +31,13 @@ import javax.servlet.http.HttpServletResponse; import tap.ServiceConnection; import tap.TAPException; import uk.ac.starlink.votable.VOSerializer; +import uws.UWSToolBox; /** * <p>TAP resource describing the availability of a TAP service.</p> * * @author Grégory Mantelet (CDS;ARI) - * @version 2.0 (09/2014) + * @version 2.0 (04/2015) */ public class Availability implements TAPResource, VOSIResource { @@ -109,6 +110,9 @@ public class Availability implements TAPResource, VOSIResource { // Set the response MIME type (XML): response.setContentType("text/xml"); + // Set the character encoding: + response.setCharacterEncoding(UWSToolBox.DEFAULT_CHAR_ENCODING); + // Get the output stream: PrintWriter pw = response.getWriter(); diff --git a/src/tap/resource/Capabilities.java b/src/tap/resource/Capabilities.java index 4afdcca..e8b2aa7 100644 --- a/src/tap/resource/Capabilities.java +++ b/src/tap/resource/Capabilities.java @@ -31,6 +31,7 @@ import javax.servlet.http.HttpServletResponse; import tap.TAPException; import uk.ac.starlink.votable.VOSerializer; +import uws.UWSToolBox; /** * <p>TAP resource describing the capabilities of a TAP service.</p> @@ -38,7 +39,7 @@ import uk.ac.starlink.votable.VOSerializer; * <p>This resource just return an XML document giving a description of the TAP service and list all its VOSI resources.</p> * * @author Grégory Mantelet (CDS;ARI) - * @version 2.0 (02/2015) + * @version 2.0 (04/2015) */ public class Capabilities implements TAPResource, VOSIResource { @@ -112,6 +113,9 @@ public class Capabilities implements TAPResource, VOSIResource { // Set the response MIME type (XML): response.setContentType("application/xml"); + // Set the character encoding: + response.setCharacterEncoding(UWSToolBox.DEFAULT_CHAR_ENCODING); + // Get the response stream: PrintWriter out = response.getWriter(); diff --git a/src/tap/resource/HomePage.java b/src/tap/resource/HomePage.java index 280ab99..b0f5551 100644 --- a/src/tap/resource/HomePage.java +++ b/src/tap/resource/HomePage.java @@ -120,8 +120,8 @@ public class HomePage implements TAPResource { // Set the content type: response.setContentType(tap.homePageMimeType); - // set character encoding: - response.setCharacterEncoding("UTF-8"); + // Set the character encoding: + response.setCharacterEncoding(UWSToolBox.DEFAULT_CHAR_ENCODING); // Get the character writer: PrintWriter writer = response.getWriter(); @@ -216,6 +216,9 @@ public class HomePage implements TAPResource { // Set the content type: HTML document response.setContentType("text/html"); + // Set the character encoding: + response.setCharacterEncoding(UWSToolBox.DEFAULT_CHAR_ENCODING); + // Write the home page: writer.println("<html><head><title>TAP HOME PAGE</title></head><body><h1 style=\"text-align: center\">TAP HOME PAGE</h1><h2>Available resources:</h2><ul>"); for(TAPResource res : tap.resources.values()) diff --git a/src/tap/resource/TAP.java b/src/tap/resource/TAP.java index 57f1518..b8a399b 100644 --- a/src/tap/resource/TAP.java +++ b/src/tap/resource/TAP.java @@ -825,6 +825,9 @@ public class TAP implements VOSIResource { throw new TAPException(ue); } + // Set the character encoding: + response.setCharacterEncoding(UWSToolBox.DEFAULT_CHAR_ENCODING); + // Display the TAP Home Page: if (resourceName.length() == 0){ resourceName = homePage.getName(); diff --git a/src/uws/UWSToolBox.java b/src/uws/UWSToolBox.java index 2658240..b582178 100644 --- a/src/uws/UWSToolBox.java +++ b/src/uws/UWSToolBox.java @@ -54,10 +54,15 @@ import uws.service.request.UploadFile; * Some useful functions for the managing of a UWS service. * * @author Grégory Mantelet (CDS;ARI) - * @version 4.1 (03/2015) + * @version 4.1 (04/2015) */ public class UWSToolBox { + /** + * Default character encoding for all HTTP response sent by this library. + * @since 4.1 */ + public final static String DEFAULT_CHAR_ENCODING = "UTF-8"; + private static UWSLog defaultLogger = null; /** <b>THIS CLASS CAN'T BE INSTANTIATED !</b> */ @@ -504,6 +509,9 @@ public class UWSToolBox { if (mimeType != null) response.setContentType(mimeType); + // Set the character encoding: + response.setCharacterEncoding(UWSToolBox.DEFAULT_CHAR_ENCODING); + // Set the HTTP content length: if (contentSize > 0) response.setContentLength((int)contentSize); diff --git a/src/uws/service/UWSService.java b/src/uws/service/UWSService.java index 4283ff5..c0e65dc 100644 --- a/src/uws/service/UWSService.java +++ b/src/uws/service/UWSService.java @@ -1128,6 +1128,9 @@ public class UWSService implements UWS { // Identify the user: user = UWSToolBox.getUser(request, userIdentifier); + // Set the character encoding: + response.setCharacterEncoding(UWSToolBox.DEFAULT_CHAR_ENCODING); + // Apply the appropriate UWS action: for(int i = 0; action == null && i < uwsActions.size(); i++){ if (uwsActions.get(i).match(urlInterpreter, user, request)){ @@ -1217,6 +1220,7 @@ public class UWSService implements UWS { public void redirect(String url, HttpServletRequest request, JobOwner user, String uwsAction, HttpServletResponse response) throws IOException, UWSException{ response.setStatus(HttpServletResponse.SC_SEE_OTHER); response.setContentType(request.getContentType()); + response.setCharacterEncoding(UWSToolBox.DEFAULT_CHAR_ENCODING); response.setHeader("Location", url); response.flushBuffer(); } diff --git a/src/uws/service/UWSServlet.java b/src/uws/service/UWSServlet.java index 9a47f3a..1f62ca7 100644 --- a/src/uws/service/UWSServlet.java +++ b/src/uws/service/UWSServlet.java @@ -342,6 +342,9 @@ public abstract class UWSServlet extends HttpServlet implements UWS, UWSFactory // Identify the user: user = UWSToolBox.getUser(req, userIdentifier); + // Set the character encoding: + resp.setCharacterEncoding(UWSToolBox.DEFAULT_CHAR_ENCODING); + // METHOD GET: if (method.equals("GET")){ // HOME PAGE: @@ -489,6 +492,7 @@ public abstract class UWSServlet extends HttpServlet implements UWS, UWSFactory protected void writeHomePage(UWSUrl requestUrl, HttpServletRequest req, HttpServletResponse resp, JobOwner user) throws UWSException, ServletException, IOException{ UWSSerializer serializer = getSerializer(req.getHeader("Accept")); resp.setContentType(serializer.getMimeType()); + resp.setCharacterEncoding(UWSToolBox.DEFAULT_CHAR_ENCODING); String serialization; try{ serialization = serializer.getUWS(this); @@ -514,6 +518,7 @@ public abstract class UWSServlet extends HttpServlet implements UWS, UWSFactory // Write the jobs list: UWSSerializer serializer = getSerializer(req.getHeader("Accept")); resp.setContentType(serializer.getMimeType()); + resp.setCharacterEncoding(UWSToolBox.DEFAULT_CHAR_ENCODING); try{ jobsList.serialize(resp.getOutputStream(), serializer, user); }catch(Exception e){ @@ -585,6 +590,7 @@ public abstract class UWSServlet extends HttpServlet implements UWS, UWSFactory // Write the job summary: UWSSerializer serializer = getSerializer(req.getHeader("Accept")); resp.setContentType(serializer.getMimeType()); + resp.setCharacterEncoding(UWSToolBox.DEFAULT_CHAR_ENCODING); try{ job.serialize(resp.getOutputStream(), serializer, user); }catch(Exception e){ @@ -664,11 +670,15 @@ public abstract class UWSServlet extends HttpServlet implements UWS, UWSFactory UWSSerializer serializer = getSerializer(req.getHeader("Accept")); String uwsField = attributes[0]; boolean jobSerialization = false; + // Set the content type: if (uwsField == null || uwsField.trim().isEmpty() || (attributes.length <= 1 && (uwsField.equalsIgnoreCase(UWSJob.PARAM_ERROR_SUMMARY) || uwsField.equalsIgnoreCase(UWSJob.PARAM_RESULTS) || uwsField.equalsIgnoreCase(UWSJob.PARAM_PARAMETERS)))){ resp.setContentType(serializer.getMimeType()); jobSerialization = true; }else resp.setContentType("text/plain"); + // Set the character encoding: + resp.setCharacterEncoding(UWSToolBox.DEFAULT_CHAR_ENCODING); + // Serialize the selected attribute: try{ job.serialize(resp.getOutputStream(), attributes, serializer); }catch(Exception e){ @@ -766,6 +776,7 @@ public abstract class UWSServlet extends HttpServlet implements UWS, UWSFactory public void redirect(String url, HttpServletRequest request, JobOwner user, String uwsAction, HttpServletResponse response) throws ServletException, IOException{ response.setStatus(HttpServletResponse.SC_SEE_OTHER); response.setContentType(request.getContentType()); + response.setCharacterEncoding(UWSToolBox.DEFAULT_CHAR_ENCODING); response.setHeader("Location", url); response.flushBuffer(); } diff --git a/src/uws/service/actions/AddJob.java b/src/uws/service/actions/AddJob.java index 5dd182b..2d5853e 100644 --- a/src/uws/service/actions/AddJob.java +++ b/src/uws/service/actions/AddJob.java @@ -16,7 +16,7 @@ package uws.service.actions; * You should have received a copy of the GNU Lesser General Public License * along with UWSLibrary. If not, see <http://www.gnu.org/licenses/>. * - * Copyright 2012,2014 - UDS/Centre de Données astronomiques de Strasbourg (CDS), + * Copyright 2012-2015 - UDS/Centre de Données astronomiques de Strasbourg (CDS), * Astronomisches Rechen Institut (ARI) */ @@ -43,7 +43,7 @@ import uws.service.log.UWSLog.LogLevel; * The response of this action is a redirection to the new job resource (that is to say: a redirection to the job summary of the new job).</p> * * @author Grégory Mantelet (CDS;ARI) - * @version 4.1 (08/2014) + * @version 4.1 (04/2015) */ public class AddJob extends UWSAction { private static final long serialVersionUID = 1L; diff --git a/src/uws/service/actions/DestroyJob.java b/src/uws/service/actions/DestroyJob.java index 2aeb76a..de75e20 100644 --- a/src/uws/service/actions/DestroyJob.java +++ b/src/uws/service/actions/DestroyJob.java @@ -16,7 +16,7 @@ package uws.service.actions; * You should have received a copy of the GNU Lesser General Public License * along with UWSLibrary. If not, see <http://www.gnu.org/licenses/>. * - * Copyright 2012,2014 - UDS/Centre de Données astronomiques de Strasbourg (CDS), + * Copyright 2012-2015 - UDS/Centre de Données astronomiques de Strasbourg (CDS), * Astronomisches Rechen Institut (ARI) */ @@ -43,7 +43,7 @@ import uws.service.log.UWSLog.LogLevel; * The response of this action is a redirection to the jobs list.</p> * * @author Grégory Mantelet (CDS;ARI) - * @version 4.1 (11/2014) + * @version 4.1 (04/2015) */ public class DestroyJob extends UWSAction { private static final long serialVersionUID = 1L; diff --git a/src/uws/service/actions/GetJobParam.java b/src/uws/service/actions/GetJobParam.java index c829887..37b23ba 100644 --- a/src/uws/service/actions/GetJobParam.java +++ b/src/uws/service/actions/GetJobParam.java @@ -16,7 +16,7 @@ package uws.service.actions; * You should have received a copy of the GNU Lesser General Public License * along with UWSLibrary. If not, see <http://www.gnu.org/licenses/>. * - * Copyright 2012,2014 - UDS/Centre de Données astronomiques de Strasbourg (CDS), + * Copyright 2012-2015 - UDS/Centre de Données astronomiques de Strasbourg (CDS), * Astronomisches Rechen Institut (ARI) */ @@ -50,7 +50,7 @@ import uws.service.request.UploadFile; * The serializer is choosen in function of the HTTP Accept header.</p> * * @author Grégory Mantelet (CDS;ARI) - * @version 4.1 (09/2014) + * @version 4.1 (04/2015) */ public class GetJobParam extends UWSAction { private static final long serialVersionUID = 1L; @@ -171,11 +171,16 @@ public class GetJobParam extends UWSAction { UWSSerializer serializer = uws.getSerializer(request.getHeader("Accept")); String uwsField = attributes[0]; boolean jobSerialization = false; + // Set the content type: if (uwsField == null || uwsField.trim().isEmpty() || (attributes.length <= 1 && (uwsField.equalsIgnoreCase(UWSJob.PARAM_ERROR_SUMMARY) || uwsField.equalsIgnoreCase(UWSJob.PARAM_RESULTS) || uwsField.equalsIgnoreCase(UWSJob.PARAM_PARAMETERS)))){ response.setContentType(serializer.getMimeType()); jobSerialization = true; }else response.setContentType("text/plain"); + + // Set the character encoding: + response.setCharacterEncoding(UWSToolBox.DEFAULT_CHAR_ENCODING); + // Serialize the selected attribute: try{ job.serialize(response.getOutputStream(), attributes, serializer); }catch(Exception e){ diff --git a/src/uws/service/actions/JobSummary.java b/src/uws/service/actions/JobSummary.java index d645259..e6cdee2 100644 --- a/src/uws/service/actions/JobSummary.java +++ b/src/uws/service/actions/JobSummary.java @@ -16,7 +16,7 @@ package uws.service.actions; * You should have received a copy of the GNU Lesser General Public License * along with UWSLibrary. If not, see <http://www.gnu.org/licenses/>. * - * Copyright 2012,2014 - UDS/Centre de Données astronomiques de Strasbourg (CDS), + * Copyright 2012-2015 - UDS/Centre de Données astronomiques de Strasbourg (CDS), * Astronomisches Rechen Institut (ARI) */ @@ -27,6 +27,7 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import uws.UWSException; +import uws.UWSToolBox; import uws.job.UWSJob; import uws.job.serializer.UWSSerializer; import uws.job.user.JobOwner; @@ -43,7 +44,7 @@ import uws.service.log.UWSLog.LogLevel; * This summary is serialized by the {@link UWSSerializer} choosed in function of the HTTP Accept header.</p> * * @author Grégory Mantelet (CDS;ARI) - * @version 4.1 (08/2014) + * @version 4.1 (04/2015) */ public class JobSummary extends UWSAction { private static final long serialVersionUID = 1L; @@ -100,6 +101,7 @@ public class JobSummary extends UWSAction { // Write the job summary: UWSSerializer serializer = uws.getSerializer(request.getHeader("Accept")); response.setContentType(serializer.getMimeType()); + response.setCharacterEncoding(UWSToolBox.DEFAULT_CHAR_ENCODING); try{ job.serialize(response.getOutputStream(), serializer, user); }catch(Exception e){ diff --git a/src/uws/service/actions/ListJobs.java b/src/uws/service/actions/ListJobs.java index 18be064..83a7a71 100644 --- a/src/uws/service/actions/ListJobs.java +++ b/src/uws/service/actions/ListJobs.java @@ -16,7 +16,7 @@ package uws.service.actions; * You should have received a copy of the GNU Lesser General Public License * along with UWSLibrary. If not, see <http://www.gnu.org/licenses/>. * - * Copyright 2012,2014 - UDS/Centre de Données astronomiques de Strasbourg (CDS), + * Copyright 2012-2015 - UDS/Centre de Données astronomiques de Strasbourg (CDS), * Astronomisches Rechen Institut (ARI) */ @@ -27,6 +27,7 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import uws.UWSException; +import uws.UWSToolBox; import uws.job.JobList; import uws.job.serializer.UWSSerializer; import uws.job.user.JobOwner; @@ -43,7 +44,7 @@ import uws.service.log.UWSLog.LogLevel; * This list is serialized by the {@link UWSSerializer} choosed in function of the HTTP Accept header.</p> * * @author Grégory Mantelet (CDS;ARI) - * @version 4.1 (08/2014) + * @version 4.1 (04/2015) */ public class ListJobs extends UWSAction { private static final long serialVersionUID = 1L; @@ -99,6 +100,7 @@ public class ListJobs extends UWSAction { // Write the jobs list: UWSSerializer serializer = uws.getSerializer(request.getHeader("Accept")); response.setContentType(serializer.getMimeType()); + response.setCharacterEncoding(UWSToolBox.DEFAULT_CHAR_ENCODING); try{ jobsList.serialize(response.getOutputStream(), serializer, user); }catch(Exception e){ diff --git a/src/uws/service/actions/SetJobParam.java b/src/uws/service/actions/SetJobParam.java index d9f1882..df67887 100644 --- a/src/uws/service/actions/SetJobParam.java +++ b/src/uws/service/actions/SetJobParam.java @@ -16,7 +16,7 @@ package uws.service.actions; * You should have received a copy of the GNU Lesser General Public License * along with UWSLibrary. If not, see <http://www.gnu.org/licenses/>. * - * Copyright 2012,2014 - UDS/Centre de Données astronomiques de Strasbourg (CDS), + * Copyright 2012-2015 - UDS/Centre de Données astronomiques de Strasbourg (CDS), * Astronomisches Rechen Institut (ARI) */ @@ -43,7 +43,7 @@ import uws.service.log.UWSLog.LogLevel; * The response of this action is a redirection to the job summary.</p> * * @author Grégory Mantelet (CDS;ARI) - * @version 4.1 (09/2014) + * @version 4.1 (04/2015) */ public class SetJobParam extends UWSAction { private static final long serialVersionUID = 1L; diff --git a/src/uws/service/actions/SetUWSParameter.java b/src/uws/service/actions/SetUWSParameter.java index dab912f..832823a 100644 --- a/src/uws/service/actions/SetUWSParameter.java +++ b/src/uws/service/actions/SetUWSParameter.java @@ -16,7 +16,7 @@ package uws.service.actions; * You should have received a copy of the GNU Lesser General Public License * along with UWSLibrary. If not, see <http://www.gnu.org/licenses/>. * - * Copyright 2014 - Astronomisches Rechen Institut (ARI) + * Copyright 2014-2015 - Astronomisches Rechen Institut (ARI) */ import java.io.IOException; @@ -40,7 +40,7 @@ import uws.service.UWSUrl; * <p><i><u>Note:</u> The corresponding name is {@link UWSAction#SET_UWS_PARAMETER}.</i></p> * * @author Grégory Mantelet (ARI) - * @version 4.1 (11/2014) + * @version 4.1 (04/2015) * @since 4.1 */ public class SetUWSParameter extends UWSAction { diff --git a/src/uws/service/actions/ShowHomePage.java b/src/uws/service/actions/ShowHomePage.java index 7d4205d..bba81eb 100644 --- a/src/uws/service/actions/ShowHomePage.java +++ b/src/uws/service/actions/ShowHomePage.java @@ -30,6 +30,7 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import uws.UWSException; +import uws.UWSToolBox; import uws.job.serializer.UWSSerializer; import uws.job.user.JobOwner; import uws.service.UWSService; @@ -100,6 +101,7 @@ public class ShowHomePage extends UWSAction { if (uws.isDefaultHomePage()){ UWSSerializer serializer = uws.getSerializer(request.getHeader("Accept")); response.setContentType(serializer.getMimeType()); + response.setCharacterEncoding(UWSToolBox.DEFAULT_CHAR_ENCODING); // Get a short and simple serialization of this UWS: String serialization; try{ @@ -127,6 +129,7 @@ public class ShowHomePage extends UWSAction { BufferedReader reader = new BufferedReader(new InputStreamReader(homePageUrl.openStream())); response.setContentType("text/html"); + response.setCharacterEncoding(UWSToolBox.DEFAULT_CHAR_ENCODING); PrintWriter writer = response.getWriter(); try{ String line = null; diff --git a/src/uws/service/error/DefaultUWSErrorWriter.java b/src/uws/service/error/DefaultUWSErrorWriter.java index 9019613..345d1c2 100644 --- a/src/uws/service/error/DefaultUWSErrorWriter.java +++ b/src/uws/service/error/DefaultUWSErrorWriter.java @@ -212,6 +212,9 @@ public class DefaultUWSErrorWriter implements ServiceErrorWriter { // Set the MIME type of the answer (XML for a VOTable document): response.setContentType(UWSSerializer.MIME_TYPE_HTML); + // Set the character encoding: + response.setCharacterEncoding(UWSToolBox.DEFAULT_CHAR_ENCODING); + }catch(IllegalStateException ise){ /* If it is not possible any more to reset the response header and body, * the error is anyway written in order to corrupt the HTTP response. @@ -292,6 +295,9 @@ public class DefaultUWSErrorWriter implements ServiceErrorWriter { // Set the MIME type of the answer (JSON): response.setContentType(UWSSerializer.MIME_TYPE_JSON); + // Set the character encoding: + response.setCharacterEncoding(UWSToolBox.DEFAULT_CHAR_ENCODING); + }catch(IllegalStateException ise){ /* If it is not possible any more to reset the response header and body, * the error is anyway written in order to corrupt the HTTP response. -- GitLab