[英]Java Spring as a client for Akka based REST HTTP call
我必须调用从java-spring用scala-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();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.