List of usage examples for org.springframework.web.client HttpClientErrorException getStatusCode
public HttpStatus getStatusCode()
From source file:com.ge.predix.integration.test.PrivilegeManagementAccessControlServiceIT.java
public void testBatchCreateResourcesEmptyList() { List<BaseResource> resources = new ArrayList<BaseResource>(); try {/* w w w . j av a 2 s .c om*/ this.acsAdminRestTemplate.postForEntity(this.acsUrl + PrivilegeHelper.ACS_RESOURCE_API_PATH, new HttpEntity<>(resources, this.zone1Headers), BaseResource[].class); } catch (HttpClientErrorException e) { Assert.assertEquals(e.getStatusCode(), HttpStatus.UNPROCESSABLE_ENTITY); return; } Assert.fail("Expected unprocessable entity http client error."); }
From source file:com.ge.predix.integration.test.PrivilegeManagementAccessControlServiceIT.java
@Test(dataProvider = "invalidResourcePostProvider") public void testPostResourceNegativeCases(final BaseResource resource, final String endpoint) { try {//from ww w . ja v a 2 s . c o m this.privilegeHelper.postResources(this.acsAdminRestTemplate, endpoint, this.zone1Headers, resource); } catch (HttpClientErrorException e) { Assert.assertEquals(e.getStatusCode(), HttpStatus.UNPROCESSABLE_ENTITY); return; } catch (Exception e) { Assert.fail("Unable to create resource."); } Assert.fail("Expected UnprocessibleEntity status code in testPostResourceNegativeCases"); }
From source file:com.ge.predix.integration.test.PrivilegeManagementAccessControlServiceIT.java
public void testUpdateResourceURIMismatch() throws Exception { try {//from w ww .j a v a 2 s . c o m this.privilegeHelper.putResource(this.acsAdminRestTemplate, SANRAMON, this.acsUrl, this.zone1Headers, this.privilegeHelper.getDefaultAttribute()); URI resourceUri = URI.create(this.acsUrl + PrivilegeHelper.ACS_RESOURCE_API_PATH + URLEncoder.encode("/different/resource", "UTF-8")); this.acsAdminRestTemplate.put(resourceUri, new HttpEntity<>(SANRAMON, this.zone1Headers)); } catch (HttpClientErrorException e) { Assert.assertEquals(e.getStatusCode(), HttpStatus.UNPROCESSABLE_ENTITY); return; } Assert.fail("Expected Unprocessible Entity status code in testUpdateResourceURIMismatchV1"); }
From source file:com.ge.predix.integration.test.PrivilegeManagementAccessControlServiceIT.java
public void testPutSubjectMismatchURI() { try {/*from ww w.j a va 2 s . c o m*/ String subjectIdentifier = "marcia"; URI subjectUri = URI.create(this.acsUrl + PrivilegeHelper.ACS_SUBJECT_API_PATH + URLEncoder.encode(subjectIdentifier, "UTF-8")); this.acsAdminRestTemplate.put(subjectUri, new HttpEntity<>(BOB_V1, this.zone1Headers)); Assert.fail("Subject " + subjectIdentifier + " was not supposed to be created"); } catch (HttpClientErrorException e) { Assert.assertEquals(e.getStatusCode(), HttpStatus.UNPROCESSABLE_ENTITY); return; } catch (Exception e) { Assert.fail("Unable to create subject."); } Assert.fail("Expected Unprocessible Entity status code in testPutSubjectMismatchURIV1"); }
From source file:com.ge.predix.integration.test.PrivilegeManagementAccessControlServiceIT.java
@Test(dataProvider = "invalidSubjectPostProvider") public void testPostSubjectNegativeCases(final BaseSubject subject, final String endpoint) { try {//from w ww . j a va 2 s . c o m this.privilegeHelper.postMultipleSubjects(this.acsAdminRestTemplate, endpoint, this.zone1Headers, subject); } catch (HttpClientErrorException e) { Assert.assertEquals(e.getStatusCode(), HttpStatus.UNPROCESSABLE_ENTITY); return; } catch (Exception e) { Assert.fail("Unable to create subject."); } Assert.fail("Expected Unprocessible Entity status code in testPostSubjectNegativeCases"); }
From source file:com.ge.predix.integration.test.PrivilegeManagementAccessControlServiceIT.java
@Test public void testBatchSubjectsDataConstraintViolationSubjectIdentifier() { List<BaseSubject> subjects = new ArrayList<BaseSubject>(); subjects.add(this.privilegeHelper.createSubject("marissa")); subjects.add(this.privilegeHelper.createSubject("marissa")); try {//w ww .j ava 2 s . co m this.acsAdminRestTemplate.postForEntity(this.acsUrl + PrivilegeHelper.ACS_SUBJECT_API_PATH, new HttpEntity<>(subjects, this.zone1Headers), ResponseEntity.class); } catch (HttpClientErrorException e) { Assert.assertEquals(e.getStatusCode(), HttpStatus.UNPROCESSABLE_ENTITY); return; } this.acsAdminRestTemplate.exchange(this.acsUrl + PrivilegeHelper.ACS_SUBJECT_API_PATH + "/marissa", HttpMethod.DELETE, new HttpEntity<>(this.zone1Headers), ResponseEntity.class); Assert.fail("Expected unprocessable entity http client error."); }
From source file:com.ge.predix.integration.test.PrivilegeManagementAccessControlServiceIT.java
public void testCreateSubjectWithMalformedJSON() { try {//from ww w . ja v a 2 s . c om String badSubject = "{\"subject\": bad-subject-form\"}"; MultiValueMap<String, String> headers = new HttpHeaders(); headers.add("Content-type", "application/json"); headers.add(PolicyHelper.PREDIX_ZONE_ID, this.acsZone1Name); HttpEntity<String> httpEntity = new HttpEntity<String>(badSubject, headers); this.acsAdminRestTemplate.put(this.acsUrl + PrivilegeHelper.ACS_SUBJECT_API_PATH + "/bad-subject-form", httpEntity); } catch (HttpClientErrorException e) { Assert.assertEquals(e.getStatusCode(), HttpStatus.BAD_REQUEST); return; } this.acsAdminRestTemplate.exchange(this.acsUrl + PrivilegeHelper.ACS_SUBJECT_API_PATH + "/bad-subject-form", HttpMethod.DELETE, new HttpEntity<>(this.zone1Headers), ResponseEntity.class); Assert.fail("testCreateSubjectWithMalformedJSON should have failed!"); }
From source file:com.ge.predix.integration.test.PrivilegeManagementAccessControlServiceIT.java
public void testCreateResourceWithMalformedJSON() { try {// w w w .java 2 s.com String badResource = "{\"resource\": bad-resource-form\"}"; MultiValueMap<String, String> headers = new HttpHeaders(); headers.add("Content-type", "application/json"); headers.add(PolicyHelper.PREDIX_ZONE_ID, this.acsZone1Name); HttpEntity<String> httpEntity = new HttpEntity<String>(badResource, headers); this.acsAdminRestTemplate .put(this.acsUrl + PrivilegeHelper.ACS_RESOURCE_API_PATH + "/bad-resource-form", httpEntity); } catch (HttpClientErrorException e) { Assert.assertEquals(e.getStatusCode(), HttpStatus.BAD_REQUEST); return; } this.acsAdminRestTemplate.exchange( this.acsUrl + PrivilegeHelper.ACS_RESOURCE_API_PATH + "/bad-resource-form", HttpMethod.DELETE, new HttpEntity<>(this.zone1Headers), ResponseEntity.class); Assert.fail("testCreateResourceWithMalformedJSON should have failed!"); }
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 ww. ja va 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:com.ge.predix.integration.test.PrivilegeManagementAccessControlServiceIT.java
public void testCreateBatchResourcesWithMalformedJSON() { try {/* ww w. j a v a2 s.c om*/ String badResource = "{\"resource\":{\"name\" : \"Site\", \"uriTemplate\" : " + "\"/secured-by-value/sites/{site_id}\"},{\"resource\": bad-resource-form\"}"; MultiValueMap<String, String> headers = new HttpHeaders(); headers.add("Content-type", "application/json"); headers.add(PolicyHelper.PREDIX_ZONE_ID, this.acsZone1Name); HttpEntity<String> httpEntity = new HttpEntity<String>(badResource, headers); this.acsAdminRestTemplate.postForEntity(this.acsUrl + PrivilegeHelper.ACS_RESOURCE_API_PATH, httpEntity, BaseResource[].class); } catch (HttpClientErrorException e) { Assert.assertEquals(e.getStatusCode(), HttpStatus.BAD_REQUEST); return; } this.acsAdminRestTemplate.exchange( this.acsUrl + PrivilegeHelper.ACS_RESOURCE_API_PATH + "/bad-resource-form", HttpMethod.DELETE, new HttpEntity<>(this.zone1Headers), ResponseEntity.class); this.acsAdminRestTemplate.exchange(this.acsUrl + PrivilegeHelper.ACS_RESOURCE_API_PATH + "/Site", HttpMethod.DELETE, new HttpEntity<>(this.zone1Headers), ResponseEntity.class); Assert.fail("testCreateBatchResourcesWithMalformedJSON should have failed!"); }