Advertisement
Guest User

Untitled

a guest
May 23rd, 2012
224
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.78 KB | None | 0 0
  1. public class AndroidHttpTransport extends Transport {
  2.  
  3. /**
  4. * Creates instance of HttpTransport with set url
  5. *
  6. * @param url
  7. * the destination to POST SOAP data
  8. */
  9. public AndroidHttpTransport(String url) {
  10. super(url);
  11. }
  12.  
  13. /**
  14. * set the desired soapAction header field
  15. *
  16. * @param soapAction
  17. * the desired soapAction
  18. * @param envelope
  19. * the envelope containing the information for the soap call.
  20. */
  21. @Override
  22. public void call(String soapAction, SoapEnvelope envelope) throws IOException, XmlPullParserException {
  23. if (soapAction == null)
  24. soapAction = "\"\"";
  25. byte[] requestData = createRequestData(envelope);
  26. requestDump = debug ? new String(requestData) : null;
  27. responseDump = null;
  28. ServiceConnection connection = getServiceConnection();
  29. connection.connect();
  30.  
  31. try {
  32. connection.setRequestProperty("User-Agent", "kSOAP/1.0");
  33. connection.setRequestProperty("SOAPAction", soapAction);
  34. connection.setRequestProperty("Content-Type", "text/xml;charset=utf-8");
  35.  
  36. connection.setRequestProperty("Connection", "close");
  37. connection.setRequestProperty("Content-Length", "" + requestData.length);
  38. connection.setRequestMethod("POST");
  39.  
  40. OutputStream os = connection.openOutputStream();
  41. os.write(requestData, 0, requestData.length);
  42. os.flush();
  43. os.close();
  44. requestData = null;
  45.  
  46. InputStream is;
  47. try {
  48. is = connection.openInputStream();
  49. } catch (IOException e) {
  50. is = connection.getErrorStream();
  51. if (is == null) {
  52. connection.disconnect();
  53. throw (e);
  54. }
  55. }
  56.  
  57. //if (debug) {
  58. if (true) {
  59. ByteArrayOutputStream bos = new ByteArrayOutputStream();
  60. byte[] buf = new byte[512];
  61. while (true) {
  62. int rd = is.read(buf, 0, 512);
  63. if (rd == -1)
  64. break;
  65. bos.write(buf, 0, rd);
  66. }
  67. bos.flush();
  68. buf = bos.toByteArray();
  69. responseDump = new String(buf);
  70. SoapExampleActivity.response = unescape(responseDump);
  71. SoapExampleActivity.response = responseDump;
  72. is.close();
  73. is = new ByteArrayInputStream(buf);
  74. }
  75.  
  76. parseResponse(envelope, is);
  77. } finally {
  78. connection.disconnect();
  79. }
  80. }
  81.  
  82. protected ServiceConnection getServiceConnection() throws IOException {
  83. return new AndroidServiceConnection(url);
  84. }
  85.  
  86. public static String unescape (String s)
  87. {
  88. while (true)
  89. {
  90. int n=s.indexOf("&#");
  91. if (n<0) break;
  92. int m=s.indexOf(";",n+2);
  93. if (m<0) break;
  94. try
  95. {
  96. s=s.substring(0,n)+(char)(Integer.parseInt(s.substring(n+2,m)))+
  97. s.substring(m+1);
  98. }
  99. catch (Exception e)
  100. {
  101. return s;
  102. }
  103. }
  104. s=s.replace("&quot;","\"");
  105. s=s.replace("&lt;","<");
  106. s=s.replace("&gt;",">");
  107. s=s.replace("&amp;","&");
  108. return s;
  109. }
  110.  
  111. @Override
  112. public List call(String arg0, SoapEnvelope arg1, List arg2)
  113. throws IOException, XmlPullParserException {
  114. return null;
  115. }
  116.  
  117. @Override
  118. public String getHost() {
  119. return null;
  120. }
  121.  
  122. @Override
  123. public String getPath() {
  124. return null;
  125. }
  126.  
  127. @Override
  128. public int getPort() {
  129. return 0;
  130. }
  131. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement