当前位置: 首页>>代码示例>>Java>>正文


Java ExceptionUtils类代码示例

本文整理汇总了Java中org.apache.commons.lang3.exception.ExceptionUtils的典型用法代码示例。如果您正苦于以下问题:Java ExceptionUtils类的具体用法?Java ExceptionUtils怎么用?Java ExceptionUtils使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


ExceptionUtils类属于org.apache.commons.lang3.exception包,在下文中一共展示了ExceptionUtils类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getChatters

import org.apache.commons.lang3.exception.ExceptionUtils; //导入依赖的package包/类
/**
 * Gets all user's present in the twitch chat of a channel.
 *
 * @param channelName Channel to fetch the information for.
 * @return All chatters in a channel, separated into groups like admins, moderators and viewers.
 */
public Chatter getChatters(String channelName) {
	// Endpoint
	String requestUrl = String.format("%s/group/user/%s/chatters", Endpoints.TMI.getURL(), channelName);
	RestTemplate restTemplate = getTwitchClient().getRestClient().getRestTemplate();

	// REST Request
	try {
		if (!restObjectCache.containsKey(requestUrl)) {
			Logger.trace(this, "Rest Request to [%s]", requestUrl);
			ChatterResult responseObject = restTemplate.getForObject(requestUrl, ChatterResult.class);
			restObjectCache.put(requestUrl, responseObject, ExpirationPolicy.CREATED, 60, TimeUnit.SECONDS);
		}

		return ((ChatterResult) restObjectCache.get(requestUrl)).getChatters();

	} catch (RestException restException) {
		Logger.error(this, "RestException: " + restException.getRestError().toString());
	} catch (Exception ex) {
		Logger.error(this, "Request failed: " + ex.getMessage());
		Logger.trace(this, ExceptionUtils.getStackTrace(ex));
	}

	// OnError: Return empty result
	return new Chatter();
}
 
开发者ID:twitch4j,项目名称:twitch4j,代码行数:32,代码来源:TMIEndpoint.java

示例2: map

import org.apache.commons.lang3.exception.ExceptionUtils; //导入依赖的package包/类
@Override
public BackgroundException map(final IOException failure) {
    final Throwable[] stack = ExceptionUtils.getThrowables(failure);
    for(Throwable t : stack) {
        if(t instanceof BackgroundException) {
            return (BackgroundException) t;
        }
    }
    if(failure instanceof SSLException) {
        return new SSLExceptionMappingService().map((SSLException) failure);
    }
    final StringBuilder buffer = new StringBuilder();
    this.append(buffer, failure.getMessage());
    for(Throwable cause : ExceptionUtils.getThrowableList(failure)) {
        if(!StringUtils.contains(failure.getMessage(), cause.getMessage())) {
            this.append(buffer, cause.getMessage());
        }
    }
    return this.wrap(failure, buffer);
}
 
开发者ID:iterate-ch,项目名称:cyberduck,代码行数:21,代码来源:DefaultIOExceptionMappingService.java

示例3: parse

import org.apache.commons.lang3.exception.ExceptionUtils; //导入依赖的package包/类
public <T> T parse(String[] args, T inputArgs, Function<? super T, String> validationFunction) {
    try {
        List<String> extraArgs = Args.parse(inputArgs, args);

        if (extraArgs.size() > 0) {
            printUsageAndExit(inputArgs, "Passed in unnecessary args: " + StringUtils.join(extraArgs, "; "));
        }

        String validationMessage = validationFunction.valueOf(inputArgs);
        if (validationMessage != null) {
            printUsageAndExit(inputArgs, validationMessage);
        }
    } catch (IllegalArgumentException exc) {
        printUsageAndExit(inputArgs, ExceptionUtils.getStackTrace(exc));
    }

    LOG.info("Arguments parsed: " + inputArgs.toString());
    
    return inputArgs;
}
 
