List of usage examples for org.springframework.web.client HttpClientErrorException toString
public String toString()
From source file:com.provenance.cloudprovenance.connector.traceability.TraceabilityStoreConnector.java
public String getCurrentTraceabilityRecordId(URL serviceId) { // URI encoded RestTemplate restTemplate = new RestTemplate(); // restTemplate.get ResponseEntity<String> traceabilityResponseEntity = null; try {//from w w w . j a v a 2s.co m traceabilityResponseEntity = restTemplate.getForEntity(serviceId.toExternalForm(), String.class); if (traceabilityResponseEntity.getStatusCode().value() == 200) { return traceabilityResponseEntity.getBody(); } else { return null; } } catch (org.springframework.web.client.HttpClientErrorException ex) { logger.warn(ex.toString()); return null; } }
From source file:com.provenance.cloudprovenance.connector.traceability.TraceabilityStoreConnector.java
public String getCurrentTraceabilityRecordId(String serviceId) { // URI encoded String restURI = UriEncoder.encode("http://" + server_add + ":" + port_no + "/" + service + "/" + resource + "/" + serviceId + "/" + this.TRACEABILITY_TYPE); RestTemplate restTemplate = new RestTemplate(); // restTemplate.get ResponseEntity<String> traceabilityResponseEntity = null; try {//w ww . j ava 2 s . c o m traceabilityResponseEntity = restTemplate.getForEntity(restURI, String.class); if (traceabilityResponseEntity.getStatusCode().value() == 200) { return traceabilityResponseEntity.getBody(); } else { return null; } } catch (org.springframework.web.client.HttpClientErrorException ex) { logger.warn(ex.toString()); return null; } // ResponseEntity<String> traceabilityDocId = // restTemplate.exchange(restURI, HttpMethod.GET, null, String.class); // System.out.println(traceabilityDocId.getBody()); // System.out.println(traceabilityDocId.getStatusCode()); // return traceabilityDocId.getBody(); }
From source file:org.energyos.espi.thirdparty.web.AuthorizationController.java
@RequestMapping(value = Routes.THIRD_PARTY_OAUTH_CODE_CALLBACK, method = RequestMethod.GET) public String authorization(String code, String state, ModelMap model, Principal principal, @RequestParam(value = "error", required = false) String error, @RequestParam(value = "error_description", required = false) String error_description, @RequestParam(value = "error_uri", required = false) String error_uri) { try {/* w ww. ja v a 2 s. c o m*/ // Is /oauth/authorization response valid (i.e. is the "state" // element correct)? Authorization authorization = authorizationService.findByState(state); // Process valid /oauth/authorization response ApplicationInformation applicationInformation = authorization.getApplicationInformation(); // Verify /oauth/authorization Endpoint process completed // successfully if (code != null) { try { // Update Authorization record with returned authorization // code for audit purposes authorization.setCode(code); authorization.setGrantType("authorization_code"); authorization.setUpdated(new GregorianCalendar()); authorizationService.merge(authorization); // Format /oauth/token Endpoint request String url = String.format("%s?redirect_uri=%s&code=%s&grant_type=authorization_code", applicationInformation.getAuthorizationServerTokenEndpoint(), applicationInformation.getRedirectUri(), code); // Build /oauth/token Endpoint request ClientRestTemplate restTemplate = templateFactory.newClientRestTemplate( applicationInformation.getClientId(), applicationInformation.getClientSecret()); // Issue /oauth/token Endpoint request AccessToken token = restTemplate.getForObject(url, AccessToken.class); // Process /oauth/token Endpoint response if (token.getAccessToken() != null) { authorization.setAccessToken(token.getAccessToken()); authorization.setTokenType(token.getTokenType()); authorization.setExpiresIn(token.getExpiresIn()); authorization.setRefreshToken(token.getRefreshToken()); authorization.setScope(token.getScope()); authorization.setAuthorizationURI(token.getAuthorizationURI()); authorization.setResourceURI(token.getResourceURI()); authorization.setUpdated(new GregorianCalendar()); authorization.setStatus("1"); // Set authorization // record status as // "Active" authorization.setState(null); // Clear State as a // security measure // Update authorization record with /oauth/token // response data authorizationService.merge(authorization); // now do the initial import of the Authorized Resource, // if it is // not ready, then we will wait till we receive a Notify // or the UX call for it. // TODO: create a Subscription to work with if needed RetailCustomer currentCustomer = currentCustomer(principal); try { usagePointRESTRepository.findAllByRetailCustomerId(currentCustomer.getId()); } catch (JAXBException e) { // nothing there, so log the fact and move on. It // will get imported later. System.out.printf("\nThirdParty Import Exception: %s\n", e.toString()); e.printStackTrace(); } } else { System.out.printf("\n/oauth/token Request did not return an access token\n"); } } catch (HttpClientErrorException x) { // TODO: Extract error, error_description and error_uri from // JSON response. Currently recording null for all three // fields. // Update authorization record System.out.printf("\nHTTPClientException: %s\n", x.toString()); authorization.setError(error); authorization.setErrorDescription(error_description); authorization.setErrorUri(error_uri); authorization.setUpdated(new GregorianCalendar()); authorization.setStatus("2"); // Set authorization record // status as "Denied" authorization.setState(null); // Clear State as a security // measure authorizationService.merge(authorization); // TODO: Should the "message" differ based on the exception? throw new UserDeniedAuthorizationException("Unable to retrieve OAuth token", x); } } else { System.out.printf("\nOAuth2 authorization_request returned an error:\n"); System.out.printf("Error: " + error + "\n"); System.out.printf("Error_description: " + error_description + "\n"); System.out.printf("Error_uri: " + error_uri + "\n"); // Update authorization record with error response authorization.setError(error); authorization.setErrorDescription(error_description); authorization.setErrorUri(error_uri); authorization.setUpdated(new GregorianCalendar()); authorization.setStatus("2"); // Set authorization record status // as "Denied" authorization.setState(null); // Clear State as a security // measure authorizationService.merge(authorization); throw new UserDeniedAuthorizationException("Error: " + error_description); } } catch (NoResultException | EmptyResultDataAccessException e) { // We received an invalid /oauth/authorization response // TODO: Log receipt of an invalid /oauth/authorization response return "/home"; } return "redirect:/RetailCustomer/" + currentCustomer(principal).getId() + "/AuthorizationList"; }
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;// ww w . j a va 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.MarketplaceIntegrationOrderRequestRenderer.java
private void orderRequestDownload(final MarketplaceStoreModel model) { if (null == model.getRequestStartTime()) { NotificationUtils/*from w ww .java 2s. 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.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);// www . j av a2 s . c om 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;/* www .j a v a 2s . c om*/ 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; }