Guest User

Untitled

a guest
Apr 21st, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.87 KB | None | 0 0
  1. public class HttpClientAndPostCheck {
  2. private StringBuilder stringBuilder;
  3.  
  4. public HttpClientAndPostCheck() {
  5.  
  6. }
  7.  
  8. public static Document VerPIN(String xml) throws Exception
  9. {
  10. DocumentBuilderFactory doc = DocumentBuilderFactory.newInstance();
  11. DocumentBuilder blr = doc.newDocumentBuilder();
  12. InputSource inser = new InputSource(new StringReader(xml));
  13. return null;
  14. }
  15.  
  16. public String runXML() {
  17. String resultat = "";
  18. stringBuilder = new StringBuilder();
  19. stringBuilder.append(String.format("<?xml version="1.0"
  20. encoding="UTF-8" ?>" +
  21. "<soapenv:Envelope
  22. xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
  23. xmlns:_0="http://test.org/ADInterface/1_0">" +
  24. "<soapenv:Header/>" +
  25. "<soapenv:Body>" +
  26. "<_0:queryData>" +
  27. " <_0:ModelCRUDRequest>" +
  28. " <_0:ModelCRUD> " +
  29. " <_0:serviceType>checkForPIN</_0:serviceType> " +
  30. " <_0:DataRow> " +
  31. " <_0:field column="UserPIN"> " +
  32. " <_0:val>0000</_0:val> " +
  33. " </_0:field> " +
  34. " <_0:field column="Phone"> " +
  35. " <_0:val>0015145542122</_0:val> " +
  36. " </_0:field> " +
  37. " </_0:DataRow> " +
  38. " </_0:ModelCRUD>" +
  39. " <_0:ADLoginRequest> " +
  40. " <_0:user>WebService</_0:user> " +
  41. " <_0:pass>WSTest3</_0:pass> " +
  42. " <_0:lang>en_US</_0:lang> " +
  43. " <_0:ClientID>1000000</_0:ClientID> " +
  44. " <_0:RoleID>1000035</_0:RoleID> " +
  45. " <_0:OrgID>1000000</_0:OrgID> " +
  46. " <_0:WarehouseID>1000000</_0:WarehouseID> " +
  47. " <_0:stage>0</_0:stage> " +
  48. " </_0:ADLoginRequest> " +
  49. " </_0:ModelCRUDRequest> " +
  50. " </_0:queryData> " +
  51. " </soapenv:Body> " +
  52. "</soapenv:Envelope>"));
  53.  
  54. return resultat;
  55. }
  56. String xml= stringBuilder.toString();
  57. HttpPost httppost = new
  58. HttpPost("http://dev.testgob.com/ADInterface/services");
  59. HttpPost post = new
  60. HttpPost("http://de.testgob.com/ADInterface/services");
  61.  
  62. AuthScope as = new AuthScope("de.testgob.com" , 452);
  63. CredentialsProvider provider=new BasicCredentialsProvider();
  64. UsernamePasswordCredentials txt = new
  65. UsernamePasswordCredentials("username", "password");
  66. **//the errors begin**
  67. provider.setCredentials(AuthScope.ANY, txt);
  68.  
  69. HttpClient client = HttpClientBuilder.create()
  70. .setDefaultCredentialsProvider(provider)
  71. .Build();
  72.  
  73. StringEntity entity;
  74.  
  75. try {
  76. entity = new StringEntity(xml, StandardCharsets.UTF_8);
  77. httppost.setHeader("Content-Type","text/xml;Charset-UTF_8");
  78. httppost.setEntity(entity);
  79.  
  80. HttpResponse response = client.execute(httppost);
  81. result = EntityUtils.toString(response.getEntity());
  82. return result;
  83. }
  84. catch(Exception e) {
  85.  
  86. e.printStackTrace();
  87. }
Add Comment
Please, Sign In to add comment