List of usage examples for org.springframework.web.client HttpClientErrorException getMessage
@Override
@Nullable
public String getMessage()
From source file:de.hybris.platform.marketplaceintegrationbackoffice.renderer.MarketplaceIntegrationOrderInitialRenderer.java
private void initialOrderDownload(final MarketplaceStoreModel model) { if (null == model.getOrderStartTime()) { NotificationUtils.notifyUserVia(Localization .getLocalizedString("type.Marketplacestore." + MarketplaceStoreModel.ORDERSTARTTIME + ".name") + " " + Labels.getLabel("backoffice.field.notfilled"), NotificationEvent.Type.WARNING, ""); LOG.warn("get order start time is not filled!"); return;/*from w w w . ja v a 2 s. c o m*/ } else if (null == model.getOrderEndTime()) { NotificationUtils.notifyUserVia(Localization .getLocalizedString("type.Marketplacestore." + MarketplaceStoreModel.ORDERENDTIME + ".name") + " " + Labels.getLabel("backoffice.field.notfilled"), NotificationEvent.Type.WARNING, ""); LOG.warn("get order end time is not filled!"); return; } else if (model.getOrderStartTime().after(model.getOrderEndTime())) { NotificationUtils.notifyUserVia(Labels.getLabel("backoffice.field.timerange.error"), NotificationEvent.Type.WARNING, ""); LOG.warn("start time is greate than end time!"); return; } else if (model.getMarketplace().getTmallOrderStatus().isEmpty() || null == model.getMarketplace().getTmallOrderStatus()) { NotificationUtils.notifyUserVia( Localization .getLocalizedString("type.Marketplace." + MarketplaceModel.TMALLORDERSTATUS + ".name") + " " + Labels.getLabel("backoffice.field.notfilled"), NotificationEvent.Type.WARNING, ""); LOG.warn("order status field is not filled!"); return; } if (!StringUtils.isBlank(model.getIntegrationId()) && !model.getAuthorized().booleanValue()) { NotificationUtils.notifyUserVia(Labels.getLabel("marketplace.order.authorization.fail"), NotificationEvent.Type.WARNING, ""); LOG.warn("authorization is expired!"); return; } // in order to avoid this value out of date, we only get it from // database final Boolean isAuth = ((MarketplaceStoreModel) modelService.get(model.getPk())).getAuthorized(); final String integrationId = ((MarketplaceStoreModel) modelService.get(model.getPk())).getIntegrationId(); model.setIntegrationId(integrationId); model.setAuthorized(isAuth); if (null == isAuth || !isAuth.booleanValue()) { NotificationUtils.notifyUserVia(Labels.getLabel("marketplace.order.initorder.unauthed"), NotificationEvent.Type.WARNING, ""); LOG.warn("marketplace store do not authorized, initial download failed!"); return; } String urlStr = ""; final String logUUID = logUtil.getUUID(); final MarketplaceSellerModel seller = model.getMarketplaceSeller(); final MarketplaceModel marketPlace = seller.getMarketplace(); try { // Configure and open a connection to the site you will send the urlStr = marketPlace.getAdapterUrl() + Config.getParameter(MARKETPLACE_ORDER_SYCHRONIZE_PATH) + Config.getParameter(MARKETPLACE_ORDER_INITIAL_PATH) + integrationId + Config.getParameter(MARKETPLACE_ORDER_INITIAL_LOGUUID) + logUUID; final JSONObject jsonObj = new JSONObject(); jsonObj.put("batchSize", BATCH_SIZE); jsonObj.put("status", getOrderStatus(model.getMarketplace().getTmallOrderStatus())); //jsonObj.put("marketplaceLogId", marketplacelogUUID); // set the correct timezone final String configTimezone = model.getMarketplace().getTimezone(); boolean isValidTimezone = false; for (final String vaildTimezone : TimeZone.getAvailableIDs()) { if (vaildTimezone.equals(configTimezone)) { isValidTimezone = true; break; } } if (!isValidTimezone) { final String[] para = { configTimezone == null ? "" : configTimezone, model.getMarketplace().getName() }; NotificationUtils.notifyUserVia(Labels.getLabel("marketplace.order.initorder.wrongtimezone", para), NotificationEvent.Type.WARNING, ""); LOG.warn("wrong timezone or missing timezone configed in market:" + model.getMarketplace().getName()); return; } final SimpleDateFormat format = new SimpleDateFormat(Config.getParameter(BACKOFFICE_FORMAT_DATEFORMAT)); format.setTimeZone(TimeZone.getTimeZone(configTimezone)); final String startTimeWithCorrectZone = format.format(model.getOrderStartTime()).toString(); final String endTimeWithCorrectZone = format.format(model.getOrderEndTime()).toString(); jsonObj.put("startCreated", startTimeWithCorrectZone); jsonObj.put("endCreated", endTimeWithCorrectZone); jsonObj.put("productCatalogVersion", model.getCatalogVersion().getCatalog().getId() + ":" + model.getCatalogVersion().getVersion()); jsonObj.put("currency", model.getCurrency().getIsocode()); NotificationUtils.notifyUserVia(Labels.getLabel("marketplace.order.initorder.success"), NotificationEvent.Type.SUCCESS, ""); final JSONObject results = marketplaceHttpUtil.post(urlStr, jsonObj.toJSONString()); final String msg = results.toJSONString(); final String responseCode = results.get("code").toString(); if ("401".equals(responseCode)) { LOG.error("========================================================================="); LOG.error("Order initial download request post to Tmall failed!"); LOG.error("Marketplacestore Code: " + model.getName()); LOG.error("Error Status Code: " + responseCode); LOG.error("Request path: " + urlStr); LOG.error("-------------------------------------------------------------------------"); LOG.error("Failed Reason:"); LOG.error("Authentication was failed, please re-authenticate again!"); LOG.error("========================================================================="); NotificationUtils.notifyUserVia(Labels.getLabel("marketplace.order.authorization.fail"), NotificationEvent.Type.FAILURE, ""); LOG.warn("Authentication was failed, please re-authenticate again!"); return; } else if (!("0".equals(responseCode))) { LOG.error("========================================================================="); LOG.error("Order initial download request post to Tmall failed!"); LOG.error("Marketplacestore Code: " + model.getName()); LOG.error("Error Status Code: " + responseCode); LOG.error("Request path: " + urlStr); LOG.error("-------------------------------------------------------------------------"); LOG.error("Failed Reason:"); LOG.error("A known issue occurs in tmall, error details :" + msg); LOG.error("========================================================================="); NotificationUtils.notifyUserVia( Labels.getLabel("marketplace.tmallapp.known.issues", new Object[] { msg }), NotificationEvent.Type.FAILURE, ""); LOG.warn("A known issue occurs in tmall, error details :" + msg); return; } } catch (final HttpClientErrorException httpError) { if (httpError.getStatusCode().is4xxClientError()) { LOG.error("========================================================================="); LOG.error("Order initial download request post to Tmall failed!"); LOG.error("Marketplacestore Code: " + model.getName()); LOG.error("Error Status Code: " + httpError.getStatusCode().toString()); LOG.error("Request path: " + urlStr); LOG.error("-------------------------------------------------------------------------"); LOG.error("Failed Reason:"); LOG.error("Requested Tmall service URL is not correct!"); LOG.error("Detail error info: " + httpError.getMessage()); LOG.error("========================================================================="); NotificationUtils.notifyUserVia(Labels.getLabel("marketplace.error.request.post.error"), NotificationEvent.Type.FAILURE, ""); } if (httpError.getStatusCode().is5xxServerError()) { LOG.error("========================================================================="); LOG.error("Order initial download request post to Tmall failed!"); LOG.error("Marketplacestore Code: " + model.getName()); LOG.error("Error Status Code: " + httpError.getStatusCode().toString()); LOG.error("Request path: " + urlStr); LOG.error("-------------------------------------------------------------------------"); LOG.error("Failed Reason:"); LOG.error("Requested Json Ojbect is not correct!"); LOG.error("Detail error info: " + httpError.getMessage()); LOG.error("========================================================================="); NotificationUtils.notifyUserVia(Labels.getLabel("marketplace.error.server.process.error"), NotificationEvent.Type.FAILURE, ""); } LOG.error(httpError.toString()); return; } catch (final ResourceAccessException raError) { LOG.error("========================================================================="); LOG.error("Order initial download request post to Tmall failed!"); LOG.error("Marketplacestore Code: " + model.getName()); LOG.error("Request path: " + urlStr); LOG.error("-------------------------------------------------------------------------"); LOG.error("Failed Reason:"); LOG.error("Marketplace order download request server access failed!"); LOG.error("Detail error info: " + raError.getMessage()); LOG.error("========================================================================="); NotificationUtils.notifyUserVia(Labels.getLabel("marketplace.error.server.access.error"), NotificationEvent.Type.FAILURE, ""); return; } catch (final HttpServerErrorException serverError) { LOG.error("========================================================================="); LOG.error("Order initial download request post to Tmall failed!"); LOG.error("Marketplacestore Code: " + model.getName()); LOG.error("Request path: " + urlStr); LOG.error("-------------------------------------------------------------------------"); LOG.error("Failed Reason:"); LOG.error("Marketplace order download request server process failed!"); LOG.error("Detail error info: " + serverError.getMessage()); LOG.error("========================================================================="); NotificationUtils.notifyUserVia(Labels.getLabel("marketplace.error.server.process.error"), NotificationEvent.Type.FAILURE, ""); return; } catch (final Exception e) { final String errorMsg = e.getClass().toString() + ":" + e.getMessage(); NotificationUtils.notifyUserVia( Labels.getLabel("marketplace.runtime.issues", new Object[] { errorMsg }), NotificationEvent.Type.FAILURE, ""); LOG.warn(e.getMessage() + e.getStackTrace()); return; } LOG.info("========================================================================="); LOG.info("Order initial download request post to Tmall suceessfully!"); LOG.info("-------------------------------------------------------------------------"); LOG.info("Marketplacestore Code: " + model.getName()); LOG.info("Request path: " + urlStr); LOG.info("========================================================================="); // logUtil.addMarketplaceLog("PENDING", model.getIntegrationId(), Labels.getLabel("marketplace.order.initial.action"), // Labels.getLabel("marketplace.order.initial.object.type"), marketPlace, model, logUUID); }
From source file:de.hybris.platform.marketplaceintegrationbackoffice.renderer.MarketplaceIntegrationOrderIncrementalRenderer.java
private boolean incrementalOrderDownload(final MarketplaceStoreModel model, final String status) { boolean flag = false; final String logUUID = logUtil.getUUID(); final MarketplaceSellerModel seller = model.getMarketplaceSeller(); final MarketplaceModel marketPlace = seller.getMarketplace(); modelService.refresh(seller);/*from w ww . j a v a 2 s .c o m*/ final String requestUrl = marketPlace.getAdapterUrl() + Config.getParameter(MARKETPLACE_ORDER_REALTIME_SYNC_PATH) + Config.getParameter(MARKETPLACE_ORDER_SYCHRONIZE_MIDDLE_PATH) + model.getIntegrationId() + Config.getParameter(MARKETPLACE_ORDER_SYCHRONIZE_LOGUUID) + logUUID; final JSONObject jsonObj = new JSONObject(); jsonObj.put("currency", model.getCurrency().getIsocode()); jsonObj.put("productCatalogVersion", model.getCatalogVersion().getCatalog().getId() + ":" + model.getCatalogVersion().getVersion()); jsonObj.put("status", status); try { this.saveMarketplaceLog(status, model, logUUID); final JSONObject results = marketplaceHttpUtil.post(requestUrl, jsonObj.toJSONString()); final String msg = results.toJSONString(); final String responseCode = results.get("code").toString(); if ("401".equals(responseCode)) { LOG.error("========================================================================="); LOG.error("Order incremental download request post to Tmall failed!"); LOG.error("Marketplacestore Code: " + model.getName()); LOG.error("Error Status Code: " + responseCode); LOG.error("Request path: " + requestUrl); LOG.error("-------------------------------------------------------------------------"); LOG.error("Failed Reason:"); LOG.error("Authentication was failed, please re-authenticate again!"); LOG.error("-------------------------------------------------------------------------"); LOG.error("========================================================================="); NotificationUtils.notifyUserVia(Labels.getLabel("marketplace.order.authorization.fail"), NotificationEvent.Type.FAILURE, ""); LOG.warn("Authentication was failed, please re-authenticate again!"); } else if (!("0".equals(responseCode))) { LOG.error("========================================================================="); LOG.error("Order incremental download request post to Tmall failed!"); LOG.error("Marketplacestore Code: " + model.getName()); LOG.error("Error Status Code: " + responseCode); LOG.error("Request path: " + requestUrl); LOG.error("-------------------------------------------------------------------------"); LOG.error("Failed Reason:"); LOG.error("A known issue occurs in tmall, error details :" + msg); LOG.error("-------------------------------------------------------------------------"); LOG.error("========================================================================="); /* * NotificationUtils.notifyUserVia(Labels.getLabel("marketplace.tmallapp.known.issues", new Object[] { msg * }), NotificationEvent.Type.FAILURE, ""); */ LOG.warn("A known issue occurs in tmall, error details :" + msg); } else if ("0".equals(responseCode)) { LOG.debug("Open listen sucessfully"); NotificationUtils.notifyUserVia(Labels.getLabel("marketplace.order.incremental.order.success"), NotificationEvent.Type.SUCCESS, ""); flag = true; LOG.info("========================================================================="); LOG.info("Order incremental download request post to Tmall suceessfully!"); LOG.info("-------------------------------------------------------------------------"); LOG.info("Marketplacestore Code: " + model.getName()); LOG.info("Request path: " + requestUrl); LOG.info("========================================================================="); } } catch (final HttpClientErrorException httpError) { if (httpError.getStatusCode().is4xxClientError()) { LOG.error("========================================================================="); LOG.error("Order incremental download request post to Tmall failed!"); LOG.error("Marketplacestore Code: " + model.getName()); LOG.error("Error Status Code: " + httpError.getStatusCode().toString()); LOG.error("Request path: " + requestUrl); LOG.error("-------------------------------------------------------------------------"); LOG.error("Failed Reason:"); LOG.error("Requested Tmall service URL is not correct!"); LOG.error("-------------------------------------------------------------------------"); LOG.error("Detail error info: " + httpError.getMessage()); LOG.error("========================================================================="); NotificationUtils.notifyUserVia(Labels.getLabel("marketplace.error.request.post.error"), NotificationEvent.Type.FAILURE, ""); } if (httpError.getStatusCode().is5xxServerError()) { LOG.error("========================================================================="); LOG.error("Order incremental download request post to Tmall failed!"); LOG.error("Marketplacestore Code: " + model.getName()); LOG.error("Error Status Code: " + httpError.getStatusCode().toString()); LOG.error("Request path: " + requestUrl); LOG.error("-------------------------------------------------------------------------"); LOG.error("Failed Reason:"); LOG.error("Requested Json Ojbect is not correct!"); LOG.error("-------------------------------------------------------------------------"); LOG.error("Detail error info: " + httpError.getMessage()); LOG.error("========================================================================="); NotificationUtils.notifyUserVia(Labels.getLabel("marketplace.error.server.process.error"), NotificationEvent.Type.FAILURE, ""); } LOG.error(httpError.toString()); return flag; } catch (final ResourceAccessException raError) { LOG.error("========================================================================="); LOG.error("Order incremental download request post to Tmall failed!"); LOG.error("Marketplacestore Code: " + model.getName()); LOG.error("Request path: " + requestUrl); LOG.error("-------------------------------------------------------------------------"); LOG.error("Failed Reason:"); LOG.error("Marketplace order download request server access failed!"); LOG.error("-------------------------------------------------------------------------"); LOG.error("Detail error info: " + raError.getMessage()); LOG.error("========================================================================="); NotificationUtils.notifyUserVia(Labels.getLabel("marketplace.error.server.access.error"), NotificationEvent.Type.FAILURE, ""); return flag; } catch (final HttpServerErrorException serverError) { LOG.error("========================================================================="); LOG.error("Order incremental download request post to Tmall failed!"); LOG.error("Marketplacestore Code: " + model.getName()); LOG.error("Request path: " + requestUrl); LOG.error("-------------------------------------------------------------------------"); LOG.error("Failed Reason:"); LOG.error("Marketplace order download request server process failed!"); LOG.error("-------------------------------------------------------------------------"); LOG.error("Detail error info: " + serverError.getMessage()); LOG.error("========================================================================="); NotificationUtils.notifyUserVia(Labels.getLabel("marketplace.error.server.process.error"), NotificationEvent.Type.FAILURE, ""); return flag; } catch (final Exception e) { final String errorMsg = e.getClass().toString() + ":" + e.getMessage(); NotificationUtils.notifyUserVia( Labels.getLabel("marketplace.runtime.issues", new Object[] { errorMsg }), NotificationEvent.Type.FAILURE, ""); LOG.error("========================================================================="); LOG.error("Order incremental download request failed!"); LOG.error("Marketplacestore Code: " + model.getName()); LOG.error("Request path: " + requestUrl); LOG.error("-------------------------------------------------------------------------"); LOG.error("Detail error info: " + e.getMessage()); LOG.error("========================================================================="); NotificationUtils.notifyUserVia(Labels.getLabel("marketplace.error.server.process.error"), NotificationEvent.Type.FAILURE, ""); LOG.warn(e.getMessage() + e.getStackTrace()); return flag; } return flag; }
From source file:org.alfresco.integrations.google.docs.service.GoogleDocsServiceImpl.java
private AccessGrant refreshAccessToken() throws GoogleDocsAuthenticationException, GoogleDocsRefreshTokenException, GoogleDocsServiceException { log.debug("Refreshing Access Token for " + AuthenticationUtil.getRunAsUser()); OAuth2CredentialsInfo credentialInfo = oauth2CredentialsStoreService .getPersonalOAuth2Credentials(GoogleDocsConstants.REMOTE_SYSTEM); if (credentialInfo.getOAuthRefreshToken() != null) { AccessGrant accessGrant = null;//from w w w . j a v a 2 s.c om try { accessGrant = connectionFactory.getOAuthOperations() .refreshAccess(credentialInfo.getOAuthRefreshToken(), GoogleDocsConstants.SCOPE, null); } catch (HttpClientErrorException hcee) { if (hcee.getStatusCode().value() == HttpStatus.SC_BAD_REQUEST) { throw new GoogleDocsAuthenticationException(hcee.getMessage()); } else if (hcee.getStatusCode().value() == HttpStatus.SC_UNAUTHORIZED) { throw new GoogleDocsAuthenticationException("Token Refresh Failed."); } else { throw new GoogleDocsServiceException(hcee.getMessage(), hcee.getStatusCode().value()); } } if (accessGrant != null) { Date expiresIn = null; if (accessGrant.getExpireTime() != null) { if (accessGrant.getExpireTime() > 0L) { expiresIn = new Date(new Date().getTime() + accessGrant.getExpireTime()); } } try { oauth2CredentialsStoreService.storePersonalOAuth2Credentials(GoogleDocsConstants.REMOTE_SYSTEM, accessGrant.getAccessToken(), credentialInfo.getOAuthRefreshToken(), expiresIn, new Date()); } catch (NoSuchSystemException nsse) { throw nsse; } } else { throw new GoogleDocsAuthenticationException("No Access Grant Returned."); } log.debug("Access Token Refreshed"); return accessGrant; } else { throw new GoogleDocsRefreshTokenException( "No Refresh Token Provided for " + AuthenticationUtil.getRunAsUser()); } }
From source file:org.alfresco.integrations.google.docs.service.GoogleDocsServiceImpl.java
/** * Get a connection to the Google APIs. Will attempt to refresh tokens if they are invalid. If unable to refresh return a * GoogleDocsRefreshTokenException.// w w w.j a v a 2 s. c o m * * @return * @throws GoogleDocsAuthenticationException * @throws GoogleDocsRefreshTokenException * @throws GoogleDocsServiceException */ private Connection<Google> getConnection() throws GoogleDocsAuthenticationException, GoogleDocsRefreshTokenException, GoogleDocsServiceException { Connection<Google> connection = null; // OAuth credentials for the current user, if the exist OAuth2CredentialsInfo credentialInfo = oauth2CredentialsStoreService .getPersonalOAuth2Credentials(GoogleDocsConstants.REMOTE_SYSTEM); if (credentialInfo != null) { log.debug("OAuth Access Token Exists: " + credentialInfo.getOAuthAccessToken()); AccessGrant accessGrant = new AccessGrant(credentialInfo.getOAuthAccessToken()); try { log.debug("Attempt to create OAuth Connection"); connection = connectionFactory.createConnection(accessGrant); } catch (HttpClientErrorException hcee) { log.debug(hcee.getResponseBodyAsString()); if (hcee.getStatusCode().value() == HttpStatus.SC_UNAUTHORIZED) { try { accessGrant = refreshAccessToken(); connection = connectionFactory.createConnection(accessGrant); } catch (GoogleDocsRefreshTokenException gdrte) { throw gdrte; } catch (GoogleDocsServiceException gdse) { throw gdse; } } else { throw new GoogleDocsServiceException(hcee.getMessage(), hcee, hcee.getStatusCode().value()); } } catch (HttpServerErrorException hsee) { throw new GoogleDocsServiceException(hsee.getMessage(), hsee, hsee.getStatusCode().value()); } } log.debug("Connection Created"); return connection; }
From source file:org.apache.servicecomb.demo.jaxrs.client.CodeFirstRestTemplateJaxrs.java
private void test404(RestTemplate template) { HttpClientErrorException exception = null; try {//from w w w .j av a 2 s.c om template.getForEntity("http://127.0.0.1:8080/aPathNotExist", String.class); } catch (RestClientException e) { if (e instanceof HttpClientErrorException) { exception = (HttpClientErrorException) e; } } TestMgr.check(404, exception.getRawStatusCode()); TestMgr.check("404 Not Found", exception.getMessage()); }
From source file:org.opentestsystem.authoring.testspecbank.client.TestSpecBankClient.java
@Override public Optional<ValidationError> deleteTestSpecification(final String testSpecificationKey) { Optional<ValidationError> maybeValidationError = Optional.empty(); final URI uri = UriComponentsBuilder .fromUriString(String.format("%stestSpecification/%s", baseUri, testSpecificationKey)).build() .toUri();//from w w w . ja v a2 s . co m try { tsbOauthRestTemplate.delete(uri); } catch (final HttpClientErrorException hce) { LOGGER.error("Error deleting {0} test specification: ", hce); if (hce.getStatusCode() == HttpStatus.UNPROCESSABLE_ENTITY) { try { // The NoContentResponseResource contains an array of ValidationErrors. If we got to this point, // the TestSpecificationController#deleteTestSpecification endpoint will have returned a // NoContentResponseResource with a single ValidationError describing what went wrong. final NoContentResponseResource response = objectMapper.readValue(hce.getResponseBodyAsString(), NoContentResponseResource.class); maybeValidationError = Optional.of(response.getErrors()[0]); } catch (final Exception mapEx) { LOGGER.error(String.format("Error mapping response %s to ValidationError: ", hce.getResponseBodyAsString()), mapEx); final String errorMessage = mapEx.getMessage() == null ? mapEx.getClass().getName() : mapEx.getMessage(); maybeValidationError = Optional.of(new ValidationError("mapping exception", errorMessage)); } } else { maybeValidationError = Optional.of(new ValidationError("client exception", hce.getMessage())); } } catch (final Exception e) { LOGGER.error("Error deleting {0} test specification: ", e); maybeValidationError = Optional.of(new ValidationError("server exception", e.getMessage())); } return maybeValidationError; }
From source file:org.springframework.social.connect.web.ConnectSupport.java
/** * Complete the connection to the OAuth2 provider. * @param connectionFactory the service provider's connection factory e.g. FacebookConnectionFactory * @param request the current web request * @return a new connection to the service provider */// w w w . j av a2s .c o m public Connection<?> completeConnection(OAuth2ConnectionFactory<?> connectionFactory, NativeWebRequest request) { if (connectionFactory.supportsStateParameter()) { verifyStateParameter(request); } String code = request.getParameter("code"); try { AccessGrant accessGrant = connectionFactory.getOAuthOperations().exchangeForAccess(code, callbackUrl(request), null); return connectionFactory.createConnection(accessGrant); } catch (HttpClientErrorException e) { logger.warn("HttpClientErrorException while completing connection: " + e.getMessage()); logger.warn(" Response body: " + e.getResponseBodyAsString()); throw e; } }