jsonp服務端代碼示例

package cn.com.acxiom.webservice.rest;

import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.util.Map;

import javax.servlet.http.HttpServletResponse;

import org.apache.commons.codec.digest.DigestUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.math.NumberUtils;
import org.codehaus.jettison.json.JSONException;
import org.codehaus.jettison.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.fasterxml.jackson.databind.util.JSONPObject;

@Controller
@RequestMapping(value = "/webservice/rest", produces = {MediaType.APPLICATION_JSON_VALUE, MediaType.APPLICATION_XML_VALUE})
public class RestController {

    @RequestMapping(method= {RequestMethod.GET}, value = "/service/resolveJSONP")

    @ResponseBody

    @RequestCallType(type="JSONP")

    public JSONPObject resolveJSONP(String data,String callback,HttpServletResponse res) {

        try {

            data = URLDecoder.decode(data,"UTF-8");}

        catch (UnsupportedEncodingException e) {

            e.printStackTrace();

        }

        ResolveResponse res= resolveData(data);

        res.addHeader("Content-Type", "application/x-javascript");

        return new JSONPObject(callback,res);

    }

}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章