尝试使用Google Place API但.wait()方法获取坐标详细信息会出现“ Rate Limited Dispatcher”错误

时间:2019-05-12 12:53:46

标签: java web-services ejb google-places-api

我的目的是通过搜索地址获取纬度和经度详细信息;例如“巴黎”是搜索项,而Google API则为我提供了Google地图上的纬度和经度。

我正在使用Java,EJB,JSF和JBoss。

我试图制作一个EJB,代码如下:

package service;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.maps.GeoApiContext;
import com.google.maps.GeocodingApi;
import com.google.maps.GeocodingApiRequest;
import com.google.maps.errors.ApiException;
import com.google.maps.model.GeocodingResult;

import javax.ejb.Stateless;
import java.io.IOException;

@Stateless
public class PlaceService {
    public String testPlacement() throws InterruptedException, ApiException, IOException {

        GeoApiContext context = new GeoApiContext.Builder()
                .apiKey("AI.....")
                .build();

        GeocodingResult[] results = new GeocodingResult[0];

        GeocodingApiRequest req = GeocodingApi.newRequest(context).address("Paris");

        results = req.await();

        Gson gson = new GsonBuilder().setPrettyPrinting().create();

        return gson.toJson(results[0].addressComponents);
    }
}

这是我的Maven依赖项:

 <dependency>
            <groupId>com.google.maps</groupId>
            <artifactId>google-maps-services</artifactId>
            <version>0.9.3</version>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-simple</artifactId>
            <version>1.7.25</version>
        </dependency>
        <dependency>
            <groupId>com.google.code.gson</groupId>
            <artifactId> gson</artifactId>
            <version>2.8.0</version>
        </dependency>
        <dependency>
            <groupId>com.squareup.okhttp3</groupId>
            <artifactId>okhttp</artifactId>
            <version>3.9.1</version>
        </dependency>
        <dependency>
            <groupId>com.squareup.retrofit2</groupId>
            <artifactId>retrofit</artifactId>
            <version>2.3.0</version>
        </dependency>
        <dependency>
            <groupId>com.squareup.retrofit2</groupId>
            <artifactId>converter-moshi</artifactId>
            <version>2.3.0</version>
        </dependency>
        <dependency>
            <groupId>com.squareup.moshi</groupId>
            <artifactId>moshi</artifactId>
            <version>1.5.0</version>
        </dependency>
        <dependency>
            <groupId>com.squareup.okio</groupId>
            <artifactId>okio</artifactId>
            <version>1.13.0</version>
        </dependency>
        <dependency>
            <groupId>com.squareup.okhttp3</groupId>
            <artifactId>logging-interceptor</artifactId>
            <version>3.9.1</version>
        </dependency>

它给了我这行错误代码:

 ERROR [stderr] (Rate Limited Dispatcher) Exception in thread "Rate Limited Dispatcher" java.lang.AbstractMethodError: com.google.maps.internal.OkHttpPendingResult$1.onResponse(Lokhttp3/Response;)V
 ERROR [stderr] (Rate Limited Dispatcher)   at okhttp3.RealCall$AsyncCall.execute(RealCall.java:133)
 ERROR [stderr] (Rate Limited Dispatcher)   at okhttp3.internal.NamedRunnable.run(NamedRunnable.java:33)
ERROR [stderr] (Rate Limited Dispatcher)    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
ERROR [stderr] (Rate Limited Dispatcher)    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
ERROR [stderr] (Rate Limited Dispatcher)    at java.lang.Thread.run(Thread.java:748)

0 个答案:

没有答案