Java Code Examples for org.fisco.bcos.channel.dto.ChannelResponse#getErrorCode()

The following examples show how to use org.fisco.bcos.channel.dto.ChannelResponse#getErrorCode() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AMOPChannel.java    From WeEvent with Apache License 2.0 6 votes vote down vote up
public FileChunksMeta createReceiverFileContext(FileChunksMeta fileChunksMeta) throws BrokerException {
    log.info("send AMOP message to create receiver file context");
    FileEvent fileEvent = new FileEvent(FileEvent.EventType.FileChannelStart, fileChunksMeta.getFileId());
    fileEvent.setFileChunksMeta(fileChunksMeta);
    ChannelResponse rsp = this.sendEvent(fileChunksMeta.getTopic(), fileEvent);
    if (rsp.getErrorCode() == ErrorCode.SUCCESS.getCode()) {
        log.info("create remote file context success");
        if (!this.senderTopics.contains(fileChunksMeta.getTopic())) {
            this.senderTopics.add(fileChunksMeta.getTopic());
        }

        return JsonHelper.json2Object(rsp.getContentByteArray(), FileChunksMeta.class);
    }

    log.error("create remote file context failed");
    throw toBrokerException(rsp);
}
 
Example 2
Source File: FileTransportService.java    From WeEvent with Apache License 2.0 6 votes vote down vote up
public void sendChunkData(String topic, String groupId, String fileId, int chunkIndex, byte[] data) throws BrokerException {
    // check file context exist
    FileChunksMeta fileChunksMeta = this.getSenderFileChunksMeta(topic, groupId, fileId);

    log.info("send chunk data via AMOP channel, {}#{}", fileId, chunkIndex);

    FileEvent fileEvent = new FileEvent(FileEvent.EventType.FileChannelData, fileId);
    fileEvent.setChunkIndex(chunkIndex);
    fileEvent.setChunkData(data);

    //AMOPChannel channel = this.getChannel(groupId);
    ChannelResponse rsp = channel.sendEvent(topic, fileEvent);
    if (rsp.getErrorCode() == ErrorCode.SUCCESS.getCode()) {
        log.info("sender chunk data to remote success");
        // local cached chunkStatus is not consistency, but show in stats and log only
        fileChunksMeta.getChunkStatus().set(chunkIndex);
    } else {
        BrokerException e = AMOPChannel.toBrokerException(rsp);
        log.error("sender chunk data to remote failed", e);
        throw e;
    }
}
 
Example 3
Source File: ChannelResponseCallback2.java    From web3sdk with Apache License 2.0 6 votes vote down vote up
public final void onResponse(ChannelResponse response) {
    if (response.getErrorCode() == ChannelMessageError.NODES_UNREACHABLE.getError()) {
        logger.error("Local node error,try the next local nodec");

        retrySendMessage(); // 1表示客户端错误
    } else {
        try {
            onResponseMessage(response);
        } catch (Exception e) {
            logger.error("response package processing error:", e);
        }

        if (message.getSeq() != null) {
            service.getSeq2Callback().remove(message.getSeq());
        }

        if (timeout != null) {
            timeout.cancel();
        }
    }
}
 
Example 4
Source File: AMOPChannel.java    From WeEvent with Apache License 2.0 5 votes vote down vote up
public FileChunksMeta cleanUpReceiverFileContext(String topic, String fileId) throws BrokerException {
    log.info("send AMOP message to clean up receiver file context");

    FileEvent fileEvent = new FileEvent(FileEvent.EventType.FileChannelEnd, fileId);
    ChannelResponse rsp = this.sendEvent(topic, fileEvent);
    if (rsp.getErrorCode() == ErrorCode.SUCCESS.getCode()) {
        log.info("clean up receiver file context success");
        return JsonHelper.json2Object(rsp.getContentByteArray(), FileChunksMeta.class);
    } else {
        log.error("clean up remote file context failed");
        throw toBrokerException(rsp);
    }
}
 
