List of usage examples for org.springframework.web.client HttpClientErrorException getStatusCode
public HttpStatus getStatusCode()
From source file:com.ge.predix.integration.test.AccessControlServiceIT.java
@Test(dataProvider = "endpointProvider") public void testPolicyUpdateWithNoOauthToken(final String endpoint) throws JsonParseException, JsonMappingException, IOException { RestTemplate acs = new RestTemplate(); // Use vanilla rest template with no oauth token. try {/* w w w . ja v a 2s. c o m*/ String policyFile = "src/test/resources/policy-set-with-multiple-policies-na-with-condition.json"; this.policyHelper.setTestPolicy(acs, this.zone1Headers, endpoint, policyFile); Assert.fail("No exception thrown when making request without token."); } catch (HttpClientErrorException e) { Assert.assertEquals(e.getStatusCode(), HttpStatus.UNAUTHORIZED); } }
From source file:com.ge.predix.integration.test.AccessControlServiceIT.java
@Test(dataProvider = "endpointProvider") public void testPolicyUpdateWithInsufficientScope(final String endpoint) throws Exception { String testPolicyName;/*from ww w. ja v a 2 s . c o m*/ try { String policyFile = "src/test/resources/policy-set-with-multiple-policies-na-with-condition.json"; testPolicyName = this.policyHelper.setTestPolicy(this.acsNoPolicyScopeRestTemplate, this.zone1Headers, endpoint, policyFile); this.policyHelper.deletePolicySet(this.acsAdminRestTemplate, this.acsUrl, testPolicyName, this.zone1Headers); Assert.fail("No exception when trying to create policy set with no acs scope"); } catch (HttpClientErrorException e) { Assert.assertEquals(e.getStatusCode(), HttpStatus.FORBIDDEN); } }
From source file:com.ge.predix.integration.test.AccessControlServiceIT.java
@Test(dataProvider = "endpointProvider") public void testPolicyEvalWithNoOauthToken(final String endpoint) { RestTemplate acs = new RestTemplate(); // Use vanilla rest template with no oauth token. try {// w w w . ja v a2 s .c om acs.postForEntity(endpoint + PolicyHelper.ACS_POLICY_EVAL_API_PATH, new HttpEntity<>( this.policyHelper.createEvalRequest(MARISSA_V1.getSubjectIdentifier(), "sanramon"), this.zone1Headers), PolicyEvaluationResult.class); Assert.fail("No exception thrown when making policy evaluation request without token."); } catch (HttpClientErrorException e) { Assert.assertEquals(e.getStatusCode(), HttpStatus.UNAUTHORIZED); } }
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 ww w.j a v a2 s . c o m } else if (null == model.getOrderEndTime()) { NotificationUtils.notifyUserVia(Localization .getLocalizedString("type.Marketplacestore." + MarketplaceStoreModel.ORDERENDTIME + ".name") + " " + Labels.getLabel("backoffice.field.notfilled"), NotificationEvent.Type.WARNING, ""); LOG.warn("get order end time is not filled!"); return; } else if (model.getOrderStartTime().after(model.getOrderEndTime())) { NotificationUtils.notifyUserVia(Labels.getLabel("backoffice.field.timerange.error"), NotificationEvent.Type.WARNING, ""); LOG.warn("start time is greate than end time!"); return; } else if (model.getMarketplace().getTmallOrderStatus().isEmpty() || null == model.getMarketplace().getTmallOrderStatus()) { NotificationUtils.notifyUserVia( Localization .getLocalizedString("type.Marketplace." + MarketplaceModel.TMALLORDERSTATUS + ".name") + " " + Labels.getLabel("backoffice.field.notfilled"), NotificationEvent.Type.WARNING, ""); LOG.warn("order status field is not filled!"); return; } if (!StringUtils.isBlank(model.getIntegrationId()) && !model.getAuthorized().booleanValue()) { NotificationUtils.notifyUserVia(Labels.getLabel("marketplace.order.authorization.fail"), NotificationEvent.Type.WARNING, ""); LOG.warn("authorization is expired!"); return; } // in order to avoid this value out of date, we only get it from // database final Boolean isAuth = ((MarketplaceStoreModel) modelService.get(model.getPk())).getAuthorized(); final String integrationId = ((MarketplaceStoreModel) modelService.get(model.getPk())).getIntegrationId(); model.setIntegrationId(integrationId); model.setAuthorized(isAuth); if (null == isAuth || !isAuth.booleanValue()) { NotificationUtils.notifyUserVia(Labels.getLabel("marketplace.order.initorder.unauthed"), NotificationEvent.Type.WARNING, ""); LOG.warn("marketplace store do not authorized, initial download failed!"); return; } String urlStr = ""; final String logUUID = logUtil.getUUID(); final MarketplaceSellerModel seller = model.getMarketplaceSeller(); final MarketplaceModel marketPlace = seller.getMarketplace(); try { // Configure and open a connection to the site you will send the urlStr = marketPlace.getAdapterUrl() + Config.getParameter(MARKETPLACE_ORDER_SYCHRONIZE_PATH) + Config.getParameter(MARKETPLACE_ORDER_INITIAL_PATH) + integrationId + Config.getParameter(MARKETPLACE_ORDER_INITIAL_LOGUUID) + logUUID; final JSONObject jsonObj = new JSONObject(); jsonObj.put("batchSize", BATCH_SIZE); jsonObj.put("status", getOrderStatus(model.getMarketplace().getTmallOrderStatus())); //jsonObj.put("marketplaceLogId", marketplacelogUUID); // set the correct timezone final String configTimezone = model.getMarketplace().getTimezone(); boolean isValidTimezone = false; for (final String vaildTimezone : TimeZone.getAvailableIDs()) { if (vaildTimezone.equals(configTimezone)) { isValidTimezone = true; break; } } if (!isValidTimezone) { final String[] para = { configTimezone == null ? "" : configTimezone, model.getMarketplace().getName() }; NotificationUtils.notifyUserVia(Labels.getLabel("marketplace.order.initorder.wrongtimezone", para), NotificationEvent.Type.WARNING, ""); LOG.warn("wrong timezone or missing timezone configed in market:" + model.getMarketplace().getName()); return; } final SimpleDateFormat format = new SimpleDateFormat(Config.getParameter(BACKOFFICE_FORMAT_DATEFORMAT)); format.setTimeZone(TimeZone.getTimeZone(configTimezone)); final String startTimeWithCorrectZone = format.format(model.getOrderStartTime()).toString(); final String endTimeWithCorrectZone = format.format(model.getOrderEndTime()).toString(); jsonObj.put("startCreated", startTimeWithCorrectZone); jsonObj.put("endCreated", endTimeWithCorrectZone); jsonObj.put("productCatalogVersion", model.getCatalogVersion().getCatalog().getId() + ":" + model.getCatalogVersion().getVersion()); jsonObj.put("currency", model.getCurrency().getIsocode()); NotificationUtils.notifyUserVia(Labels.getLabel("marketplace.order.initorder.success"), NotificationEvent.Type.SUCCESS, ""); final JSONObject results = marketplaceHttpUtil.post(urlStr, jsonObj.toJSONString()); final String msg = results.toJSONString(); final String responseCode = results.get("code").toString(); if ("401".equals(responseCode)) { LOG.error("========================================================================="); LOG.error("Order initial download request post to Tmall failed!"); LOG.error("Marketplacestore Code: " + model.getName()); LOG.error("Error Status Code: " + responseCode); LOG.error("Request path: " + urlStr); LOG.error("-------------------------------------------------------------------------"); LOG.error("Failed Reason:"); LOG.error("Authentication was failed, please re-authenticate again!"); LOG.error("========================================================================="); NotificationUtils.notifyUserVia(Labels.getLabel("marketplace.order.authorization.fail"), NotificationEvent.Type.FAILURE, ""); LOG.warn("Authentication was failed, please re-authenticate again!"); return; } else if (!("0".equals(responseCode))) { LOG.error("========================================================================="); LOG.error("Order initial download request post to Tmall failed!"); LOG.error("Marketplacestore Code: " + model.getName()); LOG.error("Error Status Code: " + responseCode); LOG.error("Request path: " + urlStr); LOG.error("-------------------------------------------------------------------------"); LOG.error("Failed Reason:"); LOG.error("A known issue occurs in tmall, error details :" + msg); LOG.error("========================================================================="); NotificationUtils.notifyUserVia( Labels.getLabel("marketplace.tmallapp.known.issues", new Object[] { msg }), NotificationEvent.Type.FAILURE, ""); LOG.warn("A known issue occurs in tmall, error details :" + msg); return; } } catch (final HttpClientErrorException httpError) { if (httpError.getStatusCode().is4xxClientError()) { LOG.error("========================================================================="); LOG.error("Order initial download request post to Tmall failed!"); LOG.error("Marketplacestore Code: " + model.getName()); LOG.error("Error Status Code: " + httpError.getStatusCode().toString()); LOG.error("Request path: " + urlStr); LOG.error("-------------------------------------------------------------------------"); LOG.error("Failed Reason:"); LOG.error("Requested Tmall service URL is not correct!"); LOG.error("Detail error info: " + httpError.getMessage()); LOG.error("========================================================================="); NotificationUtils.notifyUserVia(Labels.getLabel("marketplace.error.request.post.error"), NotificationEvent.Type.FAILURE, ""); } if (httpError.getStatusCode().is5xxServerError()) { LOG.error("========================================================================="); LOG.error("Order initial download request post to Tmall failed!"); LOG.error("Marketplacestore Code: " + model.getName()); LOG.error("Error Status Code: " + httpError.getStatusCode().toString()); LOG.error("Request path: " + urlStr); LOG.error("-------------------------------------------------------------------------"); LOG.error("Failed Reason:"); LOG.error("Requested Json Ojbect is not correct!"); LOG.error("Detail error info: " + httpError.getMessage()); LOG.error("========================================================================="); NotificationUtils.notifyUserVia(Labels.getLabel("marketplace.error.server.process.error"), NotificationEvent.Type.FAILURE, ""); } LOG.error(httpError.toString()); return; } catch (final ResourceAccessException raError) { LOG.error("========================================================================="); LOG.error("Order initial download request post to Tmall failed!"); LOG.error("Marketplacestore Code: " + model.getName()); LOG.error("Request path: " + urlStr); LOG.error("-------------------------------------------------------------------------"); LOG.error("Failed Reason:"); LOG.error("Marketplace order download request server access failed!"); LOG.error("Detail error info: " + raError.getMessage()); LOG.error("========================================================================="); NotificationUtils.notifyUserVia(Labels.getLabel("marketplace.error.server.access.error"), NotificationEvent.Type.FAILURE, ""); return; } catch (final HttpServerErrorException serverError) { LOG.error("========================================================================="); LOG.error("Order initial download request post to Tmall failed!"); LOG.error("Marketplacestore Code: " + model.getName()); LOG.error("Request path: " + urlStr); LOG.error("-------------------------------------------------------------------------"); LOG.error("Failed Reason:"); LOG.error("Marketplace order download request server process failed!"); LOG.error("Detail error info: " + serverError.getMessage()); LOG.error("========================================================================="); NotificationUtils.notifyUserVia(Labels.getLabel("marketplace.error.server.process.error"), NotificationEvent.Type.FAILURE, ""); return; } catch (final Exception e) { final String errorMsg = e.getClass().toString() + ":" + e.getMessage(); NotificationUtils.notifyUserVia( Labels.getLabel("marketplace.runtime.issues", new Object[] { errorMsg }), NotificationEvent.Type.FAILURE, ""); LOG.warn(e.getMessage() + e.getStackTrace()); return; } LOG.info("========================================================================="); LOG.info("Order initial download request post to Tmall suceessfully!"); LOG.info("-------------------------------------------------------------------------"); LOG.info("Marketplacestore Code: " + model.getName()); LOG.info("Request path: " + urlStr); LOG.info("========================================================================="); // logUtil.addMarketplaceLog("PENDING", model.getIntegrationId(), Labels.getLabel("marketplace.order.initial.action"), // Labels.getLabel("marketplace.order.initial.object.type"), marketPlace, model, logUUID); }
From source file:org.cloudfoundry.client.lib.rest.CloudControllerClientV1.java
public void createApplication(String appName, Staging staging, int memory, List<String> uris, List<String> serviceNames, boolean checkExists) { if (checkExists) { try {//from w w w . j a va2 s . c om getApplication(appName); return; } catch (HttpClientErrorException e) { if (e.getStatusCode() != HttpStatus.NOT_FOUND) { throw e; } } } if (serviceNames == null) { serviceNames = new ArrayList<String>(); } CloudApplication payload = new CloudApplication(appName, staging.getRuntime(), staging.getFramework(), memory, 1, uris, serviceNames, CloudApplication.AppState.STOPPED); payload.setCommand(staging.getCommand()); getRestTemplate().postForLocation(getUrl("apps"), payload); CloudApplication postedApp = getApplication(appName); if (serviceNames != null && serviceNames.size() != 0) { postedApp.setServices(serviceNames); updateApplication(postedApp); } }
From source file:com.ge.predix.integration.test.AccessControlServiceIT.java
@Test(dataProvider = "endpointProvider") public void testPolicyCreationInValidWithBadPolicySetNamePolicy(final String endpoint) throws Exception { String testPolicyName = ""; try {/* w w w . j av a 2 s . c o m*/ String policyFile = "src/test/resources/policy-set-with-only-name-effect.json"; testPolicyName = this.policyHelper.setTestPolicy(this.acsAdminRestTemplate, this.zone1Headers, endpoint, policyFile); } catch (HttpClientErrorException e) { this.acsTestUtil.assertExceptionResponseBody(e, "is not URI friendly"); Assert.assertEquals(e.getStatusCode(), HttpStatus.UNPROCESSABLE_ENTITY); return; } this.policyHelper.deletePolicySet(this.acsAdminRestTemplate, this.acsUrl, testPolicyName, this.zone1Headers); Assert.fail("testPolicyCreationInValidPolicy should have failed"); }
From source file:com.ge.predix.integration.test.AccessControlServiceIT.java
@Test(dataProvider = "endpointProvider") public void testPolicyCreationJsonSchemaInvalidPolicySet(final String endpoint) throws Exception { String testPolicyName = ""; try {/* www.ja va 2 s .c om*/ String policyFile = "src/test/resources/invalid-json-schema-policy-set.json"; testPolicyName = this.policyHelper.setTestPolicy(this.acsAdminRestTemplate, this.zone1Headers, endpoint, policyFile); } catch (HttpClientErrorException e) { this.acsTestUtil.assertExceptionResponseBody(e, "JSON Schema validation"); Assert.assertEquals(e.getStatusCode(), HttpStatus.UNPROCESSABLE_ENTITY); return; } this.policyHelper.deletePolicySet(this.acsAdminRestTemplate, this.acsUrl, testPolicyName, this.zone1Headers); Assert.fail("testPolicyCreationInValidPolicy should have failed"); }
From source file:com.ge.predix.integration.test.AccessControlServiceIT.java
@Test(dataProvider = "endpointProvider") public void testPolicyCreationInValidPolicy(final String endpoint) throws Exception { String testPolicyName = ""; try {//from www .j a va2 s . c o m String policyFile = "src/test/resources/missing-policy-set-name-policy.json"; testPolicyName = this.policyHelper.setTestPolicy(this.acsAdminRestTemplate, this.zone1Headers, endpoint, policyFile); } catch (HttpClientErrorException e) { this.acsTestUtil.assertExceptionResponseBody(e, "policy set name is missing"); Assert.assertEquals(e.getStatusCode(), HttpStatus.UNPROCESSABLE_ENTITY); return; } this.policyHelper.deletePolicySet(this.acsAdminRestTemplate, this.acsUrl, testPolicyName, this.zone1Headers); Assert.fail("testPolicyCreationInValidPolicy should have failed"); }
From source file:com.ge.predix.integration.test.PrivilegeManagementAccessControlServiceIT.java
public void testBatchCreateSubjectsEmptyList() { List<BaseSubject> subjects = new ArrayList<BaseSubject>(); try {//w w w .ja v a2 s. c o m this.acsAdminRestTemplate.postForEntity(this.acsUrl + PrivilegeHelper.ACS_SUBJECT_API_PATH, new HttpEntity<>(subjects, this.zone1Headers), BaseSubject[].class); } catch (HttpClientErrorException e) { Assert.assertEquals(e.getStatusCode(), HttpStatus.UNPROCESSABLE_ENTITY); return; } Assert.fail("Expected unprocessable entity http client error."); }