2017-06-28 8 views
1

私はGroovyを使用してREST APIを作成していますが、Real Shopの統合Rest APIを提供しています。しかし、私はsoapuiとコード接続のリセットエラーを取得します。あなたはこの問題で私を助けることができますか?Groovy Rest Api

レアルgetSignatureメソッドです:

private String getSignature(Map params) throws NoSuchAlgorithmException, InvalidKeyException { 

    String plainText = "GET" + "\n" + params.endpointUrl + "\n" + "" + "\n" + timess 
    Mac mac = Mac.getInstance("HmacSHA256") 
    SecretKeySpec secretKeySpec = new SecretKeySpec(params.password.getBytes(), "HmacSHA256") 
    mac.init(secretKeySpec) 
    byte[] rawHmac = mac.doFinal(plainText.getBytes()) 
    return DatatypeConverter.printHexBinary(rawHmac) 
} 

https://www.real.de/api/v1/?page=rest-api

マイコード:

@Override 
protected Map getCategories(Map params) { 
    params.authentication.timestamp = (System.currentTimeMillis() /1000L) 

    String signature = getSignature(params.authentication) 
    def client = new RESTClient(params.authentication.endpointUrl) 
    Map response = client.get(path : 'categories', 
    headers: [ 
     'accept': application/json, 
     'hm-client' : params.authentication.apiKey, 
     'hm-signature' : signature, 
     'hm-timestamp' : params.authentication.timestamp, 
     //'sslTrustAllCerts': true 
    ] 
    ) 

    assert response.status == 200 // HTTP response code 
    println response.getData() 
    return response 
} 

答えて

0

クライアント場合、私はあなたが共有ドキュメント(https://www.real.de/api/v1/?page=rest-api)で見たようサーバ時間は、約5m inutes。時間が5分を超えた場合、接続は拒否されます。サーバーの時刻とクライアントの時刻を確認できますか?

  • 段落 「HM-タイムスタンプ - 。すべての要求は、秒単位で現在のUnixタイムスタンプを持つHM-タイムスタンプヘッダーが含まれている必要があり、要求が行われた時点で最新のものにする必要があり約10分のウィンドウがありますつまり、タイムスタンプは現在のサーバー時間よりも5分早くまたは5分後にすることができます。タイムスタンプが、現在のサーバー時刻とは異なる場合は、要求を受信します要求は拒否されます。
+0

お返事ありがとうございます。私たちはリクエスト時に送信します。私はそれがそれについてだとは思わない。あなたは他に何か考えがありますか? –