开发者ID:goldmansachs,项目名称:obevo,代码行数:21,代码来源:ArgsParser.java

示例4: invokeMethod

import org.apache.commons.lang3.exception.ExceptionUtils; //导入依赖的package包/类
@Override
void invokeMethod(AbstractTest instance, Method method, TestClassContext context, boolean isBeforeAfterGroup) {
    AbstractWebServiceTest abstractWebServiceTest = (AbstractWebServiceTest) instance;
    try {
        method.setAccessible(true);
        method.invoke(instance);
    } catch (Throwable e) {
        String errorMessage = format("Precondition method '%s' failed ", method.getName()) + "\n " + ExceptionUtils.getStackTrace(e);
        if (isBeforeAfterGroup) {
            abstractWebServiceTest.setPostponedBeforeAfterGroupFail(errorMessage, context.getTestContext());
        } else {
            abstractWebServiceTest.setPostponedTestFail(errorMessage);
        }

        new Report(errorMessage).allure();
    }
}
 
开发者ID:WileyLabs,项目名称:teasy,代码行数:18,代码来源:WebServiceMethodsInvoker.java

示例5: getAll

import org.apache.commons.lang3.exception.ExceptionUtils; //导入依赖的package包/类
/**
 * Get All Streams (ordered by current viewers, desc)
 * <p>
 * Gets the list of all live streams.
 * Requires Scope: none
 *
 * @param limit       Maximum number of most-recent objects to return. Default: 25. Maximum: 100.
 * @param offset      Object offset for pagination of results. Default: 0.
 * @param language    Restricts the returned streams to the specified language. Permitted values are locale ID strings, e.g. en, fi, es-mx.
 * @param game        Restricts the returned streams to the specified game.
 * @param channelIds  Receives the streams from a comma-separated list of channel IDs.
 * @param stream_type Restricts the returned streams to a certain stream type. Valid values: live, playlist, all. Playlists are offline streams of VODs (Video on Demand) that appear live. Default: live.
 * @return Returns all streams that match with the provided filtering.
 */
public List<Stream> getAll(Optional<Long> limit, Optional<Long> offset, Optional<String> language, Optional<Game> game, Optional<String> channelIds, Optional<String> stream_type) {
	// Endpoint
	String requestUrl = String.format("%s/streams", Endpoints.API.getURL());
	RestTemplate restTemplate = getTwitchClient().getRestClient().getRestTemplate();

	// Parameters
	restTemplate.getInterceptors().add(new QueryRequestInterceptor("limit", limit.orElse(25l).toString()));
	restTemplate.getInterceptors().add(new QueryRequestInterceptor("offset", offset.orElse(0l).toString()));
	restTemplate.getInterceptors().add(new QueryRequestInterceptor("language", language.orElse(null)));
	restTemplate.getInterceptors().add(new QueryRequestInterceptor("game", game.map(Game::getName).orElse(null)));
	restTemplate.getInterceptors().add(new QueryRequestInterceptor("channel", channelIds.isPresent() ? channelIds.get() : null));
	restTemplate.getInterceptors().add(new QueryRequestInterceptor("stream_type", stream_type.orElse("all")));

	// REST Request
	try {
		StreamList responseObject = restTemplate.getForObject(requestUrl, StreamList.class);

		return responseObject.getStreams();
	} catch (Exception ex) {
		Logger.error(this, "Request failed: " + ex.getMessage());
		Logger.trace(this, ExceptionUtils.getStackTrace(ex));
	}

	return null;
}
 
开发者ID:twitch4j,项目名称:twitch4j,代码行数:40,代码来源:StreamEndpoint.java

示例6: getTopGames

import org.apache.commons.lang3.exception.ExceptionUtils; //导入依赖的package包/类
/**
 * Endpoint: Get Top Games
 * Get games by number of current viewers on Twitch.
 * Requires Scope: none
 *
 * @return todo
 */
