1.1 --- a/ko-ws-tyrus/src/main/java/org/netbeans/html/wstyrus/LoadJSON.java Tue Aug 26 18:13:30 2014 +0200
1.2 +++ b/ko-ws-tyrus/src/main/java/org/netbeans/html/wstyrus/LoadJSON.java Wed May 27 23:37:25 2015 +0200
1.3 @@ -59,11 +59,11 @@
1.4 import java.util.concurrent.ThreadFactory;
1.5 import java.util.logging.Logger;
1.6 import net.java.html.js.JavaScriptBody;
1.7 -import org.netbeans.html.json.spi.JSONCall;
1.8 import org.json.JSONArray;
1.9 import org.json.JSONException;
1.10 import org.json.JSONObject;
1.11 import org.json.JSONTokener;
1.12 +import org.netbeans.html.json.spi.JSONCall;
1.13
1.14 /** This is an implementation package - just
1.15 * include its JAR on classpath and use official {@link Context} API
1.16 @@ -101,7 +101,7 @@
1.17 final String url;
1.18 Throwable error = null;
1.19 Object json = null;
1.20 -
1.21 +
1.22 if (call.isJSONP()) {
1.23 url = call.composeURL("dummy");
1.24 } else {
1.25 @@ -113,6 +113,28 @@
1.26 if (call.isDoOutput()) {
1.27 conn.setDoOutput(true);
1.28 }
1.29 + String h = call.getHeaders();
1.30 + if (h != null) {
1.31 + int pos = 0;
1.32 + while (pos < h.length()) {
1.33 + int tagEnd = h.indexOf(':', pos);
1.34 + if (tagEnd == -1) {
1.35 + break;
1.36 + }
1.37 + int r = h.indexOf('\r', tagEnd);
1.38 + int n = h.indexOf('\n', tagEnd);
1.39 + if (r == -1) {
1.40 + r = h.length();
1.41 + }
1.42 + if (n == -1) {
1.43 + n = h.length();
1.44 + }
1.45 + String key = h.substring(pos, tagEnd).trim();
1.46 + String val = h.substring(tagEnd + 1, Math.min(r, n)).trim();
1.47 + conn.setRequestProperty(key, val);;
1.48 + pos = Math.max(r, n);
1.49 + }
1.50 + }
1.51 if (call.getMethod() != null && conn instanceof HttpURLConnection) {
1.52 ((HttpURLConnection) conn).setRequestMethod(call.getMethod());
1.53 }
1.54 @@ -235,7 +257,7 @@
1.55 return o;
1.56 }
1.57 }
1.58 -
1.59 +
1.60 public static void extractJSON(Object jsonObject, String[] props, Object[] values) {
1.61 if (jsonObject instanceof JSONObject) {
1.62 JSONObject obj = (JSONObject)jsonObject;
1.63 @@ -252,7 +274,7 @@
1.64 values[i] = getProperty(jsonObject, props[i]);
1.65 }
1.66 }
1.67 -
1.68 +
1.69 @JavaScriptBody(args = {"object", "property"},
1.70 body
1.71 = "if (property === null) return object;\n"
1.72 @@ -262,7 +284,7 @@
1.73 private static Object getProperty(Object object, String property) {
1.74 return null;
1.75 }
1.76 -
1.77 +
1.78 public static Object parse(InputStream is) throws IOException {
1.79 try {
1.80 PushbackInputStream push = new PushbackInputStream(is, 1);