Im trying to get my android app in my phone to talk with the spring boot backend. I tried setting the ip address of my pc instead of using it as the "localhost". but it does not work though.
Any idea on how to fix this and get by application to sent requests to my spring boot backend?
This is my code for the api call and the client.getProxy() will retrieve the saved "http://......" (PS: im using the volley library)
JsonObjectRequest authenticate = new JsonObjectRequest(
Request.Method.POST, client.getProxy() + "/authenticate", auth,
new Response.Listener<JSONObject>() {
#Override
public void onResponse(JSONObject response) {
resp = response.toString();
}
}, new Response.ErrorListener() {
#Override
public void onErrorResponse(VolleyError error) {
resp= "FAILED ";
}
}
Thanks in advance.
Instruction for the local host to physical mobile.
your mobile and laptop must be connected on same WiFi. Then you need to set your laptop ip on link from the command prompt.command ipconfig and get ipv4address from the result
I tried to retrieve a list of form data stored in database in my Android application. Each row of database contains some personal information of a person in string format and also an image of that person. I have stored the images in database in MEDIUMBLOB format.
Whenever I try to retrieve data from my server using JSONObjectrequest of Volley Library in my Android app, the response is usually very slow. Sometimes it takes more than 1 minute to view only 10 to 12 rows retrieved from the database.
This is my logcat:
D/Volley: [337] BasicNetwork.logSlowRequests: HTTP response for request=<[ ] http://helpclick.ahsanaasim.me/v1/tasksall/johny 0xa3e020c1 NORMAL 1> [lifetime=14740],
I tried to search for a perfect solution but I couldn't find anything satisfactory. Here is my Java code:
mRequestStartTime = System.currentTimeMillis();
JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.GET,
showUrl2, new Response.Listener<JSONObject>() {
#Override
public void onResponse(JSONObject response) {
long totalRequestTime = System.currentTimeMillis() - mRequestStartTime;
System.out.println(totalRequestTime);
System.out.println(response.toString());
try { c1++;
System.out.println(c1);
JSONArray incidents = response.getJSONArray("incidents");
for (int i = 0; i < incidents.length(); i++) {
e=0;
JSONObject incident = incidents.getJSONObject(i);
c1++;
id= incident.getString("id");
age = incident.getString("age");
gender = incident.getString("gender");
location = incident.getString("location");
//det= incident.getString("det");
String image=new String();
image = incident.getString("bigimage");
if(image.length()!=0) {
myBitmap = ConvertToImage(image);
Bitmap bitmap= Bitmap.createScaledBitmap(myBitmap,500,500,true);
imgs.add(bitmap);
ages.add(age);
genders.add(gender);
locations.add(location);
ids.add(id);
}
}
if(c1>0) {
System.out.println(ages.size());
Intent intent1 = new Intent(search_buttons_page.this, All_Incidents.class);
startActivity(intent1);
}
}
catch (JSONException e) {
e.printStackTrace();
}
}
}, new Response.ErrorListener() {
#Override
public void onErrorResponse(VolleyError error) {
System.out.append(error.getMessage());
}
});
jsonObjectRequest.setRetryPolicy(new DefaultRetryPolicy(
20000,
DefaultRetryPolicy.DEFAULT_MAX_RETRIES,
DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
requestQueue.add(jsonObjectRequest);
It would be really helpful if someone can tell me the reason of this slow performance and how to solve it by making minimum modifications in my source code.
Don't keep the images in the db. Keep them in files, and keep the URL of the files in the db. Download the images separately as needed via URL. Then you aren't killing your database access times with what should be file IO.
I am trying to edit an already registered addresses on my application, but I'm getting this error when I try to do that.
private void callServiceToEditAddress(String flatNo, String apartmentName, String landmark, String pincode) {
HashMap<String, String> hashMap = new HashMap<>();
hashMap.put("id", addressID);
hashMap.put("flat_no", flatNo);
hashMap.put("apartment_name", apartmentName);
hashMap.put("lanmark", landmark);
hashMap.put("pincode", pincode);
hashMap.put("state", selectedState);
hashMap.put("city", ID_city);
hashMap.put("location", ID_locality);
hashMap.put("country", "2");
new VolleyHelper(getActivity()).post("editAddress/", hashMap, new Response.Listener<String>() {
#Override
public void onResponse(String response) {
try {
JSONObject jsonObject = new JSONObject(response);
String success = jsonObject.getString("success");
mAddresshasbeenAdded.newAddressHasbeenAdded();
CroutonUtil.showCroutonMessage(getActivity(), success, CroutonUtil.CROUTON_STYLE_CONFIRM);
} catch (JSONException e) {
e.printStackTrace();
}
}
}, new Response.ErrorListener() {
#Override
public void onErrorResponse(VolleyError error) {
error.printStackTrace();
}
});
}
My Log cat:
E/Volley: [365] BasicNetwork.performRequest: Unexpected response code 500 for link I'm using
i solved this by changing the permission for included files in my server side
I was actually able to solve my problem eventually. What happened is that this web service that I am using "editAddress" also needed another field that I was not providing inside hashMap. I made the changes and it worked fine.
I just change my url from
http
to
https
Then it works fine for me.
The parameters put into Hashmap and get in server side was misspelled, When I have corrected the words of both side with same spelling , The problem was gone, Alhamdulillah.
I've made little server based on NodeMCU. All works good, when I'm conneting from browser, but problem starts, when I'm trying to connect from Android app uisng OkHttp or Volley, I'm receiving exceptions.
java.io.IOException: unexpected end of stream on Connection using OkHttp,
EOFException using Volley.
Problem is very similar for this
EOFException after server responds, but answer didn't found.
ESP server code
srv:listen(80, function(conn)
conn:on("receive", function(conn,payload)
print(payload)
conn:send("<h1> Hello, NodeMCU.</h1>")
end)
conn:on("sent", function(conn) conn:close() end)
end)
Android code
final RequestQueue queue = Volley.newRequestQueue(this);
final String url = "http://10.42.0.17:80";
final StringRequest request = new StringRequest(Request.Method.GET, url,
new Response.Listener<String>() {
#Override
public void onResponse(String response) {
mTemperatureTextView.setText(response.substring(0, 20));
System.out.println(response);
}
},
new Response.ErrorListener() {
#Override
public void onErrorResponse(VolleyError error) {
System.out.println("Error + " + error.toString());
mTemperatureTextView.setText("That didn't work!");
}
}
);
mUpdateButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
queue.add(request);
}
});
What you're sending back is not HTTP. It's nothing but a protocol-agnostic HTML fragment. Furthermore, there's a memory leak lingering.
Try this instead:
srv:listen(80, function(conn)
conn:on("receive", function(sck,payload)
print(payload)
sck:send("HTTP/1.0 200 OK\r\nServer: NodeMCU on ESP8266\r\nContent-Type: text/html\r\n\r\n<h1> Hello, NodeMCU.</h1>")
end)
conn:on("sent", function(sck) sck:close() end)
end)
you need to send back some HTTP headers, HTTP/1.0 200 OK and the newlines are mandatory
each function needs to use it's own copy of the passed socket instance, see how I renamed conn to sck in the two callback functions, see https://stackoverflow.com/a/37379426/131929 for details
For a more complete send example look at net.socket:send() in the docs. That becomes relevant once you start sending more than just a couple of bytes.
Im consuming a RESTful Api builded with ASP EF. I have a procedure in my DB, this is it:
ALTER PROCEDURE [Ventas].[CtasxCobxVendedor]
#AGE CHAR(1),
#VENDEDOR VARCHAR(10)
AS
BEGIN
SET NOCOUNT ON
SELECT
V.CLIENTE Codigo,
C.RazonSocialAnalitico Cliente,
C.DireccionAnalitico Direccion,
C.TelefonoAnalitico Telefono,
V.Gestion,
V.IdDos,
V.DCTO,
V.Factura,
V.Fecha,
V.Vencimiento,
SUM(B.DBB) Monto,
SUM(B.HBB) Pagos,
SUM(B.DBB-B.HBB) Saldo
FROM VENTAS.VMAESTRO V
JOIN VENTAS.CTASXCOBRAR B ON
(V.GESTION=B.GESTIONF
AND V.AGE =B.AGE
AND V.TIPO = B.TIPOF
AND V.IDDOS = B.IDDOSF
AND V.DCTO = B.DCTOF)
JOIN VENTAS.vwCLIENTES C ON
(V.CLIENTE = C.IdAnalitico)
WHERE
-- V.AGE =#AGE
V.STA = 'A'
AND V.VENDEDOR = #VENDEDOR
GROUP BY V.CLIENTE,C.RazonSocialAnalitico,C.DireccionAnalitico,C.TELEFONOAnalitico,V.Gestion,V.IdDos,V.DCTO,V.Factura,V.FECHA,V.VENCIMIENTO
HAVING SUM(B.DBB-B.HBB) > 0.001
ORDER BY C.RazonSocialAnalitico, V.FECHA, V.DCTO;
RETURN 0;
END
I created the import function, and the Complex Type on VS. So this is what I got:
public virtual ObjectResult<CtasxCobxVendedor_Result> CtasxCobrarV(string aGE, string vENDEDOR)
{
var aGEParameter = aGE != null ?
new ObjectParameter("AGE", aGE) :
new ObjectParameter("AGE", typeof(string));
var vENDEDORParameter = vENDEDOR != null ?
new ObjectParameter("VENDEDOR", vENDEDOR) :
new ObjectParameter("VENDEDOR", typeof(string));
return ((IObjectContextAdapter)this).ObjectContext.ExecuteFunction<CtasxCobxVendedor_Result>("CtasxCobrarV", aGEParameter, vENDEDORParameter);
}
Then I tried to call this SP in one of my controllers, in this case is my Personal controller, like this:
public IQueryable<CtasxCobxVendedor_Result1> GetCuenta(string id)
{
using (NemesisEntities ctx = new NemesisEntities()) {
return db.CtasxCobxVendedor("A", id).AsQueryable();
}
}
When I call this method on the browser (like this "localhost:45896/api/personals/3329672" where "3329672" is the Personal Id) works just fine, cause it gives me this result:
[{"Codigo":"1018389023","Cliente":"BAREMSA","Direccion":"Av. Cicunvalación - ITOS S/N","Telefono":"","Gestion":"15","IdDos":503,"DCTO":15001980,"Factura":1097,"Fecha":"2015-10-21T00:00:00","Vencimiento":"2015-11-20T00:00:00","Monto":1380.0000,"Pagos":0.0000,"Saldo":1380.0000},{"Codigo":"1018389023","Cliente":"BAREMSA","Direccion":"Av. Cicunvalación - ITOS S/N","Telefono":"","Gestion":"15","IdDos":509,"DCTO":15002329,"Factura":128,"Fecha":"2015-12-09T00:00:00","Vencimiento":"2016-01-08T00:00:00","Monto":1980.0000,"Pagos":0.0000,"Saldo":1980.0000},{"Codigo":"3095060012","Cliente":"BERTHA CONDORI ORURO","Direccion":"","Telefono":" 25288136","Gestion":"15","IdDos":509,"DCTO":15002349,"Factura":148,"Fecha":"2015-12-11T00:00:00","Vencimiento":"2016-01-10T00:00:00","Monto":1450.0000,"Pagos":0.0000,"Saldo":1450.0000},{"Codigo":"1015777022","Cliente":"CADEXNOR","Direccion":"","Telefono":"","Gestion":"16","IdDos":509,"DCTO":16000384,"Factura":661,"Fecha":"2016-03-09T00:00:00","Vencimiento":"2016-04-08T00:00:00","Monto":1440.0000,"Pagos":0.0000,"Saldo":1440.0000},{"Codigo":"1006965023","Cliente":"COMIBOL","Direccion":"Plaza 6 de Agosto","Telefono":" 68224768","Gestion":"14","IdDos":10,"DCTO":14000142,"Factura":314,"Fecha":"2012-08-03T00:00:00","Vencimiento":"2012-08-08T00:00:00","Monto":2770.0000,"Pagos":0.0000,"Saldo":2770.0000},{"Codigo":"1006965023","Cliente":"COMIBOL","Direccion":"Plaza 6 de Agosto","Telefono":" 68224768","Gestion":"14","IdDos":10,"DCTO":14000143,"Factura":776,"Fecha":"2013-10-03T00:00:00","Vencimiento":"2013-11-02T00:00:00","Monto":2900.0000,"Pagos":0.0000,"Saldo":2900.0000}]
Then when I try to connect it to my Android app using Volley framework:
JsonArrayRequest re= new JsonArrayRequest(Request.Method.GET, newURL, (String)null, new Response.Listener<JSONArray>() {
#Override
public void onResponse(JSONArray response) {
Toast.makeText(Cobrar.this,response.toString(),Toast.LENGTH_LONG).show();
procesarRespuesta(response);
}
}, new Response.ErrorListener() {
#Override
public void onErrorResponse(VolleyError error) {
Toast.makeText(Cobrar.this,"NOTHING",Toast.LENGTH_LONG).show();
Log.d(TAG, "Error Volley: " + error.getMessage());
}
});
Where "newURL" is like the one above. Just Give me "Error Volley:null" without any other explanation.
I really dont know what to fix, cause when I use simple GET calls for example calling this: "http://localhost:45896/api/clientes", it works fine, the problem is when I want to use the SP.
Any idea of what am I doind wrong? Since I dont get any information of where my problem actually is, Idk where to start
Please check this question posted here.
I have faced same issue.
Why this happens?
In volley, When timeout/socket timeout occurs it throws error. but
error object is null. You can override two methods in your Request
class to check if its timeout.
Solution :
JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.POST, "url", "request", new Response.Listener<JSONObject>() {
#Override
public void onResponse(JSONObject response) {
}
}, new Response.ErrorListener() {
#Override
public void onErrorResponse(VolleyError error) {
}
}) {
#Override
protected void deliverResponse(JSONObject response) {
super.deliverResponse(response);
}
#Override
public void deliverError(VolleyError error) {
super.deliverError(error);
}
};
You can get error on deliverError method in above code.
TimeOut occurs when server takes more time to respond to app then defined in RetryPolicy.
request.setRetryPolicy(new DefaultRetryPolicy(DefaultRetryPolicy.DEFAULT_TIMEOUT_MS * 48,
0, DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
default timeout is 2500 seconds for Volley.
You can avoid this issue using following improvements :
You need to improve your server performance
You can set retryCount to 1 if it suits your app requirements.
Thanks.