401 Unauthorized - Request not reaching the endpoint - android

I'm having trouble with reaching my Google Cloud Endpoints backend from my Android application. I use the following related tools and libraries:
Android Studio 2.3
Gradle plugin - com.google.appengine:gradle-appengine-plugin:1.9.49
App Engine SDK - com.google.appengine:appengine-java-sdk:1.9.49
Endpoints library - com.google.appengine:appengine-endpoints:1.9.49
Endpoints dependencies - com.google.appengine:appengine-endpoints-deps:1.9.49
I've followed the documentation on testing with a physical device against the local development server, which means I've added the line httpAddress = "0.0.0.0" to the build.gradle in the backend module, and I connect to the backend using the following code:
SomeApi.Builder builder = new SomeApi.Builder(AndroidHttp.newCompatibleTransport(), new AndroidJsonFactory(), null);
builder.setApplicationName("someapplicationname");
builder.setRootUrl("http://192.168.1.1:8080/_ah/api/");
builder.setGoogleClientRequestInitializer(new GoogleClientRequestInitializer()
{
#Override
public void initialize(AbstractGoogleClientRequest<?> abstractGoogleClientRequest) throws IOException
{
abstractGoogleClientRequest.setDisableGZipContent(true);
}
});
SomeApi api = builder.build();
I then call a method of the created api using the following line:
api.someMethod("Some random string").execute();
And this is where the problem occurs. This method call triggers the following exception pointing to the same method call (the line above):
W/System.err: com.google.api.client.googleapis.json.GoogleJsonResponseException: 401 Unauthorized
W/System.err: at com.google.api.client.googleapis.services.json.AbstractGoogleJsonClientRequest.newExceptionOnError(AbstractGoogleJsonClientRequest.java:113)
W/System.err: at com.google.api.client.googleapis.services.json.AbstractGoogleJsonClientRequest.newExceptionOnError(AbstractGoogleJsonClientRequest.java:40)
W/System.err: at com.google.api.client.googleapis.services.AbstractGoogleClientRequest$1.interceptResponse(AbstractGoogleClientRequest.java:321)
W/System.err: at com.google.api.client.http.HttpRequest.execute(HttpRequest.java:1056)
W/System.err: at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:419)
W/System.err: at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:352)
W/System.err: at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.execute(AbstractGoogleClientRequest.java:469)
W/System.err: at se.essvagsystemab.mobiltdispenssystem.licensemanager.simple.fragment.MainFragment$13.doInBackground(MainFragment.java:381)
W/System.err: at se.essvagsystemab.mobiltdispenssystem.licensemanager.simple.fragment.MainFragment$13.doInBackground(MainFragment.java:373)
W/System.err: at android.os.AsyncTask$2.call(AsyncTask.java:304)
W/System.err: at java.util.concurrent.FutureTask.run(FutureTask.java:237)
W/System.err: at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:243)
W/System.err: at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
W/System.err: at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
W/System.err: at java.lang.Thread.run(Thread.java:761)
The strange thing is that the requests doesn't even reach the endpoint. The exception seems to be thrown by the Endpoints library on the client side, because the the server log does not show any signs of error, it contains the log messages printed when starting the server, and that's it.
I have no idea what is causing this, so any help is greatly appreciated!

Turns out that I copied the wrong IP-address from the ipconfig-output, even though I mentioned I'm using the correct IP-address. Hrrm, embarassing...
After trying (what felt like) every possible solution, I once again checked the IP, and it turned out I'd copied the one labeled Default Gateway, which was obviously not as correct as the one labeled IPv4 Address!
So, if you're experiencing the same problem but still you feel like you've done everything correctly, make sure to double check the IP before giving up!

Related

Firebase Crashlytic Errors: Android

