Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- protected WsResult genericRequest(String url,
- Map<String, String> params,
- Set<String> returnValues) throws Exception {
- WsResult result = null;
- HttpClient client = new HttpClient();
- PostMethod post = new PostMethod(url);
- Set<NameValuePair> data = new LinkedHashSet<NameValuePair>();
- if (logger.isDebugEnabled()) {
- logger.debug(url);
- }
- for (Map.Entry<String, String> e: params.entrySet()) {
- data.add(new NameValuePair(e.getKey(), e.getValue()));
- logger.debug("{} - {}", e.getKey(), e.getValue());
- }
- post.addRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
- post.setRequestBody((NameValuePair[]) data.toArray(new NameValuePair[0]));
- try {
- client.getHttpConnectionManager().getParams().setConnectionTimeout(5000);
- //client.getParams().setSoTimeout(4000);
- int statusCode = client.executeMethod(post);
- if (statusCode != HttpStatus.SC_OK) {
- throw new Exception("got non 200 status code from billing: " + statusCode);
- }
- String httpRes = post.getResponseBodyAsString();
- logger.debug(httpRes);
- result = parseResult(httpRes, returnValues);
- }catch (ConnectTimeoutException e) {
- throw e;
- }catch (Exception e) {
- logger.error(e.getMessage());
- result = new WsResult(-2, "bad request to billing", null);
- } finally {
- post.releaseConnection();
- }
- return result != null ? result : new WsResult();
- }
Add Comment
Please, Sign In to add comment