Project

General

Profile

« Previous | Next » 

Revision 5752

use detected XML encoding when reading/writing files
use UTF-8 as default when performing queries in the DB (assume DB is using UTF-8)
remove as many PrintWriters (uses system default character encoding only) as possible and construct OutputStreamWriters where explicit encoding can be given.
http://bugzilla.ecoinformatics.org/show_bug.cgi?id=2495

View differences:

MetaCatServlet.java
27 27
package edu.ucsb.nceas.metacat;
28 28

  
29 29
import java.io.IOException;
30
import java.io.OutputStreamWriter;
30 31
import java.io.PrintWriter;
32
import java.io.Writer;
31 33
import java.sql.PreparedStatement;
32 34
import java.sql.ResultSet;
33 35
import java.sql.SQLException;
......
263 265
    private static final String TRUE  = "true";
264 266
    private static String LOG_CONFIG_NAME = null;
265 267
    public static final String APPLICATION_NAME = "metacat";
268
	public static final String DEFAULT_ENCODING = "UTF-8";
266 269
    
267 270
    /**
268 271
     * Initialize the servlet by creating appropriate database connections
......
631 634
			HttpServletResponse response) throws ServletException, IOException {
632 635
		Logger logMetacat = Logger.getLogger(MetaCatServlet.class);
633 636

  
637
		String requestEncoding = request.getCharacterEncoding();
638
		logMetacat.warn("requestEncoding: " + requestEncoding);
639
		
634 640
		// Update the last update time for this user if they are not new
635 641
		HttpSession httpSession = request.getSession(false);
636 642
		if (httpSession != null) {
......
829 835
			// Now that we know the session is valid, we can delegate the
830 836
			// request to a particular action handler
831 837
			if (action.equals("query")) {
832
				ServletOutputStream streamOut = response.getOutputStream();
833
				PrintWriter out = new PrintWriter(streamOut);
838
		        Writer out = new OutputStreamWriter(response.getOutputStream(), DEFAULT_ENCODING);
834 839
				handler.handleQuery(out, params, response, userName, groupNames, sessionId);
835 840
				out.close();
836 841
			} else if (action.equals("squery")) {
837
				ServletOutputStream streamOut = response.getOutputStream();
838
				PrintWriter out = new PrintWriter(streamOut);
842
				Writer out = new OutputStreamWriter(response.getOutputStream(), DEFAULT_ENCODING);
839 843
				if (params.containsKey("query")) {
840 844
					handler.handleSQuery(out, params, response, userName, groupNames, sessionId);
841 845
					out.close();
842 846
				} else {
843
					out.println("Illegal action squery without \"query\" parameter");
847
					out.write("Illegal action squery without \"query\" parameter");
844 848
					out.close();
845 849
				}
846 850
			} else if (action.trim().equals("spatial_query")) {
847 851

  
848 852
				logMetacat
849 853
						.debug("MetaCatServlet.handleGetOrPost - ******************* SPATIAL QUERY ********************");
850
				ServletOutputStream streamOut = response.getOutputStream();
851
				PrintWriter out = new PrintWriter(streamOut);
854
				Writer out = new OutputStreamWriter(response.getOutputStream(), DEFAULT_ENCODING);
852 855
				handler.handleSpatialQuery(out, params, response, userName, groupNames, sessionId);
853 856
				out.close();
854 857

  

Also available in: Unified diff