List of usage examples for org.apache.commons.httpclient.methods DeleteMethod addRequestHeader
@Override public void addRequestHeader(String headerName, String headerValue)
From source file:org.olat.test.OlatJerseyTestCase.java
public DeleteMethod createDelete(final URI requestURI, final String accept, final boolean cookie) { final DeleteMethod method = new DeleteMethod(requestURI.toString()); if (cookie) { method.getParams().setCookiePolicy(CookiePolicy.RFC_2109); }/*from ww w. j a va 2s .c om*/ if (StringHelper.containsNonWhitespace(accept)) { method.addRequestHeader("Accept", accept); } return method; }
From source file:org.sharegov.cirm.utils.GenUtils.java
public static String httpDelete(String url, String... headers) { HttpClient client = new HttpClient(); DeleteMethod method = new DeleteMethod(url); if (headers != null) { if (headers.length % 2 != 0) throw new IllegalArgumentException( "Odd number of headers argument, specify HTTP headers in pairs: name then value, etc."); for (int i = 0; i < headers.length; i++) method.addRequestHeader(headers[i], headers[++i]); }//from w w w. j a va 2 s . c o m try { // disable retries from within the HTTP client client.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, new DefaultHttpMethodRetryHandler(0, false)); int statusCode = client.executeMethod(method); if (statusCode != HttpStatus.SC_OK) throw new RuntimeException("HTTP Error " + statusCode + " while deleting " + url.toString()); return method.getResponseBodyAsString(); } catch (Exception ex) { throw new RuntimeException(ex); } finally { method.releaseConnection(); } }
From source file:org.wso2.carbon.identity.scim.common.impl.ProvisioningClient.java
public void provisionDeleteUser() throws IdentitySCIMException { String userName = null;/*from w w w.j av a 2 s.co m*/ try { //get provider details String userEPURL = provider.getProperty(SCIMConfigConstants.ELEMENT_NAME_USER_ENDPOINT); userName = provider.getProperty(SCIMConfigConstants.ELEMENT_NAME_USERNAME); String password = provider.getProperty(SCIMConfigConstants.ELEMENT_NAME_PASSWORD); String contentType = provider.getProperty(SCIMConstants.CONTENT_TYPE_HEADER); if (contentType == null) { contentType = SCIMConstants.APPLICATION_JSON; } /*get the userId of the user being provisioned from the particular provider by filtering with user name*/ GetMethod getMethod = new GetMethod(userEPURL); //add filter query parameter getMethod.setQueryString(USER_FILTER + ((User) scimObject).getUserName()); //add authorization headers getMethod.addRequestHeader(SCIMConstants.AUTHORIZATION_HEADER, BasicAuthUtil.getBase64EncodedBasicAuthHeader(userName, password)); //create http client HttpClient httpFilterClient = new HttpClient(); //send the request int responseStatus = httpFilterClient.executeMethod(getMethod); String response = getMethod.getResponseBodyAsString(); if (logger.isDebugEnabled()) { logger.debug("SCIM - filter operation inside 'delete user' provisioning " + "returned with response code: " + responseStatus); logger.debug("Filter User Response: " + response); } SCIMClient scimClient = new SCIMClient(); if (scimClient.evaluateResponseStatus(responseStatus)) { //decode the response to extract the userId. ListedResource listedResource = scimClient.decodeSCIMResponseWithListedResource(response, SCIMConstants.identifyFormat(contentType), objectType); List<SCIMObject> users = listedResource.getScimObjects(); String userId = null; //we expect only one user in the list for (SCIMObject user : users) { userId = ((User) user).getId(); } String url = userEPURL + "/" + userId; //now send the delete request. DeleteMethod deleteMethod = new DeleteMethod(url); deleteMethod.addRequestHeader(SCIMConstants.AUTHORIZATION_HEADER, BasicAuthUtil.getBase64EncodedBasicAuthHeader(userName, password)); HttpClient httpDeleteClient = new HttpClient(); int deleteResponseStatus = httpDeleteClient.executeMethod(deleteMethod); String deleteResponse = deleteMethod.getResponseBodyAsString(); logger.info("SCIM - delete user operation returned with response code: " + deleteResponseStatus); if (!scimClient.evaluateResponseStatus(deleteResponseStatus)) { //decode scim exception and extract the specific error message. AbstractCharonException exception = scimClient.decodeSCIMException(deleteResponse, SCIMConstants.identifyFormat(contentType)); logger.error(exception.getDescription()); } } else { //decode scim exception and extract the specific error message. AbstractCharonException exception = scimClient.decodeSCIMException(response, SCIMConstants.identifyFormat(contentType)); logger.error(exception.getDescription()); } } catch (CharonException | IOException | BadRequestException e) { throw new IdentitySCIMException("Error in provisioning 'delete user' operation for user :" + userName, e); } }
From source file:org.wso2.carbon.identity.scim.common.impl.ProvisioningClient.java
public void provisionDeleteGroup() throws IdentitySCIMException { String userName = null;// w w w.j a va2 s.c o m try { //get provider details String groupEPURL = provider.getProperty(SCIMConfigConstants.ELEMENT_NAME_GROUP_ENDPOINT); userName = provider.getProperty(SCIMConfigConstants.ELEMENT_NAME_USERNAME); String password = provider.getProperty(SCIMConfigConstants.ELEMENT_NAME_PASSWORD); String contentType = provider.getProperty(SCIMConstants.CONTENT_TYPE_HEADER); if (contentType == null) { contentType = SCIMConstants.APPLICATION_JSON; } /*get the groupId of the group being provisioned from the particular provider by filtering with display name*/ GetMethod getMethod = new GetMethod(groupEPURL); //add filter query parameter getMethod.setQueryString(GROUP_FILTER + ((Group) scimObject).getDisplayName()); //add authorization headers getMethod.addRequestHeader(SCIMConstants.AUTHORIZATION_HEADER, BasicAuthUtil.getBase64EncodedBasicAuthHeader(userName, password)); //create http client HttpClient httpFilterClient = new HttpClient(); //send the request int responseStatus = httpFilterClient.executeMethod(getMethod); String response = getMethod.getResponseBodyAsString(); if (logger.isDebugEnabled()) { logger.debug("SCIM - filter operation inside 'delete group' provisioning " + "returned with response code: " + responseStatus); logger.debug("Filter Group Response: " + response); } SCIMClient scimClient = new SCIMClient(); if (scimClient.evaluateResponseStatus(responseStatus)) { //decode the response to extract the groupId. ListedResource listedResource = scimClient.decodeSCIMResponseWithListedResource(response, SCIMConstants.identifyFormat(contentType), objectType); List<SCIMObject> groups = listedResource.getScimObjects(); String groupId = null; //we expect only one user in the list for (SCIMObject group : groups) { groupId = ((Group) group).getId(); } String url = groupEPURL + "/" + groupId; //now send the delete request. DeleteMethod deleteMethod = new DeleteMethod(url); deleteMethod.addRequestHeader(SCIMConstants.AUTHORIZATION_HEADER, BasicAuthUtil.getBase64EncodedBasicAuthHeader(userName, password)); HttpClient httpDeleteClient = new HttpClient(); int deleteResponseStatus = httpDeleteClient.executeMethod(deleteMethod); String deleteResponse = deleteMethod.getResponseBodyAsString(); logger.info("SCIM - delete group operation returned with response code: " + deleteResponseStatus); if (!scimClient.evaluateResponseStatus(deleteResponseStatus)) { //decode scim exception and extract the specific error message. AbstractCharonException exception = scimClient.decodeSCIMException(deleteResponse, SCIMConstants.identifyFormat(contentType)); logger.error(exception.getDescription()); } } else { //decode scim exception and extract the specific error message. AbstractCharonException exception = scimClient.decodeSCIMException(response, SCIMConstants.identifyFormat(contentType)); logger.error(exception.getDescription()); } } catch (CharonException | IOException | BadRequestException e) { throw new IdentitySCIMException("Error in provisioning 'delete group' operation for user :" + userName, e); } }
From source file:org.wso2.scim.sample.group.DeleteGroup.java
public static void main(String[] args) { try {/*from w w w . j a v a 2s . co m*/ //load sample configuration SCIMSamplesUtils.loadConfiguration(); //set the keystore SCIMSamplesUtils.setKeyStore(); String groupId = getSCIMIdOfGroup(SCIMSamplesUtils.groupDisplayNameToDeleteGroup); String url = SCIMSamplesUtils.groupEndpointURL + "/" + groupId; //now send the delete request. DeleteMethod deleteMethod = new DeleteMethod(url); //add authorization header String authHeader = SCIMSamplesUtils.getAuthorizationHeader(); deleteMethod.addRequestHeader(SCIMConstants.AUTHORIZATION_HEADER, authHeader); HttpClient httpDeleteClient = new HttpClient(); int deleteResponseStatus = httpDeleteClient.executeMethod(deleteMethod); String deleteResponse = deleteMethod.getResponseBodyAsString(); System.out.println(""); System.out.println(""); System.out.println("/******SCIM group delete response status: " + deleteResponseStatus); System.out.println("SCIM group delete response data: " + deleteResponse + "******/"); System.out.println(""); } catch (CharonException e) { e.printStackTrace(); } catch (HttpException e) { e.printStackTrace(); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } }
From source file:org.wso2.scim.sample.user.DeleteUser.java
public static void main(String[] args) { try {// w ww. j a va 2 s .co m //load sample configuration SCIMSamplesUtils.loadConfiguration(); //set the keystore SCIMSamplesUtils.setKeyStore(); String userId = getSCIMIdOfUser(SCIMSamplesUtils.userNameToDeleteUser); String url = SCIMSamplesUtils.userEndpointURL + "/" + userId; //now send the delete request. DeleteMethod deleteMethod = new DeleteMethod(url); //add authorization header String authHeader = SCIMSamplesUtils.getAuthorizationHeader(); deleteMethod.addRequestHeader(SCIMConstants.AUTHORIZATION_HEADER, authHeader); HttpClient httpDeleteClient = new HttpClient(); int deleteResponseStatus = httpDeleteClient.executeMethod(deleteMethod); String deleteResponse = deleteMethod.getResponseBodyAsString(); System.out.println(""); System.out.println(""); System.out.println("/******SCIM user delete response status: " + deleteResponseStatus); System.out.println("SCIM user delete response data: " + deleteResponse + "******/"); System.out.println(""); } catch (CharonException e) { e.printStackTrace(); } catch (HttpException e) { e.printStackTrace(); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } }