Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
796 views
in Technique[技术] by (71.8m points)

azure - Error while processing request in AzureMobile Apps HTTP2 error

This question is specific to a lately strange behavior of the Azure mobile Apps Android sdk. Everything was working fine for weeks. Now, my android client app suddenly can't connect to my web app any more. A Toast says "Error while processing request". In Android Studio debugger, I found the exception inside the SDK file MobileServiceConnection.java.

java.io.IOException: stream was reset: PROTOCOL_ERROR

In Azure Portal, my app shows "Healthy" status, but I can see the HTTP errors. Please help. Following is my code, which was working fine and now throws error.

// Create the Mobile Service Client instance, using the provided mobile app URL.
            try {
                mClient = new MobileServiceClient(mMobileBackendUrl, activityContext).withFilter(

                new ServiceFilter() {
                    @Override
                    public ListenableFuture<ServiceFilterResponse> handleRequest(ServiceFilterRequest request, NextServiceFilterCallback nextServiceFilter) {
                        // Get the request contents
                        String url = request.getUrl();
                        String content = request.getContent();

                        if (url != null) {
                            Log.d("Request URL:", url);
                        }

                        if (content != null) {
                            Log.d("Request Content:", content);
                        }

                        // Execute the next service filter in the chain
                        ListenableFuture<ServiceFilterResponse> responseFuture = nextServiceFilter.onNext(request);

                        Futures.addCallback(responseFuture, new FutureCallback<ServiceFilterResponse>() {
                            @Override
                            public void onFailure(Throwable exception) {
                                Log.d("Exception:", exception.getMessage());
                            }

                            @Override
                            public void onSuccess(ServiceFilterResponse response) {
                                if (response != null && response.getContent() != null) {
                                    Log.d("Response Content:", response.getContent());
                                }
                            }
                        });

                        return responseFuture;
                    }
                }
);

            setAzureClient(mClient);
            }catch(MalformedURLException e){
                createAndShowDialog(new Exception("There was an error creating the Mobile Service. Verify the URL"), "Error");
            }catch(Exception e){
                createAndShowDialog("There was an error creating the Mobile Service. "+ e.toString(), "Error");
            }

            Toast.makeText(context, context.getString(R.string.online_authentication), Toast.LENGTH_SHORT).show();
            authenticate();

    }

    private void authenticate() { // give access only to authenticated users via Google account authentication
        HashMap<String, String> parameters = new HashMap<>();
        parameters.put("access_type", "offline");//use "Refresh tokens"
        //login with the Google provider. This will create a call to onActivityResult() method inside the context Activity, which will then call the onActivityResult() below.
        mClient.login(MobileServiceAuthenticationProvider.Google, url_scheme_of_your_app, GOOGLE_LOGIN_REQUEST_CODE, parameters);

    }


@Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        // When request completes
        if (requestCode == 1) {
            try {
                MobileServiceActivityResult result = mClient.onActivityResult(data);
                if (result.isLoggedIn()) {
                    Toast.makeText(context, context.getString(R.string.azure_auth_login_success) /*+ " " + mClient.getCurrentUser().getUserId()*/, Toast.LENGTH_SHORT).show();
                    mUserId = mClient.getCurrentUser().getUserId();

                } else {//>>>>THIS IS WHERE I AM GETTING THE ERROR
                    String errorMessage = result.getErrorMessage();
                    Toast.makeText(context, errorMessage, Toast.LENGTH_SHORT).show();// Error While processing request (it comes form the MobileServiceConnection.java file inside sdk)

                }
            }catch(Exception e){
                Toast.makeText(context, e.toString(), Toast.LENGTH_LONG).show();
            }
        }
    }
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I found the answer myself. The error was due to an Azure App Service HTTP2 connection issue. It has nothing to do with the app code. For anyone facing the same problem, here is the solution.

  1. Go to https://resources.azure.com/
  2. Make sure you are in Read/Write mode by clicking in the option to the left of your name.
  3. From the left column, browse to: https://resources.azure.com/subscriptions/yourSubscriptionId/resourceGroups/yourWebAppResourceGroup/providers/Microsoft.Web/sites/yourWebAppName/config/web
  4. Find and Change the property: "http20Enabled": from true to false by clicking EDIT, Update value to “false” and then clicking in Save or PATCH.

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...