KSoap Request Timeout? - android-ksoap2

friends,
i dont see request timeout in KSoap library
any one guide me what should i do?
or from where to download latest version of it?
my code
SoapObject userRequest=new SoapObject(NAMESPACE, METHOD_NAME);
userRequest.addProperty("session_id", session_id );
userRequest.addProperty("page_size", PageSize);
userRequest.addProperty("offset",Offset );
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
request.addProperty("GetAlertsInput", userRequest);
SoapSerializationEnvelope envelope = new
SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.bodyOut = request;
HttpTransportAndroid androidHttpTransport = new
HttpTransportAndroid(URL);
androidHttpTransport.call(SOAP_ACTION_GETALERTS, envelope);
any help would be appreciated.

I have more than one methods on the server . I am using the same line
androidHttpTransport.call(SOAP_ACTION_GETALERTS, envelope);
With different methods name, while getting second response its crashing.

STEP : 1
Get the ksoap2-android-assembly-3.3.0-jar-with-dependencies.jar file. And place the jar file in app > libs folder.
STEP : 2
compile files('libs/ksoap2-android-assembly-3.3.0-jar-with-dependencies.jar') place the line in build gradle > dependencies.
STEP :3
static int networkTimeOut = 60 * 1000;
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.setOutputSoapObject(inserttransaction_request);
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL, networkTimeOut);

Could mention that I made a modification to the KSoap2 v2.5.2 to support timeout for HttpTransportSE class. It will throw a SocketTimeoutException when timeout occurs.
It's both jar and src is found at this url https://www.lightsoftai.com/?p=707

Related

Drupal 7 Service module node resources attach_file end point

I am implementing a Xamarin Form mobile app to allow post photo to Drupal using service module node resources. http://xxxx.com/{endpoint}/node/4/attach_file
i able to post from POSTMAN with
I tried to implement with c# HttpClient but keep getting response like "401 :Missing required argument field_name"
Please help on my code:
var httpClient = new HttpClient(new NativeMessageHandler());
httpClient.Timeout.Add(new TimeSpan(0, 0, 30));
httpClient.BaseAddress = new Uri(BaseAddress);
var content = new MultipartFormDataContent();
var streamContent = new StreamContent(g_media.GetStream());
streamContent.Headers.ContentDisposition = ContentDispositionHeaderValue.Parse("form-data");
streamContent.Headers.ContentDisposition.Parameters.Add(new NameValueHeaderValue("field_name", "field_receipt_image"));
content.Add(streamContent,"files[file]");
var response = await httpClient.PostAsync("node/4/attach_file", content);
response.EnsureSuccessStatusCode();
I had the same issue and used RestSharp to resolve it. Here is the code I used to upload a file to Drupal:
var restClient = new RestClient("http:XXXXXX/attach_file");
var request = new RestRequest(Method.POST);
request.AddFile("files[file]", fileName);
request.AddParameter("field_name", field);
IRestResponse response = restClient.Execute(request);

SOAP in SWIFT import a Objective C Class

Hi I'm gonna code my application on xCode in Swift, before i had problems with my WebService SOAP in Android, so I did some search and they're a lot of subjects about, but my WebService is particular, look in Android what I did:
SSLConnection.allowAllSSL();
SoapObject request = new SoapObject(NAMESPACE, "SendLead");
request.addProperty("xml", xml);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.setOutputSoapObject(request);
HttpTransportBasicAuth httpTransport = new HttpTransportBasicAuth(URL, getResources().getString(R.string.login), getResources().getString(R.string.mdp));
httpTransport.debug = true;
httpTransport.call(SOAP_ACTION, envelope);
SoapObject result = (SoapObject) envelope.bodyIn;
Log.i(TAG, "Result Celsius: " + result);
SoapObject SendLeadReturn = (SoapObject) result.getProperty("SendLeadReturn");
String code = SendLeadReturn.getPropertyAsString("code");
So I have many constrains:
https URL
I have to keep my login to use the other functions of the wsdl (HttpTransportBasicAuth)
I send and receive xml strings
How to do it, I think it's preferable to import a Objective C class, but which and how please ?

How do I replace an existing Community file on IBM SmartCloud

