Hi All,
first of all, sorry my rusty english
We need some help in consume a webservice in our App.
Our scenario is:
The webservice was written in Java, using Jersey, exposed by a POST and 2 queryParams, and returns a String.
The app must consume this webservice and post some data.
The called occurs, but the parameters was null.
Can anybody help? For sure, I'm doing something wrong.
My app code follow:
My webservice code follows above:
first of all, sorry my rusty english
We need some help in consume a webservice in our App.
Our scenario is:
The webservice was written in Java, using Jersey, exposed by a POST and 2 queryParams, and returns a String.
The app must consume this webservice and post some data.
The called occurs, but the parameters was null.
Can anybody help? For sure, I'm doing something wrong.
My app code follow:
B4X:
Dim job2 As HttpJob
job2.Initialize("RegisterTask", Me)
'job2.PostString(Main.BoardUrl, "deviceIdentificator="&Intent.GetExtra("registration_id")&"&deviceName="&Main.DeviceName
job2.PostString(Main.BoardUrl, "deviceIdentificator=1234&deviceName=celDaniel")
----
Sub JobDone(Job As HttpJob)
If Job.Success Then
Select Job.JobName
Case "RegisterTask"
Log(Job.GetString)
ToastMessageShow("Registration completed successfully.", False)
Case "UnregisterTask"
Log(Job.GetString)
ToastMessageShow("Unregistration completed successfully.", False)
End Select
Else
ToastMessageShow("Error sending request to GCM", True)
Log(Job.ErrorMessage)
End If
Job.Release
End Sub
My webservice code follows above:
B4X:
@Path("/registerDevice")
@POST
public Response registerDevice(
@QueryParam("deviceIdentificator") String deviceIdentificator,
@QueryParam("deviceName") String deviceName) {
String response = "";
pushNotificationBO = new PushNotificationBO();
System.out.println("deviceIdentificator: " + deviceIdentificator);
System.out.println("deviceName: " + deviceName);
C2DM c2dm = new C2DM();
c2dm.setId(deviceIdentificator);
c2dm.setName(deviceName);
c2dm.setDatatime(Calendar.getInstance());
try {
response = pushNotificationBO.registerDevice(c2dm);
} catch (DAOException e) {
e.printStackTrace();
response = e.getException().getMessage();
return Response.ok().status(500).entity(response).header("Content-Type", "text/plain;charset=UTF-8").build();
}
return Response.ok().status(200).entity(response).header("Content-Type", "text/plain;charset=UTF-8").build();
}
Last edited: