Java Code Examples for org.apache.thrift.TException#getMessage()

The following examples show how to use org.apache.thrift.TException#getMessage() . 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: ThriftNativeCodec.java    From dubbo-2.6.5 with Apache License 2.0 6 votes vote down vote up
protected void encodeRequest(Channel channel, ChannelBuffer buffer, Request request)
        throws IOException {
    Invocation invocation = (Invocation) request.getData();
    TProtocol protocol = newProtocol(channel.getUrl(), buffer);
    try {
        protocol.writeMessageBegin(new TMessage(
                invocation.getMethodName(), TMessageType.CALL,
                thriftSeq.getAndIncrement()));
        protocol.writeStructBegin(new TStruct(invocation.getMethodName() + "_args"));
        for (int i = 0; i < invocation.getParameterTypes().length; i++) {
            Class<?> type = invocation.getParameterTypes()[i];

        }
    } catch (TException e) {
        throw new IOException(e.getMessage(), e);
    }

}
 
Example 2
Source File: ThriftNativeCodec.java    From dubbox with Apache License 2.0 6 votes vote down vote up
protected void encodeRequest(Channel channel, ChannelBuffer buffer, Request request)
    throws IOException {
    Invocation invocation = (Invocation) request.getData();
    TProtocol protocol = newProtocol(channel.getUrl(), buffer);
    try {
        protocol.writeMessageBegin(new TMessage(
            invocation.getMethodName(), TMessageType.CALL, 
            thriftSeq.getAndIncrement()));
        protocol.writeStructBegin(new TStruct(invocation.getMethodName() + "_args"));
        for(int i = 0; i < invocation.getParameterTypes().length; i++) {
            Class<?> type = invocation.getParameterTypes()[i];

        }
    } catch (TException e) {
        throw new IOException(e.getMessage(), e);
    }

}
 
Example 3
Source File: ThriftNativeCodec.java    From dubbox-hystrix with Apache License 2.0 6 votes vote down vote up
protected void encodeRequest(Channel channel, ChannelBuffer buffer, Request request)
    throws IOException {
    Invocation invocation = (Invocation) request.getData();
    TProtocol protocol = newProtocol(channel.getUrl(), buffer);
    try {
        protocol.writeMessageBegin(new TMessage(
            invocation.getMethodName(), TMessageType.CALL, 
            thriftSeq.getAndIncrement()));
        protocol.writeStructBegin(new TStruct(invocation.getMethodName() + "_args"));
        for(int i = 0; i < invocation.getParameterTypes().length; i++) {
            Class<?> type = invocation.getParameterTypes()[i];

        }
    } catch (TException e) {
        throw new IOException(e.getMessage(), e);
    }

}
 
Example 4
Source File: ThriftNativeCodec.java    From dubbox with Apache License 2.0 6 votes vote down vote up
protected void encodeRequest(Channel channel, ChannelBuffer buffer, Request request)
    throws IOException {
    Invocation invocation = (Invocation) request.getData();
    TProtocol protocol = newProtocol(channel.getUrl(), buffer);
    try {
        protocol.writeMessageBegin(new TMessage(
            invocation.getMethodName(), TMessageType.CALL, 
            thriftSeq.getAndIncrement()));
        protocol.writeStructBegin(new TStruct(invocation.getMethodName() + "_args"));
        for(int i = 0; i < invocation.getParameterTypes().length; i++) {
            Class<?> type = invocation.getParameterTypes()[i];

        }
    } catch (TException e) {
        throw new IOException(e.getMessage(), e);
    }

}
 
Example 5
Source File: ThriftNativeCodec.java    From dubbox with Apache License 2.0 6 votes vote down vote up
protected void encodeRequest(Channel channel, ChannelBuffer buffer, Request request)
    throws IOException {
    Invocation invocation = (Invocation) request.getData();
    TProtocol protocol = newProtocol(channel.getUrl(), buffer);
    try {
        protocol.writeMessageBegin(new TMessage(
            invocation.getMethodName(), TMessageType.CALL, 
            thriftSeq.getAndIncrement()));
        protocol.writeStructBegin(new TStruct(invocation.getMethodName() + "_args"));
        for(int i = 0; i < invocation.getParameterTypes().length; i++) {
            Class<?> type = invocation.getParameterTypes()[i];

        }
    } catch (TException e) {
        throw new IOException(e.getMessage(), e);
    }

}
 
Example 6
Source File: AgentEventMessageSerializer.java    From pinpoint with Apache License 2.0 5 votes vote down vote up
public byte[] serialize(AgentEventType agentEventType, Object eventMessage) throws UnsupportedEncodingException {
    if (agentEventType == null) {
        throw new NullPointerException("agentEventType");
    }

    Class<?> eventMessageType = agentEventType.getMessageType();
    if (eventMessageType == Void.class) {
        return EMPTY_BYTES;
    } else {
        if (eventMessage == null) {
            throw new NullPointerException("eventMessage of type [" + eventMessageType.getName() + "] expected, but was null");
        }
    }

    if (!eventMessageType.isAssignableFrom(eventMessage.getClass())) {
        throw new IllegalArgumentException("Unexpected eventMessage of type [" + eventMessage.getClass().getName() + "] received. Expected : ["
                + eventMessageType.getClass().getName() + "]");
    }

    if (eventMessage instanceof TBase) {
        for (SerializerFactory serializerFactory : serializerFactoryList) {
            if (serializerFactory.isSupport(eventMessage)) {
                try {
                    return SerializationUtils.serialize((TBase<?, ?>) eventMessage, serializerFactory);
                } catch (TException e) {
                    throw new UnsupportedEncodingException(e.getMessage());
                }
            }
        }
    } else if (eventMessage instanceof String) {
        return BytesUtils.toBytes((String) eventMessage);
    }
    throw new UnsupportedEncodingException("Unsupported event message type [" + eventMessage.getClass().getName() + "]");
}
 
Example 7
Source File: ThriftBmiBridge.java    From OpenDA with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public String[] getOutputVarNames() throws BMIModelException {
	try {
		List<String> result = client.get_output_var_names();
		return result.toArray(new String[result.size()]);
	} catch (TException e) {
		throw new BMIModelException("failed to execute function on remote model: " + e.getMessage(), e);
	}

}
 
Example 8
Source File: HiveClientWrapper.java    From pxf with Apache License 2.0 5 votes vote down vote up
private List<Metadata.Item> getTablesFromPattern(IMetaStoreClient client, String dbPattern, String tablePattern) {

        List<String> databases;
        List<Metadata.Item> itemList = new ArrayList<>();

        if (client == null || (!dbPattern.contains(WILDCARD) && !tablePattern.contains(WILDCARD))) {
            /* This case occurs when the call is invoked as part of the fragmenter api or when metadata is requested for a specific table name */
            itemList.add(new Metadata.Item(dbPattern, tablePattern));
            return itemList;
        }

        try {
            databases = client.getDatabases(dbPattern);
            if (databases.isEmpty()) {
                LOG.warn("No database found for the given pattern: " + dbPattern);
                return null;
            }
            for (String dbName : databases) {
                for (String tableName : client.getTables(dbName, tablePattern)) {
                    itemList.add(new Metadata.Item(dbName, tableName));
                }
            }
            return itemList;

        } catch (TException cause) {
            throw new RuntimeException("Failed connecting to Hive MetaStore service: " + cause.getMessage(), cause);
        }
    }
 
Example 9
Source File: Util.java    From parquet-mr with Apache License 2.0 5 votes vote down vote up
private static <T extends TBase<?,?>> T read(InputStream from, T tbase) throws IOException {
  try {
    tbase.read(protocol(from));
    return tbase;
  } catch (TException e) {
    throw new IOException("can not read " + tbase.getClass() + ": " + e.getMessage(), e);
  }
}
 
Example 10
Source File: TransactionServiceClient.java    From phoenix-tephra with Apache License 2.0 5 votes vote down vote up
/**
 * This is a generic method implementing the somewhat complex execution
 * and retry logic for operations, to avoid repetitive code.
 *
 * Attempts to execute one operation, by obtaining an tx client from
 * the client provider and passing the operation to the client. If the
 * call fails with a Thrift exception, apply the retry strategy. If no
 * more retries are to be made according to the strategy, call the
 * operation's error method to obtain a value to return. Note that error()
 * may also throw an exception. Note also that the retry logic is only
 * applied for thrift exceptions.
 *
 * @param operation The operation to be executed
 * @param provider An tx client provider. If null, then a client will be
 *                 obtained using the client provider
 * @param <T> The return type of the operation
 * @return the result of the operation, or a value returned by error()
 */
private <T> T execute(Operation<T> operation, ThriftClientProvider provider) throws Exception {
  RetryStrategy retryStrategy = retryStrategyProvider.newRetryStrategy();
  while (true) {
    // did we get a custom client provider or do we use the default?
    if (provider == null) {
      provider = this.clientProvider;
    }
    // this will throw a TException if it cannot get a client
    try (CloseableThriftClient closeable = provider.getCloseableClient()) {
      // note that this can throw exceptions other than TException
      return operation.execute(closeable.getThriftClient());

    } catch (TException te) {
      // determine whether we should retry
      boolean retry = retryStrategy.failOnce();
      if (!retry) {
        // retry strategy is exceeded, throw an operation exception
        String message =
            "Thrift error for " + operation + ": " + te.getMessage();
        LOG.error(message);
        LOG.debug(message, te);
        throw te;
      } else {
        // call retry strategy before retrying
        retryStrategy.beforeRetry();
        String msg = "Retrying " + operation.getName() + " after Thrift error: " + te.getMessage();
        LOG.info(msg);
        LOG.debug(msg, te);
      }
    }
  }
}
 
Example 11
Source File: Util.java    From parquet-format with Apache License 2.0 5 votes vote down vote up
private static <T extends TBase<?,?>> T read(InputStream from, T tbase) throws IOException {
  try {
    tbase.read(protocol(from));
    return tbase;
  } catch (TException e) {
    throw new IOException("can not read " + tbase.getClass() + ": " + e.getMessage(), e);
  }
}
 
Example 12
Source File: WorfKeyMaster.java    From warp10-platform with Apache License 2.0 5 votes vote down vote up
public String deliverReadToken(String application, List<String> applications, String producer, List<String> producers, List<String> owners, Map<String,String> labels, long ttl) throws WorfException {
  try {
    return encoder.deliverReadToken(application, producer, owners, producers, applications, labels, null, ttl, keyStore);
  } catch (TException e) {
   throw new WorfException("Unable to deliver read token cause=" + e.getMessage());
  }
}
 
Example 13
Source File: WorfKeyMaster.java    From warp10-platform with Apache License 2.0 5 votes vote down vote up
public String deliverWriteToken(String application, String producer, String owner, Map<String,String> labels, long ttl) throws WorfException {
  try {
    // add label only if the map contains values
    Map<String,String> fixedLabels = null;

    if (null != labels && labels.size() > 0) {
      fixedLabels = labels;
    }
    return encoder.deliverWriteToken(application, producer, owner, fixedLabels, ttl, keyStore);
  } catch (TException e) {
    throw new WorfException("Unable to deliver write token cause=" + e.getMessage());
  }
}
 
Example 14
Source File: AgentCommandController.java    From pinpoint with Apache License 2.0 4 votes vote down vote up
@RequestMapping(value = "/activeThreadLightDump", method = RequestMethod.GET)
@ResponseBody
public CodeResult getActiveThreadLightDump(@RequestParam(value = "applicationName") String applicationName,
                                             @RequestParam(value = "agentId") String agentId,
                                             @RequestParam(value = "limit", required = false, defaultValue = "-1") int limit,
                                             @RequestParam(value = "threadName", required = false) String[] threadNameList,
                                             @RequestParam(value = "localTraceId", required = false) Long[] localTraceIdList) throws TException {
    if (!webProperties.isEnableActiveThreadDump()) {
        return new CodeResult(CODE_FAIL, "Disable activeThreadDump option. 'config.enable.activeThreadDump=false'");
    }

    AgentInfo agentInfo = agentService.getAgentInfo(applicationName, agentId);
    if (agentInfo == null) {
        return new CodeResult(CODE_FAIL, String.format("Can't find suitable Agent(%s/%s)", applicationName, agentId));
    }

    TCmdActiveThreadLightDump threadDump = new TCmdActiveThreadLightDump();
    if (limit > 0) {
        threadDump.setLimit(limit);
    }
    if (threadNameList != null) {
        threadDump.setThreadNameList(Arrays.asList(threadNameList));
    }
    if (localTraceIdList != null) {
        threadDump.setLocalTraceIdList(Arrays.asList(localTraceIdList));
    }

    try {
        PinpointRouteResponse pinpointRouteResponse = agentService.invoke(agentInfo, threadDump);
        if (isSuccessResponse(pinpointRouteResponse)) {
            TBase<?, ?> result = pinpointRouteResponse.getResponse();
            if (result instanceof TCmdActiveThreadLightDumpRes) {
                TCmdActiveThreadLightDumpRes activeThreadDumpResponse = (TCmdActiveThreadLightDumpRes) result;
                List<TActiveThreadLightDump> activeThreadDumps = activeThreadDumpResponse.getThreadDumps();

                AgentActiveThreadDumpFactory factory = new AgentActiveThreadDumpFactory();
                AgentActiveThreadDumpList activeThreadDumpList = factory.create2(activeThreadDumps);

                Map<String, Object> responseData = createResponseData(activeThreadDumpList, activeThreadDumpResponse.getType(), activeThreadDumpResponse.getSubType(), activeThreadDumpResponse.getVersion());
                return new CodeResult(CODE_SUCCESS, responseData);
            }
        }
        return handleFailedResponse(pinpointRouteResponse);
    } catch (TException e) {
        return new CodeResult(CODE_FAIL, e.getMessage());
    }
}
 
Example 15
Source File: AgentCommandController.java    From pinpoint with Apache License 2.0 4 votes vote down vote up
@RequestMapping(value = "/activeThreadDump", method = RequestMethod.GET)
@ResponseBody
public CodeResult getActiveThreadDump(@RequestParam(value = "applicationName") String applicationName,
                                      @RequestParam(value = "agentId") String agentId,
                                      @RequestParam(value = "limit", required = false, defaultValue = "-1") int limit,
                                      @RequestParam(value = "threadName", required = false) String[] threadNameList,
                                      @RequestParam(value = "localTraceId", required = false) Long[] localTraceIdList) throws TException {
    if (!webProperties.isEnableActiveThreadDump()) {
        return new CodeResult(CODE_FAIL, "Disable activeThreadDump option. 'config.enable.activeThreadDump=false'");
    }

    AgentInfo agentInfo = agentService.getAgentInfo(applicationName, agentId);
    if (agentInfo == null) {
        return new CodeResult(CODE_FAIL, String.format("Can't find suitable Agent(%s/%s)", applicationName, agentId));
    }

    TCmdActiveThreadDump threadDump = new TCmdActiveThreadDump();
    if (limit > 0) {
        threadDump.setLimit(limit);
    }

    if (threadNameList != null) {
        threadDump.setThreadNameList(Arrays.asList(threadNameList));
    }
    if (localTraceIdList != null) {
        threadDump.setLocalTraceIdList(Arrays.asList(localTraceIdList));
    }

    try {
        PinpointRouteResponse pinpointRouteResponse = agentService.invoke(agentInfo, threadDump);
        if (isSuccessResponse(pinpointRouteResponse)) {
            TBase<?, ?> result = pinpointRouteResponse.getResponse();
            if (result instanceof TCmdActiveThreadDumpRes) {
                TCmdActiveThreadDumpRes activeThreadDumpResponse = (TCmdActiveThreadDumpRes) result;
                List<TActiveThreadDump> activeThreadDumps = activeThreadDumpResponse.getThreadDumps();

                AgentActiveThreadDumpFactory factory = new AgentActiveThreadDumpFactory();
                AgentActiveThreadDumpList activeThreadDumpList = factory.create1(activeThreadDumps);

                Map<String, Object> responseData = createResponseData(activeThreadDumpList, activeThreadDumpResponse.getType(), activeThreadDumpResponse.getSubType(), activeThreadDumpResponse.getVersion());
                return new CodeResult(CODE_SUCCESS, responseData);
            }
        }
        return handleFailedResponse(pinpointRouteResponse);
    } catch (TException e) {
        return new CodeResult(CODE_FAIL, e.getMessage());
    }
}
 
Example 16
Source File: ThriftCodec.java    From dubbox with Apache License 2.0 2 votes vote down vote up
public Object decode( Channel channel, ChannelBuffer buffer ) throws IOException {

        int available = buffer.readableBytes();

        if ( available < MESSAGE_SHORTEST_LENGTH ) {

            return DecodeResult.NEED_MORE_INPUT;

        } else {

            TIOStreamTransport transport = new TIOStreamTransport( new ChannelBufferInputStream(buffer));

            TBinaryProtocol protocol = new TBinaryProtocol( transport );

            short magic;
            int messageLength;

            try{
//                protocol.readI32(); // skip the first message length
                byte[] bytes = new byte[4];
                transport.read( bytes, 0, 4 );
                magic = protocol.readI16();
                messageLength = protocol.readI32();

            } catch ( TException e ) {
                throw new IOException( e.getMessage(), e );
            }

            if ( MAGIC != magic ) {
                throw new IOException(
                        new StringBuilder( 32 )
                                .append( "Unknown magic code " )
                                .append( magic )
                                .toString() );
            }

            if ( available < messageLength ) { return  DecodeResult.NEED_MORE_INPUT; }

            return decode( protocol );

        }

    }
 