public List<TopGame> getTopGames() {
	// Endpoint
	String requestUrl = String.format("%s/games/top", Endpoints.API.getURL());
	RestTemplate restTemplate = getTwitchClient().getRestClient().getRestTemplate();

	// REST Request
	try {
		Logger.trace(this, "Rest Request to [%s]", requestUrl);
		TopGameList responseObject = restTemplate.getForObject(requestUrl, TopGameList.class);

		return responseObject.getTop();
	} catch (Exception ex) {
		Logger.error(this, "Request failed: " + ex.getMessage());
		Logger.trace(this, ExceptionUtils.getStackTrace(ex));
	}

	return null;
}
 
开发者ID:twitch4j,项目名称:twitch4j,代码行数:26,代码来源:GameEndpoint.java

示例7: getUserSubcriptionCheck

import org.apache.commons.lang3.exception.ExceptionUtils; //导入依赖的package包/类
/**
 * Endpoint: Check User Subscription by Channel
 * Checks if a specified user is subscribed to a specified channel.
 * Requires Scope: user_subscriptions
 *
 * @param userId    UserId of the user.
 * @param channelId ChannelId of the channel you are checking against.
 * @return Optional of Type UserSubscriptionCheck. Is only present, when the user is subscribed.
 */
public Optional<UserSubscriptionCheck> getUserSubcriptionCheck(Long userId, Long channelId) {
	// Endpoint
	String requestUrl = String.format("%s/users/%s/subscriptions/%s", Endpoints.API.getURL(), userId, channelId);
	RestTemplate restTemplate = getTwitchClient().getRestClient().getRestTemplate();

	// REST Request
	try {
		Logger.trace(this, "Rest Request to [%s]", requestUrl);
		UserSubscriptionCheck responseObject = restTemplate.getForObject(requestUrl, UserSubscriptionCheck.class);

		return Optional.ofNullable(responseObject);
	} catch (RestException restException) {
		if (restException.getRestError().getStatus().equals(422)) {
			// Channel has no subscription program.
			Logger.info(this, "Channel %s has no subscription programm.", channelId);
		} else {
			Logger.error(this, "RestException: " + restException.getRestError().toString());
		}
	} catch (Exception ex) {
		Logger.error(this, "Request failed: " + ex.getMessage());
		Logger.trace(this, ExceptionUtils.getStackTrace(ex));
	}

	return Optional.empty();
}
 
开发者ID:twitch4j,项目名称:twitch4j,代码行数:35,代码来源:UserEndpoint.java

示例8: storeConfig

import org.apache.commons.lang3.exception.ExceptionUtils; //导入依赖的package包/类
/**
 * 缓存配置
 */
public void storeConfig(Map<String, String> properties) {
    try {
        // 如果缓存文件不存在,则创建
        FileUtils.createFileIfAbsent(cacheFile.getPath());
        OutputStream out = null;
        try {
            out = new FileOutputStream(cacheFile);
            mapToProps(properties).store(out, "updated at " + DateFormatUtils.format(new Date(), "yyyy-MM-dd HH:mm:ss"));
        } finally {
            if (out != null) {
                out.close();
            }
        }
    } catch (IOException e) {
        ExceptionUtils.rethrow(e);
    }
}
 
开发者ID:zhongxunking,项目名称:configcenter,代码行数:21,代码来源:CacheFileHandler.java

示例9: selectList

import org.apache.commons.lang3.exception.ExceptionUtils; //导入依赖的package包/类
@Transactional(rollbackFor={Exception.class})
public void selectList() throws Exception {
	try {
	//单表查找
	ExprBuilder expr = new ExprBuilder(Brand.class);
	expr.In("code", brandCode).In("name", brandName).orderAsc("id").orderChDesc("name").limit(0, 2000);
	expr.propEqual("id", "id");
	ResultEntity<Brand> brands =baseMapper.selectList(new Brand(),expr);
	
	//use Cache
	ExprBuilder expr2 = new ExprBuilder(Brand.class);
	expr2.In("code", brandCode).In("name", brandName).orderDesc("id").orderChAsc("name").limit(0, 2000);
	expr2.propEqual("id", "id");
	ResultEntity<Brand> brands2 =baseMapper.selectList(new Brand(),expr);
	Assert.isTrue(brands.getTotal()>0,"can't find result");	
	Assert.isTrue(brands2.getTotal()>0,"can't find result");	
	} catch (Exception e) {
		logger.error(ExceptionUtils.getStackTrace(e));
		throw e;
	}
}
 
