Click here to Skip to main content
15,884,176 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
GetReport.java

package com.example.clientnetpositionreport;

import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.PropertyInfo;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapPrimitive;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;
import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.util.Log;
import android.widget.TextView;

public class GetReport extends Activity{
private static final String NAMESPACE ="http://tempuri.org"; //com.service.ServiceImpl
private static final String URL = "http://commodities.karvy.com/services/NetPositionReport.asmx";
private static final String METHOD_NAME = "NetPositionReport";
private static final String SOAP_ACTION = "http://tempuri.org/NetPositionReport";
private String webResponse = "";
private Handler handler = new Handler();
private Thread thread;

private TextView textView1;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(1);
setContentView(R.layout.activity_tv);
textView1 = (TextView) findViewById(R.id.textview1);

//int val=getIntent().getExtras().getInt("Title");
String title= getIntent().getExtras().getString("ClientCode");
//Log.d("Data is", val);

System.out.println("Data is "+title);

startWebAccess(title);

}
public void startWebAccess(String a){
final String aa=a;
thread = new Thread(){
public void run(){
try{
Log.d("Req value0R", "Starting...");//log.d is used for debug
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
//simple object access protocol
PropertyInfo fromProp =new PropertyInfo();
fromProp.setName("ClientCode");
fromProp.setValue(aa);
fromProp.setType(String.class);
request.addProperty(fromProp);

PropertyInfo fromProp2 =new PropertyInfo();
fromProp2.setName("String");
fromProp2.setValue("Om$@!#@M^#R");
fromProp2.setType(String.class);
request.addProperty(fromProp2);

Log.d("Req value1", request.toString());
System.out.println("ok1");
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = false;
envelope.setOutputSoapObject(request);

Log.d("Req value2", envelope.toString());
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
androidHttpTransport.debug = true;
Log.d("Req value2B", androidHttpTransport.toString());
androidHttpTransport.call(SOAP_ACTION, envelope);
System.out.println("ok2");
Log.d("Req value2C", androidHttpTransport.toString());
// Object objectResult = (Object)envelope.getResponse();
SoapPrimitive response = (SoapPrimitive)envelope.getResponse();
// System.out.println("Output: "+response.toString());
// Log.d("Req value3", response.toString());
System.out.println("ok3");
//textView1.setText(objectResult.toString());
System.out.println("ok4");
webResponse = response.toString();
Log.d("Req value4", webResponse.toString());
System.out.println("ok5");
}

catch(Exception e){
System.out.println("inside catch");
Log.d("Req value4", e.getMessage());
webResponse = "Connection/Internet problem";
// Toast.makeText(getApplicationContext(), "Loading problem/Server down", Toast.LENGTH_SHORT).show();
}

handler.post(createUI);
}
};

thread.start();
}


final Runnable createUI = new Runnable() {

public void run(){
if(webResponse!=null) {

textView1.setText(webResponse);
}
else {
webResponse ="No data provided presently";
textView1.setText(webResponse);
}
}
};

}



LogCat.

02-25 09:59:39.710: D/gralloc_goldfish(539): Emulator without GPU emulation detected.
02-25 10:00:28.019: I/System.out(539): Data is 64396
02-25 10:00:28.060: D/Req value0R(539): Starting...
02-25 10:00:28.070: D/Req value1(539): NetPositionReport{ClientCode=64396; String=Om$@!#@M^#R; }
02-25 10:00:28.080: I/System.out(539): ok1
02-25 10:00:28.349: D/Req value2(539): org.ksoap2.serialization.SoapSerializationEnvelope@4108c840
02-25 10:00:28.389: D/Req value2B(539): org.ksoap2.transport.HttpTransportSE@4108dda0
02-25 10:00:28.509: D/dalvikvm(539): GC_FOR_ALLOC freed 116K, 4% free 6976K/7239K, paused 48ms
02-25 10:00:33.320: I/System.out(539): ok2
02-25 10:00:33.320: D/Req value2C(539): org.ksoap2.transport.HttpTransportSE@4108dda0
02-25 10:00:33.330: I/System.out(539): ok3
02-25 10:00:33.330: I/System.out(539): ok4
02-25 10:00:33.330: I/System.out(539): inside catch
02-25 10:00:33.330: W/dalvikvm(539): threadid=11: thread exiting with uncaught exception (group=0x409961f8)
02-25 10:00:33.330: E/AndroidRuntime(539): FATAL EXCEPTION: Thread-72
02-25 10:00:33.330: E/AndroidRuntime(539): java.lang.NullPointerException: println needs a message
02-25 10:00:33.330: E/AndroidRuntime(539): at android.util.Log.println_native(Native Method)
02-25 10:00:33.330: E/AndroidRuntime(539): at android.util.Log.d(Log.java:138)
02-25 10:00:33.330: E/AndroidRuntime(539): at com.example.clientnetpositionreport.GetReport$2.run(GetReport.java:87)
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900