Search in sources :

Example 6 with At

use of org.nutz.mvc.annotation.At in project nutzboot by nutzam.

the class EthModule method sendTransaction.

// @POST
@At("/eth/sendTransaction/?/?")
public NutMap sendTransaction(String from, String to, @Param("wei") double wei) {
    // from 必须是本地账号
    // to 必须是address
    NutMap re = new NutMap();
    // 检查转账金额
    if (wei < 0.01) {
        re.put("msg", "起码转账 0.01 eth");
        return re;
    }
    if (wei > 100) {
        re.put("msg", "最多转账 100 eth");
        return re;
    }
    Web3jAccount account = web3jCredentials.get(from);
    if (account == null) {
        return re.setv("msg", "不存在这个本地账号: " + from);
    }
    // 发起转账
    BigInteger value = Convert.toWei(new BigDecimal(wei), Convert.Unit.ETHER).toBigInteger();
    Transaction transaction = Transaction.createEtherTransaction(account.getAddress(), null, null, null, to, value);
    try {
        EthSendTransaction est = web3jAdmin.personalSendTransaction(transaction, account.getPassword()).send();
        String hash = est.getTransactionHash();
        return re.setv("ok", true).setv("hash", hash);
    } catch (Exception e) {
        log.warn("转账失败!!!", e);
        return re.setv("msg", e.getMessage());
    }
}
Also used : EthSendTransaction(org.web3j.protocol.core.methods.response.EthSendTransaction) Web3jAccount(org.nutz.boot.starter.web3.Web3jAccount) Transaction(org.web3j.protocol.core.methods.request.Transaction) EthSendTransaction(org.web3j.protocol.core.methods.response.EthSendTransaction) BigInteger(java.math.BigInteger) BigDecimal(java.math.BigDecimal) IOException(java.io.IOException) NutMap(org.nutz.lang.util.NutMap) At(org.nutz.mvc.annotation.At)

Example 7 with At

use of org.nutz.mvc.annotation.At in project incubator-skywalking by apache.

the class ActionMethodInterceptor method beforeMethod.

@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);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) ContextCarrier(org.apache.skywalking.apm.agent.core.context.ContextCarrier) At(org.nutz.mvc.annotation.At) CarrierItem(org.apache.skywalking.apm.agent.core.context.CarrierItem) AbstractSpan(org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan)

Example 8 with At

use of org.nutz.mvc.annotation.At in project incubator-skywalking by apache.

the class ActionConstructorInterceptor method onConstruct.

@Override
public void onConstruct(EnhancedInstance objInst, Object[] allArguments) {
    String basePath = "";
    At basePathRequestMapping = objInst.getClass().getAnnotation(At.class);
    if (basePathRequestMapping != null) {
        basePath = basePathRequestMapping.value()[0];
    }
    PathMappingCache pathMappingCache = new PathMappingCache(basePath);
    objInst.setSkyWalkingDynamicField(pathMappingCache);
}
Also used : At(org.nutz.mvc.annotation.At)

Example 9 with At

use of org.nutz.mvc.annotation.At in project nutz by nutzam.

the class UserModule method login.

@Filters
@POST
@At
public NutMap login(String username, String password, HttpSession session) {
    NutMap re = new NutMap("ok", false);
    if (Strings.isBlank(username) || Strings.isBlank(password)) {
        log.debug("username or password is null");
        return re.setv("msg", "用户名或密码不能为空");
    }
    User user = dao.fetch(User.class, username);
    if (user == null) {
        log.debug("no such user = " + username);
        return re.setv("msg", "没有该用户");
    }
    String tmp = Lang.digest("SHA-256", user.getSalt() + password);
    if (!tmp.equals(user.getPassword())) {
        log.debug("password is wrong");
        return re.setv("msg", "密码错误");
    }
    session.setAttribute("me", user);
    return re.setv("ok", true);
}
Also used : User(net.wendal.nutzdemo.bean.User) NutMap(org.nutz.lang.util.NutMap) Filters(org.nutz.mvc.annotation.Filters) At(org.nutz.mvc.annotation.At) POST(org.nutz.mvc.annotation.POST)

Example 10 with At

use of org.nutz.mvc.annotation.At in project nutzboot by nutzam.

the class UserModule method apitest.

/**
 * 这是演示api调用的入口,会顺序调用一堆请求,请关注日志
 */
@Ok("raw")
@At
public String apitest() {
    List<User> users = userService.list();
    log.info("users=" + Json.toJson(users));
    User haoqoo = userService.add("haoqoo", 19);
    User wendal = userService.add("wendal", 28);
    users = userService.list();
    log.info("users=" + Json.toJson(users));
    userService.delete(haoqoo.getId());
    userService.delete(wendal.getId());
    users = userService.list();
    log.info("users=" + Json.toJson(users));
    return "done";
}
Also used : User(io.nutz.demo.feign.bean.User) At(org.nutz.mvc.annotation.At) Ok(org.nutz.mvc.annotation.Ok)

Aggregations

At (org.nutz.mvc.annotation.At)14 NutMap (org.nutz.lang.util.NutMap)7 Ok (org.nutz.mvc.annotation.Ok)6 IOException (java.io.IOException)3 POST (org.nutz.mvc.annotation.POST)3 User (net.wendal.nutzdemo.bean.User)2 Web3jAccount (org.nutz.boot.starter.web3.Web3jAccount)2 User (io.nutz.cloud.demo.bean.User)1 User (io.nutz.demo.feign.bean.User)1 User (io.nutz.demo.simple.bean.User)1 File (java.io.File)1 BigDecimal (java.math.BigDecimal)1 BigInteger (java.math.BigInteger)1 HashMap (java.util.HashMap)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 Sha256Hash (org.apache.shiro.crypto.hash.Sha256Hash)1 Subject (org.apache.shiro.subject.Subject)1 CarrierItem (org.apache.skywalking.apm.agent.core.context.CarrierItem)1 ContextCarrier (org.apache.skywalking.apm.agent.core.context.ContextCarrier)1 AbstractSpan (org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan)1