2017-05-31 16 views
0

WebLogic 12.1.3からPayara 4.1にアプリケーションを移動するタスクが与えられており、トラブルシューティングの行の終わりにはそれ以下になるようにしてください。 私たちには、Google Maps Directions APIを呼び出す方法と、Google Maps Geocoding APIを呼び出す方法の2つのメソッド(ステートレスBean)があります。両方とも、同じ資格情報とGooglesクライアントライブラリをJava用に使用しています。どちらのメソッドもWebLogic上で動作しますが、Payaraに切り替えるとDirections APIを使用するとエラーになります。ここではスタックトレースの関連部分です:WebLogicではなくPayaraにGoogle Maps API(Directions)が403エラーを投げる

java.io.IOException: Server Error: 403 Forbidden 
    at com.google.maps.internal.OkHttpPendingResult.parseResponse(OkHttpPendingResult.java:258) 
    at com.google.maps.internal.OkHttpPendingResult.await(OkHttpPendingResult.java:167) 
    at com.google.maps.PendingResultBase.await(PendingResultBase.java:56) 
    at com.somecompany.integration.GoogleDirectionsIntegration.getDirections(GoogleDirectionsIntegration.java:XXX) 
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) 
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 
    at java.lang.reflect.Method.invoke(Method.java:498) 

だから、ジオコーディング-方法はまだ両方のプラットフォームで動作しますが、行き方APIへの呼び出しをしようとしたとき、私は私の資格情報が台無しにされていることを示すGoogleからの403背中を取得し、ジオコーディング呼び出しでは、同じ資格情報が機能します。あるプラットフォームから別のプラットフォームに切り替えるコードは変更されていません。

私はログからグーグルへの呼び出しの実際のURLを取得し、私のブラウザでそれをしようとした場合どのようなさらに混乱だが、すなわち「ペーストされていることをhttps://maps.googleapis.com/maps/api/directions/json?client=gme-company&mode=driving&arrival_time=1435825037&o RIGIN =どこか&先=どこか+ & alternat アイヴス=偽&署名= nfre3XYZ2kmuDX8Qibce87ZFKQQ = "Chromeに、それは動作します。私はGoogleから適切な答えを得る。 (btw、それらは私が使っている実際の信用証明書や起源と目的地ではなく、 "匿名化"されています:-))。私はまた、このURL(クライアントライブラリによって構築されている)が両方のプラットフォームで実行されているのと同じであることと、Googleの開発者ページでURL署名デバッガを使用していることを確認しました。私の信任状に間違いはないはずです。

解決策を見つけることなくトラブルシューティングとオンライン検索を行っています。

は、その多くが重要ないことが、私はこのコードを自分で書いていない、そしてもちろんやった人はこちらのコード(やや匿名化は)ですが、とにかくもう、ここ

:-P動作しません。

@Stateless 
public class GoogleDirectionsIntegration { 

private static final Logger LOGGER = Logger.getLogger(GoogleDirectionsIntegration.class.getName()); 

private GeoApiContext context = null; 

/** 
* Initializer 
*/ 
@PostConstruct 
public void init() { 
    LOGGER.log(Level.INFO, "initiating {0}", this.getClass().getSimpleName()); 
    this.context = new GeoApiContext().setEnterpriseCredentials("gme-company", "companyGoogleCryptographicSecret"); 
    this.context.setReadTimeout(1, TimeUnit.SECONDS) 
      .setRetryTimeout(1, TimeUnit.SECONDS) 
      .setConnectTimeout(1, TimeUnit.SECONDS) 
      .setWriteTimeout(1, TimeUnit.SECONDS); 
    OkHttpRequestHandler okHttpRequestHandler = null; 
    OkHttpClient okHttpClient = null; 

    try { 
     Field requestField = this.context.getClass().getDeclaredField("requestHandler"); 
     requestField.setAccessible(true); 
     okHttpRequestHandler = (OkHttpRequestHandler) requestField.get(this.context); 
     Field f = okHttpRequestHandler.getClass().getDeclaredField("client"); 
     f.setAccessible(true); 
     okHttpClient = (OkHttpClient) f.get(okHttpRequestHandler); 
    } catch (NoSuchFieldException | SecurityException | IllegalAccessException | IllegalArgumentException e) { 
     throw new IllegalStateException("Failed to create SSL context", e); 
    } 

    SSLContext sslCtx = this.getSslContext(); 

    if (sslCtx != null && okHttpClient != null) { 
     SSLSocketFactory sslSocketFactory = sslCtx.getSocketFactory(); 
     okHttpClient.setSslSocketFactory(sslSocketFactory); 
    } 
} 

private SSLContext getSslContext() { 
    TrustManager[] tm = new TrustManager[] { 
      new CustomTrustManager() 
    }; 

    SSLContext sslContext = null; 
    try { 
     sslContext = SSLContext.getInstance("TLSv1.2"); 
     sslContext.init(null, tm, new SecureRandom()); 
    } catch (NoSuchAlgorithmException | KeyManagementException ex) { 
     throw new IllegalStateException("Failed to create SSL context", ex); 
    } 
    return sslContext; 
} 

public DirectionsRoute getDirections(final String origin, final String destination, final DistanceUnit distanceUnit, 
     @Nullable TransportMode mode, @NotNull Instant arrivalTime) throws NotFoundException { 
    TransportMode actualMode = mode == null ? TransportMode.CAR : mode; 
    DirectionsRoute[] directionsRoutes; 

    DirectionsApiRequest directionsApiRequest = DirectionsApi.getDirections(this.context, origin, destination); 
    directionsApiRequest.arrivalTime(new Instant(arrivalTime)); 
    directionsApiRequest.alternatives(false); 
    directionsApiRequest.mode(this.toTravelMode(actualMode)); 

    try { 
     DirectionsResult res = directionsApiRequest.await(); // THIS IS WHERE IT BREAKS! 
     directionsRoutes = res.routes; 
    } catch (Exception e) { 
     LOGGER.log(Level.WARNING, e.getMessage(), e); 
     throw new NotFoundException(e.getMessage()); 
    } 

    if (directionsRoutes.length != 1) { 
     throw new NotFoundException("Failed to fetch valid directions"); 
    } 

    return directionsRoutes[0]; 
} 

public void getAddress(LatLng startLocation, Location location, boolean cacheOverride) throws Exception { 
    com.google.maps.model.LatLng gLatLng = new com.google.maps.model.LatLng(startLocation.getLat(), startLocation.getLng()); 
    GeocodingApiRequest geocodingApiRequest = GeocodingApi.reverseGeocode(this.context, gLatLng); 
    GeocodingResult[] geocodingResults; 
    geocodingResults = geocodingApiRequest.await(); 
    if (0 < geocodingResults.length) { 
     //.. Code that does stuff with the result.. 
    } else { 
     LOGGER.log(Level.WARNING, "Received empty results from Google reverse geocode for [{0}].", startLocation); 
    } 
} 

} 
+0

あなたのキーのGoogle Maps Directions Webサービスを有効にしましたか? ([Google APIコンソール](https://console.developers.google.com/)) – geocodezip

+0

@geocodezipもちろん、WebLogic上でアプリケーションを実行するとすべて正常に動作します。 – FighterHayabusa

+0

それはそれが同じドメイン/ウェブサーバであることは明らかでした(それは?)。 – geocodezip

答えて

0

私はそれを解決しました。この問題はコードではなく、依存関係、または依存関係の1つに依存していました - OkHttp。私は単にバージョンを変更し、今すぐ動作します。

関連する問題