We are using the latest Firebase Crashlytic dependency com.google.firebase:firebase-crashlytics:18.0.0
The issues are:
W/OkHttpClient: A connection to https://firebase-settings.crashlytics.com/ was leaked. Did you forget to close a response body?
E/FirebaseCrashlytics: Settings request failed.
java.io.FileNotFoundException: https://firebase-settings.crashlytics.com/spi/v2/platforms/android/gmp/1:582811355855:android:a439b44cdd024799/settings?instance=de187b29e345c342d109ce02e794bff07e1613b0&build_version=7&display_version=1.2.0&source=1
at com.android.okhttp.internal.huc.HttpURLConnectionImpl.getInputStream(HttpURLConnectionImpl.java:251)
at com.android.okhttp.internal.huc.DelegatingHttpsURLConnection.getInputStream(DelegatingHttpsURLConnection.java:210)
at com.android.okhttp.internal.huc.HttpsURLConnectionImpl.getInputStream(Unknown Source:0)
at j1.a.c(HttpGetRequest.java:80)
at com.google.firebase.crashlytics.internal.settings.network.a.a(DefaultSettingsSpiCall.java:113)
at com.google.firebase.crashlytics.internal.settings.d$a.b(SettingsController.java:199)
at com.google.firebase.crashlytics.internal.settings.d$a.a(SettingsController.java:192)
at com.google.android.gms.tasks.g0.run(com.google.android.gms:play-services-tasks##17.2.1:1)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
at com.google.firebase.crashlytics.internal.common.t$a$a.a(ExecutorUtils.java:64)
at com.google.firebase.crashlytics.internal.common.c.run(BackgroundPriorityRunnable.java:27)
at java.lang.Thread.run(Thread.java:764)
The console also is not responding on enabling the feature unlike on other apps we worked on where it works pretty well.

Connecting to Cloud SQL using Compute Engine via JDBC

I cannot connect to my database thru Compute Engine.
Things I have done so far:
Setup my Compute Engine
Connect my Compute Engine to my Cloud SQL
Install and run Cloud Proxy on my Compute Engine
Included the JDBC Jar file on my libs folder
Created the JDBC Connection string
"jdbc:mysql:///?cloudSqlInstance=&socketFactory=com.google.cloud.sql.mysql.SocketFactory;user=&password=";
Added dependency on my Gradle file
-implementation fileTree(dir: 'libs', include: ['*.jar'])
-implementation 'com.google.cloud.sql:mysql-socket-factory-connector-j-8:1.1.0'
Here is the stack trace:
W/System.err: java.sql.SQLNonTransientConnectionException: Cannot
connect to MySQL server on localhost:3,306. W/System.err: Make sure
that there is a MySQL server running on the machine/port you are
trying to connect to and that the machine this software is running on
is able to connect to this host/port (i.e. not firewalled). Also make
sure that the server has not been started with the --skip-networking
flag.
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:110)
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:97)
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:89)
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:63)
W/System.err: at
com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:73)
at com.mysql.cj.jdbc.ConnectionImpl.(ConnectionImpl.java:470)
at com.mysql.cj.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:246)
W/System.err: at
com.mysql.cj.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:197)
at java.sql.DriverManager.getConnection(DriverManager.java:569)
at java.sql.DriverManager.getConnection(DriverManager.java:237)
W/System.err: at
com.dedase.dedaseconstruction.ui.login.LoginActivity$GetPatientID.doInBackground(LoginActivity.java:150)
at com.dedase.dedaseconstruction.ui.login.LoginActivity$GetPatientID.doInBackground(LoginActivity.java:136)
at android.os.AsyncTask$2.call(AsyncTask.java:333)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:245)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
W/System.err: at java.lang.Thread.run(Thread.java:764)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'com.mysql.cj.protocol.SocketConnection
com.mysql.cj.protocol.a.NativeProtocol.getSocketConnection()' on a
null object reference
at com.mysql.cj.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:980)
at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:826)
W/System.err: at
com.mysql.cj.jdbc.ConnectionImpl.(ConnectionImpl.java:456)
... 12 more I/Choreographer: Skipped 58 frames! The application may be doing too much work on its main thread. I/zygote: Do full code
cache collection, code=123KB, data=111KB
After code cache collection, code=117KB, data=78KB
This line localhost:3,306. looks really suspicious. Are you sure you don't have a typo somewhere?
You probably came across this repo, and it's not very accurate. I don't have a java client at hand to test it, but I do use Cloud SQL with a different stack and the point of using Proxy is that your app connects to the DB via it as if the DB itself is running locally. Your connection string should not have anything apart from creds and localhost:3306.

Getting file not found exception while trying to connect with url in android studio.How to solve this?

I am trying to connect to mysql using wampp and the following error is thrown how to solve this?
W/System.err: java.io.FileNotFoundException: http://192.168.2.198/login.php
at com.android.okhttp.internal.huc.HttpURLConnectionImpl.getInputStream(HttpURLConnectionImpl.java:250)
at com.example.mysqltest.BackgroundWorker.doInBackground(BackgroundWorker.java:46)
at com.example.mysqltest.BackgroundWorker.doInBackground(BackgroundWorker.java:19)
at android.os.AsyncTask$2.call(AsyncTask.java:304)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:243)
W/System.err: at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
at java.lang.Thread.run(Thread.java:761)
There are following possibility to occur this issue
maybe your project or file location is not perfect
maybe because of the port number or IP not match time of calling
First, try to run this page in your mobile browser web browser and it will work in mobile browser then it will work in API definitely if not work then you need to change in your config

SipManager cannot create SipService. Cannot Bind Context.SIP_SERVICE in Nougat

