Java Spring作为基于Akka的REST HTTP调用的客户端

我必须使用java-springscala-akka项目中编写这个REST服务。

我的scala 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 ) 

所以我必须从java spring调用这个REST服务。 我从java调用http://ipadress:port/notification/signUp苦苦挣扎。

你可以通过这个来打电话。 实施后:

 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(); }