我一直在尝试使用播放框架 1.2.4 在我的应用程序中实现 WURFL Cloud API。不幸的是,play 没有 HttpServletRequest 和 HttpServletResponse 仍然有一个 Request 和一个 Response 对象,可以转换为 HttpServeletRequest 和 HttpServletResponse 但是当我尝试这个时,我有一个NullPointerException ....谁能帮我解决这个问题或者更好地指导我实施。我还查看了这个模块(https://github.com/revbingo/play-wurfl),但是关于它的实现的信息很少。
下面是我的代码片段
package controllers;
import play.*;
import play.mvc.*;
import play.mvc.Http.Request;
import play.mvc.Http.Response;
import play.mvc.Http.Header;
import play.server.ServletWrapper;
import javax.servlet.ServletRequest;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.scientiamobile.wurflcloud.CloudClientLoader;
import com.scientiamobile.wurflcloud.CloudClientManager;
import com.scientiamobile.wurflcloud.device.AbstractDevice;
import com.sun.xml.internal.ws.client.RequestContext;
import net.sourceforge.wurfl.core.Device;
import net.sourceforge.wurfl.core.WURFLHolder;
import net.sourceforge.wurfl.core.WURFLManager;
import models.*;
public class Application extends Controller {
private static final String API_KEY = "xxxx:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
public static void index() throws Exception {
HttpServletRequest request = (HttpServletRequest) Request.current().args.get(ServletWrapper.SERVLET_REQ);
HttpServletResponse response = (HttpServletResponse) Request.current().args.get(ServletWrapper.SERVLET_RES);
CloudClientLoader loader = new CloudClientLoader(API_KEY);
CloudClientManager manager = (CloudClientManager) loader.getClientManager();
try{
AbstractDevice device = manager.getDeviceFromRequest(request,response);
Object deviceCapability = device.getCapabilities();
render(request, response, deviceCapability);
}catch(NullPointerException ex){
render(request, response);
}
}
}