I have an application that uses SipManager to open a SIP profile. I have no difficulties opening the SIP profile on my older(KitKat) device, but my new(Nougat) device throws the a SipException "SipService is dead and is restarting..."
Stepping through the SipManager reveals that 'createSipService' is not binding 'Context.SIP_SERVICE'.
I found this post, which seems to be the same issue.
Does anyone know what changed between KitKat and Nougat that would cause such an error, and what I can do to resolve it?
UPDATE
This is the Exception I get when trying to run mySipManager.open(mSipProfile, pendingIntent, null);
`
W/System.err: android.net.sip.SipException: SipService is dead and is restarting...
W/System.err: at android.net.sip.SipManager.checkSipServiceConnection(SipManager.java:183)
at android.net.sip.SipManager.open(SipManager.java:244)
W/System.err: at com.example.angrinord.myApplication.MyApplication.refreshSipManager(MyApplication.java:59)
at com.example.angrinord.myApplication.MyApplication.onCreate(MyApplication.java:41)
W/System.err: at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1032)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6017)
W/System.err: at android.app.ActivityThread.-wrap3(ActivityThread.java)
W/System.err: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1727)
at android.os.Handler.dispatchMessage(Handler.java:102)
W/System.err: at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6823)
W/System.err: at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1557)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1445
)`
This happens on running .open() and .close().
UPDATE 2
I just bought a Pixel 3 (Android 9) and it does not have the issue. I can't speak for 5,6, or 8, but this maybe a bug with 7, as both 4 and 9 do not have the issue.
Is Wifi Calling enabled (or can be enabled) on your device?
I have the same issue with an Asus (model X00PD), android is 8.0.
SipManager.IsApiSupported() and SipManager.IsVoipSupported() both return true, however, if I view services under Developer options, Wifi Calling is not running, and the Asus ui disables the option to enable it.
To contrast the Wifi-Calling service is running on my S8 (also 8.0), by default. Same with an older S6(7.0) and a Nokia 6.1(8.1).

OpeningHandshakeException for Meteor Backend for Android app

I've just learnt and implemented my first Meteor app with simple meteor create hellometeor command, then have used ngrok to make localhost:3000 port live.
Then I have used delight-im/Android-DDP library to connect to the direct ws url as per the following code:
// create a new instance, where mMeteor is a global var.
mMeteor = new Meteor(this, "ws://180a3c0e.ngrok.io", new InMemoryDatabase()); // "ws://180a3c0e.ngrok.io" is the temp. url after tunneling `localhost:3000`
// register the callback that will handle events and receive messages
mMeteor.addCallback(this); // as the activity implements MeteorCallback
// establish the connection
mMeteor.connect();
But every-time I try to run this code, I'm getting the following error, for which I've found no suggestion or straight-forward solution, for a newbie like me in Meteor like platforms during the past 6hrs of googling and reading:
W/System.err: java.lang.Exception: com.neovisionaries.ws.client.OpeningHandshakeException: The status code of the opening handshake response is not '101 Switching Protocols'. The status line is: HTTP/1.0 502 Bad Gateway
W/System.err: at im.delight.android.ddp.Meteor$1.onError(Meteor.java:195)
W/System.err: at com.neovisionaries.ws.client.ListenerManager.callOnError(ListenerManager.java:432)
W/System.err: at com.neovisionaries.ws.client.ConnectThread.handleError(ConnectThread.java:50)
W/System.err: at com.neovisionaries.ws.client.ConnectThread.run(ConnectThread.java:41)
W/System.err: Caused by: com.neovisionaries.ws.client.OpeningHandshakeException: The status code of the opening handshake response is not '101 Switching Protocols'. The status line is: HTTP/1.0 502 Bad Gateway
W/System.err: at com.neovisionaries.ws.client.HandshakeReader.validateStatusLine(HandshakeReader.java:232)
W/System.err: at com.neovisionaries.ws.client.HandshakeReader.readHandshake(HandshakeReader.java:54)
W/System.err: at com.neovisionaries.ws.client.WebSocket.readHandshake(WebSocket.java:3113)
W/System.err: at com.neovisionaries.ws.client.WebSocket.shakeHands(WebSocket.java:2992)
W/System.err: at com.neovisionaries.ws.client.WebSocket.connect(WebSocket.java:2034)
W/System.err: at com.neovisionaries.ws.client.ConnectThread.run(ConnectThread.java:37)
May be I'm missing a very common thing in the Meteor server-side, as I haven't code a single line in it, other than initiating the project.Please enlighten me in this regard.
TIA.
I should be crucified for not knowing that Meteor has its websocket connection at ws://.../websocket url.
I have just added /websocket at the end of the previous URL and everything is working just as smooth.

Categories

Resources