List of usage examples for org.apache.commons.httpclient HttpStatus SC_CREATED
int SC_CREATED
To view the source code for org.apache.commons.httpclient HttpStatus SC_CREATED.
Click Source Link
From source file:org.wso2.bps.integration.common.clients.bpmn.ActivitiRestClient.java
/** * Method is used to acquire deployment details using the deployment ID * * @param deploymentID Deployment ID of the BPMN Package * @throws java.io.IOException/*from www .jav a 2s. co m*/ * @throws org.json.JSONException * @returns String Array with status, deploymentID and Name */ public String[] getDeploymentInfoById(String deploymentID) throws Exception { String url = serviceURL + "repository/deployments/" + deploymentID; HttpHost target = new HttpHost(hostname, port, "http"); DefaultHttpClient httpClient = new DefaultHttpClient(); httpClient.getCredentialsProvider().setCredentials(new AuthScope(target.getHostName(), target.getPort()), new UsernamePasswordCredentials(username, password)); HttpGet httpget = new HttpGet(url); HttpResponse response = httpClient.execute(httpget); String status = response.getStatusLine().toString(); String responseData = EntityUtils.toString(response.getEntity()); JSONObject jsonResponseObject = new JSONObject(responseData); if (status.contains(Integer.toString(HttpStatus.SC_CREATED)) || status.contains(Integer.toString(HttpStatus.SC_OK))) { String ID = jsonResponseObject.getString("id"); String name = jsonResponseObject.getString("name"); return new String[] { status, ID, name }; } else if (status.contains(Integer.toString(HttpStatus.SC_NOT_FOUND))) { throw new RestClientException(NOT_AVAILABLE); } else { throw new RestClientException("Cannot find deployment"); } }
From source file:org.wso2.bps.integration.common.clients.bpmn.ActivitiRestClient.java
/** * Method use to instantiate a process instance using the definition ID * * @param processDefintionID used to start a processInstance * @throws IOException//from w w w .ja v a 2s . c om * @throws JSONException * @returns String Array which contains status and processInstanceID */ public String[] startProcessInstanceByDefintionID(String processDefintionID) throws Exception { String url = serviceURL + "runtime/process-instances"; HttpHost target = new HttpHost(hostname, port, "http"); DefaultHttpClient httpClient = new DefaultHttpClient(); httpClient.getCredentialsProvider().setCredentials(new AuthScope(target.getHostName(), target.getPort()), new UsernamePasswordCredentials(username, password)); HttpPost httpPost = new HttpPost(url); StringEntity params = new StringEntity("{\"processDefinitionId\":\"" + processDefintionID + "\"}", ContentType.APPLICATION_JSON); httpPost.setEntity(params); HttpResponse response = httpClient.execute(httpPost); String status = response.getStatusLine().toString(); String responseData = EntityUtils.toString(response.getEntity()); JSONObject jsonResponseObject = new JSONObject(responseData); if (status.contains(Integer.toString(HttpStatus.SC_CREATED)) || status.contains(Integer.toString(HttpStatus.SC_OK))) { String processInstanceID = jsonResponseObject.getString("id"); return new String[] { status, processInstanceID }; } throw new RestClientException("Cannot Find Process Instance"); }
From source file:org.wso2.bps.integration.common.clients.bpmn.ActivitiRestClient.java
/** * Method used to suspend a process instance * * @param processInstanceID used to identify the process instance to suspend * @return String array containing the status and the current state * @throws IOException//from w w w.j a v a2 s . c om * @throws JSONException */ public String[] suspendProcessInstanceById(String processInstanceID) throws Exception { String url = serviceURL + "runtime/process-instances/" + processInstanceID; HttpHost target = new HttpHost(hostname, port, "http"); DefaultHttpClient httpClient = new DefaultHttpClient(); httpClient.getCredentialsProvider().setCredentials(new AuthScope(target.getHostName(), target.getPort()), new UsernamePasswordCredentials(username, password)); HttpPut httpPut = new HttpPut(url); StringEntity params = new StringEntity("{\"action\":\"suspend\"}", ContentType.APPLICATION_JSON); httpPut.setEntity(params); HttpResponse response = httpClient.execute(httpPut); String status = response.getStatusLine().toString(); String responseData = EntityUtils.toString(response.getEntity()); JSONObject jsonResponseObject = new JSONObject(responseData); if (status.contains(Integer.toString(HttpStatus.SC_CREATED)) || status.contains(Integer.toString(HttpStatus.SC_OK))) { String state = jsonResponseObject.getString("suspended"); return new String[] { status, state }; } throw new RestClientException("Cannot Suspend Process"); }
From source file:org.wso2.bps.integration.common.clients.bpmn.ActivitiRestClient.java
/** * Method used to add a new comment to a task * * @param taskID used to identify the task * @param comment comment to be added// w ww . jav a2s .c om * @return String Array containing status and the message * @throws IOException * @throws JSONException */ public String[] addNewCommentOnTaskByTaskId(String taskID, String comment) throws Exception { String url = serviceURL + "runtime/tasks/" + taskID + "/comments"; HttpHost target = new HttpHost(hostname, port, "http"); DefaultHttpClient httpClient = new DefaultHttpClient(); httpClient.getCredentialsProvider().setCredentials(new AuthScope(target.getHostName(), target.getPort()), new UsernamePasswordCredentials(username, password)); HttpPost httpPost = new HttpPost(url); StringEntity params = new StringEntity( "{\"message\" : \"" + comment + "\",\"saveProcessInstanceId\" : true}", ContentType.APPLICATION_JSON); httpPost.setEntity(params); HttpResponse response = httpClient.execute(httpPost); String status = response.getStatusLine().toString(); String responseData = EntityUtils.toString(response.getEntity()); JSONObject jsonResponseObject = new JSONObject(responseData); if (status.contains(Integer.toString(HttpStatus.SC_CREATED)) || status.contains(Integer.toString(HttpStatus.SC_OK))) { String message = jsonResponseObject.getString("message"); String commentID = jsonResponseObject.getString("id"); return new String[] { status, message, commentID }; } else { throw new RestClientException("Cannot Add Comment"); } }
From source file:org.wso2.carbon.appfactory.git.repository.provider.GithubRepositoryProvider.java
/** * {@inheritDoc}// ww w. j a va 2 s. c o m */ @Override public String createRepository(String applicationKey, String tenantDomain) throws RepositoryMgtException { Repository repository = new Repository(); repository.setName(applicationKey); repository.setType("git"); Permission permission = new Permission(); permission.setGroupPermission(true); permission.setName(applicationKey); permission.setType(PermissionType.WRITE); ArrayList<Permission> permissions = new ArrayList<Permission>(); permissions.add(permission); repository.setPermissions(permissions); HttpClient client = new HttpClient(); PostMethod post = new PostMethod("https://api.github.com/orgs/" + ORG_NAME + "/repos"); post.setDoAuthentication(true); post.addRequestHeader("Authorization", "Basic " + githubAuthtoken); StringRequestEntity requestEntity; try { requestEntity = new StringRequestEntity( " {\n \"name\":\"" + applicationKey + "\",\n\"auto_init\":\"true\"\n}", "application/json", "UTF-8"); } catch (UnsupportedEncodingException e) { String msg = "Error while invoking gitHub API"; log.error(msg, e); throw new RepositoryMgtException(msg, e); } post.setRequestEntity(requestEntity); try { client.executeMethod(post); log.debug("HTTP status " + post.getStatusCode() + " creating repo\n\n"); if (post.getStatusCode() == HttpStatus.SC_CREATED) { log.debug("Repository creation successful"); } else if (post.getStatusCode() == HttpStatus.SC_UNPROCESSABLE_ENTITY) { String msg = "Repository creation is failed for" + applicationKey + ". Repository with the same name already exists"; log.error(msg); throw new RepositoryMgtException(msg); } else { String msg = "Repository creation is failed for" + applicationKey + "Server returned status:" + post.getStatusCode(); log.error(msg); throw new RepositoryMgtException(msg); } } catch (IOException e) { String msg = "Error while invoking gitHub API"; log.error(msg, e); throw new RepositoryMgtException(msg, e); } finally { post.releaseConnection(); } createTeam(applicationKey); return getAppRepositoryURL(applicationKey, tenantDomain); }
From source file:org.wso2.carbon.appfactory.git.repository.provider.GithubRepositoryProvider.java
private void createTeam(String applicationKey) throws RepositoryMgtException { HttpClient client = new HttpClient(); PostMethod post = new PostMethod("https://api.github.com/orgs/" + ORG_NAME + "/teams"); // https://api.github.com/teams/627395/members/manishagele post.setDoAuthentication(true);//from w ww. j a v a2 s. com post.addRequestHeader("Authorization", "Basic " + githubAuthtoken); StringRequestEntity requestEntity; try { requestEntity = new StringRequestEntity("{\n" + " \"name\": \"team_" + applicationKey + "\",\n" + " \"permission\": \"push\",\n" + " \"repo_names\": [\n" + " \"" + ORG_NAME + "/" + applicationKey + "\"\n" + " ]\n" + "}", "application/json", "UTF-8"); } catch (UnsupportedEncodingException e) { String msg = "Error while invoking gitHub API"; log.error(msg, e); throw new RepositoryMgtException(msg, e); } post.setRequestEntity(requestEntity); try { client.executeMethod(post); log.debug("HTTP status " + post.getStatusCode() + " creating team\n\n"); if (post.getStatusCode() == HttpStatus.SC_CREATED) { log.debug("team creation successful"); } else if (post.getStatusCode() == HttpStatus.SC_UNPROCESSABLE_ENTITY) { String msg = "team creation is failed for" + applicationKey + ". team with the same name already exists"; log.error(msg); throw new RepositoryMgtException(msg); } else { String msg = "team creation is failed for" + applicationKey + "Server returned status:" + post.getStatusCode(); log.error(msg); throw new RepositoryMgtException(msg); } } catch (IOException e) { String msg = "Error while invoking gitHub API"; log.error(msg, e); throw new RepositoryMgtException(msg, e); } finally { post.releaseConnection(); } }
From source file:org.wso2.carbon.appfactory.git.repository.provider.SCMManagerBasedGITRepositoryProvider.java
/** * {@inheritDoc}/*w w w. ja v a 2 s .c o m*/ */ @Override public String createRepository(String applicationKey, String tenantDomain) throws RepositoryMgtException { HttpClient client = getClient(); PostMethod post = new PostMethod(getServerURL() + REST_BASE_URI + REST_CREATE_REPOSITORY_URI); Repository repository = new Repository(); repository.setName(applicationKey); repository.setType("git"); Permission permission = new Permission(); permission.setGroupPermission(true); permission.setName(applicationKey); permission.setType(PermissionType.WRITE); ArrayList<Permission> permissions = new ArrayList<Permission>(); permissions.add(permission); repository.setPermissions(permissions); post.setRequestEntity(new ByteArrayRequestEntity(getRepositoryAsString(repository))); post.setDoAuthentication(true); post.addRequestHeader("Content-Type", "application/xml;charset=UTF-8"); String url; try { client.executeMethod(post); } catch (IOException e) { String msg = "Error while invoking the web service"; log.error(msg, e); throw new RepositoryMgtException(msg, e); } finally { post.releaseConnection(); } if (post.getStatusCode() == HttpStatus.SC_CREATED) { url = getAppRepositoryURL(applicationKey, tenantDomain); } else { String msg = "Repository creation is failed for " + applicationKey + " server returned status " + post.getStatusText(); log.error(msg); throw new RepositoryMgtException(msg); } return url; }
From source file:org.wso2.carbon.appfactory.s4.integration.StratosRestClient.java
public void createApplication(String applicationId, String repoUrl, String repoUsername, String repoPassword, String cartridgeType, String cartridgeTypePrefix, String deploymentPolicy, String autoScalingPolicy) throws AppFactoryException { String stratosApplicationJson = getStratosApplicationJson(applicationId, repoUrl, repoUsername, repoPassword, cartridgeType, cartridgeTypePrefix, deploymentPolicy, autoScalingPolicy); ServerResponse response = MutualAuthHttpClient.sendPostRequest(stratosApplicationJson, this.stratosManagerURL + APPLICATIONS_REST_END_POINT, username); if (response.getStatusCode() == HttpStatus.SC_CREATED) { if (log.isDebugEnabled()) { log.debug("Stratos application created for appId : " + applicationId); }// w w w . ja v a 2 s . co m } else { String errorMsg = "Error occured while creating stratos appliction for ID : " + applicationId + "HTTP Status code : " + response.getStatusCode() + " server response : " + response.getResponse(); handleException(errorMsg); } }
From source file:org.wso2.carbon.appfactory.svn.repository.provider.SCMManagerBasedSVNRepositoryProvider.java
@Override public String createRepository(String applicationKey, String tenantDomain) throws RepositoryMgtException { HttpClient client = getClient();// w ww . j a v a 2s . c om PostMethod post = new PostMethod(getServerURL() + REST_BASE_URI + REST_CREATE_REPOSITORY_URI); Repository repository = new Repository(); repository.setName(applicationKey); repository.setType("svn"); Permission permission = new Permission(); permission.setGroupPermission(true); permission.setName(applicationKey); permission.setType(PermissionType.WRITE); ArrayList<Permission> permissions = new ArrayList<Permission>(); permissions.add(permission); repository.setPermissions(permissions); post.setRequestEntity(new ByteArrayRequestEntity(getRepositoryAsString(repository))); post.setDoAuthentication(true); post.addRequestHeader("Content-Type", "application/xml;charset=UTF-8"); String url; try { client.executeMethod(post); } catch (IOException e) { String msg = "Error while invoking the web service"; log.error(msg, e); throw new RepositoryMgtException(msg, e); } finally { post.releaseConnection(); } if (post.getStatusCode() == HttpStatus.SC_CREATED) { url = getAppRepositoryURL(applicationKey, tenantDomain); } else { String msg = "Repository creation is failed for " + applicationKey + " server returned status " + post.getStatusText(); log.error(msg); throw new RepositoryMgtException(msg); } return url; }
From source file:org.wso2.carbon.appfactory.webdavsvn.svn.repository.provider.Apache2WebDAVSVNRepositoryProvider.java
/** * {@inheritDoc}//from ww w .j ava 2s . c om */ @Override public String createRepository(String applicationKey, String tenantDomain) throws RepositoryMgtException { /*String fullRepositoryPath=configuration.getFirstProperty(getPropertyKey(REMOTE_PARENT_REPO_LOCATION))+"/"+applicationKey; String username=configuration.getFirstProperty(getPropertyKey(REMOTE_USER_NAME)); String password=configuration.getFirstProperty(getPropertyKey(REMOTE_USER_PASSWORD)); String hostName=configuration.getFirstProperty(getPropertyKey(HOST_NAME)); client=new SSHClient(); client.createRepositoryRemotely(fullRepositoryPath,configuration.getFirstProperty(getPropertyKey(REMOTE_HOST_SUPER_USER_PASSWORD)),username,password,hostName); return getAppRepositoryURL(applicationKey);*/ HttpClient client = getClient(); GetMethod get = new GetMethod(getBackendUrl() + CREATE_REPO_EPR); NameValuePair[] repositoryName = new NameValuePair[1]; repositoryName[0] = new NameValuePair(); repositoryName[0].setName(CREATE_REPO_REQUEST_REPO_NAME_PARAMETER_NAME); repositoryName[0].setValue(applicationKey); get.setQueryString(repositoryName); get.setDoAuthentication(true); try { client.executeMethod(get); if (get.getStatusCode() == HttpStatus.SC_CREATED) { return getAppRepositoryURL(applicationKey, tenantDomain); } else { String msg = "Repository creation is failed for " + applicationKey + " server returned status " + get.getStatusText(); log.error(msg); throw new RepositoryMgtException(msg); } } catch (IOException e) { String msg = "Error while invoking the web service"; log.error(msg, e); throw new RepositoryMgtException(msg, e); } finally { get.releaseConnection(); } }