I am trying to replace an existing Community file using the following java
Map<String, String> paramsMap = new HashMap<String, String>();
paramsMap.put("createVersion", "false");
fileEntry = fileService.updateCommunityFile(fis, fileUuid, fileName, communityLibraryId, paramsMap);
But it is returning a HTTP 411:Length required error.
I am using the latest build (1.1.5.20150520-1200.jar)
Does anyone have a suggestion as to what i am missing?
I tried recreating the issue but I am able to upload New version of Community file correctly with and without version, using the updateCommunityFile API. I do not get any Length related error. This is the snippet I am using :
java.io.File file = new java.io.File("C://TestUploadCommunity.txt");
FileInputStream fis = null;
try {
fis = new FileInputStream(file);
} catch (Exception e) {
//TODO
}
fileEntry = fileService.updateCommunityFile(fis, fileEntry.getFileId(), fileEntry.getLabel(), communityLibraryId, params);
Can you share more details on your sample, what exactly is your fis?
I have tried this on 2 environments and I do not see any issue.
Also, from the entry you have pasted,
"Request to url apps.na.collabserv.com/files/basic/api/library... /document/... /entry?content-length=6600&createVersion=false returned an error response 411:Length Required HTTP/1.1 411"
It seems that somehow an incorrect content-length is passed for your request.
Can you share the sample that you are using?

MultipartEntityBuilder setMode() not working

Using apache httpcomponents-client-4.3.6-bin libs.
This code is producing an HttpEntity intance with both parts containing the Content-Tranfer-Encoding header. I can't eliminate these headers using setMode(HttpMultipartMode.BROWSER_COMPATIBLE) or setLaxMode(). Does anyone have any suggestions please?
MultipartEntityBuilder builder = MultipartEntityBuilder.create();
builder.setMode(HttpMultipartMode.BROWSER_COMPATIBLE);
List<ContentType> contentTypeList = new ArrayList<>();
contentTypeList.add(ContentType.create("application/x-dmas+json"));
contentTypeList.add(ContentType.create("application/exe"));
int idx = 0;
while(paramKeysIt.hasNext()) {
builder.addBinaryBody(key = paramKeysIt.next(), params.get(key), contentTypeList.get(idx++), params.get(key).getName());
}
HttpEntity reqEntity = builder.build();
Very strange. By POSTing my request to an echo server I am able to see that the Content-Transfer-Encoding headers are indeed absent, even though they show up clearly, and repeatedly in the debugger!
Using NetBeans IDE 8.0

WebClient NotFound error but working with HttpWebRequest/Response

In my WinPhone app I'm accessing a REST service.
At the beginnings I was using this code:
WebClient wc = new WebClient();
wc.Credentials = credentials;
wc.Headers["App-Key"] = appKey;
wc.DownloadStringCompleted +=
(o, args) => MessageBox.Show(args.Error == null ? "OK" : "Error");
wc.DownloadStringAsync(uri);
but it suddenly stopped working returning me a "The remote server returned an error: NotFound" error. After a google session and some clicks in the control panel, I didn't get it to work.
I decided to try this other way:
HttpWebRequest request = HttpWebRequest.CreateHttp(uri);
request.Credentials = credentials;
request.Headers["App-Key"] = appKey;
request.BeginGetResponse(asResult =>
{
var response = request.EndGetResponse(asResult) as HttpWebResponse;
StreamReader reader = new StreamReader(response.GetResponseStream());
string responseString = reader.ReadToEnd();
Dispatcher.BeginInvoke(
() => MessageBox.Show(response.StatusCode.ToString()));
}, null);
and it works.
I also tried to run the first snipped pointing the URI to google's home page and it works (I had to remove the credentials, of course).
Can anyone explain what's going on?
UPDATE
I managed to get it working by replacing the
wc.Credentials = new NetworkCredentials(username, password);
with
wc.Headers["Authorization"] = "Basic someBase64encodedString";
but i still wonder what happened and which are the differences between the first and the second line.
PS: the test URI is: https://api.pingdom.com/api/2.0/checks but you will need an app-key from them.
When using the Credentials property, the HttpWebRequest implementation will wait the challenge response from server before to send the 'Authorization' header value.
But this can be an issue in some cases, so you have to force Basic authentication by providing directly the Authorization header.
Example when using a REST Client library like Spring.Rest :
RestTemplate template = new RestTemplate("http://example.com");
template.RequestInterceptors.Add(new BasicSigningRequestInterceptor("login", "password"));
string result = template.GetForObject<string>(uri);

Resources