Index: core/kernel/src/main/java/com/sun/enterprise/v3/server/DomainXmlPersistence.java =================================================================== --- core/kernel/src/main/java/com/sun/enterprise/v3/server/DomainXmlPersistence.java (revision 43981) +++ core/kernel/src/main/java/com/sun/enterprise/v3/server/DomainXmlPersistence.java (working copy) @@ -150,7 +150,7 @@ XMLStreamWriter writer = null; OutputStream fos = getOutputStream(f); try { - writer = xmlFactory.createXMLStreamWriter(new BufferedOutputStream(fos)); + writer = xmlFactory.createXMLStreamWriter(new BufferedOutputStream(fos), "UTF-8"); IndentingXMLStreamWriter indentingXMLStreamWriter = new IndentingXMLStreamWriter(writer); doc.writeTo(indentingXMLStreamWriter); indentingXMLStreamWriter.close(); Index: admin/rest/src/main/java/org/glassfish/admin/rest/adapter/RestAdapter.java =================================================================== --- admin/rest/src/main/java/org/glassfish/admin/rest/adapter/RestAdapter.java (revision 43981) +++ admin/rest/src/main/java/org/glassfish/admin/rest/adapter/RestAdapter.java (working copy) @@ -82,6 +82,7 @@ import java.util.StringTokenizer; import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; +import org.glassfish.admin.rest.Constants; import org.glassfish.admin.rest.provider.ActionReportResultHtmlProvider; import org.glassfish.admin.rest.provider.ActionReportResultJsonProvider; import org.glassfish.admin.rest.provider.ActionReportResultXmlProvider; @@ -143,6 +144,7 @@ LogHelper.getDefaultLogger().finer("Received resource request: " + req.getRequestURI()); try { + res.setCharacterEncoding(Constants.ENCODING); if (!latch.await(20L, TimeUnit.SECONDS)) { String msg = localStrings.getLocalString("rest.adapter.server.wait", "Server cannot process this command at this time, please wait"); Index: admin/rest/src/main/java/org/glassfish/admin/rest/provider/BaseProvider.java =================================================================== --- admin/rest/src/main/java/org/glassfish/admin/rest/provider/BaseProvider.java (revision 43981) +++ admin/rest/src/main/java/org/glassfish/admin/rest/provider/BaseProvider.java (working copy) @@ -39,6 +39,7 @@ */ package org.glassfish.admin.rest.provider; +import org.glassfish.admin.rest.Constants; import org.jvnet.hk2.component.Habitat; import org.glassfish.admin.rest.RestConfig; import java.util.Collections; @@ -106,7 +107,7 @@ @Override public void writeTo(T proxy, Class type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap httpHeaders, OutputStream entityStream) throws IOException, WebApplicationException { - entityStream.write(getContent(proxy).getBytes()); + entityStream.write(getContent(proxy).getBytes(Constants.ENCODING)); } public abstract String getContent(T proxy); Index: admin/rest/src/main/java/org/glassfish/admin/rest/Constants.java =================================================================== --- admin/rest/src/main/java/org/glassfish/admin/rest/Constants.java (revision 43981) +++ admin/rest/src/main/java/org/glassfish/admin/rest/Constants.java (working copy) @@ -63,4 +63,6 @@ public static final String VAR_PARENT = "$parent"; public static final String VAR_GRANDPARENT = "$grandparent"; + + public static final String ENCODING = "UTF-8"; } \ No newline at end of file Index: common/common-util/src/main/java/com/sun/enterprise/universal/xml/MiniXmlParser.java =================================================================== --- common/common-util/src/main/java/com/sun/enterprise/universal/xml/MiniXmlParser.java (revision 43981) +++ common/common-util/src/main/java/com/sun/enterprise/universal/xml/MiniXmlParser.java (working copy) @@ -225,7 +225,7 @@ private void createParser() throws FileNotFoundException, XMLStreamException { domainXmlstream = new FileInputStream(domainXml); parser = getXmlInputFactory().createXMLStreamReader( - domainXml.toURI().toString(), domainXmlstream); + domainXmlstream, "UTF-8"); } // In JDK 1.6, StAX is part of JRE, so we use no argument variant of Index: common/common-util/src/main/java/com/sun/enterprise/universal/xml/XmlParserHelper.java =================================================================== --- common/common-util/src/main/java/com/sun/enterprise/universal/xml/XmlParserHelper.java (revision 43981) +++ common/common-util/src/main/java/com/sun/enterprise/universal/xml/XmlParserHelper.java (working copy) @@ -51,7 +51,7 @@ public XmlParserHelper(final File f) throws FileNotFoundException, XMLStreamException { stream = new FileInputStream(f); parser = XMLInputFactory.newInstance().createXMLStreamReader( - f.toURI().toString(), stream); + stream, "UTF-8"); } public final XMLStreamReader get() { Index: admingui/common/src/main/java/org/glassfish/admingui/common/util/JSONUtil.java =================================================================== --- admingui/common/src/main/java/org/glassfish/admingui/common/util/JSONUtil.java (revision 43981) +++ admingui/common/src/main/java/org/glassfish/admingui/common/util/JSONUtil.java (working copy) @@ -40,6 +40,7 @@ package org.glassfish.admingui.common.util; +import java.io.UnsupportedEncodingException; import java.lang.reflect.Method; import java.lang.reflect.Modifier; import java.text.StringCharacterIterator; @@ -50,6 +51,8 @@ import java.util.List; import java.util.Map; import java.util.Stack; +import java.util.logging.Level; +import java.util.logging.Logger; /** @@ -62,6 +65,10 @@ *
  • {@link #javaToJSON(Object obj, int depth)}
  • */ public class JSONUtil { + private static final String ABORT_PROCESSING = "____EnD___"; + private static final String COLON = "____CoLoN___"; + private static final String COMMA = "____CoMmA___"; + private static final String NULL = "____NuLl___"; /** *

    This method returns a Java representation of the given JSON @@ -70,7 +77,7 @@ * specified by the JSON String.

    */ public static Object jsonToJava(String json) { - return replaceSpecial(jsonToJava(new JSONBytes(json))); + return replaceSpecial(jsonToJava(new JsonChars(json))); } /** @@ -290,10 +297,11 @@ *

    This is the primary switching method which determines the context * in which the processing should occur.

    */ - private static Object jsonToJava(JSONBytes json) { + private static Object jsonToJava(JsonChars json) { Object value = null; while (json.hasNext() && (value == null)) { - switch (json.next()) { + char ch = json.next(); + switch (ch) { case '{' : value = readObject(json); break; @@ -365,9 +373,9 @@ /** *

    This method creates a HashMap to represent the JSON Object.

    */ - private static Map readObject(JSONBytes json) { + private static Map readObject(JsonChars json) { // Save the ending char... - json.pushContextEnd((byte) '}'); + json.pushContextEnd('}'); // Create the Map Map map = new HashMap(10); @@ -417,9 +425,9 @@ *

    This function will process a JSON string and convert it into * an array.

    */ - private static List readArray(JSONBytes json) { + private static List readArray(JsonChars json) { // Save the ending char... - json.pushContextEnd((byte) ']'); + json.pushContextEnd(']'); // Create the List List list = new ArrayList(10); @@ -454,13 +462,13 @@ /** *

    This function reads a String and returns it.

    */ - private static String readString(JSONBytes json) { + private static String readString(JsonChars json) { // Save the ending char... json.pushContextEnd(json.current()); // Build the String... StringBuilder builder = new StringBuilder(); - char ch = (char) json.next(); + char ch = json.next(); while (!json.isAtContextEnd()) { if (ch == '\\') { ch = (char) json.next(); @@ -509,9 +517,9 @@ /** *

    Returns either a Float or an Long depending on the data.

    */ - private static Object readNumber(JSONBytes json) { + private static Object readNumber(JsonChars json) { StringBuilder builder = new StringBuilder(); - char ch = (char) json.current(); + Character ch = json.current(); if (ch == '-') { builder.append('-'); ch = (char) json.next(); @@ -536,8 +544,7 @@ case '.' : if (hasDecimal) { throw new IllegalArgumentException( - "Error while parsing number! " + - "Found multiple decimal points."); + "Error while parsing number! Found multiple decimal points."); } hasDecimal = true; builder.append(ch); @@ -547,8 +554,7 @@ // We have an exponent if (hasExp) { throw new IllegalArgumentException( - "An attempt was made to parse an Long value, " - + "however, it was malformed (had to exponents)."); + "An attempt was made to parse an Long value, however, it was malformed (had to exponents)."); } hasExp = true; builder.append(ch); @@ -559,8 +565,7 @@ } if ((ch < '0') || (ch > '9')) { throw new IllegalArgumentException( - "Required a digit after an exponent, " - + "however received: '" + ch + "'."); + "Required a digit after an exponent, however received: '" + ch + "'."); } builder.append(ch); break; @@ -568,7 +573,11 @@ done = true; continue; } - ch = (char) json.next(); + ch = json.next(); + if (ch == null) { + done = true; + continue; + } } // Numbers don't have an ending delimiter, so we need to push the last // value back onto the queue @@ -584,10 +593,10 @@ *

    This method attempts to read a true/false/null value and returns a * Boolean for true/false values or {@link #NULL} for null values.

    */ - private static Object readConstant(JSONBytes json, String constant) { + private static Object readConstant(JsonChars json, String constant) { byte[] good = constant.getBytes(); int len = good.length; - char ch; + Character ch; boolean match = true; for (int idx=1; idx endContext = new Stack(); + + /** * Constructor. */ - JSONBytes(String json) { - bytes = json.getBytes(); - len = bytes.length; + JsonChars(String json) { + string = json; +// bytes = json.getBytes("UTF-8"); + len = string.length(); } /** *

    Returns the current byte.

    */ - byte current() { - return bytes[loc-1]; + Character current() { + return string.charAt(loc-1); } /** *

    Returns the current byte and increments the location by 1.

    */ - byte next() { - return (loc len) { after = len; } - return new String(bytes, before, after - before); + return string.substring(before, after - before); +// new String(bytes, before, after - before); } /** @@ -669,22 +686,17 @@ * Object is a '}' byte.

    */ boolean isAtContextEnd() { - return !hasNext() || (bytes[loc-1] == endContext.peek()); + return !hasNext() || (string.charAt(loc-1) == endContext.peek()); } - void pushContextEnd(byte end) { + void pushContextEnd(Character end) { endContext.push(end); } - byte popContextEnd() { + Character popContextEnd() { return endContext.pop(); } - byte peekContextEnd() { + Character peekContextEnd() { return endContext.peek(); } - - private byte[] bytes; - private int len; - private int loc = 0; - private Stack endContext = new Stack(); } /** @@ -706,52 +718,4 @@ } return val; } - - /** - * Used for testing... - */ - public static void main(String args[]) { - // FIXME: Convert to a real test... - test("3"); - test("true"); - test("false"); - test("null"); - test("[null]"); - test("[true,false,null,{'a':'b'},['1','2','3']]"); - test("[true,false,null,{'a':'b'},[1,2,3]]"); - test("[true,false,null,{'a':'b'},[1.1,2.2,3.3]]"); - test("[true,false,null,{'a':'b'},['1',2,3.3]]"); - test("{'x':['foo',null ,{'a':true, 'b':false }]}"); - test("{ 'key' : \"value\" ,\n \r \"key2\" : { 'innerKey' : [ 3.3E-2 , false , 800e+8, null , 37 , \"test\" ] , \n \"innerKey2\" : {'a' : 'b', 'c' : 'd'}, 'innerKey3' : true} }"); - - testJavaToJSON(new HashMap() {{ put("foo", "bar"); }}); - - System.out.println("\n\n"); - encodeDecodeTest("[true,false,null,{'a':'b'},['1','2','3']]"); - encodeDecodeTest("3"); - encodeDecodeTest("true"); - encodeDecodeTest("false"); - encodeDecodeTest("null"); - encodeDecodeTest("[null]"); - encodeDecodeTest("[true,false,null,{'a':'b'},['1','2','3']]"); - encodeDecodeTest("[true,false,null,{'a':'b'},[1,2,3]]"); - encodeDecodeTest("[true,false,null,{'a':'b'},[1.1,2.2,3.3]]"); - encodeDecodeTest("[true,false,null,{'a':'b'},['1',2,3.3]]"); - encodeDecodeTest("{'x':['foo',null ,{'a':true, 'b':false }]}"); - encodeDecodeTest("{ 'key' : \"value\" ,\n \r \"key2\" : { 'innerKey' : [ 3.3E-2 , false , 800e+8, null , 37 , \"test\" ] , \n \"innerKey2\" : {'a' : 'b', 'c' : 'd'}, 'innerKey3' : true} }"); - } - private static void test(String json) { - System.out.println("src:\t\t" + json + "\n\tresult:\t" + jsonToJava(json)); - } - private static void testJavaToJSON(Object obj) { - System.out.println("obj:\t\t" + obj + "\n\tJSON Result:\t" + javaToJSON(obj, 2)); - } - private static void encodeDecodeTest(String json) { - System.out.println("before:\t\t" + json + "\n\tafter:\t" + javaToJSON(jsonToJava(json), 9)); - } - - private static final String ABORT_PROCESSING = "____EnD___"; - private static final String COLON = "____CoLoN___"; - private static final String COMMA = "____CoMmA___"; - private static final String NULL = "____NuLl___"; -} +} \ No newline at end of file Index: admingui/common/src/main/java/org/glassfish/admingui/common/util/RestResponse.java =================================================================== --- admingui/common/src/main/java/org/glassfish/admingui/common/util/RestResponse.java (revision 43981) +++ admingui/common/src/main/java/org/glassfish/admingui/common/util/RestResponse.java (working copy) @@ -157,7 +157,7 @@ if (contentType != null) { String responseBody = getResponseBody(); contentType = contentType.toLowerCase(); - if (contentType.endsWith("xml")) { + if (contentType.startsWith("application/xml")) { InputStream input = null; try { XMLInputFactory inputFactory = XMLInputFactory.newInstance(); @@ -212,7 +212,7 @@ // // Generate a generic Java structure from the XML // result.put("data", getJavaFromXML(root)); // } - } else if (contentType.endsWith("json")) { + } else if (contentType.startsWith("application/json")) { // Decode JSON result.put("data", JSONUtil.jsonToJava(responseBody)); } else {