本文整理汇总了Java中org.nutz.mvc.Mvcs类的典型用法代码示例。如果您正苦于以下问题:Java Mvcs类的具体用法?Java Mvcs怎么用?Java Mvcs使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Mvcs类属于org.nutz.mvc包,在下文中一共展示了Mvcs类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: make
import org.nutz.mvc.Mvcs; //导入依赖的package包/类
public View make(Ioc ioc, String type, String value) {
if ("fm".equalsIgnoreCase(type) || "ftl".equalsIgnoreCase(type)) {
if (freeMarkerConfigurer == null) {
for (String name : ioc.getNames()) {
if (iocName.equals(name)) {
freeMarkerConfigurer = ioc.get(FreeMarkerConfigurer.class);
break;
}
}
if (freeMarkerConfigurer == null) {
Configuration configuration = new Configuration();
freeMarkerConfigurer = new FreeMarkerConfigurer(configuration, Mvcs.getServletContext(),"WEB-INF", ".html", null);
freeMarkerConfigurer.init();
}
}
return new WindowsFreemarkerView(freeMarkerConfigurer, value);
}
return null;
}
示例2: getTemplateShareVars
import org.nutz.mvc.Mvcs; //导入依赖的package包/类
/**
* 模板引擎共用的变量
*/
public static NutMap getTemplateShareVars() {
NutMap share = new NutMap();
Ioc ioc = Mvcs.getIoc();
share.put("ioc", ioc);
PropertiesProxy conf = ioc.get(PropertiesProxy.class, "conf");
share.put("conf", conf.toMap());
if (!conf.getBoolean("cdn.enable", false) || Strings.isBlank(conf.get("cdn.urlbase"))) {
share.put("cdnbase", "");
} else {
share.put("cdnbase", conf.get("cdn.urlbase"));
}
return share;
}
示例3: upload
import org.nutz.mvc.Mvcs; //导入依赖的package包/类
@At({"/iot/device/?/sensor/?/datapoints", "/v1.1/device/?/sensor/?/datapoints"})
@POST
@AdaptBy(type=VoidAdaptor.class)
@Ok("void")
public void upload(String device_id, String sensor_id, InputStream in, @Attr(Zs.UID)long userId, HttpServletResponse resp) throws IOException {
IotSensor sensor = dao.fetch(IotSensor.class, Cnd.where("deviceId", "=", device_id).and(Zs.UID, "=", userId).and("id", "=", sensor_id));
if (sensor == null) {
resp.setStatus(406);
resp.getWriter().write(Iots.NOTFOUND);
return;
}
if (sensor.getLastUpdateTime() != null && System.currentTimeMillis() - sensor.getLastUpdateTime().getTime() < Iots.Limit_Sensor_Update_Interval * 1000 ) {
resp.setStatus(406);
resp.getWriter().write(Iots.TOOFAST);
return ; // too fast
}
SensorUploadResult re = iotSensorService.upload(sensor, in);
if (re.err == null)
return;
resp.setStatus(406);
Mvcs.write(resp, re, JsonFormat.compact());
}
示例4: getIoc
import org.nutz.mvc.Mvcs; //导入依赖的package包/类
public Ioc getIoc(){
if(ioc == null){
ioc = Mvcs.getIoc();
}else if(ioc == null){
ioc = Mvcs.ctx().getDefaultIoc();
}
return ioc;
}
示例5: Accepter
import org.nutz.mvc.Mvcs; //导入依赖的package包/类
/**
*
* @author tanyaowu
*/
public Accepter() {
handlers.addv(String.valueOf(Type.REQFRIEND),Mvcs.getIoc().get(ReqMessageHandler.class,"reqMessageHandler"));
handlers.addv(String.valueOf(Type.DELFRIEND),Mvcs.getIoc().get(DelFriendMessageHandler.class,"delFriendMessageHandler"));
handlers.addv(String.valueOf(Type.JOIN_GROUP_REQ),Mvcs.getIoc().get(JoinGroupMessageHandler.class,"joinGroupMessageHandler"));
handlers.addv(String.valueOf(Type.OUT_GROUP_REQ),Mvcs.getIoc().get(OutGroupMessageHandler.class,"outGroupMessageHandler"));
handlers.addv(String.valueOf(Type.P2P_REQ),Mvcs.getIoc().get(P2PMessageHandler.class,"p2PMessageHandler"));
handlers.addv(String.valueOf(Type.GROUP_MSG_REQ),Mvcs.getIoc().get(GroupMessageHandler.class,"groupMessageHandler"));
handlers.addv(String.valueOf(Type.LOGIN_REQ_MSG),Mvcs.getIoc().get(LoginMessageHandler.class,"loginMessageHandler"));
handlers.addv(String.valueOf(Type.OLD_MESSAGE_REQ_MSG),Mvcs.getIoc().get(OldMessageHandler.class,"oldMessageHandler"));
}
示例6: render
import org.nutz.mvc.Mvcs; //导入依赖的package包/类
public void render(HttpServletRequest req, HttpServletResponse resp,
Object obj) throws Exception {
String path = evalPath(req, obj);
String args = "";
if (path != null && path.contains("?")) { // 将参数部分分解出来
args = path.substring(path.indexOf('?'));
path = path.substring(0, path.indexOf('?'));
}
String ext = getExt();
// 空路径,采用默认规则
if (Strings.isBlank(path)) {
path = Mvcs.getRequestPath(req);
path = (path.startsWith("/") ? "" : "/")
+ Files.renameSuffix(path, ext);
}
// 绝对路径 : 以 '/' 开头的路径不增加 '/WEB-INF'
else if (path.charAt(0) == '/') {
if (!path.toLowerCase().endsWith(ext))
path += ext;
}
// 包名形式的路径
else {
path = path.replace('.', '/') + ext;
}
// 执行 Forward
path = path + args;
RequestDispatcher rd = req.getRequestDispatcher(path);
if (rd == null)
throw Lang.makeThrow("Fail to find Forward '%s'", path);
// Do rendering
rd.forward(req, resp);
}
示例7: test
import org.nutz.mvc.Mvcs; //导入依赖的package包/类
@At
public Object test(){
NutMap nm = new NutMap();
String contextPath = Mvcs.getServletContext().getContextPath();
String realPath = Mvcs.getServletContext().getRealPath("/");
String parent = new File(realPath).getParent();
nm.setv("contextPath",contextPath);
nm.setv("realPath",realPath);
nm.setv("parent",parent);
return nm;
}
示例8: dao
import org.nutz.mvc.Mvcs; //导入依赖的package包/类
public Dao dao() {
if (dao == null) {
dao = Mvcs.ctx().getDefaultIoc().get(Dao.class, "dao");
return dao;
}
return dao;
}
示例9: dao
import org.nutz.mvc.Mvcs; //导入依赖的package包/类
private Dao dao() {
if (null == dao) {
Ioc ioc = Mvcs.getIoc();
if (null == ioc)
ioc = Mvcs.ctx.getDefaultIoc();
dao = ioc.get(Dao.class);
}
return dao;
}
示例10: beforeMethod
import org.nutz.mvc.Mvcs; //导入依赖的package包/类
@Override
public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes,
MethodInterceptResult result) throws Throwable {
PathMappingCache pathMappingCache = (PathMappingCache)objInst.getSkyWalkingDynamicField();
String requestURL = pathMappingCache.findPathMapping(method);
if (requestURL == null) {
At methodRequestMapping = method.getAnnotation(At.class);
if (methodRequestMapping.value().length > 0) {
requestURL = methodRequestMapping.value()[0];
} else {
requestURL = "";
}
pathMappingCache.addPathMapping(method, requestURL);
requestURL = pathMappingCache.findPathMapping(method);
}
HttpServletRequest request = Mvcs.getReq();
ContextCarrier contextCarrier = new ContextCarrier();
CarrierItem next = contextCarrier.items();
while (next.hasNext()) {
next = next.next();
next.setHeadValue(request.getHeader(next.getHeadKey()));
}
AbstractSpan span = ContextManager.createEntrySpan(requestURL, contextCarrier);
Tags.URL.set(span, request.getRequestURL().toString());
Tags.HTTP.METHOD.set(span, request.getMethod());
span.setComponent(ComponentsDefine.NUTZ_MVC_ANNOTATION);
SpanLayer.asHttp(span);
}
示例11: afterMethod
import org.nutz.mvc.Mvcs; //导入依赖的package包/类
@Override
public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes,
Object ret) throws Throwable {
HttpServletResponse response = Mvcs.getResp();
AbstractSpan span = ContextManager.activeSpan();
if (response.getStatus() >= 400) {
span.errorOccurred();
Tags.STATUS_CODE.set(span, Integer.toString(response.getStatus()));
}
ContextManager.stopSpan();
return ret;
}
示例12: end
import org.nutz.mvc.Mvcs; //导入依赖的package包/类
public void end(Object ctx) {
try {
if (Mvcs.getReq().getRequestURI().endsWith(".json")) {
Mvcs.write((HttpServletResponse)ctx, list, JsonFormat.compact());
} else {
Writer writer = ((HttpServletResponse)ctx).getWriter();
for (NutMap map : list) {
writer.write(String.format("%s,%s\n", map.get("ok"), map.get("msg")));
}
}
} catch (IOException e) {
e.printStackTrace();//不常见
}
}
示例13: login
import org.nutz.mvc.Mvcs; //导入依赖的package包/类
@At
public boolean login(@Param("name")String name,
@Param("passwd")String password,
@Param("captcha")String captcha,
@Attr(value=Zs.UID)Long uid){
if (uid != null) {
return true;
}
if (name == null || password == null || captcha == null)
return false;
if (name.length() > 64 || password.length() > 64 || captcha.length() > 64)
return false;
HttpSession session = Mvcs.getHttpSession(false);
if (session == null) { // 直接调用login,没门!
return false;
}
Object _captcha = session.getAttribute(Toolkit.captcha_attr);
if (_captcha == null) //连验证码都没有咯,没门!
return false;
if (!Toolkit.checkCaptcha(_captcha.toString(), captcha)) {
Lang.sleep(1000); // 暂停1s再响应. TODO 容易导致DDOS
return false; // 验证码不过? 没门!
}
// TODO 下面是检查登录信息的逻辑,应当抽象为一个接口实现.
User usr = dao.fetch(User.class, Cnd.where("name", "=", name));
if (usr == null || !Toolkit.passwordEncode(password, usr.getSlat()).equals(usr.getPasswd())) {
Lang.sleep(1000); // 暂停1s再响应. TODO 容易导致DDOS
return false;
}
log.debug("User login success >> " + name);
// TODO 记录到系统操作日志中
session.setAttribute(Zs.UID, usr.getId()); // session里面只放id哦
return true;
}
示例14: requirePasswdReset
import org.nutz.mvc.Mvcs; //导入依赖的package包/类
@At("/pwd_reset")
public boolean requirePasswdReset(@Param("name")String name,
@Param("email")String email,
@Param("captcha")String captcha) {
if (name == null || email == null || captcha == null)
return false;
if (name.length() > 64 || email.length() > 64 || captcha.length() > 64)
return false;
HttpSession session = Mvcs.getHttpSession(false);
if (session == null) { // 直接调用login,没门!
return false;
}
Object _captcha = session.getAttribute(Toolkit.captcha_attr);
if (_captcha == null) //连验证码都没有咯,没门!
return false;
if (!Toolkit.checkCaptcha(_captcha.toString(), captcha)) {
Lang.sleep(1000); // 暂停1s再响应. TODO 容易导致DDOS
return false; // 验证码不过? 没门!
}
User usr = dao.fetch(User.class, name);
if (usr == null || !email.equalsIgnoreCase(usr.getEmail())) {
log.debug("email not match");
return false;
}
String tpl = "URL: ${url}/callback/${token}";
Context ctx = Lang.context();
ctx.set("url", Mvcs.getReq().getRequestURL().toString());
String token = String.format("u=%s,t=%d,slat=%s", name, System.currentTimeMillis(), usr.getSlat());
token = Toolkit._3DES_encode(pwdResetKey, token.getBytes());
if (token == null)
return false;
ctx.set("token", token);
return mailService.send(usr.getEmail(), "Password reset", tpl, ctx);
}
示例15: checkCaptcha
import org.nutz.mvc.Mvcs; //导入依赖的package包/类
@At("/captcha/check")
public boolean checkCaptcha(@Param("answer")String answer) {
HttpSession session = Mvcs.getHttpSession(false);
if (session != null) {
Object text = session.getAttribute(answer);
if (text != null) {
if (Toolkit.checkCaptcha(text.toString(), answer))
return true;
}
// 当输入出错,强制要求重新生成新的验证码
//session.removeAttribute(captcha_attr);
}
return false;
}