Home Groovy HTTPBuilder + RxJava returns an empty object/observable
Reply: 0

Groovy HTTPBuilder + RxJava returns an empty object/observable

user1657
1#
user1657 Published in April 21, 2018, 3:09 pm
def login(String email, String password, String apiKey) throws HttpResponseException {

    def postBody = [
            email   : email,
            password: password
    ]

    def http = new HTTPBuilder('https://www.googleapis.com/identitytoolkit/v3/relyingparty/verifyPassword?key=' + apiKey)

    return Observable.just({ Observer observer ->

        def thread = new Thread({

            http.post(body: postBody, requestContentType: ContentType.JSON) { resp, json  ->
                println 'status code ' + resp.statusLine.statusCode
                if (resp.statusLine.statusCode == 200 || resp.statusLine.statusCode == 201) {
                    observer.onNext(json)
                } else {
                    observer.onError(new Throwable('broken'))
                }

                observer.onCompleted()

            }

            http.handler.failure = { resp ->
                observer.onError(new Throwable('failure'))
                observer.onCompleted()

            }

            http.handler.'400' = { resp ->
                observer.onError(new Throwable('bad request'))
                observer.onCompleted()

            }

        } as Runnable)

        thread.start()

        return Subscriptions.empty()
    })
}

So this is the method that I wrote in the service class to call login for Firebase auth REST API. But the thing right now is that it didnt return me any data.

I was debugging this in Intellij and what I found out is that when I do a login.subscribe I was expecting it to return json to me but it didn't.

So what did I do wrong?

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.299302 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO