Advertisement
Guest User

Untitled

a guest
Aug 27th, 2017
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.72 KB | None | 0 0
  1. package com.venkattt.pack;
  2.  
  3. import java.net.SocketException;
  4.  
  5. import org.ksoap2.SoapEnvelope;
  6. import org.ksoap2.serialization.SoapObject;
  7. import org.ksoap2.serialization.SoapPrimitive;
  8. import org.ksoap2.serialization.SoapSerializationEnvelope;
  9. import org.ksoap2.transport.AndroidHttpTransport;
  10. import org.ksoap2.transport.HttpTransportSE;
  11.  
  12. import android.app.Activity;
  13. import android.os.Bundle;
  14.  
  15. public class SoapWebservicesExampleActivity extends Activity {
  16. /** Called when the activity is first created. */
  17. final String NAMESPACE = "urn:sap-com:document:sap:soap:functions:mc-style";
  18. final String URL = "http://**********:8000/sap/bc/srt/wsdl/srvc_14DAE9C8D79F1EE196F1FC6C6518A345/wsdl11/allinone/ws_policy/document?sap-client=800&sap-user=*******&sap-password=*******";
  19. final String METHOD_NAME = "Z_GET_CUST_GEN";
  20. final String SOAP_ACTION = "urn:sap-com:document:sap:soap:functions:mc-style/Z_GET_CUST_GEN";
  21. @Override
  22. public void onCreate(Bundle savedInstanceState) {
  23. super.onCreate(savedInstanceState);
  24. setContentView(R.layout.main);
  25.  
  26. SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME); // set up
  27. request.addProperty("Input", "1460");
  28. request.addProperty("Langu", "d");
  29. SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER12); // put all required data into a soap
  30. envelope.dotNet = false;
  31. envelope.setOutputSoapObject(request);
  32. HttpTransportSE httpTransport = new HttpTransportSE(URL);
  33. httpTransport.debug = true;
  34.  
  35. try {
  36.  
  37. httpTransport.call(SOAP_ACTION, envelope);
  38. Object result = (Object) envelope.getResponse();
  39.  
  40. System.out.println("theeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee result"+result);
  41.  
  42. }
  43. catch(SocketException ex){
  44. ex.printStackTrace();
  45. } catch (Exception e) {
  46. e.printStackTrace();
  47. }
  48. }
  49. }
  50.  
  51. HttpPost httppost = new HttpPost("http://192.168.1.103/test/index1.php");
  52. //httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
  53. HttpResponse response = httpclient.execute(httppost);
  54. HttpEntity entity = response.getEntity();
  55. is = entity.getContent();
  56. Log.e("log_tag", "connection success ");
  57. //convert response to string
  58.  
  59. BufferedReader reader = new BufferedReader(new InputStreamReader(is,"iso-8859-1"),8);
  60. StringBuilder sb = new StringBuilder();
  61. String line = null;
  62. while ((line = reader.readLine()) != null)
  63. {
  64. sb.append(line + "n");
  65.  
  66. }
  67. is.close();
  68. result=sb.toString();
  69. //Log.e("",""+result);
  70.  
  71. public class From extends Activity
  72. {
  73. HttpPost httppost;
  74. InputStream is;
  75. ListView lv;
  76. TextView displayStrip;
  77. ArrayList<String> atcodeid=new ArrayList<String>();
  78. ArrayAdapter<String> adapter;
  79. ArrayList<String> listItems=new ArrayList<String>();
  80. ArrayList<String> originalname=new ArrayList<String>();
  81. String mode;
  82. Button btn_name;
  83. Button btn_map;
  84. SharedPreferences prefs;
  85. int testing;
  86. String shortcutname;
  87. @Override
  88. public void onCreate(Bundle savedInstanceState) {
  89. super.onCreate(savedInstanceState);
  90. setContentView(R.layout.from);
  91.  
  92. lv = (ListView)findViewById(R.id.listView1);
  93. displayStrip= (TextView)findViewById(R.id.displayStrip);
  94. btn_name = (Button)findViewById(R.id.name);
  95. btn_map = (Button)findViewById(R.id.map);
  96. prefs = PreferenceManager.getDefaultSharedPreferences(this);
  97. testing = prefs.getInt("settings",0);
  98.  
  99. adapter=new ArrayAdapter<String>(From.this,
  100. android.R.layout.simple_list_item_1,
  101. listItems);
  102. lv.setAdapter(adapter);
  103. lv.setFastScrollEnabled(true);
  104. String result = "";
  105. // ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
  106. // nameValuePairs.add(new BasicNameValuePair("birthyear","1990"));
  107. try{
  108. HttpClient httpclient = new DefaultHttpClient();
  109.  
  110. HttpPost httppost = new HttpPost("http://192.168.1.103/test/index1.php");
  111. //httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
  112. HttpResponse response = httpclient.execute(httppost);
  113. HttpEntity entity = response.getEntity();
  114. is = entity.getContent();
  115. //Log.e("log_tag", "connection success ");
  116. // Toast.makeText(getApplicationContext(), "pass", Toast.LENGTH_SHORT).show();
  117. }catch(Exception e){
  118. Log.e("log_tag", "Error in http connection "+e.toString());
  119. }
  120. //convert response to string
  121. try
  122. {
  123. BufferedReader reader = new BufferedReader(new InputStreamReader(is,"iso-8859-1"),8);
  124. StringBuilder sb = new StringBuilder();
  125. String line = null;
  126. while ((line = reader.readLine()) != null)
  127. {
  128. sb.append(line + "n");
  129. // Toast.makeText(getApplicationContext(), "pass", Toast.LENGTH_SHORT).show();
  130. }
  131. is.close();
  132. result=sb.toString();
  133. //Log.e("",""+result);
  134. }catch(Exception e){
  135. Log.e("log_tag", "Error converting result "+e.toString());
  136. }
  137. try{
  138. JSONArray jArray = new JSONArray(result);
  139. JSONObject json_data=null;
  140. for(int i=0;i<jArray.length();i++)
  141. {
  142. json_data =jArray.getJSONObject(i);
  143. String src_name=json_data.getString("commonname");
  144. originalname.add(src_name);
  145. if(src_name.contains("Wharf"))
  146. {
  147. shortcutname=src_name.substring(0, src_name.indexOf("Wharf"));
  148. }
  149. else if(src_name.contains("Station"))
  150. {
  151. shortcutname=src_name.substring(0, src_name.indexOf("Station"));
  152. }
  153. else
  154. shortcutname=src_name;
  155. listItems.add(shortcutname);
  156. //listItems.add(src_name);
  157. //Log.e("",i+"testing"+src_name);
  158. atcodeid.add(json_data.getString("Atcocode"));
  159. adapter.notifyDataSetChanged();
  160. }
  161. }catch(JSONException e){
  162. Log.e("log_tag", "Error parsing data "+e.toString());
  163. Toast.makeText(getApplicationContext(), "fail", Toast.LENGTH_SHORT).show();
  164. }
  165. lv.setOnItemClickListener(new OnItemClickListener() {
  166.  
  167. public void onItemClick(AdapterView arg0,
  168. View arg1, int position, long arg3) {
  169. Intent i = new Intent(From.this, To.class);
  170. //Toast.makeText(From.this, ""+atcodeid.get(position)+" "+originalname.get(position), Toast.LENGTH_SHORT).show();
  171. i.putExtra("mode", mode);
  172. i.putExtra("id", atcodeid.get(position));
  173. i.putExtra("fromacto", originalname.get(position));
  174. startActivity(i);
  175. }
  176. });
  177. btn_map.setOnClickListener(new OnClickListener() {
  178. public void onClick(View v) {
  179. btn_map.requestFocus();
  180. btn_map.setFocusable(true);
  181. SharedPreferences.Editor prefsEditor = prefs.edit();
  182. prefsEditor.putInt("settings", 1);
  183. prefsEditor.commit();
  184. Intent intent=new Intent(From.this , FromGoogleMaps.class);
  185. startActivity(intent);
  186. }
  187. });
  188. btn_name.setOnClickListener(new OnClickListener() {
  189. public void onClick(View v) {
  190. btn_name.requestFocus();
  191. btn_name.setFocusable(true);
  192. SharedPreferences.Editor prefsEditor = prefs.edit();
  193. prefsEditor.putInt("settings", 0);
  194. prefsEditor.commit();
  195. Intent intent=new Intent(From.this , From.class);
  196. startActivity(intent);
  197. }
  198. });
  199. }
  200.  
  201. responseDump = new String(buf);
  202. unescape(responseDump);
  203. your_string = responseDump;
  204.  
  205. String SOAP_ACTION = "http://www.webserviceX.NET/GetWeather";
  206. String METHOD_NAME = "GetWeather";
  207. String NAMESPACE = "http://www.webserviceX.NET";
  208. String SOAP_ADDRESS = "http://www.webservicex.com/globalweather.asmx";
  209.  
  210. SoapObject request = new SoapObject(NAMESPACE,METHOD_NAME);
  211. request.addProperty("login",login_id);
  212. request.addProperty("pwd",Password_id);
  213.  
  214. SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
  215. envelope.dotNet = true;
  216. envelope.setOutputSoapObject(request);
  217. envelope.implicitTypes = true;
  218.  
  219. HttpTransportSE httpTransaport = new HttpTransportSE(SOAP_ADDRESS);
  220. httpTransaport.debug = true;
  221.  
  222. String response = null;
  223.  
  224.  
  225. try
  226. {
  227. httpTransaport.call(SOAP_ACTION,envelope);
  228. response = httpTransaport.responseDump;
  229. } catch (XmlPullParserException e) {
  230. e.printStackTrace();
  231. } catch (IOException e) {
  232. e.printStackTrace();
  233. }
  234. return response;
  235. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement