Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
New Developer
Posts: 120
Registered: ‎05-20-2011
My Device: Touch 9800

KSoap(Complex Type) issue

Hello everybody,

 

I am newbie in BB development.I want to use Ksoap to call the web service. For simple parameters i used this code snipet:-

username = uid.getText();
password = pass.getText();

String serviceUrl = urlS;
String serviceNamespace = "http://impl.service.hercules.zanibal.com/";
String soapAction = "\"\"";

SoapObject rpc = new SoapObject(serviceNamespace, "login");
SoapSerializationEnvelope envelope =newSoapSerializationEnvelope(SoapEnvelope.VER11);


rpc.addProperty("arg0", username);
rpc.addProperty("arg1", password);
envelope.dotNet = false;
envelope.setOutputSoapObject(rpc);

envelope.encodingStyle = SoapSerializationEnvelope.XSD;
HttpTransportBasicAuth ht = new HttpTransportBasicAuth(serviceUrl, wsunS, wspwdS);

ht.debug = true;

String result;

try
{
ht.call(soapAction, envelope);
result = (envelope.getResponse()).toString();


token = result;
System.out.println("Token: " + token);
System.out.println("Request::::::::::::::::::::::::::::::::::: \n" + ht.requestDump);
System.out.println("Response>>>>>>>>>>>>>>>>> \n" + ht.responseDump);
UiApplication.getUiApplication().invokeLater(new Runnable() {
public void run()
{
Dialog.alert("Login Successful!");
}
});

}
catch (Exception ex)
{
result = ex.toString();
System.out.println("Exception: " + result);
System.out.println("Request::::::::::::::::::::::::::::::::::: \n" + ht.requestDump);
System.out.println("Response>>>>>>>>>>>>>>>>> \n" + ht.responseDump);
UiApplication.getUiApplication().invokeLater(new Runnable() {
public void run()
{
Dialog.alert("Login Unsuccessful!\nPlease try again.");
}
});
}

}

 


This works fine for me.....Now the problem is when i have a complex type i don't able to retrieve the response....my code snippet is:-

                                          

String serviceUrl = urlS;
String serviceNamespace = "http://impl.service.hercules.zanibal.com/";
String soapAction = "\"\"";



SoapObject rpc = new SoapObject(serviceNamespace, "findCustomerPortfolios");

MCustomer MC = new MCustomer();

//MC.id = "1";

PropertyInfo pi = new PropertyInfo();
rpc.addProperty(pi,MC);


SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);



envelope.dotNet = false;
envelope.setOutputSoapObject(rpc);
envelope.encodingStyle = SoapSerializationEnvelope.XSD;

envelope.addMapping(serviceNamespace, "MCustomer",new MCustomer().getClass());

HttpTransportBasicAuth ht = new HttpTransportBasicAuth(serviceUrl, wsunS, wspwdS);

ht.debug = true;

String result;

try
{
ht.call(soapAction, envelope);

result = (envelope.getResponse()).toString();

token = result;
System.out.println("Token: " + token);
System.out.println("Request::::::::::::::::::::::::::::::::::: \n" + ht.requestDump);
System.out.println("Response>>>>>>>>>>>>>>>>> \n" + ht.responseDump);
UiApplication.getUiApplication().invokeLater(new Runnable() {
public void run()
{
Dialog.alert("Login Successful!");
}
});

}
catch (Exception ex)
{
result = ex.toString();
System.out.println("Exception: " + result);
System.out.println("Request::::::::::::::::::::::::::::::::::: \n" + ht.requestDump);
System.out.println("Response>>>>>>>>>>>>>>>>> \n" + ht.responseDump);
UiApplication.getUiApplication().invokeLater(new Runnable() {
public void run()
{
Dialog.alert("herrererere Login Unsuccessful!\nPlease try again.");
}
});
}


 

I have created the complex class MCustomer and is posted below  with this post pls refer to it.

Please help me out .I get the java null pointer exception
Thanks.

 

package com.emx.forex.complex;

import java.util.Date;
import java.util.Hashtable;
import org.ksoap2.serialization.KvmSerializable;
import org.ksoap2.serialization.PropertyInfo;

