List of usage examples for org.apache.commons.httpclient HttpStatus SC_BAD_REQUEST
int SC_BAD_REQUEST
To view the source code for org.apache.commons.httpclient HttpStatus SC_BAD_REQUEST.
Click Source Link
From source file:org.wso2.carbon.mdm.api.Policy.java
@POST @Path("bulk-remove") @Consumes("application/json") @Produces("application/json") public Response bulkRemovePolicy(List<Integer> policyIds) throws MDMAPIException { PolicyManagerService policyManagementService = MDMAPIUtils.getPolicyManagementService(); boolean policyDeleted = true; try {// w w w .j av a 2s . c o m PolicyAdministratorPoint pap = policyManagementService.getPAP(); for (int i : policyIds) { org.wso2.carbon.policy.mgt.common.Policy policy = pap.getPolicy(i); if (!pap.deletePolicy(policy)) { policyDeleted = false; } } } catch (PolicyManagementException e) { String error = "Exception in deleting policies."; log.error(error, e); throw new MDMAPIException(error, e); } ResponsePayload responsePayload = new ResponsePayload(); if (policyDeleted) { responsePayload.setStatusCode(HttpStatus.SC_OK); responsePayload.setMessageFromServer("Policies have been successfully deleted."); return Response.status(HttpStatus.SC_OK).entity(responsePayload).build(); } else { responsePayload.setStatusCode(HttpStatus.SC_BAD_REQUEST); responsePayload.setMessageFromServer("Policy does not exist."); return Response.status(HttpStatus.SC_BAD_REQUEST).entity(responsePayload).build(); } }
From source file:org.wso2.carbon.mdm.api.User.java
/** * Method to get user information from emm-user-store. * * @param username User-name of the user * @return {Response} Status of the request wrapped inside Response object * @throws MDMAPIException/*from www . j ava 2s .c om*/ */ @GET @Path("view") @Produces({ MediaType.APPLICATION_JSON }) public Response getUser(@QueryParam("username") String username) throws MDMAPIException { UserStoreManager userStoreManager = MDMAPIUtils.getUserStoreManager(); ResponsePayload responsePayload = new ResponsePayload(); try { if (userStoreManager.isExistingUser(username)) { UserWrapper user = new UserWrapper(); user.setUsername(username); user.setEmailAddress(getClaimValue(username, Constants.USER_CLAIM_EMAIL_ADDRESS)); user.setFirstname(getClaimValue(username, Constants.USER_CLAIM_FIRST_NAME)); user.setLastname(getClaimValue(username, Constants.USER_CLAIM_LAST_NAME)); // Outputting debug message upon successful retrieval of user if (log.isDebugEnabled()) { log.debug("User by username: " + username + " was found."); } responsePayload.setStatusCode(HttpStatus.SC_OK); responsePayload.setMessageFromServer("User information was retrieved successfully."); responsePayload.setResponseContent(user); return Response.status(HttpStatus.SC_OK).entity(responsePayload).build(); } else { // Outputting debug message upon trying to remove non-existing user if (log.isDebugEnabled()) { log.debug("User by username: " + username + " does not exist."); } // returning response with bad request state responsePayload.setStatusCode(HttpStatus.SC_BAD_REQUEST); responsePayload.setMessageFromServer("User by username: " + username + " does not exist."); return Response.status(HttpStatus.SC_NOT_FOUND).entity(responsePayload).build(); } } catch (UserStoreException e) { String msg = "Exception in trying to retrieve user by username: " + username; log.error(msg, e); throw new MDMAPIException(msg, e); } }
From source file:org.wso2.carbon.mdm.api.User.java
/** * Method to remove user from emm-user-store. * * @param username Username of the user/*from ww w.j a va 2 s . c o m*/ * @return {Response} Status of the request wrapped inside Response object * @throws MDMAPIException */ @DELETE @Produces({ MediaType.APPLICATION_JSON }) public Response removeUser(@QueryParam("username") String username) throws MDMAPIException { UserStoreManager userStoreManager = MDMAPIUtils.getUserStoreManager(); ResponsePayload responsePayload = new ResponsePayload(); try { if (userStoreManager.isExistingUser(username)) { // if user already exists, trying to remove user userStoreManager.deleteUser(username); // Outputting debug message upon successful removal of user if (log.isDebugEnabled()) { log.debug("User by username: " + username + " was successfully removed."); } // returning response with success state responsePayload.setStatusCode(HttpStatus.SC_OK); responsePayload .setMessageFromServer("User by username: " + username + " was successfully removed."); return Response.status(HttpStatus.SC_OK).entity(responsePayload).build(); } else { // Outputting debug message upon trying to remove non-existing user if (log.isDebugEnabled()) { log.debug("User by username: " + username + " does not exist for removal."); } // returning response with bad request state responsePayload.setStatusCode(HttpStatus.SC_BAD_REQUEST); responsePayload .setMessageFromServer("User by username: " + username + " does not exist for removal."); return Response.status(HttpStatus.SC_BAD_REQUEST).entity(responsePayload).build(); } } catch (UserStoreException e) { String msg = "Exception in trying to remove user by username: " + username; log.error(msg, e); throw new MDMAPIException(msg, e); } }
From source file:org.wso2.carbon.mdm.api.User.java
/** * Get user's roles by username/*from w ww . j a v a2s . c o m*/ * * @param username Username of the user * @return {Response} Status of the request wrapped inside Response object * @throws MDMAPIException */ @GET @Path("roles") @Produces({ MediaType.APPLICATION_JSON }) public Response getRoles(@QueryParam("username") String username) throws MDMAPIException { UserStoreManager userStoreManager = MDMAPIUtils.getUserStoreManager(); ResponsePayload responsePayload = new ResponsePayload(); try { if (userStoreManager.isExistingUser(username)) { responsePayload.setResponseContent(Arrays.asList(getFilteredRoles(userStoreManager, username))); // Outputting debug message upon successful removal of user if (log.isDebugEnabled()) { log.debug("User by username: " + username + " was successfully removed."); } // returning response with success state responsePayload.setStatusCode(HttpStatus.SC_OK); responsePayload.setMessageFromServer("User roles obtained for user " + username); return Response.status(HttpStatus.SC_OK).entity(responsePayload).build(); } else { // Outputting debug message upon trying to remove non-existing user if (log.isDebugEnabled()) { log.debug("User by username: " + username + " does not exist for role retrieval."); } // returning response with bad request state responsePayload.setStatusCode(HttpStatus.SC_BAD_REQUEST); responsePayload.setMessageFromServer( "User by username: " + username + " does not exist for role retrieval."); return Response.status(HttpStatus.SC_BAD_REQUEST).entity(responsePayload).build(); } } catch (UserStoreException e) { String msg = "Exception in trying to retrieve roles for user by username: " + username; log.error(msg, e); throw new MDMAPIException(msg, e); } }
From source file:org.wso2.carbon.mdm.api.util.CredentialManagementResponseBuilder.java
/** * Builds the response to change the password of a user * @param credentials - User credentials * @return Response Object/*from w ww . ja v a 2 s. com*/ * @throws MDMAPIException */ public static Response buildChangePasswordResponse(UserCredentialWrapper credentials) throws MDMAPIException { UserStoreManager userStoreManager = MDMAPIUtils.getUserStoreManager(); ResponsePayload responsePayload = new ResponsePayload(); try { byte[] decodedNewPassword = Base64.decodeBase64(credentials.getNewPassword()); byte[] decodedOldPassword = Base64.decodeBase64(credentials.getOldPassword()); userStoreManager.updateCredential(credentials.getUsername(), new String(decodedNewPassword, "UTF-8"), new String(decodedOldPassword, "UTF-8")); responsePayload.setStatusCode(HttpStatus.SC_CREATED); responsePayload.setMessageFromServer( "User password by username: " + credentials.getUsername() + " was successfully changed."); return Response.status(HttpStatus.SC_CREATED).entity(responsePayload).build(); } catch (UserStoreException e) { log.error(e.getMessage(), e); responsePayload.setStatusCode(HttpStatus.SC_BAD_REQUEST); responsePayload.setMessageFromServer("Old password does not match."); return Response.status(HttpStatus.SC_BAD_REQUEST).entity(responsePayload).build(); } catch (UnsupportedEncodingException e) { String errorMsg = "Could not change the password of the user: " + credentials.getUsername() + ". The Character Encoding is not supported."; log.error(errorMsg, e); throw new MDMAPIException(errorMsg, e); } }
From source file:org.wso2.carbon.mdm.api.util.CredentialManagementResponseBuilder.java
/** * Builds the response to reset the password of a user * @param credentials - User credentials * @return Response Object//from w w w .j a va2s.c o m * @throws MDMAPIException */ public static Response buildResetPasswordResponse(UserCredentialWrapper credentials) throws MDMAPIException { UserStoreManager userStoreManager = MDMAPIUtils.getUserStoreManager(); ResponsePayload responsePayload = new ResponsePayload(); try { byte[] decodedNewPassword = Base64.decodeBase64(credentials.getNewPassword()); userStoreManager.updateCredentialByAdmin(credentials.getUsername(), new String(decodedNewPassword, "UTF-8")); responsePayload.setStatusCode(HttpStatus.SC_CREATED); responsePayload.setMessageFromServer( "User password by username: " + credentials.getUsername() + " was successfully changed."); return Response.status(HttpStatus.SC_CREATED).entity(responsePayload).build(); } catch (UserStoreException e) { log.error(e.getMessage(), e); responsePayload.setStatusCode(HttpStatus.SC_BAD_REQUEST); responsePayload.setMessageFromServer("Could not change the password."); return Response.status(HttpStatus.SC_BAD_REQUEST).entity(responsePayload).build(); } catch (UnsupportedEncodingException e) { String errorMsg = "Could not change the password of the user: " + credentials.getUsername() + ". The Character Encoding is not supported."; log.error(errorMsg, e); throw new MDMAPIException(errorMsg, e); } }
From source file:org.xwiki.formula.internal.GoogleChartsFormulaRenderer.java
/** * {@inheritDoc}//from www . j a v a 2 s. c o m */ @Override protected ImageData renderImage(String formula, boolean inline, FormulaRenderer.FontSize size, FormulaRenderer.Type type) throws IllegalArgumentException, IOException { String encodedFormula = URLEncoder.encode(formula, "UTF-8"); GetMethod method = new GetMethod(SERVICE_BASE_URL + encodedFormula); method.setRequestHeader("accept", type.getMimetype()); method.setFollowRedirects(true); // Execute the GET method int statusCode = this.client.executeMethod(method); if (statusCode >= HttpStatus.SC_OK && statusCode < HttpStatus.SC_BAD_REQUEST) { byte[] b = method.getResponseBody(); method.releaseConnection(); return new ImageData(b, type); } throw new IOException("Can't load image from the Google server"); }
From source file:org.xwiki.formula.internal.MathTranFormulaRenderer.java
/** * {@inheritDoc}//from w ww .j av a 2 s. c o m */ @Override protected ImageData renderImage(String formula, boolean inline, FormulaRenderer.FontSize size, FormulaRenderer.Type type) throws IllegalArgumentException, IOException { String encodedFormula = URLEncoder.encode((inline ? "" : "\\displaystyle") + formula, "UTF-8"); GetMethod method = new GetMethod( MATHTRAN_BASE_URL + "D=" + Math.max(size.ordinal() - 3, 0) + "&tex=" + encodedFormula); method.setRequestHeader("accept", type.getMimetype()); method.setFollowRedirects(true); // Execute the GET method int statusCode = this.client.executeMethod(method); if (statusCode >= HttpStatus.SC_OK && statusCode < HttpStatus.SC_BAD_REQUEST) { byte[] b = method.getResponseBody(); method.releaseConnection(); return new ImageData(b, type); } throw new IOException("Can't load image from MathTran server"); }
From source file:org.xwiki.test.rest.ObjectsResourceTest.java
@Test public void testPOSTInvalidObject() throws Exception { final String TAG_VALUE = "TAG"; Property property = new Property(); property.setName("tags"); property.setValue(TAG_VALUE);/*from w ww . j ava2 s.c o m*/ Object object = objectFactory.createObject(); object.getProperties().add(property); PostMethod postMethod = executePostXml( buildURI(ObjectsResource.class, getWiki(), MAIN_SPACE, "WebHome").toString(), object, TestUtils.ADMIN_CREDENTIALS.getUserName(), TestUtils.ADMIN_CREDENTIALS.getPassword()); Assert.assertEquals(getHttpMethodInfo(postMethod), HttpStatus.SC_BAD_REQUEST, postMethod.getStatusCode()); }
From source file:org.xwiki.test.rest.PageResourceTest.java
@Test public void testPUTWithInvalidRepresentation() throws Exception { Page page = getFirstPage();/* w w w . jav a 2 s. c o m*/ Link link = getFirstLinkByRelation(page, Relations.SELF); PutMethod putMethod = executePut(link.getHref(), "<?xml version=\"1.0\" encoding=\"UTF-8\"?><invalidPage><content/></invalidPage>", MediaType.TEXT_XML); Assert.assertEquals(getHttpMethodInfo(putMethod), HttpStatus.SC_BAD_REQUEST, putMethod.getStatusCode()); }