Odoo-mobile / framework

Odoo Mobile Framework
https://play.google.com/store/apps/dev?id=8607973775002477408
Other
330 stars 374 forks source link

E/Login Failed: Session expired #273

Open purevsurento opened 7 years ago

purevsurento commented 7 years ago

Odoo 10 server code update

E/Login Failed: Session expired

I/System.out: error : OdooError{message='Session expired', serverTrace='Traceback (most recent call last): odoo10_server/odoo/http.py", line 639, in _handle_exception return super(JsonRequest, self)._handle_exception(exception) odoo10_server/odoo/addons/base/ir/ir_http.py", line 186, in _dispatch auth_method = cls._authenticate(func.routing["auth"]) odoo10_server/odoo/addons/base/ir/ir_http.py", line 112, in _authenticate getattr(cls, "_authmethod%s" % auth_method)() odoo10_server/odoo/addons/base/ir/ir_http.py", line 85, in _auth_method_user raise http.SessionExpiredException("Session expired") SessionExpiredException: Session expired exceptionType='internal_error', errors=[Session expired], throwable=null, responseCode=200} Session expired

naitikvithlani commented 7 years ago

Hello @purevsurento ,

Can you please share the block of code to find out the solution, Because of i am also using the same framework with many of addons of odoo it work completely fine.(Find attached screen shot)

image

purevsurento commented 7 years ago

Hi. The following changes are made. OdooWrapper.class

private void newJSONPOSTRequest(final String url, JSONObject params,
                                IOdooResponse odooResponse, OdooSyncResponse backResponse) {
    OdooLog.d("REQUEST URL : " + url);
    final JSONObject postData = createRequestWrapper(params, odooResponse);
    OdooLog.d("POST DATA: " + postData);
    RequestFuture<JSONObject> requestFuture = RequestFuture.newFuture();
    if (backResponse == null) {
        Response.ErrorListener errorListener = new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                OdooLog.d("ERROR RESPONSE : " + error.getMessage());
                String message = error.getMessage();
                int responseCode = -1;
                if (error.networkResponse != null) {
                    message = "Server Error :" + error.networkResponse.statusCode;
                    switch (error.networkResponse.statusCode) {
                        case 400:
                            responseCode = Odoo.ErrorCode.OdooServerError.get();
                            break;
                        case 404:
                            responseCode = Odoo.ErrorCode.InvalidURL.get();
                            break;
                        default:
                            responseCode = Odoo.ErrorCode.UnknownError.get();
                    }
                }
                OdooError odooError = new OdooError(message, error);
                odooError.setResponseCode(responseCode);
                if (error instanceof TimeoutError) {
                    odooError.setMessage("Request Time out");
                    odooError.setServerTrace("Requested too many records. \n\n" +
                            "You can update values before requesting data:\n" +
                            "Odoo.REQUEST_TIMEOUT_MS\n" +
                            "Odoo.DEFAULT_MAX_RETRIES");
                }
                try {
                    IOdooResponse response = responseQueue.get(postData.getInt("id"));
                    if (response != null) {
                        response.onError(odooError);
                        responseQueue.remove(postData.getInt("id"));
                    }
                } catch (JSONException e) {
                    OdooLog.e(e, e.getMessage());
                }
            }
        };
        JsonObjectRequest2 request = new JsonObjectRequest2(url, postData, OdooWrapper.this, errorListener);
        request.setRetryPolicy(new DefaultRetryPolicy(new_request_timeout, new_request_max_retry,
                DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
        requestQueue.add(request);
    } else {
        JsonObjectRequest2 request = new JsonObjectRequest2(url, postData, requestFuture, requestFuture);
        request.setRetryPolicy(new DefaultRetryPolicy(new_request_timeout, new_request_max_retry,
                DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
        requestQueue.add(request);
        try {
            backResponse.setResponse(parseToResponse(requestFuture.get()));
        } catch (Exception e) {
            OdooLog.e(e);
        }
    }
    new_request_timeout = Odoo.REQUEST_TIMEOUT_MS;
    new_request_max_retry = Odoo.DEFAULT_MAX_RETRIES;
}

private class JsonObjectRequest2 extends JsonObjectRequest {

    public JsonObjectRequest2(int method, String url, JSONObject jsonRequest,
                              Response.Listener<JSONObject> listener, Response.ErrorListener errorListener) {
        super(method, url, jsonRequest, listener, errorListener);
    }

    /**
     * Constructor which defaults to <code>GET</code> if <code>jsonRequest</code> is
     * <code>null</code>, <code>POST</code> otherwise.
     *
     *
     */
    public JsonObjectRequest2(String url, JSONObject jsonRequest, Response.Listener<JSONObject> listener,
                              Response.ErrorListener errorListener) {
        this(jsonRequest == null ? Method.GET : Method.POST, url, jsonRequest,
                listener, errorListener);
    }

    public Map<String, String> getHeaders() throws AuthFailureError {
        Map<String, String> headers = new HashMap<>();
        headers.put("X-Openerp-Session-Id", odooSession.getSessionId());
        return headers;
    }
}
naitikvithlani commented 7 years ago

Okay, How you make a call for login / authenticate and search read records, because of it works for me without any changes of base odoo code.