public class MCustomer implements KvmSerializable
{
	public String id;
	public String name;
	public String label;
	public String lastName;
	public String prefix;
	public String salutation;
	public String suffix;
	public String firstName;
	public String middleName;
	public String title;
	public String postNominal;
	public String ethnicity;
	public String sex;
	public Date birthDate;
	public String martialStatus;
	public String motherMaidenName;
	public String cellPhone;
	public String avialableCashBalanceCurrency;
	public float avialableCashBalanceAmount;
	public String unclearedCashBalanceCurrency;
	public float unclearedCashBalanceAmount;
	public String avialableCreditLimitCurrency;
	public float avialableCreditLimitAmount;

	public MCustomer()
	{
	}

	public MCustomer(String Id, String Name, String Label, String LastName/*, String Prefix, String Salutation, String Suffix, String FirstName, String MiddleName, String Title, String PostNominal, String Ethnicity, String Sex, Date BirthDate, String MartialStatus, String MotherMaidenName,
			String CellPhone, String AvialableCashBalanceCurrency, float AvialableCashBalanceAmount, String UnclearedCashBalanceCurrency, float UnclearedCashBalanceAmount, String AvialableCreditLimitCurrency, float AvialableCreditLimitAmount*/)
	{

		id = Id;
		name = Name;
		label = Label;
		lastName = LastName;
	/*	prefix = Prefix;
		salutation = Salutation;
		suffix = Suffix;
		firstName = FirstName;
		middleName = MiddleName;
		title = Title;
		postNominal = PostNominal;
		ethnicity = Ethnicity;
		sex = Sex;
		birthDate = BirthDate;
		martialStatus = MartialStatus;
		motherMaidenName = MotherMaidenName;
		cellPhone = CellPhone;
		avialableCashBalanceCurrency = AvialableCashBalanceCurrency;
		avialableCashBalanceAmount = AvialableCashBalanceAmount;
		unclearedCashBalanceCurrency = UnclearedCashBalanceCurrency;
		unclearedCashBalanceAmount = UnclearedCashBalanceAmount;
		avialableCreditLimitCurrency = AvialableCreditLimitCurrency;
		avialableCreditLimitAmount = AvialableCreditLimitAmount;*/
	}

	public Object getProperty(int arg0)
	{
		switch (arg0)
		{
		case 0:
			return id;
		case 1:
			return name;
		case 2:
			return label;
		case 3:
			return lastName;
	/*	case 4:
			return prefix;
		case 5:
			return salutation;
		case 6:
			return suffix;
		case 7:
			return firstName;
		case 8:
			return middleName;
		case 9:
			return title;
		case 10:
			return postNominal;
		case 11:
			return ethnicity;
		case 12:
			return sex;
		case 13:
			return birthDate;
		case 14:
			return martialStatus;
		case 15:
			return motherMaidenName;
		case 16:
			return cellPhone;
		case 17:
			return avialableCashBalanceCurrency;
		case 18:
			return new Float(avialableCashBalanceAmount);
		case 19:
			return unclearedCashBalanceCurrency;
		case 20:
			return new Float(unclearedCashBalanceAmount);
		case 21:
			return avialableCreditLimitCurrency;
		case 22:
			return new Float(unclearedCashBalanceAmount);*/
		}
		return null;
	}

	public int getPropertyCount()
	{
		// TODO Auto-generated method stub
		return 5;
	}

	public void getPropertyInfo(int index, Hashtable arg1, PropertyInfo info)
	{
		switch (index)
		{
		case 0:
			info.type = PropertyInfo.INTEGER_CLASS;
			info.name = "id";
			break;
		case 1:
			info.type = PropertyInfo.STRING_CLASS;
			info.name = "name";
			break;
		case 2:
			info.type = PropertyInfo.STRING_CLASS;
			info.name = "label";
			break;
		case 3:
			info.type = PropertyInfo.STRING_CLASS;
			info.name = "lastName";
			break;
		/*case 4:
			info.type = PropertyInfo.INTEGER_CLASS;
			info.name = "prefix";
			break;
		case 5:
			info.type = PropertyInfo.STRING_CLASS;
			info.name = "salutation";
			break;
		case 6:
			info.type = PropertyInfo.STRING_CLASS;
			info.name = "suffix";
			break;
		case 7:
			info.type = PropertyInfo.INTEGER_CLASS;
			info.name = "firstName";
			break;
		case 8:
			info.type = PropertyInfo.STRING_CLASS;
			info.name = "middleName";
			break;
		case 9:
			info.type = PropertyInfo.STRING_CLASS;
			info.name = "title";
			break;
		case 10:
			info.type = PropertyInfo.INTEGER_CLASS;
			info.name = "postNominal";
			break;
		case 11:
			info.type = PropertyInfo.STRING_CLASS;
			info.name = "ethnicity";
			break;
		case 12:
			info.type = PropertyInfo.STRING_CLASS;
			info.name = "sex";
			break;
		case 13:
			info.type = PropertyInfo.OBJECT_CLASS;
			info.name = "birthDate";
			break;
		case 14:
			info.type = PropertyInfo.INTEGER_CLASS;
			info.name = "martialStatus";
			break;
		case 15:
			info.type = PropertyInfo.STRING_CLASS;
			info.name = "motherMaidenName";
			break;
		case 16:
			info.type = PropertyInfo.STRING_CLASS;
			info.name = "cellPhone";
			break;
		case 17:
			info.type = PropertyInfo.INTEGER_CLASS;
			info.name = "avialableCashBalanceCurrency";
			break;
		case 18:
			info.type = PropertyInfo.OBJECT_CLASS;
			info.name = "avialableCashBalanceAmount";
			break;
		case 19:
			info.type = PropertyInfo.STRING_CLASS;
			info.name = "unclearedCashBalanceCurrency";
			break;
		case 20:
			info.type = PropertyInfo.OBJECT_CLASS;
			info.name = "unclearedCashBalanceAmount";
			break;
		case 21:
			info.type = PropertyInfo.STRING_CLASS;
			info.name = "avialableCreditLimitCurrency";
			break;
		case 22:
			info.type = PropertyInfo.OBJECT_CLASS;
			info.name = "avialableCreditLimitAmount";
			break;*/
		default:
			break;
		}

	}

	public void setProperty(int index, Object value)
	{
		 switch(index)
		        {
		        case 0:
				id = value.toString();
				break;
			case 1:
				name = value.toString();
				break;
			case 2:
				label = value.toString();
				break;
			case 3:
				 lastName  =  value.toString();
				 break;
			/*case 4:
				 prefix  =  value.toString();
				 break;
			case 5:
				 salutation  =  value.toString();
				 break;
			case 6:
				 suffix  =  value.toString();
				 break;
			case 7:
				 firstName  =  value.toString();
				 break;
			case 8:
				 middleName  =  value.toString();
				 break;
			case 9:
				 title  =  value.toString();
				 break;
			case 10:
				 postNominal  =  value.toString();
				 break;
			case 11:
				 ethnicity  =  value.toString();
				 break;
			case 12:
				 sex  =  value.toString();
				 break;
			case 13:
				 birthDate  =  (Date) value;
				 break;
			case 14:
				 martialStatus  =  value.toString();
				 break;
			case 15:
				 motherMaidenName  =  value.toString();
				 break;
			case 16:
				 cellPhone  =  value.toString();
				 break;
			case 17:
				 avialableCashBalanceCurrency  =  value.toString();
				 break;
			case 18:
				 avialableCashBalanceAmount   =  Float.parseFloat(value.toString());
				 break;
			case 19:
				 unclearedCashBalanceCurrency   =  value.toString();
				 break;
			case 20:
				unclearedCashBalanceAmount   = Float.parseFloat(value.toString());
				break;
			case 21:
				 avialableCreditLimitCurrency =  value.toString();
				 break;
			case 22:
				 unclearedCashBalanceAmount =  Float.parseFloat(value.toString());
				 break;*/
		        default:
		            break;
		        }

	}

}

 

Amar
Developer
Posts: 16,517
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport

Re: KSoap(Complex Type) issue

i would suggest that you debug your code and try to find the issue.
to make this easier:
you can use HttpTransportSE, which is the desktop java version of HttpTransport, with JUnit.
If you encapsulate your webservice not to use RIM/J2ME-code you can execute your webservice using test cases.
As Junit testcases are much faster to execute and have a better debugging support they help a lot when it comes to checking a webservice.
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
New Developer
Posts: 120
Registered: ‎05-20-2011
My Device: Touch 9800

Re: KSoap(Complex Type) issue

Hello Simon, Thanks for your reply . If u have used ksoap2 for complex type in BB then can you please paste your snippet here ....i am struggling with this from a week.... I would be very thankful to you Thanks.
Amar