本文整理汇总了Java中org.nutz.mvc.annotation.Attr类的典型用法代码示例。如果您正苦于以下问题:Java Attr类的具体用法?Java Attr怎么用?Java Attr使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Attr类属于org.nutz.mvc.annotation包,在下文中一共展示了Attr类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: resetApikey
import org.nutz.mvc.annotation.Attr; //导入依赖的package包/类
@At("/ukey/reset")
@GET
@Filters()
public Object resetApikey(@Attr(IotKeys.UID)long userId) {
if (userId == 0)
return Collections.EMPTY_MAP;
IotUser usr = dao.fetch(IotUser.class, userId);
if (usr == null) {
usr = new IotUser();
iotService.makeApiKey(usr);
dao.insert(usr);
} else {
iotService.makeApiKey(usr);
dao.update(usr);
}
return new NutMap().addv("apikey", usr.getApikey());
}
示例2: createSensor
import org.nutz.mvc.annotation.Attr; //导入依赖的package包/类
@At({"/device/?/sensors"})
@POST
@AdaptBy(type=JsonAdaptor.class)
public IotSensor createSensor(long device_id, @Param("..")IotSensor sensor, @Attr(IotKeys.UID)long userId) {
if (sensor == null)
return null;
IotDevice dev = dao.fetch(IotDevice.class, Cnd.where("deviceId", "=", device_id).and(IotKeys.UID, "=", userId));
if (dev == null)
return null;
int sensorCount = dao.count(IotSensor.class, Cnd.where("deviceId", "=", device_id).and(IotKeys.UID, "=", userId));
if (sensorCount > Iots.Limit_Sensor_Per_Dev) {
return null;
}
sensor.setDeviceId(device_id);
sensor.setUserId(userId);
dao.insert(sensor);
return sensor;
}
示例3: query
import org.nutz.mvc.annotation.Attr; //导入依赖的package包/类
@At({"/?", "/?/?"})
public Object query(String openid, String clientId,
Map<String, Object> map, @Param("..")Pager pager,
@Attr(value="usr", scope=Scope.SESSION)String usr) {
WxMpInfo master = (WxMpInfo) wxctx.get(openid);
if (master == null || usr.equals(master.getOwner()))
return new HttpStatusView(403);
Cnd cnd = Cnd.NEW();
if (clientId != null)
cnd.and("client", "=", clientId);
if (map != null) {
for (Entry<String, Object> en : map.entrySet()) {
cnd.and(en.getKey(), "=", en.getValue());
}
}
int count = ExtDaos.ext(dao, openid).count(WxMsgHistory.class, cnd);
cnd.desc("createTime"); // count之后再加orderBy嘛
List<WxMsgHistory> list = ExtDaos.ext(dao, FieldFilter.locked(WxMsgHistory.class, "$(body)$"), openid).query(WxMsgHistory.class, cnd, pager);
pager.setRecordCount(count);
return new QueryResult(list, pager);
}
示例4: readMedia
import org.nutz.mvc.annotation.Attr; //导入依赖的package包/类
@GET
@At("/media/?/?")
@Ok("raw")
@Fail("http:404")
public InputStream readMedia(String openid, String mediaId, @Attr("usr")String usr, HttpServletResponse resp) throws IOException {
WxMaster master = wxctx.get(openid);
if (master == null || !master.getOpenid().equals(usr)) {
throw new IllegalArgumentException("not allow " + openid + "," + mediaId);
}
WxMedia media = mediaService.get(openid, mediaId);
if (media == null) {
throw new IllegalArgumentException("not found " + openid + "," + mediaId);
}
if (Strings.isBlank(media.getContentType())) {
resp.setContentType(media.getContentType());
}
return media.getStream();
}
示例5: upload
import org.nutz.mvc.annotation.Attr; //导入依赖的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());
}
示例6: resetApikey
import org.nutz.mvc.annotation.Attr; //导入依赖的package包/类
@At("/iot/apikey/reset")
@GET
@Filters()
public Object resetApikey(@Attr(Zs.UID)long userId) {
if (userId == 0)
return Collections.EMPTY_MAP;
IotUser usr = dao.fetch(IotUser.class, userId);
if (usr == null) {
usr = new IotUser();
iotService.makeApiKey(usr);
dao.insert(usr);
} else {
iotService.makeApiKey(usr);
dao.update(usr);
}
return new NutMap().addv("apikey", usr.getApikey());
}
示例7: createSensor
import org.nutz.mvc.annotation.Attr; //导入依赖的package包/类
@At({"/iot/device/?/sensors", "/v1.1/device/?/sensors"})
@POST
@AdaptBy(type=JsonAdaptor.class)
public IotSensor createSensor(long device_id, @Param("..")IotSensor sensor, @Attr(Zs.UID)long userId) {
if (sensor == null)
return null;
IotDevice dev = dao.fetch(IotDevice.class, Cnd.where("deviceId", "=", device_id).and(Zs.UID, "=", userId));
if (dev == null)
return null;
int sensorCount = dao.count(IotSensor.class, Cnd.where("deviceId", "=", device_id).and(Zs.UID, "=", userId));
if (sensorCount > Iots.Limit_Sensor_Per_Dev) {
return null;
}
sensor.setDeviceId(device_id);
sensor.setUserId(userId);
dao.insert(sensor);
return sensor;
}
示例8: upload
import org.nutz.mvc.annotation.Attr; //导入依赖的package包/类
@At({"/up", "/up/?"})
@AdaptBy(type=VoidAdaptor.class)
public void upload(long sensor_id, @Attr(IotKeys.UID)long userId, HttpServletResponse resp, HttpServletRequest req) throws IOException {
if (req.getHeader("Content-Length") == null) {
badReq(resp, Iots.NEED_CONTENT_LENGTH);
return;
}
if (req.getContentLength() < 1) {
badReq(resp, Iots.EMTRY_BODY);
return;
}
if (req.getContentLength() > 1024*1024) {
badReq(resp, Iots.TOOBIG);
return;
}
if (sensor_id > 0) { // 图片上传
IotSensor sensor = dao.fetch(IotSensor.class, Cnd.where("id", "=", sensor_id).and(IotKeys.UID, "=", userId));
if (sensor == null) {
badReq(resp, Iots.NOTFOUND);
return;
}
// 保存一下
File tmp = File.createTempFile("iot", ".jpg");
try {
Files.write(tmp, req.getInputStream());
BufferedImage image = Images.read(tmp);
iotSensorService.saveImage(sensor, tmp, image.getWidth(), image.getHeight());
} catch (Exception e) {
log.info("bad image", e);
} finally {
tmp.delete();
}
} else {
// 普通上传
iotHttpCmdHandler.exec(resp.getWriter(), Streams.readAndClose(req.getReader()), iotSensorService, dao);
}
}
示例9: readApikey
import org.nutz.mvc.annotation.Attr; //导入依赖的package包/类
@At("/ukey")
@GET
@Filters()
public Object readApikey(@Attr(IotKeys.UID)long userId) {
if (userId == 0)
return Collections.EMPTY_MAP;
IotUser usr = dao.fetch(IotUser.class, userId);
if (usr == null) {
usr = new IotUser();
iotService.makeApiKey(usr);
usr.setUserLevel(IotUserLevel.FREE);
dao.insert(usr);
}
return new NutMap().addv("apikey", usr.getApikey());
}
示例10: listSensors
import org.nutz.mvc.annotation.Attr; //导入依赖的package包/类
@At({"/device/?/sensors"})
@GET
@Filters()
// TODO 区分private和public设备
public List<IotSensor> listSensors(long deviceId, @Attr(IotKeys.UID)long userId) throws IllegalAccessException {
return dao.query(IotSensor.class, Cnd.where("deviceId", "=", deviceId));
}
示例11: createDev
import org.nutz.mvc.annotation.Attr; //导入依赖的package包/类
@At({"/devices"})
@POST
@AdaptBy(type=JsonAdaptor.class)
public IotDevice createDev(@Param("..")IotDevice dev, @Attr(IotKeys.UID)long userId) {
if (dev == null) {
return null;
}
int devCount = dao.count(IotDevice.class, Cnd.where(IotKeys.UID, "=", userId));
if (devCount > Iots.Limit_Dev_Per_User) { // TODO 可扩展,可配置
return null;
}
dev.setId(userId);
dev.setSensors(null);
return dao.insert(dev);
}
示例12: updateDev
import org.nutz.mvc.annotation.Attr; //导入依赖的package包/类
@At({"/device/?"})
@PUT
@AdaptBy(type=JsonAdaptor.class)
public IotDevice updateDev(long device_id, @Param("..")IotDevice dev, @Attr(IotKeys.UID)long userId) {
if (dev == null || 0 == dao.count(IotDevice.class, Cnd.where("id", "=", device_id).and(IotKeys.UID, "=", userId))) {
return null;
}
dev.setId(device_id);
dev.setUserId(userId);
dao.update(dev);
return dev;
}
示例13: deleteDev
import org.nutz.mvc.annotation.Attr; //导入依赖的package包/类
@At({"/device/?"})
@DELETE
@Ok("void")
public void deleteDev(long device_id, @Attr(IotKeys.UID)long userId) {
dao.clear(IotDevice.class, Cnd.where("id", "=", device_id).and(IotKeys.UID, "=", userId));
dao.clear(IotSensor.class, Cnd.where("deviceId", "=", device_id).and(IotKeys.UID, "=", userId));
}
示例14: updateSensor
import org.nutz.mvc.annotation.Attr; //导入依赖的package包/类
@At({"/device/?/sensor/?"})
@PUT
@AdaptBy(type=JsonAdaptor.class)
public IotSensor updateSensor(long device_id, @Param("..")IotSensor sensor, @Attr(IotKeys.UID)long userId) {
if (sensor == null)
return null;
IotDevice dev = dao.fetch(IotDevice.class, Cnd.where("deviceId", "=", device_id).and(IotKeys.UID, "=", userId));
if (dev == null)
return null;
sensor.setDeviceId(device_id);
sensor.setUserId(userId);
dao.update(sensor);
return sensor;
}
示例15: login
import org.nutz.mvc.annotation.Attr; //导入依赖的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;
}