Example 5
Source File: AMOPChannel.java    From WeEvent with Apache License 2.0 5 votes vote down vote up
public FileChunksMeta getReceiverFileContext(String topic, String fileId) throws BrokerException {
    log.info("send AMOP message to get receiver file context");
    ChannelResponse rsp = this.sendEvent(topic, new FileEvent(FileEvent.EventType.FileChannelStatus, fileId));
    if (rsp.getErrorCode() == ErrorCode.SUCCESS.getCode()) {
        log.info("receive file context is ready, go");
        return JsonHelper.json2Object(rsp.getContentByteArray(), FileChunksMeta.class);
    }

    log.error("receive file context is not exist");
    throw toBrokerException(rsp);
}
 
Example 6
Source File: AMOPChannel.java    From WeEvent with Apache License 2.0 5 votes vote down vote up
public boolean isFileExist(FileChunksMeta fileChunksMeta) throws BrokerException {
    log.info("send AMOP message to Check file existence");
    FileEvent fileEvent = new FileEvent(FileEvent.EventType.FileChannelExist, fileChunksMeta.getFileId());
    fileEvent.setFileChunksMeta(fileChunksMeta);
    ChannelResponse rsp = this.sendEvent(fileChunksMeta.getTopic(), fileEvent);
    if (rsp.getErrorCode() == ErrorCode.SUCCESS.getCode()) {
        log.info("Check file existence success");
        return JsonHelper.json2Object(rsp.getContentByteArray(), Boolean.class);
    }

    log.error("Check file existence failed");
    throw toBrokerException(rsp);
}
 
Example 7
Source File: AMOPChannel.java    From WeEvent with Apache License 2.0 5 votes vote down vote up
public static BrokerException toBrokerException(ChannelResponse reply) {
    if (reply.getErrorCode() < 100000) {
        return new BrokerException(reply.getErrorCode(), reply.getErrorMessage());
    } else {
        return new BrokerException(reply.getErrorCode(), ErrorCode.getDescByCode(reply.getErrorCode()));
    }

}
 
Example 8
Source File: Service.java    From web3sdk with Apache License 2.0 4 votes vote down vote up
public void checkSignForAmop(
        String topic,
        String randValue,
        String nodeid,
        ChannelHandlerContext ctx,
        ChannelResponse response)
        throws IOException {

    if (response.getErrorCode() != 0) {
        logger.error(
                "get signature failed :{}:{}",
                response.getErrorCode(),
                response.getErrorMessage());
        return;
    }
    logger.info(
            "check signature:{} length:{}",
            Arrays.toString(response.getContentByteArray()),
            response.getContentByteArray().length);
    String content =
            topicVerify.parseDataFromPush(
                    response.getContentByteArray().length, response.getContentByteArray());
    logger.info("content:{} content:{}", content, Arrays.toString(content.getBytes()));
    TopicVerifyRespProtocol topicVerifyRespProtocol =
            ObjectMapperFactory.getObjectMapper()
                    .readValue(content, TopicVerifyRespProtocol.class);
    String signature = topicVerifyRespProtocol.getSignature();
    logger.info("signature:{} ", signature);
    int checkResult = topicVerify.checkSignatureValidate(topic, signature, randValue);

    SdkRequestNodeUpdateTopicStatus sdkRequestNodeUpdateTopicStatus =
            new SdkRequestNodeUpdateTopicStatus();
    sdkRequestNodeUpdateTopicStatus.setCheckResult(checkResult);
    sdkRequestNodeUpdateTopicStatus.setNodeId(nodeid);
    sdkRequestNodeUpdateTopicStatus.setTopic(topic);
    String jsonStr =
            ObjectMapperFactory.getObjectMapper()
                    .writeValueAsString(sdkRequestNodeUpdateTopicStatus);
    logger.info("check signature result:{}", jsonStr);
    ChannelRequest request = new ChannelRequest();
    request.setMessageID(newSeq());
    request.setToTopic(topic);
    request.setTimeout(5000);
    request.setContent(jsonStr.getBytes());
    sendCheckResultToNode(
            request, ctx, (short) ChannelMessageType.UPDATE_TOPIICSTATUS.getType());
}
 