开发者ID:endend20000,项目名称:mybatisx,代码行数:22,代码来源:DEMO.java

示例10: doCommand

import org.apache.commons.lang3.exception.ExceptionUtils; //导入依赖的package包/类
@Override
public boolean doCommand(MessageReceivedEvent message, BotContext context, String query) {
    if (!discordService.isSuperUser(message.getAuthor()) || StringUtils.isEmpty(query)) {
        return false;
    }
    message.getChannel().sendTyping();
    String script = CommonUtils.unwrapCode(query);
    try {
        Object result = getShell(message).evaluate(script);
        if (result != null) {
            messageService.sendMessageSilent(message.getChannel()::sendMessage,
                    "```groovy\n" + String.valueOf(result) + "```");
        }
    } catch (Exception e) {
        String errorText = String.format("\n`%s`\n\nStack trace:```javascript\n%s", e.getMessage(), ExceptionUtils.getStackTrace(e));
        EmbedBuilder builder = messageService.getBaseEmbed();
        builder.setTitle(e.getClass().getName());
        builder.setColor(Color.RED);
        builder.setDescription(CommonUtils.trimTo(errorText, 2045) + "```");
        messageService.sendMessageSilent(message.getChannel()::sendMessage, builder.build());
        return fail(message);
    }
    return ok(message);
}
 
开发者ID:GoldRenard,项目名称:JuniperBotJ,代码行数:25,代码来源:GroovyCommand.java

示例11: selectOne

import org.apache.commons.lang3.exception.ExceptionUtils; //导入依赖的package包/类
@Transactional(rollbackFor={Exception.class})
public void selectOne() throws Exception {
	try {
	//单表查找
	logger.debug("查找单挑记录");
	Brand param=new Brand();
	param.setId(1);
	Brand brand =customizeSqlMapper.selectOne(param,new SqlBuilder(Brand.class));
	Assert.isTrue(brand!=null,"can't find result");	
	
	Shop siteParam=new Shop();
	siteParam.setId(1);
	SqlBuilder sb=new SqlBuilder(Shop.class)
			.include("brands")
			.include("pictures")
			.include("address");
	Shop site =customizeSqlMapper.selectOne(siteParam,sb);
	
	Assert.isTrue(site!=null,"can't find result");	


	} catch (Exception e) {
		logger.error(ExceptionUtils.getStackTrace(e));
		throw e;
	}
}
 
开发者ID:endend20000,项目名称:mybatisx,代码行数:27,代码来源:DEMO.java

示例12: getFeedPosts

import org.apache.commons.lang3.exception.ExceptionUtils; //导入依赖的package包/类
/**
 * Gets posts from a specified channel feed.
 *
 * @param channelId    The channel id, which the posts should be retrieved from.
 * @param limit        Maximum number of most-recent objects to return. Default: 10. Maximum: 100.
 * @param cursor       Tells the server where to start fetching the next set of results in a multi-page response.
 * @param commentLimit Specifies the number of most-recent comments on posts that are included in the response. Default: 5. Maximum: 5.
 * @return posts from a specified channel feed.
 */
