2016-07-15 62 views
2

我必須將這個REST服務寫成scala-akka項目來自java-springJava Spring作爲基於Akka的REST HTTP調用的客戶端

我的階REST服務是像

val route = 
    post { 
     path("notification"/"signUp"){ 
      headerValueByName("App_Key") { app_key => { 
       handleWith { 
       requestParameters: RequestParameters => 
        //application specific implementation 

       } 
      } 
      } 
     } 

含有APP_KEY和Content-Type首部中和請求參數 JSON格式。

請求參數是這樣的:

case class RequestParameters (
    var name: String, 
    var email: String, 
    var password: String, 
    var hashKey: String 
    ) 

所以我必須調用此REST的java彈簧服務。我一直在努力從java調用http://ipadress:port/notification/signUp

+0

任何控制檯輸出? –

+0

我怎麼稱呼它? – Nilesh

回答

2

ü可以通過調用這個。執行如下:

try { 

      Client client = Client.create(); 

      WebResource webResource = client.resource(http://ipadress:port/notification/signUp); 

      JSONObject formData=new JSONObject(); 
      formData.put("name", UserName); 
      formData.put("email", EmailId); 
      formData.put("password", Password); 
      formData.put("urlHash",HashKey); 

      ClientResponse response = webResource.header("App_Key",xxxxxxxxxxxxxxxxxxxxxxxxxx).type(MediaType.APPLICATION_JSON_TYPE).post(ClientResponse.class, formData); 

     } catch (Exception e) { 

      e.printStackTrace(); 
     } 
+1

Thanks..it工作異步調用REST從Spring噴出 – Nilesh