Browse Source

修改jsonp逻辑

周浩 9 years ago
parent
commit
90669c65fd

+ 5 - 2
hsweb-web-core/src/main/java/org/hsweb/web/core/message/FastJsonHttpMessageConverter.java

@@ -4,6 +4,7 @@ import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.serializer.PropertyPreFilter;
 import com.alibaba.fastjson.serializer.SerializerFeature;
 import com.alibaba.fastjson.serializer.SimplePropertyPreFilter;
+import org.hsweb.web.core.utils.ThreadLocalUtils;
 import org.springframework.http.HttpInputMessage;
 import org.springframework.http.HttpOutputMessage;
 import org.springframework.http.MediaType;
@@ -85,9 +86,11 @@ public class FastJsonHttpMessageConverter extends AbstractHttpMessageConverter<O
             if (message.isSuccess() && message.isOnlyData())
                 obj = message.getData();
             text = JSON.toJSONString(obj, parseFilter(message), features);
-            if (!StringUtils.isNullOrEmpty(message.getCallback())) {
+            String callback = ThreadLocalUtils.get("jsonp-callback");
+            if (callback == null) message.getCallback();
+            if (!StringUtils.isNullOrEmpty(callback)) {
                 text = new StringBuilder()
-                        .append(message.getCallback())
+                        .append(callback)
                         .append("(").append(text).append(")")
                         .toString();
             }