Example 9
Source File: Channel2ClientBinNeedVerify.java    From web3sdk with Apache License 2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {
    if (args.length < 2) {
        System.out.println("param: target topic filename of request");
        return;
    }
    String topic = args[0];
    String filename = args[1];
    Integer count = 10;

    DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");

    logger.debug("init client");

    ApplicationContext context =
            new ClassPathXmlApplicationContext("classpath:applicationContext.xml");

    Service service = context.getBean(Service.class);
    service.run();

    System.out.println("3s ...");
    Thread.sleep(1000);
    System.out.println("2s ...");
    Thread.sleep(1000);
    System.out.println("1s ...");
    Thread.sleep(1000);

    System.out.println("start test");
    System.out.println("===================================================================");

    for (Integer i = 0; i < count; ++i) {
        Thread.sleep(2000);
        ChannelRequest request = new ChannelRequest();
        request.setToTopic(topic);
        request.setMessageID(service.newSeq());
        request.setTimeout(5000);

        /*设置为-128表示为传输二进制*/
        int flag = -128;
        byte[] byteflag = intToByteArray(flag);
        int filelength = filename.length();
        byte[] bytelength = intToByteArray(filelength);
        byte[] bytefilename = filename.getBytes();
        byte[] contentfile = toByteArrFromFile(filename);
        byte[] content =
                byteCat(byteCat(byteCat(byteflag, bytelength), bytefilename), contentfile);
        request.setContent(content);

        logger.info("msg:" + Arrays.toString(content));

        System.out.println(
                df.format(LocalDateTime.now())
                        + " request seq:"
                        + String.valueOf(request.getMessageID())
                        + " content length:"
                        + content.length);

        ChannelResponse response = service.sendChannelMessageForVerifyTopic(request);

        System.out.println(
                df.format(LocalDateTime.now())
                        + "response seq:"
                        + String.valueOf(response.getMessageID())
                        + ", ErrorCode:"
                        + response.getErrorCode()
                        + ", Content:"
                        + response.getContent());
        if (response.getErrorCode() != 0) {
            System.out.println("Error message" + response.getErrorMessage());
        }
    }
}
 
Example 10
Source File: Channel2ClientBin.java    From web3sdk with Apache License 2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {
    if (args.length < 2) {
        System.out.println("param: target topic filename of request");
        return;
    }
    String topic = args[0];
    String filename = args[1];
    Integer count = 1;

    DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");

    logger.debug("init client");

    ApplicationContext context =
            new ClassPathXmlApplicationContext("classpath:applicationContext.xml");

    Service service = context.getBean(Service.class);
    service.run();

    System.out.println("3s ...");
    Thread.sleep(1000);
    System.out.println("2s ...");
    Thread.sleep(1000);
    System.out.println("1s ...");
    Thread.sleep(1000);

    System.out.println("start test");
    System.out.println("===================================================================");

    for (Integer i = 0; i < count; ++i) {
        Thread.sleep(2000);
        ChannelRequest request = new ChannelRequest();
        request.setToTopic(topic);
        request.setMessageID(service.newSeq());
        request.setTimeout(5000);

        /*设置为-128表示为传输二进制*/
        int flag = -128;
        byte[] byteflag = intToByteArray(flag);
        int filelength = filename.length();
        byte[] bytelength = intToByteArray(filelength);
        byte[] bytefilename = filename.getBytes();
        byte[] contentfile = toByteArrFromFile(filename);
        byte[] content =
                byteCat(byteCat(byteCat(byteflag, bytelength), bytefilename), contentfile);
        request.setContent(content);

        logger.info("msg:" + Arrays.toString(content));

        System.out.println(
                df.format(LocalDateTime.now())
                        + " request seq:"
                        + String.valueOf(request.getMessageID())
                        + " content length:"
                        + content.length);

        ChannelResponse response = service.sendChannelMessage2(request);

        System.out.println(
                df.format(LocalDateTime.now())
                        + "response seq:"
                        + String.valueOf(response.getMessageID())
                        + ", ErrorCode:"
                        + response.getErrorCode()
                        + ", Content:"
                        + response.getContent());
        if (response.getErrorCode() != 0) {
            System.out.println("Error message" + response.getErrorMessage());
        }
    }
}