public List<ChannelFeedPost> getFeedPosts(Long channelId, Optional<Long> limit, Optional<String> cursor, Optional<Long> commentLimit) {
	// Endpoint
	String requestUrl = String.format("%s/feed/%s/posts", Endpoints.API.getURL(), channelId);
	RestTemplate restTemplate = getTwitchClient().getRestClient().getRestTemplate();

	// Parameters
	restTemplate.getInterceptors().add(new QueryRequestInterceptor("limit", limit.orElse(10l).toString()));
	restTemplate.getInterceptors().add(new QueryRequestInterceptor("cursor", cursor.orElse("")));
	restTemplate.getInterceptors().add(new QueryRequestInterceptor("comments", commentLimit.orElse(5l).toString()));

	// REST Request
	try {
		Logger.trace(this, "Rest Request to [%s]", requestUrl);
		ChannelFeed responseObject = restTemplate.getForObject(requestUrl, ChannelFeed.class);

		return responseObject.getPosts();
	} catch (RestException restException) {
		Logger.error(this, "RestException: " + restException.getRestError().toString());
	} catch (Exception ex) {
		Logger.error(this, "Request failed: " + ex.getMessage());
		Logger.trace(this, ExceptionUtils.getStackTrace(ex));
	}

	return new ArrayList<ChannelFeedPost>();
}
 
开发者ID:twitch4j,项目名称:twitch4j,代码行数:35,代码来源:ChannelFeedEndpoint.java

示例13: selectUseGetDetail

import org.apache.commons.lang3.exception.ExceptionUtils; //导入依赖的package包/类
/**
 * 使用sqlbuild查询 使用getDetail方法 暂时废弃
 * @throws Exception
 */
//@SuppressWarnings("deprecation")
@Transactional(rollbackFor={Exception.class})
public void selectUseGetDetail() throws Exception {
	try {
		Shop shop=new Shop();
		shop.setId(1);
		ExprBuilder expr = new ExprBuilder(Shop.class);
		expr.In("id", 1,2,3,4,8);			
		SqlBuilder sb=new SqlBuilder();
		    sb.getDetail(Shop.class, "brands").orderAsc("id");
		
		ResultEntity<Shop> sites =customizeSqlMapper.select(shop,sb,expr);			
		Assert.isTrue(sites.getTotal()>0,"can't find result");					
	} catch (Exception e) {
		logger.error(ExceptionUtils.getStackTrace(e));
		throw e;
	}
}
 
开发者ID:endend20000,项目名称:mybatisx,代码行数:23,代码来源:DEMO.java

示例14: getInstancesMapForZone

import org.apache.commons.lang3.exception.ExceptionUtils; //导入依赖的package包/类
@Override
public Map<AvailabilityZone, List<Instance>> getInstancesMapForZone(
    AvailabilityZone zone, AmazonEC2Client client) throws Exception {

  OperationStats op = new OperationStats("ec2InstanceStore", "getInstancesMapForZone");

  try {
    Map<AvailabilityZone, List<Instance>> ret = new HashMap<>();
    ret.put(zone, getInstancesForZone(zone, client));

    op.succeed();
    return ret;

  } catch (Exception e) {

    op.failed();
    logger.error(ExceptionUtils.getRootCauseMessage(e));
    throw e;
  }
}
 
开发者ID:pinterest,项目名称:soundwave,代码行数:21,代码来源:Ec2InstanceStore.java

示例15: add

import org.apache.commons.lang3.exception.ExceptionUtils; //导入依赖的package包/类
@Override
public void add(Product... products) {
    new Txn(dBase).call(session -> {
        for (Product product : products) {
            try {
                session.sql("INSERT INTO category_product (category_id, product_id) VALUES (?, ?)")
                        .set(category.id())
                        .set(product.number())
                        .insert(Outcome.VOID);
            } catch (SQLException e) {
                ExceptionUtils.rethrow(e);
            }
        }
        return null;
    });
}
 
开发者ID:yaroska,项目名称:true_oop,代码行数:17,代码来源:H2CategoryProducts.java


注:本文中的org.apache.commons.lang3.exception.ExceptionUtils类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。