Java tutorial
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package es.carebear.rightmanagement.client.user; import es.carebear.rightmanagement.client.exceptions.BadRequestException; import es.carebear.rightmanagement.client.exceptions.InternalServerErrorException; import es.carebear.rightmanagement.client.exceptions.UnknownResponseException; import es.carebear.rightmanagement.core.exceptions.UnauthorizedException; import es.carebear.rightmanagement.core.user.User; import java.io.IOException; import javax.ws.rs.ForbiddenException; import org.apache.commons.httpclient.HttpClient; import org.apache.commons.httpclient.HttpStatus; import org.apache.commons.httpclient.methods.PostMethod; /** * * @author hannes */ public class AddAllowedUserId { private String baseUri; private HttpClient httpClient; public AddAllowedUserId(String baseUri) { this.baseUri = baseUri; this.httpClient = new HttpClient(); } public void AddUser(String authName, String target, String rightMask) throws BadRequestException, InternalServerErrorException, IOException, UnknownResponseException, UnauthorizedException { PostMethod postMethod = new PostMethod(baseUri + "/client/users/change/allowed"); postMethod.addParameter("authName", authName); postMethod.addParameter("target", target); postMethod.addParameter("rightMask", rightMask); int responseCode = httpClient.executeMethod(postMethod); switch (responseCode) { case HttpStatus.SC_OK: break; case HttpStatus.SC_BAD_REQUEST: throw new BadRequestException(); case HttpStatus.SC_INTERNAL_SERVER_ERROR: throw new InternalServerErrorException(); case HttpStatus.SC_UNAUTHORIZED: throw new UnauthorizedException(); case HttpStatus.SC_FORBIDDEN: throw new ForbiddenException(); default: throw new UnknownResponseException((new Integer(responseCode)).toString()); } } public void AddUser(String authName, String target, String rigthTarget, String rightMask) throws BadRequestException, InternalServerErrorException, IOException, UnknownResponseException { PostMethod postMethod = new PostMethod(baseUri + "/client/users/change/allowed/" + target); postMethod.addParameter("authName", authName); postMethod.addParameter("rigthTarget", rigthTarget); postMethod.addParameter("rightMask", rightMask); int responseCode = httpClient.executeMethod(postMethod); switch (responseCode) { case HttpStatus.SC_OK: break; case HttpStatus.SC_BAD_REQUEST: throw new BadRequestException(); case HttpStatus.SC_INTERNAL_SERVER_ERROR: throw new InternalServerErrorException(); case HttpStatus.SC_FORBIDDEN: throw new ForbiddenException(); default: throw new UnknownResponseException((new Integer(responseCode)).toString()); } } }