Java Code Examples for com.google.protobuf.InvalidProtocolBufferException#printStackTrace()
The following examples show how to use
com.google.protobuf.InvalidProtocolBufferException#printStackTrace() .
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: TestKitGrpcClientErrorUtils.java From titus-control-plane with Apache License 2.0 | 6 votes |
private static void print(Any any) { Descriptors.Descriptor descriptor = any.getDescriptorForType(); Descriptors.FieldDescriptor typeUrlField = descriptor.findFieldByName("type_url"); String typeUrl = (String) any.getField(typeUrlField); Class type; if (typeUrl.contains(DebugInfo.class.getSimpleName())) { type = DebugInfo.class; } else if (typeUrl.contains(BadRequest.class.getSimpleName())) { type = BadRequest.class; } else { System.out.println("Unknown detail type " + typeUrl); return; } try { System.out.printf("Detail %s:\n", type); System.out.println(any.unpack(type)); } catch (InvalidProtocolBufferException e) { System.out.println("Something went wrong with detail parsing"); e.printStackTrace(); } }
Example 2
Source File: TransactionUtil.java From chain33-sdk-java with BSD 2-Clause "Simplified" License | 6 votes |
/** * * @description 本地创建token完成交易 * @param symbol token地址 * @param execer user.p.xxx.token * @param ownerAddr token拥有者地址 * @param managerPrivateKey 超级管理员私钥 * @return 交易 * */ public static String createTokenFinishTx(String symbol, String execer, String ownerAddr, String managerPrivateKey) { TokenActionProtoBuf.TokenFinishCreate.Builder payloadBuilder = TokenActionProtoBuf.TokenFinishCreate .newBuilder(); payloadBuilder.setSymbol(symbol); payloadBuilder.setOwner(ownerAddr); TokenFinishCreate tokenFinishCreate = payloadBuilder.build(); TokenActionProtoBuf.TokenAction.Builder tokenActionBuilder = TokenActionProtoBuf.TokenAction.newBuilder(); tokenActionBuilder.setTy(8); tokenActionBuilder.setTokenFinishCreate(tokenFinishCreate); TokenAction tokenAction = tokenActionBuilder.build(); String createTxWithoutSign = TransactionUtil.createTxWithoutSign(execer.getBytes(), tokenAction.toByteArray(), DEFAULT_FEE, 0); byte[] fromHexString = HexUtil.fromHexString(createTxWithoutSign); TransactionProtoBuf.Transaction parseFrom = null; try { parseFrom = TransactionProtoBuf.Transaction.parseFrom(fromHexString); } catch (InvalidProtocolBufferException e) { e.printStackTrace(); } TransactionProtoBuf.Transaction signProbuf = TransactionUtil.signProbuf(parseFrom, managerPrivateKey); String hexString = HexUtil.toHexString(signProbuf.toByteArray()); return hexString; }
Example 3
Source File: TransactionProcessor.java From sawtooth-sdk-java with Apache License 2.0 | 6 votes |
/** * Find the handler that should be used to process the given message. * * @param message The message that has the TpProcessRequest that the header that will be checked * against the handler. * @return the handler that should be used to processor the given message */ private TransactionHandler findHandler(final Message message) { try { TpProcessRequest transactionRequest = TpProcessRequest.parseFrom(this.currentMessage.getContent()); TransactionHeader header = transactionRequest.getHeader(); for (int i = 0; i < this.handlers.size(); i++) { TransactionHandler handler = this.handlers.get(i); if (header.getFamilyName().equals(handler.transactionFamilyName()) && header.getFamilyVersion().equals(handler.getVersion())) { return handler; } } LOGGER.info("Missing handler for header: " + header.toString()); } catch (InvalidProtocolBufferException ipbe) { LOGGER.info("Received Message that isn't a TransactionProcessRequest"); ipbe.printStackTrace(); } return null; }
Example 4
Source File: TransactionUtil.java From chain33-sdk-java with BSD 2-Clause "Simplified" License | 6 votes |
/** * 创建并签名管理合约交易 * @param key * @param value * @param op 操作符,add或delete * @return */ public static String createManage(String key, String value, String op, String privateKey, String execer) { Builder managerBuilder = ManageProtobuf.ModifyConfig.newBuilder(); managerBuilder.setKey(key); managerBuilder.setValue(value); managerBuilder.setOp(op); cn.chain33.javasdk.model.protobuf.ManageProtobuf.ManageAction.Builder actionBuilder = ManageProtobuf.ManageAction.newBuilder(); actionBuilder.setTy(0); actionBuilder.setModify(managerBuilder.build()); ManageAction managerAction = actionBuilder.build(); String createTxWithoutSign = TransactionUtil.createTxWithoutSign(execer.getBytes(), managerAction.toByteArray(), DEFAULT_FEE, 0); byte[] fromHexString = HexUtil.fromHexString(createTxWithoutSign); TransactionProtoBuf.Transaction parseFrom = null; try { parseFrom = TransactionProtoBuf.Transaction.parseFrom(fromHexString); } catch (InvalidProtocolBufferException e) { e.printStackTrace(); return null; } TransactionProtoBuf.Transaction signProbuf = signProbuf(parseFrom, privateKey); return HexUtil.toHexString(signProbuf.toByteArray()); }
Example 5
Source File: EncryptSetupManager.java From apollo-DuerOS with Apache License 2.0 | 6 votes |
public void getAESKey(Message msg) { CarlifeCmdMessage aesKey = (CarlifeCmdMessage) msg.obj; CarlifeMdAesKeyRequestProto.CarlifeMdAesKeyRequest aesKeyRequest = null; try { aesKeyRequest = CarlifeMdAesKeyRequestProto.CarlifeMdAesKeyRequest.parseFrom(aesKey.getData()); } catch (InvalidProtocolBufferException e) { e.printStackTrace(); } if (aesKeyRequest == null) { return; } String aesKeyStr = mRSAManager.decrypt(aesKeyRequest.getAesKey(), mRSAManager.getPrivateKey()); setAesKey(aesKeyStr); DebugLogUtil.getInstance().println("AES key: " + getAesKey()); }
Example 6
Source File: ESPDevice.java From esp-idf-provisioning-android with Apache License 2.0 | 6 votes |
private Object[] processProvisioningStatusResponse(byte[] responseData) { WifiConstants.WifiStationState wifiStationState = WifiConstants.WifiStationState.Disconnected; WifiConstants.WifiConnectFailedReason failedReason = WifiConstants.WifiConnectFailedReason.UNRECOGNIZED; if (responseData == null) { return new Object[]{wifiStationState, failedReason}; } try { WifiConfig.WiFiConfigPayload wiFiConfigPayload = WifiConfig.WiFiConfigPayload.parseFrom(responseData); wifiStationState = wiFiConfigPayload.getRespGetStatus().getStaState(); failedReason = wiFiConfigPayload.getRespGetStatus().getFailReason(); } catch (InvalidProtocolBufferException e) { e.printStackTrace(); } return new Object[]{wifiStationState, failedReason}; }
Example 7
Source File: TxUtils.java From julongchain with Apache License 2.0 | 5 votes |
public static Common.Envelope getEnvelopeFromBlock(byte[] data) { Common.Envelope envelope= null; try { envelope = Common.Envelope.parseFrom(data); } catch (InvalidProtocolBufferException e) { e.printStackTrace(); } return envelope; }
Example 8
Source File: CommonUtils.java From julongchain with Apache License 2.0 | 5 votes |
public static Common.Envelope unmarshalEnvelope(byte[] encoded) { Common.Envelope envelope = null; try { envelope = Common.Envelope.parseFrom(encoded); } catch (InvalidProtocolBufferException e) { e.printStackTrace(); } return envelope; }
Example 9
Source File: Utils.java From julongchain with Apache License 2.0 | 5 votes |
public static Common.GroupHeader unmarshalGroupHeader(byte[] bytes) { Common.GroupHeader groupHeader = null; try { groupHeader = Common.GroupHeader.parseFrom(bytes); } catch (InvalidProtocolBufferException e) { e.printStackTrace(); } return groupHeader; }
Example 10
Source File: JRedisSerializationUtils.java From springJredisCache with Apache License 2.0 | 5 votes |
/** * @param bytes 字节数据 * @param messageLite 序列化对应的类型 * @return * @throws JRedisCacheException */ public static MessageLite protoDeserialize(byte[] bytes, MessageLite messageLite) throws JRedisCacheException { assert (bytes != null && messageLite != null); try { return messageLite.getParserForType().parsePartialFrom(CodedInputStream.newInstance(bytes), ExtensionRegistryLite.getEmptyRegistry()); } catch (InvalidProtocolBufferException e) { e.printStackTrace(); return null; } }
Example 11
Source File: ConfirmTransactionActivity.java From tron-wallet-android with Apache License 2.0 | 5 votes |
@Override public void onActivityResult(int requestCode, int resultCode, Intent data) { if(resultCode == SignTransactionActivity.TRANSACTION_SIGN_REQUEST_CODE) { byte[] transactionData = data.getByteArrayExtra(SignTransactionActivity.TRANSACTION_SIGNED_EXTRA); try { mTransactionSigned = Protocol.Transaction.parseFrom(transactionData); } catch (InvalidProtocolBufferException e) { e.printStackTrace(); } updateConfirmButton(); setupBandwidth(); } }
Example 12
Source File: FreezeContractFragment.java From tron-wallet-android with Apache License 2.0 | 5 votes |
@Override public void setContract(Protocol.Transaction.Contract contract) { try { mContract = TransactionUtils.unpackContract(contract, Contract.FreezeBalanceContract.class); updateUI(); } catch (InvalidProtocolBufferException e) { e.printStackTrace(); } }
Example 13
Source File: KafkaMessageDeserializer.java From binlake with Apache License 2.0 | 5 votes |
public KafkaEntryMessage deserialize(String s, byte[] bytes) { try { WaveEntry.Entry entry = WaveEntry.Entry.parseFrom(bytes); KafkaEntryMessage kafkaEntryMessage = new KafkaEntryMessage(entry); switch (entry.getEntryType()) { case TRANSACTIONBEGIN: WaveEntry.TransactionBegin begin = WaveEntry.TransactionBegin.parseFrom(entry.getStoreValue()); kafkaEntryMessage.setEntryType(WaveEntry.EntryType.TRANSACTIONBEGIN); kafkaEntryMessage.setBegin(begin); break; case TRANSACTIONEND: WaveEntry.TransactionEnd end = WaveEntry.TransactionEnd.parseFrom(entry.getStoreValue()); kafkaEntryMessage.setEntryType(WaveEntry.EntryType.TRANSACTIONEND); kafkaEntryMessage.setEnd(end); break; case HEARTBEAT: break; case ROWDATA: WaveEntry.RowChange rowChange = WaveEntry.RowChange.parseFrom(entry.getStoreValue()); kafkaEntryMessage.setEntryType(WaveEntry.EntryType.ROWDATA); kafkaEntryMessage.setRowChange(rowChange); break; } return kafkaEntryMessage; } catch (InvalidProtocolBufferException e) { e.printStackTrace(); } return null; }
Example 14
Source File: DFClusterActor.java From dfactor with MIT License | 5 votes |
private void _procRpcCallFail(int cmd, ByteBuf buf){ //headLen(2) + head(N) + userCmd(4) + userDataType(1) + userData(N) int headLen = buf.readShort(); byte[] bufHead = new byte[headLen]; buf.readBytes(bufHead); DMCluster.UserMsgHead head = null; try { head = DMCluster.UserMsgHead.parseFrom(bufHead); } catch (InvalidProtocolBufferException e) { e.printStackTrace(); return ; } _mgrActor.send(id, head.getDstActor(), head.getSessionId(), DFActorDefine.SUBJECT_CB_FAILED, RpcError.REMOTE_FAILED, null, true, null, null); }
Example 15
Source File: DemoCapillaryHandler.java From capillary with Apache License 2.0 | 5 votes |
/** * Shows the decrypted message as an Android notification. */ @Override public void handleData(boolean isAuthKey, byte[] data, Object extra) { try { SecureNotification secureNotification = SecureNotification.parseFrom(data); Utils.showNotification(context, secureNotification); } catch (InvalidProtocolBufferException e) { e.printStackTrace(); } }
Example 16
Source File: ESSCTest.java From julongchain with Apache License 2.0 | 5 votes |
@Test public void transformProtobuf() { try { ProposalResponsePackage.Response successResponse = ProposalResponsePackage.Response.newBuilder(). setStatus(200).setMessage("OK").setPayload(ByteString.copyFromUtf8("payload")).build(); ByteString byteString = successResponse.toByteString(); ProposalResponsePackage.Response transformedResponse = ProposalResponsePackage.Response.parseFrom(byteString); assertThat(transformedResponse.getStatus(),is(200)); ProposalResponsePackage.Response successResponse2 = ProposalResponsePackage.Response.newBuilder(). setStatus(200).setMessage("OK").setPayload(ByteString.copyFromUtf8("payload")).build(); ByteString byteString2 = successResponse.toByteString(); String string2=byteString2.toStringUtf8(); ByteString transformByteString=ByteString.copyFromUtf8(string2); ProposalResponsePackage.Response transformedResponse2 = ProposalResponsePackage.Response.parseFrom(transformByteString); assertThat(transformedResponse2.getStatus(),not(200)); ProposalResponsePackage.Response successResponse3= ProposalResponsePackage.Response.newBuilder(). setStatus(200).setMessage("OK").setPayload(ByteString.copyFromUtf8("payload")).build(); ByteString byteString3 = successResponse.toByteString(); byte[] byteArray3 = byteString3.toByteArray(); ProposalResponsePackage.Response transformedResponse3 = ProposalResponsePackage.Response.parseFrom(byteArray3); assertThat(transformedResponse3.getStatus(),is(200)); } catch (InvalidProtocolBufferException e) { e.printStackTrace(); } }
Example 17
Source File: SendReceiveThread.java From sawtooth-sdk-java with Apache License 2.0 | 5 votes |
@Override public int handle(final ZLoop loop, final ZMQ.PollItem item, final Object arg) { ZMsg msg = ZMsg.recvMsg(item.getSocket()); Iterator<ZFrame> multiPartMessage = msg.iterator(); ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); while (multiPartMessage.hasNext()) { ZFrame frame = multiPartMessage.next(); try { byteArrayOutputStream.write(frame.getData()); } catch (IOException ioe) { ioe.printStackTrace(); } } try { Message message = Message.parseFrom(byteArrayOutputStream.toByteArray()); if (this.futures.containsKey(message.getCorrelationId())) { Future future = this.futures.get(message.getCorrelationId()); future.setResult(message.getContent()); this.futures.remove(message.getCorrelationId(), future); } else { MessageWrapper wrapper = new MessageWrapper(message); this.receiveQueue.put(wrapper); } } catch (InterruptedException ie) { ie.printStackTrace(); } catch (InvalidProtocolBufferException ipe) { ipe.printStackTrace(); } catch (ValidatorConnectionError vce) { vce.printStackTrace(); } return 0; }
Example 18
Source File: TCPClientReadThread.java From game-server with MIT License | 4 votes |
/** * @param key * @throws IOException */ public void read(SelectionKey key) throws IOException { SocketChannel channel = (SocketChannel) key.channel(); try { ByteBuffer buffer = ByteBuffer.allocate(1024); int count = channel.read(buffer); if (count < 4) { return; } buffer.flip(); buffer.mark(); // 读取short len byte[] dst = new byte[2]; buffer.get(dst, 0, 2); int len = IntUtil.bytes2Short(dst, ByteOrder.LITTLE_ENDIAN); int lastLen = buffer.remaining(); if (lastLen < len) { buffer.reset(); return; } // 读取int mid dst = new byte[4]; buffer.get(dst, 0, 4); int mid = IntUtil.bytes2Int(dst, ByteOrder.LITTLE_ENDIAN); System.out.println("mid: " + mid); // 读取冗余的protobuf len dst = new byte[4]; buffer.get(dst, 0, 4); int protobufLen = IntUtil.bytes2Int(dst, ByteOrder.LITTLE_ENDIAN); // System.out.println("protobufLen: " + protobufLen); byte[] bytes = new byte[protobufLen]; buffer.get(bytes, 0, protobufLen); buffer.clear(); for (byte c : bytes) { System.out.print(c + ","); } System.out.println(); parseResponse(mid, bytes); } catch (InvalidProtocolBufferException e) { e.printStackTrace(); } }
Example 19
Source File: AccountTest.java From chain33-sdk-java with BSD 2-Clause "Simplified" License | 4 votes |
/** * 注册账户,并查询 * * @throws Exception */ @Test public void registeAndQueryAccount() throws Exception { String accountId = "testAccount2"; AccountInfo accountInfo = account.newAccountLocal(); String createTxWithoutSign = client.registeAccount("accountmanager", "Register", accountId); byte[] fromHexString = HexUtil.fromHexString(createTxWithoutSign); TransactionProtoBuf.Transaction parseFrom = null; try { parseFrom = TransactionProtoBuf.Transaction.parseFrom(fromHexString); } catch (InvalidProtocolBufferException e) { e.printStackTrace(); } TransactionProtoBuf.Transaction signProbuf = TransactionUtil.signProbuf(parseFrom, accountInfo.getPrivateKey()); String hexString = HexUtil.toHexString(signProbuf.toByteArray()); String submitTransaction = client.submitTransaction(hexString); System.out.println(submitTransaction); // 一般1秒一个区块 QueryTransactionResult queryTransaction1; for (int i = 0; i < 5; i++) { queryTransaction1 = client.queryTransaction(submitTransaction); if (null == queryTransaction1) { Thread.sleep(1000); } else { break; } } // 根据accountId查询账户信息 JSONObject resultJson = client.queryAccountById(accountId); System.out.println("账户ID:" + resultJson.getString("accountID")); System.out.println("过期时间:" + resultJson.getString("expireTime")); System.out.println("创建时间:" + resultJson.getString("createTime")); // 账户状态 0 正常, 1表示冻结, 2表示锁定 3,过期注销 System.out.println("账户状态:" + resultJson.getString("status")); //等级权限 0普通,后面根据业务需要可以自定义,有管理员授予不同的权限 System.out.println("等级权限:" + resultJson.getString("level")); // 账户地址 System.out.println("地址:" + resultJson.getString("addr")); // 根据状态查账户信息 String status = "0"; resultJson = client.queryAccountByStatus(status); System.out.println(resultJson); }
Example 20
Source File: AccountTest.java From chain33-sdk-java with BSD 2-Clause "Simplified" License | 4 votes |
/** * 账户操作 * * @param accountIds * @param op * @param level * @throws Exception */ private void manageAccount(String[] accountIds, String op, String level) throws Exception { String createTxWithoutSign = client.authAccount("accountmanager", "Supervise", accountIds, op, level); byte[] fromHexString = HexUtil.fromHexString(createTxWithoutSign); TransactionProtoBuf.Transaction parseFrom = null; try { parseFrom = TransactionProtoBuf.Transaction.parseFrom(fromHexString); } catch (InvalidProtocolBufferException e) { e.printStackTrace(); } TransactionProtoBuf.Transaction signProbuf = TransactionUtil.signProbuf(parseFrom, "3990969DF92A5914F7B71EEB9A4E58D6E255F32BF042FEA5318FC8B3D50EE6E8"); String hexString = HexUtil.toHexString(signProbuf.toByteArray()); String submitTransaction = client.submitTransaction(hexString); System.out.println(submitTransaction); // 一般1秒一个区块 QueryTransactionResult queryTransaction1; for (int i = 0; i < 5; i++) { queryTransaction1 = client.queryTransaction(submitTransaction); if (null == queryTransaction1) { Thread.sleep(1000); } else { break; } } // 根据accountId查询账户信息 JSONObject resultJson = client.queryAccountById(accountIds[0]); System.out.println("账户ID:" + resultJson.getString("accountID")); System.out.println("过期时间:" + resultJson.getString("expireTime")); System.out.println("创建时间:" + resultJson.getString("createTime")); // 账户状态 0 正常, 1表示冻结, 2表示锁定 3,过期注销 System.out.println("账户状态:" + resultJson.getString("status")); //等级权限 0普通,后面根据业务需要可以自定义,有管理员授予不同的权限 System.out.println("等级权限:" + resultJson.getString("level")); // 账户地址 System.out.println("地址:" + resultJson.getString("addr")); }