2016-07-15 107 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