List of usage examples for org.springframework.web.client ResourceAccessException getMessage
@Override
@Nullable
public String getMessage()
From source file:org.kaaproject.kaa.server.common.admin.KaaRestTemplate.java
@Override protected <T> T doExecute(URI url, HttpMethod method, RequestCallback requestCallback, ResponseExtractor<T> responseExtractor) throws ResourceAccessException { int maxRetry = hosts.length; while (true) { try {// w ww.j av a 2s . c o m return super.doExecute(url, method, requestCallback, responseExtractor); } catch (ResourceAccessException ex) { logger.info("Connect to ({}:{}) failed", getCurHost(), getCurPort(), ex); boolean isRequestFactorySet = false; while (!isRequestFactorySet) { if (index < hosts.length - 1) { index++; } else { index = 0; } logger.info("Trying connect to ({}:{})", getCurHost(), getCurPort(), ex); if (maxRetry <= 0) { logger.error("Failed to connect to ({}:{})", getCurHost(), getCurPort(), ex); throw new ResourceAccessException( "I/O error on " + method.name() + " request for \"" + url + "\":" + ex.getMessage(), new IOException(ex)); } else { maxRetry--; } try { setNewRequestFactory(index); } catch (Exception exception) { logger.info("Failed to initialize new request factory ({}:{})", getCurHost(), getCurPort(), exception); continue; } url = updateUrl(url); isRequestFactorySet = true; } } catch (RestClientException ex) { throw ex; } } }
From source file:de.hybris.platform.marketplaceintegrationbackoffice.renderer.MarketplaceIntegrationOrderRequestRenderer.java
private void orderRequestDownload(final MarketplaceStoreModel model) { if (null == model.getRequestStartTime()) { NotificationUtils// www .j av a2 s. co m .notifyUserVia( Localization.getLocalizedString( "type.Marketplacestore." + MarketplaceStoreModel.REQUESTSTARTTIME + ".name") + " " + Labels.getLabel("backoffice.field.notfilled"), NotificationEvent.Type.WARNING, ""); LOG.warn("Order request start time is not filled!"); return; } else if (null == model.getRequestEndTime()) { NotificationUtils.notifyUserVia(Localization .getLocalizedString("type.Marketplacestore." + MarketplaceStoreModel.REQUESTENDTIME + ".name") + " " + Labels.getLabel("backoffice.field.notfilled"), NotificationEvent.Type.WARNING, ""); LOG.warn("Order request end time is not filled!"); return; } else if (model.getRequestStartTime().after(model.getRequestEndTime())) { NotificationUtils.notifyUserVia(Labels.getLabel("backoffice.field.timerange.error"), NotificationEvent.Type.WARNING, ""); LOG.warn("start time is greater than end time!"); 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.refund.requestorder.unauthed"), NotificationEvent.Type.WARNING, ""); LOG.warn("marketplace store do not authorized, download refund/return order 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_REFUND_SYCHRONIZE_PATH) + Config.getParameter(MARKETPLACE_REFUND_REQUEST_PATH) + integrationId + Config.getParameter(MARKETPLACE_REFUND_REQUEST_LOGUUID) + logUUID; final JSONObject jsonObj = new JSONObject(); jsonObj.put("batchSize", BATCH_SIZE); //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.getRequestStartTime()).toString(); final String endTimeWithCorrectZone = format.format(model.getRequestEndTime()).toString(); logUtil.addMarketplaceLog("PENDING", integrationId, Labels.getLabel("marketplace.order.requestorder.action"), model.getItemtype(), marketPlace, model, logUUID); jsonObj.put("startCreated", startTimeWithCorrectZone); jsonObj.put("endCreated", endTimeWithCorrectZone); jsonObj.put("productCatalogVersion", model.getCatalogVersion().getCatalog().getId() + ":" + model.getCatalogVersion().getVersion()); jsonObj.put("currency", model.getCurrency().getIsocode()); marketplaceHttpUtil.post(urlStr, jsonObj.toJSONString()); } catch (final HttpClientErrorException httpError) { if (httpError.getStatusCode().is4xxClientError()) { LOG.error("========================================================================="); LOG.error("Order 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("-------------------------------------------------------------------------"); 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 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("-------------------------------------------------------------------------"); 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 Request post to Tmall failed!"); LOG.error("Marketplacestore Code: " + model.getName()); LOG.error("Request path: " + urlStr); LOG.error("-------------------------------------------------------------------------"); LOG.error("Failed Reason:"); LOG.error("Order 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; } catch (final HttpServerErrorException serverError) { LOG.error("========================================================================="); LOG.error("Order Request post to Tmall failed!"); LOG.error("Marketplacestore Code: " + model.getName()); LOG.error("Request path: " + urlStr); LOG.error("-------------------------------------------------------------------------"); LOG.error("Failed Reason:"); LOG.error("Order 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; } catch (final Exception e) { LOG.error("========================================================================="); LOG.error("Order Request failed!"); LOG.error("Marketplacestore Code: " + model.getName()); LOG.error("Request path: " + urlStr); LOG.error("-------------------------------------------------------------------------"); LOG.error("Failed Reason:"); LOG.error("Order Request server process failed!"); LOG.error("-------------------------------------------------------------------------"); LOG.error("Detail error info: " + e.getMessage()); LOG.error("========================================================================="); NotificationUtils.notifyUserVia(Labels.getLabel("marketplace.refund.requestorder.fail"), NotificationEvent.Type.FAILURE, ""); return; } NotificationUtils.notifyUserVia(Labels.getLabel("marketplace.refund.requestorder.success"), NotificationEvent.Type.SUCCESS, ""); }
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 www . j a v a 2s.c om*/ } 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 ww w . jav 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:de.hybris.platform.mpintgomsbackoffice.actions.sync.SyncToMarketplaceAction.java
@Override public ActionResult<ConsignmentModel> perform(final ActionContext<ConsignmentModel> actionContext) { String result = StringUtils.EMPTY; final ConsignmentModel consignment = actionContext.getData(); final TmallOrderModel order = (TmallOrderModel) consignment.getOrder(); if (order == null) { result = ActionResult.ERROR;/* w w w . jav a 2 s. c o m*/ final ActionResult<ConsignmentModel> actionResult = new ActionResult<ConsignmentModel>(result); actionResult.getStatusFlags().add(ActionResult.StatusFlag.OBJECT_PERSISTED); NotificationUtils.notifyUserVia(Labels.getLabel("marketplace.consignment.integrity.error"), NotificationEvent.Type.FAILURE, ""); LOG.warn("Can not find corresponding order for this consignment: " + consignment.getCode()); return actionResult; } final Set<ConsignmentEntryModel> consignmentEntries = consignment.getConsignmentEntries(); final Set<ConsignmentModel> consignments = order.getConsignments(); String subTid = ""; String urlStr = ""; String marketplaceLogId = ""; getModelService().save(consignment); if (StringUtils.isBlank(order.getMarketplaceStore().getIntegrationId())) { NotificationUtils.notifyUserVia( Labels.getLabel("marketplace.consignment.request.url.error", new Object[] { order.getMarketplaceStore().getName() }), NotificationEvent.Type.WARNING, ""); LOG.warn("authorization is expired!"); result = ActionResult.ERROR; final ActionResult<ConsignmentModel> actionResult = new ActionResult<ConsignmentModel>(result); actionResult.getStatusFlags().add(ActionResult.StatusFlag.OBJECT_PERSISTED); return actionResult; } else if (StringUtils.isBlank(consignment.getMarketplaceTrackingID())) { NotificationUtils.notifyUserVia(Labels.getLabel("marketplace.consignment.trackingid.empty"), NotificationEvent.Type.WARNING, ""); LOG.warn("Confirm failed due to trackingid is empty for model " + consignment); result = ActionResult.ERROR; final ActionResult<ConsignmentModel> actionResult = new ActionResult<ConsignmentModel>(result); actionResult.getStatusFlags().add(ActionResult.StatusFlag.OBJECT_PERSISTED); return actionResult; } else if (null == consignment.getStandardCarrier()) { NotificationUtils.notifyUserVia(Labels.getLabel("marketplace.consignment.carrier.null"), NotificationEvent.Type.WARNING, ""); LOG.warn("Confirm failed due to carrier is null for model " + consignment); result = ActionResult.ERROR; final ActionResult<ConsignmentModel> actionResult = new ActionResult<ConsignmentModel>(result); actionResult.getStatusFlags().add(ActionResult.StatusFlag.OBJECT_PERSISTED); return actionResult; } if (!MARKETPLACE_CONSIGNMENT_CONFIRM_STATUS.equals(order.getTmallOrderStatus().getCode())) { if (!MARKETPLACE_CONSIGNMENT_PART_STATUS.equals(order.getTmallOrderStatus().getCode())) { NotificationUtils.notifyUserVia(Labels.getLabel("marketplace.consignment.status.fail"), NotificationEvent.Type.WARNING, ""); LOG.warn("Confirm failed due to order status is not correct!"); result = ActionResult.ERROR; final ActionResult<ConsignmentModel> actionResult = new ActionResult<ConsignmentModel>(result); actionResult.getStatusFlags().add(ActionResult.StatusFlag.OBJECT_PERSISTED); return actionResult; } } for (final ConsignmentEntryModel consignmententry : consignmentEntries) { final TmallOrderEntryModel tmallOrderEntry = (TmallOrderEntryModel) consignmententry.getOrderEntry(); subTid = subTid + tmallOrderEntry.getOid() + ","; if (RefundStatus.WAIT_SELLER_AGREE.equals(tmallOrderEntry.getRefundStatus()) || RefundStatus.WAIT_BUYER_RETURN_GOODS.equals(tmallOrderEntry.getRefundStatus()) || RefundStatus.WAIT_SELLER_CONFIRM_GOODS.equals(tmallOrderEntry.getRefundStatus()) || RefundStatus.SUCCESS.equals(tmallOrderEntry.getRefundStatus())) { NotificationUtils.notifyUserVia(Labels.getLabel("marketplace.consignment.status.fail"), NotificationEvent.Type.WARNING, ""); LOG.warn("Confirm failed due to refund status is not correct!"); result = ActionResult.ERROR; final ActionResult<ConsignmentModel> actionResult = new ActionResult<ConsignmentModel>(result); actionResult.getStatusFlags().add(ActionResult.StatusFlag.OBJECT_PERSISTED); return actionResult; } } try { marketplaceLogId = marketplaceHttpUtil.getUUID(); logUtil.addMarketplaceLog("PENDING", consignment.getCode(), Labels.getLabel("mpintgomsbackoffice.consignment.action"), consignment.getItemtype(), order.getMarketplaceStore().getMarketplace(), consignment, marketplaceLogId); urlStr = requestUrl + Config.getParameter(MARKETPLACE_CONSIGNMENT_CONFIRM_PATH); final JSONObject jsonObj = new JSONObject(); jsonObj.put("integrationId", order.getMarketplaceStore().getIntegrationId()); //Whether splited if (consignments.size() > 1) { final String isSplit = "1"; jsonObj.put("isSplit", isSplit); jsonObj.put("subTid", subTid); } jsonObj.put("tmallOrderId", order.getTmallOrderId()); jsonObj.put("trackingId", consignment.getMarketplaceTrackingID()); //jsonObj.put("companyCode", consignment.getMarketplaceCarrier().getCode()); final String standardCarrierPK = consignment.getStandardCarrier().getPk().getLongValueAsString(); final String marketplacePK = order.getMarketplaceStore().getMarketplace().getPk() .getLongValueAsString(); final String queryString = "SELECT {" + MarketplaceCarrierModel.CODE + "} FROM {" + MarketplaceCarrierModel._TYPECODE + "} " + "WHERE {" + MarketplaceCarrierModel.MARKETPLACE + "}=?marketplacePK" + " and {" + MarketplaceCarrierModel.STANDARDCARRIER + "}=?standardCarrierPK"; final FlexibleSearchQuery query = new FlexibleSearchQuery(queryString); query.addQueryParameter("marketplacePK", marketplacePK); query.addQueryParameter("standardCarrierPK", standardCarrierPK); final SearchResult<String> companyCode = flexibleSearchService.<String>search(query); jsonObj.put("companyCode", companyCode); jsonObj.put("marketplaceLogId", marketplaceLogId); JSONObject results = new JSONObject(); results = marketplaceHttpUtil.post(urlStr, jsonObj.toJSONString()); final String msg = results.toJSONString(); final String responseCode = results.get("code").toString(); if ("401".equals(responseCode)) { NotificationUtils.notifyUserVia(Labels.getLabel("marketplace.order.authorization.fail"), NotificationEvent.Type.FAILURE, ""); LOG.warn("Authentication was failed, please re-authenticate again!"); result = ActionResult.ERROR; } else if (!("0".equals(responseCode))) { 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); result = ActionResult.ERROR; } } catch (final HttpClientErrorException httpError) { if (httpError.getStatusCode().is4xxClientError()) { LOG.error("========================================================================="); LOG.error("Order consignment upload request post to Datahub failed!"); LOG.error("Consignment Code: " + consignment.getCode()); LOG.error("Error Status Code: " + httpError.getStatusCode().toString()); LOG.error("Request path: " + urlStr); LOG.error("-------------------------------------------------------------------------"); LOG.error("Failed Reason:"); LOG.error("Requested Datahub service URL is not correct!"); LOG.error("-------------------------------------------------------------------------"); LOG.error("========================================================================="); NotificationUtils.notifyUserVia(Labels.getLabel("marketplace.consignment.request.post.error"), NotificationEvent.Type.FAILURE, ""); } if (httpError.getStatusCode().is5xxServerError()) { LOG.error("========================================================================="); LOG.error("Order consignment upload request post to Datahub failed!"); LOG.error("Consignment Code: " + consignment.getCode()); 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("-------------------------------------------------------------------------"); LOG.error("========================================================================="); NotificationUtils.notifyUserVia(Labels.getLabel("marketplace.consignment.server.process.error"), NotificationEvent.Type.FAILURE, ""); } LOG.error(httpError.toString()); result = ActionResult.ERROR; final ActionResult<ConsignmentModel> actionResult = new ActionResult<ConsignmentModel>(result); return actionResult; } catch (final ResourceAccessException raError) { LOG.error("========================================================================="); LOG.error("Order consignment upload request post to Datahub failed!"); LOG.error("Consignment Code: " + consignment.getCode()); LOG.error("Request path: " + urlStr); LOG.error("-------------------------------------------------------------------------"); LOG.error("Failed Reason:"); LOG.error("Marketplace order consignment upload request server access failed!"); LOG.error("-------------------------------------------------------------------------"); LOG.error("Detail error info: " + raError.getMessage()); LOG.error("========================================================================="); //LOG.error(raError.toString()); NotificationUtils.notifyUserVia(Labels.getLabel("marketplace.consignment.server.access.error"), NotificationEvent.Type.FAILURE, ""); result = ActionResult.ERROR; final ActionResult<ConsignmentModel> actionResult = new ActionResult<ConsignmentModel>(result); return actionResult; } catch (final HttpServerErrorException serverError) { LOG.error("========================================================================="); LOG.error("Order consignment upload request post to Datahub failed!"); LOG.error("Consignment Code: " + consignment.getCode()); LOG.error("Request path: " + urlStr); LOG.error("-------------------------------------------------------------------------"); LOG.error("Failed Reason:"); LOG.error("Marketplace order consignment upload request server process failed!"); LOG.error("-------------------------------------------------------------------------"); LOG.error("Detail error info: " + serverError.getMessage()); LOG.error("========================================================================="); //LOG.error(raError.toString()); NotificationUtils.notifyUserVia(Labels.getLabel("marketplace.consignment.server.process.error"), NotificationEvent.Type.FAILURE, ""); result = ActionResult.ERROR; final ActionResult<ConsignmentModel> actionResult = new ActionResult<ConsignmentModel>(result); return actionResult; } catch (final Exception e) { NotificationUtils.notifyUserVia(Labels.getLabel("marketplace.consignment.upload.fail"), NotificationEvent.Type.FAILURE, ""); result = ActionResult.ERROR; LOG.error("========================================================================="); LOG.error("Order consignment failed!"); LOG.error("Marketplacestore Code: " + consignment.getCode()); LOG.error("Request path: " + requestUrl); LOG.error("-------------------------------------------------------------------------"); LOG.error("Detail error info: " + e.getMessage()); LOG.error("-------------------------------------------------------------------------"); LOG.error("========================================================================="); final ActionResult<ConsignmentModel> actionResult = new ActionResult<ConsignmentModel>(result); return actionResult; } LOG.info("========================================================================="); LOG.info("Order consignment upload request post to Datahub suceessfully!"); LOG.info("Consignment Code: " + consignment.getCode()); LOG.info("Request path: " + urlStr); LOG.info("========================================================================="); NotificationUtils.notifyUserVia(Labels.getLabel("marketplace.consignment.upload.success"), NotificationEvent.Type.SUCCESS, ""); result = ActionResult.SUCCESS; setFlag(consignment); final ActionResult<ConsignmentModel> actionResult = new ActionResult<ConsignmentModel>(result); actionResult.getStatusFlags().add(ActionResult.StatusFlag.OBJECT_PERSISTED); return actionResult; }
From source file:org.pesc.cds.web.TranscriptRequestController.java
private void sendDocument(File outboxFile, String endpointURI, Transaction tx, String fileFormat, String documentType, String department) throws IOException { byte[] fileSignature = pkiService.createDigitalSignature(new FileInputStream(outboxFile), pkiService.getSigningKeys().getPrivate()); try {// w w w . j a v a 2 s . c o m LinkedMultiValueMap<String, Object> map = new LinkedMultiValueMap<>(); map.add("recipient_id", tx.getRecipientId()); map.add("sender_id", tx.getSenderId()); map.add("signer_id", localServerId); map.add("file_format", fileFormat); map.add("document_type", documentType); map.add("department", department); map.add("transaction_id", tx.getId()); map.add("ack_url", localServerWebServiceURL); map.add("file", new FileSystemResource(outboxFile)); map.add("signature", new ByteArrayResource(fileSignature) { @Override public String getFilename() { return "signature.dat"; } }); org.springframework.http.HttpHeaders headers = new org.springframework.http.HttpHeaders(); headers.setContentType(org.springframework.http.MediaType.MULTIPART_FORM_DATA); ResponseEntity<String> response = restTemplate.exchange(endpointURI, HttpMethod.POST, new org.springframework.http.HttpEntity<Object>(map, headers), String.class); if (response.getStatusCode() != HttpStatus.OK) { throw new IllegalArgumentException( "Failed to send document. Reason: " + response.getStatusCode().getReasonPhrase()); } log.info(response.getStatusCode().getReasonPhrase()); } catch (ResourceAccessException e) { //Force the OAuth client to retrieve the token again whenever it is used again. restTemplate.getOAuth2ClientContext().setAccessToken(null); tx.setError(e.getMessage()); transactionService.update(tx); log.error(e); throw new IllegalArgumentException(e); } catch (Exception e) { tx.setError(e.getMessage()); transactionService.update(tx); log.error(e); throw new IllegalArgumentException(e); } }