android ksoap2 Caused by: java.lang.RuntimeException: Cannot serialize: - Android Software Development

Hi
In my project i am using ksoap2-android-assembly-2.4-jar-with-dependencies.jar for web service purpose.
I got able to access the service and passing simple parameters and get the objects and iterate it.
But the problem is i cant able to send the complex object. Can anybody know how to pass the complex object with date and double values.
Employee object have string name, int number, double salary and Date dateOfBirth.
And the employee object implements KvmSerializable
name="Mike"
number=2;
salary=20000
dateOfBirth = new Date();
and the code is
SOAP_ACTION = "http://xysed/GetHRA";
METHOD_NAME = "GetHRA";
TextView authenticate = new TextView(this);
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
PropertyInfo pi = new PropertyInfo();
pi.setName("employee");
Employee e = new Employee();
e.setNumber(4);
e.setName("Ananth");
e.setSalary(20000);
e.setDob(new Date());
pi.setValue(e);
pi.setType(Employee.EMPLOYEE_CLASS);
request.addProperty(pi);
request.addProperty("employee", e);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.setOutputSoapObject(request);
Marshal dateMarshal = new MarshalDate();
dateMarshal.register(envelope);
//envelope.addMapping(Employee.NAMESPACE, "Employee", new Employee().getClass());
try {
AndroidHttpTransport androidHttpTransport = new AndroidHttpTransport(URL);
androidHttpTransport.call(SOAP_ACTION, envelope);
//String fullName = (String)envelope.getResponse();
Log.v("Full String :", envelope.getResponse().toString());
Log.v("body in :", envelope.bodyIn.toString());
Log.v("body out :", envelope.bodyOut.toString());
authenticate.setText(envelope.getResponse().toString());
this.setContentView(authenticate);
} catch (IOException ioe) {
ioe.printStackTrace();
} catch (XmlPullParserException xpe) {
xpe.printStackTrace();
}
I pass this employee object as a request i got an error like
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.oak.soap.test/com.oak.soap.test.WebserviceDisplay}: java.lang.RuntimeException: Cannot serialize: 20000.0
here 20000.0 is a salary ( double value)
ERROR/AndroidRuntime(287): Caused by: java.lang.RuntimeException: Cannot serialize: 20000.0
Can anybody provide samples for how to pass complex object as request to web service
Thanks
mindus

Related

Newbie url text download problem

Hi guys,
I am totally new at this. I mean completely raw .
I successfully put together a searchlight project by following a tutorial on youtube.
Now I want to do some work on a project that will fetch information from my employers website into the app. This information will be inform of text and images.
Here's the code I'm using in my attempt to read the remote text:
Code:
try {
URL url = new URL( "fullpath-url-to-file-dot-php" );
URLConnection conn = url.openConnection();
// Get the response
BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
String line = "";
while ((line = rd.readLine()) != null) {
Message lmsg;
lmsg = new Message();
lmsg.obj = line;
lmsg.what = 0;
Context context = getApplicationContext();
CharSequence text = "Hello toast! "+lmsg;
int duration = Toast.LENGTH_LONG;
Toast toast = Toast.makeText(context, text, duration);toast.show();
}
} catch (IOException e) {
// TODO Auto-generated catch block
//e.printStackTrace();
Context context = getApplicationContext();
CharSequence text = "error!";
int duration = Toast.LENGTH_LONG;
Toast toast = Toast.makeText(context, text, duration);toast.show();
}
I admit I barely know what I am doing. My attempt to download a simple line of text from a website url keeps failing.
Anyway, Can you guys give me an idea what I am doing wrong and what I should be doing instead?
Thanks
Update
I found out what the nature of the exception is.
It's a
Code:
java.net.socketexception: permission denied
exception.
Can anyone please shed some light on this for me ?
Did you add the internet permission to your manifest file?
Should be something like
<uses-permission>android.permission.INTERNET</uses-permission>

HttpClient Issues

I am making an application that requires maintaining a session with a server, aka Cookie management. I am currently unable to hold a session with my current code, though I was able to with code that was not separated into methods. I am not sure if that is the problem. If anyone is able to help I'd really appreciate it.
Here is the relevant code
Code:
public class MYHTTP
{
DefaultHttpClient client = new DefaultHttpClient();
HttpGet request;
HttpEntity entity;
HttpResponse response;
HttpPost post;;
public void getPage(String url) throws Exception
{
request = new HttpGet(url);
response = client.execute(request);
PARSER.preParse(url, response);
entity = response.getEntity();
if(entity != null)
{
entity.consumeContent();
}
}
public HttpResponse postPage(List<NameValuePair> params, String host, String action) throws Exception
{
post = new HttpPost(host + action);
post.setEntity(new UrlEncodedFormEntity(params, HTTP.UTF_8));
response = client.execute(post);
entity = response.getEntity();
if(entity != null)
{
entity.consumeContent();
}
return response;
}
public void destoyHttp()
{
client.getConnectionManager().shutdown();
}
}

Getting the html source code of a web page given by an url

Hi all,
I'm developping an application that needs to get the html source code of a web page.
I found this method:
Code:
public String getHtml(String url) throws ClientProtocolException, IOException
{
HttpClient client = new DefaultHttpClient();
HttpGet request = new HttpGet(url);
HttpResponse response = client.execute(request);
String html = "";
InputStream in = response.getEntity().getContent();
BufferedReader reader = new BufferedReader(new InputStreamReader(in));
StringBuilder str = new StringBuilder();
String line = null;
while((line = reader.readLine()) != null)
{
str.append(line);
}
in.close();
html = str.toString();
return html;
}
But this one cause a FC before the first line (tried with a toast). I looked on google but nothing looked better than this method. I don't understant why the FC appears and I don't know how I could debug this.
Can you give me some helps?
hey,
I have the same problem.
i dont want to show the complete website with an webview, i only want to use some parts of the site...
isn't there a way to look through the html and search for something?
Try using Watin..........

SAP webservice consuming

Hi all ,
I am developing an android app to invoke a webservice in SAP side.i have deployed the webservice and i have sucessfully invoked it using soapui.i am connected to my sap network via vpn.when i try to invoke the webservice from eclipse in the emulator.i am getting an warning "UnknownHostException: Unable to resolve host "myhostaddress": No address associated with hostname".
here is the code i used
public class customer_complaint extends Activity {
/** Called when the activity is first created. */
private static String SOAP_ACTION1 = "";
private static String METHOD_NAME1 = "ZfmCoeMob";
private static String NAMESPACE = "urn:sap-com:document:sap:soap:functions:mc-style";
private static String URL = "hypertextprotocol://10.201.52.86:8003/sap/bc/srt/wsdl/bndg_E2C5751FB4DDC7F192D3000E0CB7EB52/wsdl11/allinone/ws_policy/document?sap-language=EN&sap-client=100&sap-user=abap&[email protected]";
Button submit;
EditText editText_Customer,editText_Invoice;
@override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
setContentView(R.layout.customer_complaint);
submit = (Button)findViewById(R.id.submit);
editText_Customer = (EditText)findViewById(R.id.editText_Customer);
editText_Invoice = (EditText)findViewById(R.id.editText_Invoice);
submit.setOnClickListener(new View.OnClickListener()
{
@override
public void onClick(View v)
{
//Initialize soap request + add parameters
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME1);
//Use this to add parameters
request.addProperty("ZfmCoeMob",editText_Customer.getText().toString());
//Declare the version of the SOAP request
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.setOutputSoapObject(request);
try {
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
//this is the actual part that will call the webservice
androidHttpTransport.call(SOAP_ACTION1, envelope);
// Get the SoapResult from the envelope body.
// SoapObject result = (SoapObject)envelope.bodyIn;
SoapPrimitive resultString = (SoapPrimitive)envelope.getResponse();
if(resultString != null)
{
//Get the first property and change the label text
// editText_Invoice.setText(result.getProperty(0).toString());
editText_Invoice.setText(resultString.toString());
}
else
{
Toast.makeText(getApplicationContext(), "No Response",Toast.LENGTH_LONG).show();
}
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
}
is it something wrong due to the url link.but i am able to invoke the same service using soapui.i have attached my wsdl file with this thread.

Help with Apple WeatherKit

I hope someone can help me.
I'm having trouble getting an Apple WeatherKit REST request working. I'm trying to follow all of the requirements listed on https://developer.apple.com/documen...equest_authentication_for_weatherkit_rest_api, but I still get a 403 response code -- and I can't locate any Java samples to follow. I've been sweating this for weeks and haven't gotten anywhere.
Here's what I have:
URL url = new URL ("https://weatherkit.apple.com/api/v1/weather/en/40.75/-73.00?dataSets=currentWeather&timezone=Europe/London");
PrivateKey pkey = getPrivateKey ("AuthKey_CXXXXXXXXX.p8");
String jwts = getJwtsString (pkey);
HttpURLConnection conn = getConnection (url, jwts);
conn.connect();
int responsecode = conn.getResponseCode();
Just in case I've got something wrong, here are the three functions I'm calling. First, the one that creates the PrivateKey from the p8 file (I'm pretty sure this one is OK):
private PrivateKey getPrivateKey (String filename) {
PrivateKey privateKey = null;
try {
AssetManager assetManager = this.getAssets();
InputStream stream = assetManager.open(filename);
byte[] bytes = new byte[stream.available()];
int bytesRead = stream.read(bytes);
byte[] pkcs8EncodedKey = new byte[0];
pkcs8EncodedKey = Base64.getDecoder().decode(bytes);
KeyFactory factory = KeyFactory.getInstance("EC");
privateKey = factory.generatePrivate(new PKCS8EncodedKeySpec(pkcs8EncodedKey));
} catch (Exception e) { }
return privateKey;
}
Next, creating the JWTS string:
private String getJwtsString(PrivateKey privateKey) {
long t1 = System.currentTimeMillis();
return Jwts.builder()
.setHeaderParam ("alg", "ES256")
.setHeaderParam ("kid", "CXXXXXXXXX")
.setHeaderParam ("id", "QXXXXXXXXX.com.mydomain.myproject")
.claim ("iss", "Q5DC438ZG4")
.claim ("iat", t1)
.claim ("exp", t1 + 60000)
.claim ("sub", "com.mydomain.myproject") // obviously, replaced with my project info
.signWith (privateKey, SignatureAlgorithm.ES256)
.compact ();
}
And finally, creating the connection:
private HttpURLConnection getConnection(URL url, String jws) {
HttpURLConnection conn = (HttpURLConnection) Objects.requireNonNull(url).openConnection();
conn.setRequestMethod ("GET")
conn.setRequestProperty ("Authorization", "Bearer "+ jws);
conn.setRequestProperty ("Content-Type", "application/x-www-form-urlencoded");
conn.setRequestProperty ("Content-Language", "en-US");
conn.setUseCaches (false);
conn.setDoInput (true);
conn.setDoOutput (true);
conn.setConnectTimeout (30000); //set timeout to 30 seconds
return conn;
}
Obviously, this is the first time I've tried creating an authenticated http call, so I wouldn't be at all surprised if this is wrong.
Can anybody supply some sample code that I could follow?
Thanks in advance...

Categories

Resources