To implement a Basic authentication, you have to add a special http header to your service (before you invoke any methods). Here you have an example how to do this:
svcTC2APISoap service = new svcTC2APISoap();
service.httpHeaders.add(new HeaderProperty("Authorization", "Basic " +
org.kobjects.base64.Base64.encode("user:password".getBytes())));
service.CheckSecurityPanelLastCommandStateExV2();
Some web services use <any> element to return/retrieve any type of data. The schema (structure) of these data is unknown so EasyWSDL are not able to generate a strongly typed
fields for them. Instead, there is one field any which is a collection of PropertyInfo objects and using it you can still retrieve or send such data in a raw format.
You can also add any collection to all generated classes by selecting Generate All classes in generator settings.
Use this feature only if you find that some elements are missing in the generated classes.
Here you will find example how to retrieve and send data using any collection.
<n4:SearchGroups xmlns:n4="http://namespace.url/IBodyArchitectAccessService/">
<n5:ExerciseSearchCriteriaGroup xmlns:n5="http://schemas.datacontract.org/2004/07/BodyArchitect.Service.V2.Model">
Global
</n5:ExerciseSearchCriteriaGroup>
</n4:SearchGroups>
PartialRetrievingInfo info=new PartialRetrievingInfo();
ExerciseSearchCriteria exerciseSearchCriteria = new ExerciseSearchCriteria();
exerciseSearchCriteria.ExerciseTypes=new ArrayOfExerciseType();
//begin of creating data for any collection
PropertyInfo exerciseTypeAny = new PropertyInfo();
exerciseTypeAny.name="SearchGroups";
exerciseTypeAny.namespace="http://namespace.url/IBodyArchitectAccessService/";
SoapObject obj = new SoapObject("http://schemas.datacontract.org/2004/07/BodyArchitect.Service.V2.Model","ExerciseSearchCriteriaGroup");
exerciseTypeAny.setValue(obj);
PropertyInfo inner = new PropertyInfo();
inner.name="ExerciseSearchCriteriaGroup";
inner.namespace="http://schemas.datacontract.org/2004/07/BodyArchitect.Service.V2.Model";
inner.type= PropertyInfo.STRING_CLASS;
inner.setValue("Global");
obj.addProperty(inner);
exerciseSearchCriteria.any.add(exerciseTypeAny);
//end
PagedResultOfExerciseDTO5oAtqRlh exercises = service.GetExercises(sessionData.Token, exerciseSearchCriteria, info);
ProfileInformationDTO profileInfo=service.GetProfileInformation(sessionData.Token, criteria);
for (PropertyInfo info : profileInfo.any)
{
if(info.name.equals("Name"))
{
Object value=info.getValue();
}
else if(info.name.equals("Age"))
{
//...
}
}
In the latest generator we have introduced a feature to detect a strong types in any
collections. To use this option, you have to set CreateClassesForAny
property in you service class:
service.CreateClassesForAny=true;
With this option, you should find your objects instead of raw SoapObject
in any
collection.
SoapObject
objects in any
collection, you should generate classes with option Advanced settings -> Generate All classes.
Sometimes you need to modify generated classes. The recommended way of doing it is to create a new class inherits from the generated class and make changes there (if possible of course). Using this you can easly regenerate classes again without loosing your modifications.
Here you find an example how to configure internal ksoap2 Transport class in your service class
public class MyService extends svcTC2APISoap
{
@Override
protected Transport createTransport() {
//changing transport to HttpsTransportSE
Transport transport= new HttpsTransportSE(Proxy.NO_PROXY,url,500,"",timeOut);
transport.debug=true;
return transport;
}
@Override
protected ExtendedSoapSerializationEnvelope createEnvelope() {
//configure envelope
ExtendedSoapSerializationEnvelope envelope= super.createEnvelope();
envelope.dotNet=true;
envelope.implicitTypes=false;
return envelope;
}
@Override
protected void sendRequest(String methodName, ExtendedSoapSerializationEnvelope envelope, Transport transport) throws Exception {
try{
//here we want to print to output requestDump and responseDump after sending request to the server
super.sendRequest(methodName, envelope, transport);
}
catch (Exception e) {
throw e;
} finally {
if (transport.debug) {
if (transport.requestDump != null) {
System.err.println(transport.requestDump);
}
if (transport.responseDump != null) {
System.err.println(transport.responseDump);
}
}
}
}
}
Now to connect to your web service you should use MyService class instead of svcTC2APISoap.
The easiest way is to maintain a cookies between requests is to use CookieManager class. Basically put these two lines at the start of your application
CookieManager cookieManager = new CookieManager();
CookieHandler.setDefault(cookieManager);
If you find that easyWSDL classes handle date/time in a wrong way, you can create a custom provider. First step is to create a converter class, where you could override one or more methods:
public class MyCustomDateConverter extends StandardDateTimeConverter
{
@Override
public DateTime convertDateTime(String strDate) {
DateTimeFormatter parser1 = ISODateTimeFormat.dateTimeNoMillis();
return parser1.parseDateTime(strDate);
}
}
Next is to create an instance of this class and set it into ExtendedSoapSerializationEnvelope. You need to do this before you connect to your webservice.
MyCustomDateConverter converter = new MyCustomDateConverter();
ExtendedSoapSerializationEnvelope.setDateTimeConverter(converter);