JavaSpring作为基于Akka的RESTHTTP调用的客户端
我必须调用java spring中scala akka项目中编写的REST服务 我的scala REST服务就像JavaSpring作为基于Akka的RESTHTTP调用的客户端,java,scala,http,spring-boot,akka,Java,Scala,Http,Spring Boot,Akka,我必须调用java spring中scala akka项目中编写的REST服务 我的scala REST服务就像 val route = post { path("notification" / "signUp"){ headerValueByName("App_Key") { app_key => { handleWith { requestParameters: RequestP
val route =
post {
path("notification" / "signUp"){
headerValueByName("App_Key") { app_key => {
handleWith {
requestParameters: RequestParameters =>
//application specific implementation
}
}
}
}
它包含头中的App_键和内容类型以及json格式的请求参数
请求参数如下所示:
case class RequestParameters (
var name: String,
var email: String,
var password: String,
var hashKey: String
)
因此,我必须从JavaSpring调用这个REST服务。我在呼叫
http://ipadress:port/notification/signUp
来自java。您可以通过调用。以下实施:
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();
}
有控制台输出吗?我怎么能调用它呢?谢谢..异步调用REST可以从Spring中喷射出来