List of usage examples for org.apache.commons.httpclient HttpStatus SC_FORBIDDEN
int SC_FORBIDDEN
To view the source code for org.apache.commons.httpclient HttpStatus SC_FORBIDDEN.
Click Source Link
From source file:org.wso2.am.integration.tests.other.APIImportExportTestCase.java
@Test(groups = { "wso2.am" }, description = "Invoke the newly imported API", dependsOnMethods = "testNewAPIState") public void testNewAPIInvokeAfterImport() throws Exception { //publish the api APILifeCycleStateRequest updateRequest = new APILifeCycleStateRequest(NEW_API_NAME, user.getUserName(), APILifeCycleState.PUBLISHED); HttpResponse serviceResponse = apiPublisher.changeAPILifeCycleStatus(updateRequest); verifyResponse(serviceResponse);/*from ww w . j a va2 s. c om*/ apiStore = new APIStoreRestClient(storeURLHttp); apiStore.login(deniedUser, String.valueOf(DENIED_USER_PASS)); //add a application serviceResponse = apiStore.addApplication(NEW_APP_NAME, APIThrottlingTier.UNLIMITED.getState(), "", "this-is-test"); verifyResponse(serviceResponse); String provider = user.getUserName(); //subscribe to the api SubscriptionRequest subscriptionRequest = new SubscriptionRequest(NEW_API_NAME, provider); subscriptionRequest.setApplicationName(NEW_APP_NAME); subscriptionRequest.setTier(APIMIntegrationConstants.API_TIER.GOLD); serviceResponse = apiStore.subscribe(subscriptionRequest); verifyResponse(serviceResponse); //generate the key for the subscription APPKeyRequestGenerator generateAppKeyRequest = new APPKeyRequestGenerator(NEW_APP_NAME); generateAppKeyRequest.setTokenScope(SCOPE_NAME); String responseString = apiStore.generateApplicationKey(generateAppKeyRequest).getData(); JSONObject response = new JSONObject(responseString); String accessToken = response.getJSONObject("data").getJSONObject("key").get("accessToken").toString(); Assert.assertNotNull("Access Token not found " + responseString, accessToken); //invoke the API requestHeaders.clear(); requestHeaders.put(APIMIntegrationConstants.AUTHORIZATION_HEADER, "Bearer " + accessToken); String invokeURL = getAPIInvocationURLHttp(NEW_API_CONTEXT, API_VERSION); serviceResponse = HTTPSClientUtils.doGet(invokeURL + "/add?x=1&y=1", requestHeaders); Assert.assertEquals(HttpStatus.SC_FORBIDDEN, serviceResponse.getResponseCode(), "Imported API not in Created state"); }
From source file:org.wso2.carbon.appfactory.jenkins.deploy.JenkinsArtifactDeployer.java
/** * This method is used to build the specified job * build parameters are set in such a way that it does not execute any post build actions * * @param jobName/*from w ww.j a va 2 s . com*/ * job that we need to build * @param buildUrl * url used to trigger the build * @throws AppFactoryException */ protected void triggerBuild(String jobName, String buildUrl, NameValuePair[] queryParameters) throws AppFactoryException { PostMethod buildMethod = new PostMethod(buildUrl); buildMethod.setDoAuthentication(true); if (queryParameters != null) { buildMethod.setQueryString(queryParameters); } HttpClient httpClient = new HttpClient(); httpClient.getState().setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(getAdminUsername(), getServerAdminPassword())); httpClient.getParams().setAuthenticationPreemptive(true); int httpStatusCode = -1; try { httpStatusCode = httpClient.executeMethod(buildMethod); } catch (Exception ex) { String errorMsg = String.format("Unable to start the build on job : %s", jobName); log.error(errorMsg); throw new AppFactoryException(errorMsg, ex); } finally { buildMethod.releaseConnection(); } if (HttpStatus.SC_FORBIDDEN == httpStatusCode) { final String errorMsg = "Unable to start a build for job [".concat(jobName) .concat("] due to invalid credentials.").concat("Jenkins returned, http status : [") .concat(String.valueOf(httpStatusCode)).concat("]"); log.error(errorMsg); throw new AppFactoryException(errorMsg); } if (HttpStatus.SC_NOT_FOUND == httpStatusCode) { final String errorMsg = "Unable to find the job [" + jobName + "Jenkins returned, " + "http status : [" + httpStatusCode + "]"; log.error(errorMsg); throw new AppFactoryException(errorMsg); } }
From source file:se.sperber.cryson.apitest.CrysonAPITest.java
@Test public void shouldNotCommitInvalidEntities() throws Exception { Long entityId = foundEntity.getId(); String commitJson = "{\"updatedEntities\":[{\"crysonEntityClass\":\"CrysonTestEntity\",\"id\":" + entityId + ",\"name\":\"LONGNAMELONGNAMELONGNAMELONGNAMELONGNAME\",\"childEntities_cryson_ids\":[]}], \"deletedEntities\":[], \"persistedEntities\":[]}"; PostMethod postMethod = new PostMethod("http://localhost:8789/cryson/commit"); postMethod.setRequestEntity(new StringRequestEntity(commitJson, "application/json", "UTF-8")); assertEquals(HttpStatus.SC_FORBIDDEN, httpClient.executeMethod(postMethod)); assertEquals(// www. j a va 2 s.com "{\"message\":\"CrysonTestEntity name size must be between 0 and 30\\n\",\"validationFailures\":[{\"entityClass\":\"CrysonTestEntity\",\"entityId\":" + entityId + ",\"keyPath\":\"name\",\"message\":\"size must be between 0 and 30\"}]}", postMethod.getResponseBodyAsString()); }
From source file:slash.navigation.rest.HttpRequest.java
public boolean isForbidden() throws IOException { return getResult() == HttpStatus.SC_FORBIDDEN; }