List of usage examples for org.apache.commons.httpclient.methods PostMethod addParameter
public void addParameter(String paramString1, String paramString2) throws IllegalArgumentException
From source file:es.carebear.rightmanagement.client.admin.GetAllUsers.java
public User[] getAll(String authName) throws IOException, IllegalArgumentException, InternalServerErrorException, BadRequestException, UnauthorizedException, UnknownResponseException { PostMethod postMethod = new PostMethod(baseUri + "/client/users/all"); postMethod.addParameter("authName", authName); int responseCode = httpClient.executeMethod(postMethod); switch (responseCode) { case HttpStatus.SC_ACCEPTED: String response = XMLHelper.fromStreamToXML(postMethod.getResponseBodyAsStream()); StringListContainer lc = XMLHelper.fromXML(response, StringListContainer.class); List<User> ls = new ArrayList<>(); lc.getContainer().stream().forEach(obj -> { Gson gson = new Gson(); ls.add(gson.fromJson(obj, User.class)); });// w w w .ja v a 2 s . co m return ls.toArray(new User[ls.size()]); case HttpStatus.SC_INTERNAL_SERVER_ERROR: throw new InternalServerErrorException(); case HttpStatus.SC_UNAUTHORIZED: throw new UnauthorizedException(); case HttpStatus.SC_BAD_REQUEST: throw new BadRequestException(); default: throw new UnknownResponseException((new Integer(responseCode)).toString()); } }
From source file:es.carebear.rightmanagement.client.user.LogInUser.java
public User LogIn(String userName, String password) throws IOException, IllegalArgumentException, InternalServerErrorException, BadRequestException, UnauthorizedException, UnknownResponseException { PostMethod postMethod = new PostMethod(baseUri + "/client/users/login/" + userName); postMethod.addParameter("password", password); //System.err.println(postMethod.getPath()); int responseCode = httpClient.executeMethod(postMethod); switch (responseCode) { case HttpStatus.SC_CREATED: String response = XMLHelper.fromStreamToXML(postMethod.getResponseBodyAsStream()); return XMLHelper.fromXML(response, User.class); case HttpStatus.SC_FORBIDDEN: throw new UnauthorizedException(); case HttpStatus.SC_BAD_REQUEST: throw new BadRequestException(); default:/*from w ww . j a v a 2 s . co m*/ throw new UnknownResponseException((new Integer(responseCode)).toString()); } }
From source file:es.carebear.rightmanagement.client.admin.DeleteGroup.java
public void deleteGroup(String groupName, String authName) throws IOException, IllegalArgumentException, InternalServerErrorException, BadRequestException, UnauthorizedException, UnknownResponseException { PostMethod postMethod = new PostMethod(baseUri + "/client/groups/delete/" + groupName); postMethod.addParameter("authName", authName); int responseCode = httpClient.executeMethod(postMethod); switch (responseCode) { case HttpStatus.SC_OK: break;/* w w w . j av a 2 s .c o m*/ case HttpStatus.SC_INTERNAL_SERVER_ERROR: throw new InternalServerErrorException(); case HttpStatus.SC_UNAUTHORIZED: throw new UnauthorizedException(); case HttpStatus.SC_BAD_REQUEST: throw new BadRequestException(); default: throw new UnknownResponseException((new Integer(responseCode)).toString()); } }
From source file:es.carebear.rightmanagement.client.group.AddUserToGroup.java
public void AddUser(String executing, String target, String group) throws BadRequestException, InternalServerErrorException, IOException, UnknownResponseException { PostMethod postMethod = new PostMethod(baseUri + "/client/groups/add/" + target + "/" + group); postMethod.addParameter("authName", executing); int responseCode = httpClient.executeMethod(postMethod); switch (responseCode) { case HttpStatus.SC_OK: break;//from ww w . j ava2s . c om 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()); } }
From source file:es.carebear.rightmanagement.client.admin.CreateUser.java
public User createUser(String authName, String userName, String password) throws IOException, IllegalArgumentException, InternalServerErrorException, BadRequestException, UnauthorizedException, UnknownResponseException { PostMethod postMethod = new PostMethod(baseUri + "/client/users/create/" + userName); postMethod.addParameter("creatorName", authName); postMethod.addParameter("password", password); int responseCode = httpClient.executeMethod(postMethod); switch (responseCode) { case HttpStatus.SC_CREATED: String response = postMethod.getResponseBodyAsString(); return XMLHelper.fromXML(response, User.class); case HttpStatus.SC_INTERNAL_SERVER_ERROR: throw new InternalServerErrorException(); case HttpStatus.SC_UNAUTHORIZED: throw new UnauthorizedException(); case HttpStatus.SC_BAD_REQUEST: throw new BadRequestException(); default:/* www . j a v a 2 s .c o m*/ throw new UnknownResponseException((new Integer(responseCode)).toString()); } }
From source file:es.carebear.rightmanagement.client.admin.GetAllGroups.java
public Group[] getAll(String authName) throws IOException, IllegalArgumentException, InternalServerErrorException, BadRequestException, UnauthorizedException, UnknownResponseException { PostMethod postMethod = new PostMethod(baseUri + "/client/groups/all"); postMethod.addParameter("authName", authName); int responseCode = httpClient.executeMethod(postMethod); switch (responseCode) { case HttpStatus.SC_ACCEPTED: String response = XMLHelper.fromStreamToXML(postMethod.getResponseBodyAsStream()); StringListContainer lc = XMLHelper.fromXML(response, StringListContainer.class); List<Group> ls = new ArrayList<>(); lc.getContainer().stream().forEach(obj -> { Gson gson = new Gson(); ls.add(gson.fromJson(obj, Group.class)); });/*from w w w . jav a2 s . com*/ return ls.toArray(new Group[ls.size()]); case HttpStatus.SC_INTERNAL_SERVER_ERROR: throw new InternalServerErrorException(); case HttpStatus.SC_UNAUTHORIZED: throw new UnauthorizedException(); case HttpStatus.SC_BAD_REQUEST: throw new BadRequestException(); default: throw new UnknownResponseException((new Integer(responseCode)).toString()); } }
From source file:com.cloud.cluster.ClusterServiceServletImpl.java
@Override public String execute(ClusterServicePdu pdu) throws RemoteException { HttpClient client = getHttpClient(); PostMethod method = new PostMethod(_serviceUrl); method.addParameter("method", Integer.toString(RemoteMethodConstants.METHOD_DELIVER_PDU)); method.addParameter("sourcePeer", pdu.getSourcePeer()); method.addParameter("destPeer", pdu.getDestPeer()); method.addParameter("pduSeq", Long.toString(pdu.getSequenceId())); method.addParameter("pduAckSeq", Long.toString(pdu.getAckSequenceId())); method.addParameter("agentId", Long.toString(pdu.getAgentId())); method.addParameter("gsonPackage", pdu.getJsonPackage()); method.addParameter("stopOnError", pdu.isStopOnError() ? "1" : "0"); method.addParameter("pduType", Integer.toString(pdu.getPduType())); return executePostMethod(client, method); }
From source file:com.cloud.cluster.ClusterServiceServletImpl.java
@Override public boolean ping(String callingPeer) throws RemoteException { if (s_logger.isDebugEnabled()) { s_logger.debug("Ping at " + _serviceUrl); }// w w w . j a v a2 s . co m HttpClient client = getHttpClient(); PostMethod method = new PostMethod(_serviceUrl); method.addParameter("method", Integer.toString(RemoteMethodConstants.METHOD_PING)); method.addParameter("callingPeer", callingPeer); String returnVal = executePostMethod(client, method); if ("true".equalsIgnoreCase(returnVal)) { return true; } return false; }
From source file:com.stormpath.spring.boot.examples.filter.ReCaptchaFilter.java
@Override public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException { if (!(req instanceof HttpServletRequest) || !("POST".equalsIgnoreCase(((HttpServletRequest) req).getMethod()))) { chain.doFilter(req, res);/*from w ww .j a va 2 s . co m*/ return; } PostMethod method = new PostMethod(RECAPTCHA_URL); method.addParameter("secret", RECAPTCHA_SECRET); method.addParameter("response", req.getParameter(RECAPTCHA_RESPONSE_PARAM)); method.addParameter("remoteip", req.getRemoteAddr()); HttpClient client = new HttpClient(); client.executeMethod(method); BufferedReader br = new BufferedReader(new InputStreamReader(method.getResponseBodyAsStream())); String readLine; StringBuffer response = new StringBuffer(); while (((readLine = br.readLine()) != null)) { response.append(readLine); } JSONObject jsonObject = new JSONObject(response.toString()); boolean success = jsonObject.getBoolean("success"); if (success) { chain.doFilter(req, res); } else { ((HttpServletResponse) res).sendError(HttpStatus.BAD_REQUEST.value(), "Bad ReCaptcha"); } }
From source file:es.carebear.rightmanagement.client.admin.CreateGroup.java
public Group createGroup(String authName, String groupName) throws IOException, IllegalArgumentException, InternalServerErrorException, BadRequestException, UnauthorizedException, UnknownResponseException { PostMethod postMethod = new PostMethod(baseUri + "/client/groups/create/" + groupName); postMethod.addParameter("creatorName", authName); int responseCode = httpClient.executeMethod(postMethod); switch (responseCode) { case HttpStatus.SC_CREATED: String response = postMethod.getResponseBodyAsString(); return XMLHelper.fromXML(response, Group.class); case HttpStatus.SC_INTERNAL_SERVER_ERROR: throw new InternalServerErrorException(); case HttpStatus.SC_UNAUTHORIZED: throw new UnauthorizedException(); case HttpStatus.SC_BAD_REQUEST: throw new BadRequestException(); default:/* w w w. j a va 2 s . com*/ throw new UnknownResponseException((new Integer(responseCode)).toString()); } }