List of usage examples for org.apache.thrift TDeserializer TDeserializer
public TDeserializer()
From source file:com.onesite.sdk.api.ApiMethod.java
License:Apache License
/** * Call the API via the OnesiteClient and populate the TBase obj. A OnesiteException * will be returned if an error occured during deserialization of the TBase obj * /*from ww w.j av a 2 s . c o m*/ * @param path * @param params * @param type * * @throws Exception */ protected void get(String path, Map<String, String> params, TBase obj) throws Exception { try { this.client.get(path, params); } catch (Exception e) { log.error("Error occurred during client call to " + path); throw e; } if (this.client.getHttpStatusCode() == HttpStatus.SC_OK) { try { TDeserializer deserializer = new TDeserializer(); deserializer.fromString(obj, this.client.getHttpResult()); Status status = (Status) obj.getFieldValue(obj.fieldForId(1)); if (status.getCode() != OnesiteResultCode.OK) { throw new OnesiteException(status.getCode(), status.getMessage()); } } catch (Exception e) { throw new Exception("Error deserializing result ", e); } } else { throw new OnesiteException(this.client.getHttpStatusCode(), this.client.getHttpStatusMessage()); } }
From source file:com.vmware.photon.controller.common.zookeeper.ZookeeperHostReader.java
License:Open Source License
/** * @param data the znode payload/*from w w w. ja v a2 s .c om*/ * @return the Inet address of the host captured in the payload. */ public InetSocketAddress deserialize(byte[] data) { HostConfig config = new HostConfig(); try { new TDeserializer().deserialize(config, data); } catch (TException e) { throw new RuntimeException(e); } return new InetSocketAddress(config.getAddress().getHost(), config.getAddress().getPort()); }
From source file:com.vmware.photon.controller.common.zookeeper.ZookeeperServiceReader.java
License:Open Source License
/** * @param data the znode payload//from w ww. jav a 2 s . c om * @return the service ip address */ public InetSocketAddress deserialize(byte[] data) { ServerAddress serverAddress = new ServerAddress(); try { new TDeserializer().deserialize(serverAddress, data); } catch (TException e) { throw new RuntimeException(e); } return new InetSocketAddress(serverAddress.getHost(), serverAddress.getPort()); }
From source file:ezbake.deployer.impl.HdfsArtifactWriter.java
License:Apache License
@Override public DeploymentArtifact readArtifact(DeploymentMetadata metadata) throws DeploymentException { Path artifactPath = createPath(ArtifactHelpers.getFqAppId(metadata), metadata.getVersion()); DeploymentArtifact artifact = new DeploymentArtifact(); try {//w w w . j a va 2s. c o m if (!fs.exists(artifactPath)) { throw new DeploymentException("Could not find artifact at " + artifactPath.toString()); } FSDataInputStream input = fs.open(artifactPath); byte[] artifactBytes = ByteStreams.toByteArray(input); input.close(); TDeserializer deserializer = new TDeserializer(); deserializer.deserialize(artifact, artifactBytes); } catch (IOException e) { logger.error("Could not read data from : " + artifactPath.toString(), e); throw new DeploymentException(e.getMessage()); } catch (TException e) { logger.error("Could not deserialize artifact!", e); throw new DeploymentException(e.getMessage()); } return artifact; }
From source file:ezbake.deployer.impl.LocalFileArtifactWriter.java
License:Apache License
@Override public DeploymentArtifact readArtifact(DeploymentMetadata metadata) throws DeploymentException { File artifactFile = new File(buildFilePath(metadata)); DeploymentArtifact artifact = new DeploymentArtifact(); if (artifactFile.exists()) { TDeserializer deserializer = new TDeserializer(); try {// w w w .ja v a 2s . com byte[] fileBytes = FileUtils.readFileToByteArray(artifactFile); deserializer.deserialize(artifact, fileBytes); } catch (Exception ex) { log.error("Failed reading artifact", ex); throw new DeploymentException("Failed to read artifact file from disk." + ex.getMessage()); } } else { log.warn("The artifact {} {} could not be loaded from disk. Only metadata is available", ArtifactHelpers.getAppId(metadata), ArtifactHelpers.getServiceId(metadata)); artifact.setMetadata(metadata); } return artifact; }
From source file:ezbake.intents.common.RedisUtils.java
License:Apache License
/** * Constructor//from w w w. j av a 2 s . c o m * * @param configuration - EZConfiguration object which has Redis configuration */ public RedisUtils(EzConfiguration configuration) { String redisHost = configuration.getProperties().getProperty(EzBakePropertyConstants.REDIS_HOST); int redisPort = Integer .parseInt(configuration.getProperties().getProperty(EzBakePropertyConstants.REDIS_PORT)); appLog.info("Redis Host ({}) Redis Port({})", redisHost, redisPort); jedisPool = new JedisPool(redisHost, redisPort); deserializer = new TDeserializer(); }
From source file:ezbake.security.EzSecurityClientIT.java
License:Apache License
@Test public void testValidateReceivedToken() throws PKeyCryptoException, TException, IOException { ProxyPrincipal dn = getSignedPrincipal(DN); EzSecurityToken info = ezbakeSecurityClient.fetchTokenForProxiedUser(dn, App); byte[] bytes = new TSerializer().serialize(info); EzSecurityToken token = new EzSecurityToken(); new TDeserializer().deserialize(token, bytes); ezbakeSecurityClient.validateReceivedToken(token); }
From source file:ezbake.security.EzSecurityClientIT.java
License:Apache License
@Test public void testValidateReceivedTokenFutureCompatibility() throws PKeyCryptoException, TException, IOException { ProxyPrincipal dn = getSignedPrincipal(DN); EzSecurityToken info = ezbakeSecurityClient.fetchTokenForProxiedUser(dn, App); byte[] bytes = new TSerializer().serialize(info); EzSecurityToken token = new EzSecurityToken(); new TDeserializer().deserialize(token, bytes); ezbakeSecurityClient.validateReceivedToken(token); }
From source file:ezbake.security.EzSecurityClientIT.java
License:Apache License
@Test public void testValidateReceivedTokenFuture() throws PKeyCryptoException, TException, IOException { ProxyPrincipal dn = getSignedPrincipal(DN); EzSecurityToken info = ezbakeSecurityClient.fetchTokenForProxiedUser(dn, App); byte[] bytes = new TSerializer().serialize(info); EzSecurityToken token = new EzSecurityToken(); new TDeserializer().deserialize(token, bytes); ezbakeSecurityClient.validateReceivedToken(token); }
From source file:ezbake.services.graph.archive.AccumuloTransactionArchive.java
License:Apache License
@Override public void init(Properties properties) throws TransactionArchiveException { final AccumuloHelper helper = new AccumuloHelper(properties); tableName = TABLENAME_DEFAULT;// w w w . j a va 2 s . c om try { connector = helper.getConnector(false); if (!connector.tableOperations().exists(tableName)) { connector.tableOperations().create(tableName); } final BatchWriterConfig bwc = new BatchWriterConfig(); bwc.setMaxMemory(MAX_BATCHWRITER_MEMORY); bwc.setMaxWriteThreads(MAX_BATCHWRITER_THREADS); bwc.setMaxLatency(Long.MAX_VALUE, TimeUnit.MILLISECONDS); writer = connector.createBatchWriter(tableName, bwc); } catch (final TableNotFoundException ex) { throw new TransactionArchiveException(ex); } catch (final AccumuloException ex) { throw new TransactionArchiveException(ex); } catch (final AccumuloSecurityException ex) { throw new TransactionArchiveException(ex); } catch (final TableExistsException ex) { throw new TransactionArchiveException(ex); } catch (final IOException ex) { throw new TransactionArchiveException(ex); } tSerializer = new TSerializer(); tDeserializer = new TDeserializer(); }