Guest User

Untitled

a guest
Jun 21st, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.74 KB | None | 0 0
  1. protected WsResult genericRequest(String url,
  2. Map<String, String> params,
  3. Set<String> returnValues) throws Exception {
  4. WsResult result = null;
  5. HttpClient client = new HttpClient();
  6. PostMethod post = new PostMethod(url);
  7. Set<NameValuePair> data = new LinkedHashSet<NameValuePair>();
  8.  
  9. if (logger.isDebugEnabled()) {
  10. logger.debug(url);
  11. }
  12.  
  13.  
  14. for (Map.Entry<String, String> e: params.entrySet()) {
  15. data.add(new NameValuePair(e.getKey(), e.getValue()));
  16. logger.debug("{} - {}", e.getKey(), e.getValue());
  17. }
  18.  
  19. post.addRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
  20. post.setRequestBody((NameValuePair[]) data.toArray(new NameValuePair[0]));
  21.  
  22. try {
  23.  
  24. client.getHttpConnectionManager().getParams().setConnectionTimeout(5000);
  25. //client.getParams().setSoTimeout(4000);
  26.  
  27. int statusCode = client.executeMethod(post);
  28.  
  29. if (statusCode != HttpStatus.SC_OK) {
  30. throw new Exception("got non 200 status code from billing: " + statusCode);
  31. }
  32.  
  33. String httpRes = post.getResponseBodyAsString();
  34.  
  35. logger.debug(httpRes);
  36. result = parseResult(httpRes, returnValues);
  37. }catch (ConnectTimeoutException e) {
  38. throw e;
  39. }catch (Exception e) {
  40. logger.error(e.getMessage());
  41. result = new WsResult(-2, "bad request to billing", null);
  42. } finally {
  43. post.releaseConnection();
  44. }
  45.  
  46. return result != null ? result : new WsResult();
  47. }
Add Comment
Please, Sign In to add comment