本文整理汇总了Java中com.google.api.server.spi.response.BadRequestException类的典型用法代码示例。如果您正苦于以下问题:Java BadRequestException类的具体用法?Java BadRequestException怎么用?Java BadRequestException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
BadRequestException类属于com.google.api.server.spi.response包,在下文中一共展示了BadRequestException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: read
import com.google.api.server.spi.response.BadRequestException; //导入依赖的package包/类
@Override
public Object[] read() throws ServiceException {
// Assumes input stream to be encoded in UTF-8
// TODO: Take charset from content-type as encoding
try {
String requestBody = IoUtil.readStream(servletRequest.getInputStream());
logger.log(Level.FINE, "requestBody=" + requestBody);
if (requestBody == null || requestBody.trim().isEmpty()) {
return new Object[0];
}
JsonNode node = objectReader.readTree(requestBody);
return deserializeParams(node);
} catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException
| IOException e) {
throw new BadRequestException(e);
}
}
示例2: createSession
import com.google.api.server.spi.response.BadRequestException; //导入依赖的package包/类
/**
* Creates a new session from {@link WaxNewSessionRequest}.
*
* @return {@link WaxNewSessionResponse} with the created session id
* @throws InternalServerErrorException if the session creation failed
* @throws BadRequestException if the requested session name is bad
*/
@ApiMethod(
name = "sessions.create",
path = "newsession",
httpMethod = HttpMethod.POST)
public WaxNewSessionResponse createSession(WaxNewSessionRequest request)
throws InternalServerErrorException, BadRequestException {
if (Strings.isNullOrEmpty(request.getSessionName())) {
throw new BadRequestException("Name must be non-empty");
}
String sessionId =
store.createSession(request.getSessionName(), request.getDurationInMillis());
if (sessionId != null) {
return new WaxNewSessionResponse(sessionId);
}
throw new InternalServerErrorException("Error while adding session");
}
示例3: sendTestSms
import com.google.api.server.spi.response.BadRequestException; //导入依赖的package包/类
@ApiMethod(
name = "sendTestSms",
path = "sendTestSms",
httpMethod = ApiMethod.HttpMethod.POST
)
@SuppressWarnings("unused")
public StringWrapperObject sendTestSms(
// final HttpServletRequest httpServletRequest,
final User googleUser,
final @Named("phoneNumber") String phoneNumber,
final @Named("smsMessage") String smsMessage
// see: https://cloud.google.com/appengine/docs/java/endpoints/exceptions
) throws UnauthorizedException, BadRequestException, NotFoundException, NumberParseException,
IllegalArgumentException, TwilioRestException {
/* --- Check authorization: */
CryptonomicaUser cryptonomicaUser = UserTools.ensureCryptonomicaOfficer(googleUser);
/* --- Send SMS */
Message message = TwilioUtils.sendSms(phoneNumber, smsMessage);
return new StringWrapperObject(message.toJSON());
}
示例4: removeFriend
import com.google.api.server.spi.response.BadRequestException; //导入依赖的package包/类
/**
* Remove user's friend
*
* @param friendId The user id of the friend to remove
* @param user The Google Authenticated User
*/
@ApiMethod(
name = "friends.remove",
path = "friends/{friendId}",
httpMethod = ApiMethod.HttpMethod.DELETE
)
public void removeFriend(@Named("friendId") long friendId, User user)
throws OAuthRequestException, BadRequestException, NotFoundException, IOException {
UserRecord currentUser = userDAO.getUserRecord(user);
if (currentUser == null) {
throw new OAuthRequestException(Messages.ERROR_AUTH);
}
if (friendId == 0) {
throw new BadRequestException(Messages.ERROR_INVALID_PARAMETERS);
}
FriendRecord friendRecord = friendDAO.getFriendRecord(currentUser);
if (friendRecord != null && friendRecord.removeFriend(friendId)) {
// if friend was found and removed then update friend record
friendDAO.save(friendRecord);
} else {
throw new NotFoundException(Messages.ERROR_FRIEND_NOT_FOUND);
}
}
示例5: unregister
import com.google.api.server.spi.response.BadRequestException; //导入依赖的package包/类
/**
* Unregister a device
* This will not remove a user
*
* @param deviceId The Google Cloud Messaging registration Id to remove
* @param user The Google Authenticated User
*/
@ApiMethod(
name = "users.unregister",
path = "users/unregister",
httpMethod = HttpMethod.POST
)
public void unregister(@Named("deviceId") String deviceId, User user) throws OAuthRequestException, BadRequestException {
UserRecord currentUser = userDAO.getUserRecord(user);
if (currentUser == null) {
throw new OAuthRequestException(Messages.ERROR_AUTH);
}
if (deviceId == null) {
throw new BadRequestException(Messages.ERROR_INVALID_PARAMETERS);
}
for (String id : currentUser.getDevices()) {
if (id.equals(deviceId)) {
// found device - unregister it
currentUser.removeDevice(id);
userDAO.save(currentUser);
return;
}
}
}
示例6: getUserSkill
import com.google.api.server.spi.response.BadRequestException; //导入依赖的package包/类
@Override
public Skill getUserSkill(String techId, TechGalleryUser user) throws BadRequestException,
OAuthRequestException, NotFoundException, InternalServerErrorException {
// User can't be null
if (user == null) {
throw new OAuthRequestException(i18n.t("Null user reference!"));
}
// Technology can't be null
final Technology technology = techService.getTechnologyById(techId, null);
if (technology == null) {
throw new NotFoundException(i18n.t("Technology do not exists!"));
}
final Skill userSkill = skillDao.findByUserAndTechnology(user, technology);
if (userSkill == null) {
return null;
} else {
return userSkill;
}
}
示例7: getTechnologies
import com.google.api.server.spi.response.BadRequestException; //导入依赖的package包/类
/**
* GET for getting all technologies.
*
* @throws NotFoundException
* .
*/
@Override
public Response getTechnologies(User user)
throws InternalServerErrorException, NotFoundException, BadRequestException {
List<Technology> techEntities = technologyDAO.findAllActives();
// if list is null, return a not found exception
if (techEntities == null || techEntities.isEmpty()) {
return new TechnologiesResponse();
} else {
verifyTechnologyFollowedByUser(user, techEntities);
TechnologiesResponse response = new TechnologiesResponse();
Technology.sortTechnologiesDefault(techEntities);
response.setTechnologies(techEntities);
return response;
}
}
示例8: addOrUpdateSkill
import com.google.api.server.spi.response.BadRequestException; //导入依赖的package包/类
@Override
public Skill addOrUpdateSkill(Skill skill, User user)
throws InternalServerErrorException, BadRequestException, NotFoundException {
log.info("Starting creating or updating skill");
validateInputs(skill, user);
Technology technology = skill.getTechnology().get();
TechGalleryUser techUser = userService.getUserByGoogleId(user.getUserId());
Skill skillEntity = skillDao.findByUserAndTechnology(techUser, technology);
// if there is a skillEntity, it is needed to inactivate it and create a new
// one
inactivateSkill(skillEntity);
final Skill newSkill = addNewSkill(skill, techUser, technology);
UserProfileServiceImpl.getInstance().handleSkillChanges(newSkill);
return newSkill;
}
示例9: getRecommendations
import com.google.api.server.spi.response.BadRequestException; //导入依赖的package包/类
@Override
public List<Response> getRecommendations(String technologyId, User user)
throws BadRequestException, InternalServerErrorException {
Technology technology;
try {
technology = technologyService.getTechnologyById(technologyId, user);
} catch (final NotFoundException e) {
return null;
}
final List<TechnologyRecommendation> recommendations =
technologyRecommendationDAO.findAllActivesByTechnology(technology);
final List<Response> recommendationTOs = new ArrayList<Response>();
for (final TechnologyRecommendation recommendation : recommendations) {
recommendationTOs.add(techRecTransformer.transformTo(recommendation));
}
return recommendationTOs;
}
示例10: deleteRecommendById
import com.google.api.server.spi.response.BadRequestException; //导入依赖的package包/类
@Override
public Response deleteRecommendById(Long recommendId, User user)
throws BadRequestException, NotFoundException, InternalServerErrorException {
final TechnologyRecommendation recommendation =
technologyRecommendationDAO.findById(recommendId);
final TechGalleryUser techUser = userService.getUserByEmail(user.getEmail());
validateDeletion(recommendId, recommendation, user, techUser);
recommendation.setActive(false);
technologyRecommendationDAO.update(recommendation);
technologyService.removeRecomendationCounter(recommendation.getTechnology().get(),
recommendation.getScore());
UserProfileServiceImpl.getInstance().handleRecommendationChanges(recommendation);
return techRecTransformer.transformTo(recommendation);
}
示例11: addComment
import com.google.api.server.spi.response.BadRequestException; //导入依赖的package包/类
@Override
public TechnologyComment addComment(TechnologyComment comment, User user)
throws InternalServerErrorException, BadRequestException, NotFoundException {
log.info("Starting creating Technology Comment.");
final Technology technology = comment.getTechnology().get();
validateUser(user);
validateComment(comment);
validateTechnology(technology);
final TechGalleryUser techUser = userService.getUserByGoogleId(user.getUserId());
final TechnologyComment newComment = addNewComment(comment, techUser, technology);
techService.addCommentariesCounter(technology);
techService.audit(technology.getId(), user);
followTechnology(technology, techUser);
UserProfileServiceImpl.getInstance().handleCommentChanges(newComment);
return newComment;
}
示例12: getCommentsByTech
import com.google.api.server.spi.response.BadRequestException; //导入依赖的package包/类
@Override
public Response getCommentsByTech(String techId, User user) throws InternalServerErrorException,
BadRequestException, NotFoundException, OAuthRequestException {
final Technology technology = techService.getTechnologyById(techId, user);
validateUser(user);
validateTechnology(technology);
final List<TechnologyComment> commentsByTech =
technologyCommentDao.findAllActivesByTechnology(technology);
final TechnologyCommentsTO response = new TechnologyCommentsTO();
response.setComments(commentsByTech);
/*
* for (TechnologyComment comment : response.getComments()) { setCommentRecommendation(comment);
* }
*/
return response;
}
示例13: addRecommendationComment
import com.google.api.server.spi.response.BadRequestException; //导入依赖的package包/类
@Override
public TechnologyRecommendation addRecommendationComment(TechnologyRecommendation recommendation,
TechnologyComment comment, Technology technology, User user)
throws BadRequestException, InternalServerErrorException, NotFoundException {
if (!isValidComment(comment)) {
throw new BadRequestException(ValidationMessageEnums.COMMENT_CANNOT_BLANK.message());
}
Key<Technology> techKey = Key.create(Technology.class, technology.getId());
comment.setTechnology(Ref.create(techKey));
comment = comService.addComment(comment, user);
recommendation.setComment(Ref.create(comment));
recommendation.setTimestamp(new Date());
recommendation.setTechnology(Ref.create(techKey));
recommendation = recService.addRecommendation(recommendation, user);
technologyService.audit(technology.getId(), user);
return recommendation;
}
示例14: followTechnology
import com.google.api.server.spi.response.BadRequestException; //导入依赖的package包/类
@Override
@Transactional
public Technology followTechnology(String technologyId, TechGalleryUser techUser)
throws BadRequestException, NotFoundException, InternalServerErrorException {
Technology technology = techService.getTechnologyById(technologyId, null);
TechnologyFollowers technologyFollowers = followersDao.findById(technology.getId());
if (technologyFollowers == null
|| !technologyFollowers.getFollowers().contains(Ref.create(techUser))) {
technologyFollowers = follow(technologyFollowers, techUser, technology);
} else if (technologyFollowers != null
&& technologyFollowers.getFollowers().contains(Ref.create(techUser))) {
technologyFollowers = unfollow(technologyFollowers, techUser, technology);
}
update(technologyFollowers);
userService.updateUser(techUser);
return technology;
}
示例15: update
import com.google.api.server.spi.response.BadRequestException; //导入依赖的package包/类
@Override
public void update(TechnologyFollowers technologyFollowers) throws BadRequestException {
if (technologyFollowers != null) {
if (technologyFollowers.getTechnology() == null) {
throw new BadRequestException(ValidationMessageEnums.TECHNOLOGY_ID_CANNOT_BLANK.message());
}
if (technologyFollowers.getFollowers() == null
|| technologyFollowers.getFollowers().isEmpty()) {
throw new BadRequestException(ValidationMessageEnums.FOLLOWERS_CANNOT_EMPTY.message());
}
if (technologyFollowers.getId() != null
&& followersDao.findById(technologyFollowers.getId()) != null) {
followersDao.update(technologyFollowers);
} else {
followersDao.add(technologyFollowers);
}
}
}