Author: groldan Date: 2011-10-27 13:23:12 -0700 (Thu, 27 Oct 2011) New Revision: 38281 Modified: branches/2.7.x/modules/unsupported/wfs/src/main/java/org/geotools/data/wfs/WFSDataStoreFactory.java branches/2.7.x/modules/unsupported/wfs/src/main/java/org/geotools/data/wfs/v1_0_0/WFSTransactionState.java branches/2.7.x/modules/unsupported/wfs/src/main/java/org/geotools/data/wfs/v1_0_0/WFS_1_0_0_DataStore.java branches/2.7.x/modules/unsupported/wfs/src/main/java/org/geotools/data/wfs/v1_1_0/WFS_1_1_0_Protocol.java branches/2.7.x/modules/unsupported/wfs/src/test/java/org/geotools/data/wfs/v1_1_0/DataTestSupport.java branches/2.7.x/modules/unsupported/wfs/src/test/java/org/geotools/data/wfs/v1_1_0/WFS_1_1_0_ProtocolTest.java Log: GEOT-987: make wfs datastore respect the provided encoding parameter when writing out xml Modified: branches/2.7.x/modules/unsupported/wfs/src/main/java/org/geotools/data/wfs/WFSDataStoreFactory.java =================================================================== --- branches/2.7.x/modules/unsupported/wfs/src/main/java/org/geotools/data/wfs/WFSDataStoreFactory.java 2011-10-27 20:23:03 UTC (rev 38280) +++ branches/2.7.x/modules/unsupported/wfs/src/main/java/org/geotools/data/wfs/WFSDataStoreFactory.java 2011-10-27 20:23:12 UTC (rev 38281) @@ -27,8 +27,10 @@ import java.net.MalformedURLException; import java.net.URL; import java.nio.charset.Charset; +import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; +import java.util.List; import java.util.Map; import java.util.logging.Level; import java.util.logging.Logger; @@ -199,7 +201,9 @@ clazz = String.class; description = "This allows the user to specify the character encoding of the " + "XML-Requests sent to the Server. Defaults to UTF-8"; - parametersInfo[4] = new WFSFactoryParam(name, clazz, description, "UTF-8"); + List<String> options = new ArrayList<String>(Charset.availableCharsets().keySet()); + Collections.sort(options); + parametersInfo[4] = new WFSFactoryParam(name, clazz, description, "UTF-8", "options", options); name = "WFSDataStoreFactory:TIMEOUT"; clazz = Integer.class; @@ -383,7 +387,7 @@ } else { InputStream capsIn = new ByteArrayInputStream(wfsCapabilitiesRawData); - WFS_1_1_0_Protocol wfs = new WFS_1_1_0_Protocol(capsIn, http); + WFS_1_1_0_Protocol wfs = new WFS_1_1_0_Protocol(capsIn, http, defaultEncoding); WFSStrategy strategy = determineCorrectStrategy(getCapabilitiesRequest, capsDoc); wfs.setStrategy(strategy); Modified: branches/2.7.x/modules/unsupported/wfs/src/main/java/org/geotools/data/wfs/v1_0_0/WFSTransactionState.java =================================================================== --- branches/2.7.x/modules/unsupported/wfs/src/main/java/org/geotools/data/wfs/v1_0_0/WFSTransactionState.java 2011-10-27 20:23:03 UTC (rev 38280) +++ branches/2.7.x/modules/unsupported/wfs/src/main/java/org/geotools/data/wfs/v1_0_0/WFSTransactionState.java 2011-10-27 20:23:12 UTC (rev 38281) @@ -277,7 +277,8 @@ OutputStream os = hc.getOutputStream(); // write request - Writer w = new OutputStreamWriter(os); + final String encoding = ds.getDefaultEncoding(); + Writer w = new OutputStreamWriter(os, encoding); Logger logger = Logging.getLogger("org.geotools.data.wfs"); if (logger.isLoggable(Level.FINE)) { w = new LogWriterDecorator(w, logger, Level.FINE); Modified: branches/2.7.x/modules/unsupported/wfs/src/main/java/org/geotools/data/wfs/v1_0_0/WFS_1_0_0_DataStore.java =================================================================== --- branches/2.7.x/modules/unsupported/wfs/src/main/java/org/geotools/data/wfs/v1_0_0/WFS_1_0_0_DataStore.java 2011-10-27 20:23:03 UTC (rev 38280) +++ branches/2.7.x/modules/unsupported/wfs/src/main/java/org/geotools/data/wfs/v1_0_0/WFS_1_0_0_DataStore.java 2011-10-27 20:23:12 UTC (rev 38281) @@ -176,6 +176,11 @@ determineCorrectStrategy(); } + + public String getDefaultEncoding() { + return protocolHandler.getEncoding(); + } + public WFSServiceInfo getInfo() { return new WFSServiceInfo() { public String getDescription() { @@ -555,7 +560,8 @@ Writer getOutputStream(HttpURLConnection hc) throws IOException { OutputStream os = hc.getOutputStream(); - Writer w = new OutputStreamWriter(os); + final String encoding = getDefaultEncoding(); + Writer w = new OutputStreamWriter(os, encoding); // write request Logger logger = Logging.getLogger("org.geotools.data.wfs"); if (logger.isLoggable(Level.FINE)) { Modified: branches/2.7.x/modules/unsupported/wfs/src/main/java/org/geotools/data/wfs/v1_1_0/WFS_1_1_0_Protocol.java =================================================================== --- branches/2.7.x/modules/unsupported/wfs/src/main/java/org/geotools/data/wfs/v1_1_0/WFS_1_1_0_Protocol.java 2011-10-27 20:23:03 UTC (rev 38280) +++ branches/2.7.x/modules/unsupported/wfs/src/main/java/org/geotools/data/wfs/v1_1_0/WFS_1_1_0_Protocol.java 2011-10-27 20:23:12 UTC (rev 38281) @@ -137,7 +137,11 @@ private HTTPProtocol http; - public WFS_1_1_0_Protocol(InputStream capabilitiesReader, HTTPProtocol http) throws IOException { + private final Charset defaultEncoding; + + public WFS_1_1_0_Protocol(InputStream capabilitiesReader, HTTPProtocol http, + Charset defaultEncoding) throws IOException { + this.defaultEncoding = defaultEncoding; this.strategy = new DefaultWFSStrategy(); this.capabilities = parseCapabilities(capabilitiesReader); this.http = http; @@ -632,7 +636,8 @@ } public void writeBody(final OutputStream out) throws IOException { - final Charset charset = Charset.forName("UTF-8"); + final Charset charset = defaultEncoding == null ? Charset.forName("UTF-8") + : defaultEncoding; encoder.setEncoding(charset); // if (LOGGER.isLoggable(Level.FINEST)) { // System.err.println("Sending POST request: "); Modified: branches/2.7.x/modules/unsupported/wfs/src/test/java/org/geotools/data/wfs/v1_1_0/DataTestSupport.java =================================================================== --- branches/2.7.x/modules/unsupported/wfs/src/test/java/org/geotools/data/wfs/v1_1_0/DataTestSupport.java 2011-10-27 20:23:03 UTC (rev 38280) +++ branches/2.7.x/modules/unsupported/wfs/src/test/java/org/geotools/data/wfs/v1_1_0/DataTestSupport.java 2011-10-27 20:23:12 UTC (rev 38281) @@ -179,7 +179,7 @@ public TestWFS_1_1_0_Protocol(InputStream capabilitiesReader, HTTPProtocol http) throws IOException { - super(capabilitiesReader, http); + super(capabilitiesReader, http, null); } /** Modified: branches/2.7.x/modules/unsupported/wfs/src/test/java/org/geotools/data/wfs/v1_1_0/WFS_1_1_0_ProtocolTest.java =================================================================== --- branches/2.7.x/modules/unsupported/wfs/src/test/java/org/geotools/data/wfs/v1_1_0/WFS_1_1_0_ProtocolTest.java 2011-10-27 20:23:03 UTC (rev 38280) +++ branches/2.7.x/modules/unsupported/wfs/src/test/java/org/geotools/data/wfs/v1_1_0/WFS_1_1_0_ProtocolTest.java 2011-10-27 20:23:12 UTC (rev 38281) @@ -122,7 +122,7 @@ try { InputStream badData = new ByteArrayInputStream(new byte[1024]); HTTPProtocol connFac = new DefaultHTTPProtocol(); - new WFS_1_1_0_Protocol(badData, connFac); + new WFS_1_1_0_Protocol(badData, connFac, null); fail("Excpected IOException as a capabilities document was not provided"); } catch (IOException e) { assertTrue(true); |