Example 17
Source File: ThriftCodec.java    From dubbox with Apache License 2.0 2 votes vote down vote up
public Object decode( Channel channel, ChannelBuffer buffer ) throws IOException {

        int available = buffer.readableBytes();

        if ( available < MESSAGE_SHORTEST_LENGTH ) {

            return DecodeResult.NEED_MORE_INPUT;

        } else {

            TIOStreamTransport transport = new TIOStreamTransport( new ChannelBufferInputStream(buffer));

            TBinaryProtocol protocol = new TBinaryProtocol( transport );

            short magic;
            int messageLength;

            try{
//                protocol.readI32(); // skip the first message length
                byte[] bytes = new byte[4];
                transport.read( bytes, 0, 4 );
                magic = protocol.readI16();
                messageLength = protocol.readI32();

            } catch ( TException e ) {
                throw new IOException( e.getMessage(), e );
            }

            if ( MAGIC != magic ) {
                throw new IOException(
                        new StringBuilder( 32 )
                                .append( "Unknown magic code " )
                                .append( magic )
                                .toString() );
            }

            if ( available < messageLength ) { return  DecodeResult.NEED_MORE_INPUT; }

            return decode( protocol );

        }

    }
 
Example 18
Source File: ThriftCodec.java    From dubbox-hystrix with Apache License 2.0 2 votes vote down vote up
public Object decode( Channel channel, ChannelBuffer buffer ) throws IOException {

        int available = buffer.readableBytes();

        if ( available < MESSAGE_SHORTEST_LENGTH ) {

            return DecodeResult.NEED_MORE_INPUT;

        } else {

            TIOStreamTransport transport = new TIOStreamTransport( new ChannelBufferInputStream(buffer));

            TBinaryProtocol protocol = new TBinaryProtocol( transport );

            short magic;
            int messageLength;

            try{
//                protocol.readI32(); // skip the first message length
                byte[] bytes = new byte[4];
                transport.read( bytes, 0, 4 );
                magic = protocol.readI16();
                messageLength = protocol.readI32();

            } catch ( TException e ) {
                throw new IOException( e.getMessage(), e );
            }

            if ( MAGIC != magic ) {
                throw new IOException(
                        new StringBuilder( 32 )
                                .append( "Unknown magic code " )
                                .append( magic )
                                .toString() );
            }

            if ( available < messageLength ) { return  DecodeResult.NEED_MORE_INPUT; }

            return decode( protocol );

        }

    }
 
Example 19
Source File: ThriftCodec.java    From dubbox with Apache License 2.0 2 votes vote down vote up
public Object decode( Channel channel, ChannelBuffer buffer ) throws IOException {

        int available = buffer.readableBytes();

        if ( available < MESSAGE_SHORTEST_LENGTH ) {

            return DecodeResult.NEED_MORE_INPUT;

        } else {

            TIOStreamTransport transport = new TIOStreamTransport( new ChannelBufferInputStream(buffer));

            TBinaryProtocol protocol = new TBinaryProtocol( transport );

            short magic;
            int messageLength;

            try{
//                protocol.readI32(); // skip the first message length
                byte[] bytes = new byte[4];
                transport.read( bytes, 0, 4 );
                magic = protocol.readI16();
                messageLength = protocol.readI32();

            } catch ( TException e ) {
                throw new IOException( e.getMessage(), e );
            }

            if ( MAGIC != magic ) {
                throw new IOException(
                        new StringBuilder( 32 )
                                .append( "Unknown magic code " )
                                .append( magic )
                                .toString() );
            }

            if ( available < messageLength ) { return  DecodeResult.NEED_MORE_INPUT; }

            return decode( protocol );

        }

    }
 
Example 20
Source File: ThriftCodec.java    From dubbo-2.6.5 with Apache License 2.0 2 votes vote down vote up
@Override
    public Object decode(Channel channel, ChannelBuffer buffer) throws IOException {

        int available = buffer.readableBytes();

        if (available < MESSAGE_SHORTEST_LENGTH) {

            return DecodeResult.NEED_MORE_INPUT;

        } else {

            TIOStreamTransport transport = new TIOStreamTransport(new ChannelBufferInputStream(buffer));

            TBinaryProtocol protocol = new TBinaryProtocol(transport);

            short magic;
            int messageLength;

            try {
//                protocol.readI32(); // skip the first message length
                byte[] bytes = new byte[4];
                transport.read(bytes, 0, 4);
                magic = protocol.readI16();
                messageLength = protocol.readI32();

            } catch (TException e) {
                throw new IOException(e.getMessage(), e);
            }

            if (MAGIC != magic) {
                throw new IOException("Unknown magic code " + magic);
            }

            if (available < messageLength) {
                return DecodeResult.NEED_MORE_INPUT;
            }

            return decode(protocol);

        }

    }